summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in2
-rw-r--r--kex.h7
-rw-r--r--kexc25519.c122
-rw-r--r--kexc25519c.c145
-rw-r--r--kexc25519s.c136
-rw-r--r--kexkemc.c30
-rw-r--r--kexkems.c18
-rw-r--r--monitor.c4
-rw-r--r--ssh-keyscan.c4
-rw-r--r--ssh_api.c6
-rw-r--r--sshconnect2.c4
-rw-r--r--sshd.c4
12 files changed, 170 insertions, 312 deletions
diff --git a/Makefile.in b/Makefile.in
index 2b22e9f47..89f930367 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -98,8 +98,6 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
98 ssh-ed25519.o digest-openssl.o digest-libc.o hmac.o \ 98 ssh-ed25519.o digest-openssl.o digest-libc.o hmac.o \
99 sc25519.o ge25519.o fe25519.o ed25519.o verify.o hash.o \ 99 sc25519.o ge25519.o fe25519.o ed25519.o verify.o hash.o \
100 kex.o kexdh.o kexgex.o kexecdh.o kexc25519.o \ 100 kex.o kexdh.o kexgex.o kexecdh.o kexc25519.o \
101 kexdhc.o kexgexc.o kexecdhc.o kexc25519c.o \
102 kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o \
103 sntrup4591761.o kexsntrup4591761x25519.o kexkemc.o kexkems.o \ 101 sntrup4591761.o kexsntrup4591761x25519.o kexkemc.o kexkems.o \
104 platform-pledge.o platform-tracing.o platform-misc.o 102 platform-pledge.o platform-tracing.o platform-misc.o
105 103
diff --git a/kex.h b/kex.h
index 258a64712..2eec2e04f 100644
--- a/kex.h
+++ b/kex.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.h,v 1.99 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: kex.h,v 1.100 2019/01/21 10:24:09 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
@@ -211,6 +211,11 @@ int kexc25519_server(struct ssh *);
211int kex_kem_client(struct ssh *); 211int kex_kem_client(struct ssh *);
212int kex_kem_server(struct ssh *); 212int kex_kem_server(struct ssh *);
213 213
214int kex_c25519_keypair(struct kex *);
215int kex_c25519_enc(struct kex *, const u_char *, size_t, struct sshbuf **,
216 struct sshbuf **);
217int kex_c25519_dec(struct kex *, const u_char *, size_t, struct sshbuf **);
218
214int kex_kem_sntrup4591761x25519_keypair(struct kex *); 219int kex_kem_sntrup4591761x25519_keypair(struct kex *);
215int kex_kem_sntrup4591761x25519_enc(struct kex *, const u_char *, size_t, 220int kex_kem_sntrup4591761x25519_enc(struct kex *, const u_char *, size_t,
216 struct sshbuf **, struct sshbuf **); 221 struct sshbuf **, struct sshbuf **);
diff --git a/kexc25519.c b/kexc25519.c
index 3911baf14..a06c6e44b 100644
--- a/kexc25519.c
+++ b/kexc25519.c
@@ -1,6 +1,6 @@
1/* $OpenBSD: kexc25519.c,v 1.13 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: kexc25519.c,v 1.14 2019/01/21 10:24:09 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001, 2013 Markus Friedl. All rights reserved. 3 * Copyright (c) 2019 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved. 4 * Copyright (c) 2010 Damien Miller. All rights reserved.
5 * Copyright (c) 2013 Aris Adamantiadis. All rights reserved. 5 * Copyright (c) 2013 Aris Adamantiadis. All rights reserved.
6 * 6 *
@@ -29,20 +29,16 @@
29 29
30#include <sys/types.h> 30#include <sys/types.h>
31 31
32#include <signal.h> 32#include <stdio.h>
33#include <string.h> 33#include <string.h>
34#include <signal.h>
34 35
35#include <openssl/bn.h>
36#include <openssl/evp.h>
37
38#include "sshbuf.h"
39#include "ssh2.h"
40#include "sshkey.h" 36#include "sshkey.h"
41#include "cipher.h"
42#include "kex.h" 37#include "kex.h"
43#include "log.h" 38#include "sshbuf.h"
44#include "digest.h" 39#include "digest.h"
45#include "ssherr.h" 40#include "ssherr.h"
41#include "ssh2.h"
46 42
47extern int crypto_scalarmult_curve25519(u_char a[CURVE25519_SIZE], 43extern int crypto_scalarmult_curve25519(u_char a[CURVE25519_SIZE],
48 const u_char b[CURVE25519_SIZE], const u_char c[CURVE25519_SIZE]) 44 const u_char b[CURVE25519_SIZE], const u_char c[CURVE25519_SIZE])
@@ -142,3 +138,109 @@ kex_c25519_hash(
142#endif 138#endif
143 return 0; 139 return 0;
144} 140}
141
142int
143kex_c25519_keypair(struct kex *kex)
144{
145 struct sshbuf *buf = NULL;
146 u_char *cp = NULL;
147 int r;
148
149 if ((buf = sshbuf_new()) == NULL)
150 return SSH_ERR_ALLOC_FAIL;
151 if ((r = sshbuf_reserve(buf, CURVE25519_SIZE, &cp)) != 0)
152 goto out;
153 kexc25519_keygen(kex->c25519_client_key, cp);
154#ifdef DEBUG_KEXECDH
155 dump_digest("client public key c25519:", cp, CURVE25519_SIZE);
156#endif
157 kex->kem_client_pub = buf;
158 buf = NULL;
159 out:
160 sshbuf_free(buf);
161 return r;
162}
163
164int
165kex_c25519_enc(struct kex *kex, const u_char *pkblob,
166 size_t pklen, struct sshbuf **server_blobp, struct sshbuf **shared_secretp)
167{
168 struct sshbuf *server_blob = NULL;
169 struct sshbuf *buf = NULL;
170 u_char *server_pub;
171 u_char server_key[CURVE25519_SIZE];
172 int r;
173
174 *server_blobp = NULL;
175 *shared_secretp = NULL;
176
177 if (pklen != CURVE25519_SIZE) {
178 r = SSH_ERR_SIGNATURE_INVALID;
179 goto out;
180 }
181#ifdef DEBUG_KEXECDH
182 dump_digest("client public key 25519:", pkblob, CURVE25519_SIZE);
183#endif
184 /* allocate space for encrypted KEM key and ECDH pub key */
185 if ((server_blob = sshbuf_new()) == NULL) {
186 r = SSH_ERR_ALLOC_FAIL;
187 goto out;
188 }
189 if ((r = sshbuf_reserve(server_blob, CURVE25519_SIZE, &server_pub)) != 0)
190 goto out;
191 kexc25519_keygen(server_key, server_pub);
192 /* allocate shared secret */
193 if ((buf = sshbuf_new()) == NULL) {
194 r = SSH_ERR_ALLOC_FAIL;
195 goto out;
196 }
197 if ((r = kexc25519_shared_key_ext(server_key, pkblob, buf, 0)) < 0)
198 goto out;
199#ifdef DEBUG_KEXECDH
200 dump_digest("server public key 25519:", server_pub, CURVE25519_SIZE);
201 dump_digest("encoded shared secret:", sshbuf_ptr(buf), sshbuf_len(buf));
202#endif
203 *server_blobp = server_blob;
204 *shared_secretp = buf;
205 server_blob = NULL;
206 buf = NULL;
207 out:
208 explicit_bzero(server_key, sizeof(server_key));
209 sshbuf_free(server_blob);
210 sshbuf_free(buf);
211 return r;
212}
213
214int
215kex_c25519_dec(struct kex *kex, const u_char *pkblob,
216 size_t pklen, struct sshbuf **shared_secretp)
217{
218 struct sshbuf *buf = NULL;
219 int r;
220
221 *shared_secretp = NULL;
222
223 if (pklen != CURVE25519_SIZE) {
224 r = SSH_ERR_SIGNATURE_INVALID;
225 goto out;
226 }
227#ifdef DEBUG_KEXECDH
228 dump_digest("server public key c25519:", pkblob, CURVE25519_SIZE);
229#endif
230 /* shared secret */
231 if ((buf = sshbuf_new()) == NULL) {
232 r = SSH_ERR_ALLOC_FAIL;
233 goto out;
234 }
235 if ((r = kexc25519_shared_key_ext(kex->c25519_client_key, pkblob,
236 buf, 0)) < 0)
237 goto out;
238#ifdef DEBUG_KEXECDH
239 dump_digest("encoded shared secret:", sshbuf_ptr(buf), sshbuf_len(buf));
240#endif
241 *shared_secretp = buf;
242 buf = NULL;
243 out:
244 sshbuf_free(buf);
245 return r;
246}
diff --git a/kexc25519c.c b/kexc25519c.c
deleted file mode 100644
index cc6e54cc7..000000000
--- a/kexc25519c.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/* $OpenBSD: kexc25519c.c,v 1.13 2019/01/21 10:20:12 djm Exp $ */
2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved.
5 * Copyright (c) 2013 Aris Adamantiadis. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "includes.h"
29
30#include <sys/types.h>
31
32#include <stdio.h>
33#include <string.h>
34#include <signal.h>
35
36#include "sshkey.h"
37#include "cipher.h"
38#include "kex.h"
39#include "log.h"
40#include "packet.h"
41#include "ssh2.h"
42#include "sshbuf.h"
43#include "digest.h"
44#include "ssherr.h"
45
46static int
47input_kex_c25519_reply(int type, u_int32_t seq, struct ssh *ssh);
48
49int
50kexc25519_client(struct ssh *ssh)
51{
52 struct kex *kex = ssh->kex;
53 int r;
54
55 kexc25519_keygen(kex->c25519_client_key, kex->c25519_client_pubkey);
56#ifdef DEBUG_KEXECDH
57 dump_digest("client private key:", kex->c25519_client_key,
58 sizeof(kex->c25519_client_key));
59#endif
60 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_INIT)) != 0 ||
61 (r = sshpkt_put_string(ssh, kex->c25519_client_pubkey,
62 sizeof(kex->c25519_client_pubkey))) != 0 ||
63 (r = sshpkt_send(ssh)) != 0)
64 return r;
65
66 debug("expecting SSH2_MSG_KEX_ECDH_REPLY");
67 ssh_dispatch_set(ssh, SSH2_MSG_KEX_ECDH_REPLY, &input_kex_c25519_reply);
68 return 0;
69}
70
71static int
72input_kex_c25519_reply(int type, u_int32_t seq, struct ssh *ssh)
73{
74 struct kex *kex = ssh->kex;
75 struct sshkey *server_host_key = NULL;
76 struct sshbuf *shared_secret = NULL;
77 u_char *server_pubkey = NULL;
78 u_char *server_host_key_blob = NULL, *signature = NULL;
79 u_char hash[SSH_DIGEST_MAX_LENGTH];
80 size_t slen, pklen, sbloblen, hashlen;
81 int r;
82
83 /* hostkey */
84 if ((r = sshpkt_get_string(ssh, &server_host_key_blob,
85 &sbloblen)) != 0 ||
86 (r = sshkey_from_blob(server_host_key_blob, sbloblen,
87 &server_host_key)) != 0)
88 goto out;
89 if ((r = kex_verify_host_key(ssh, server_host_key)) != 0)
90 goto out;
91
92 /* Q_S, server public key */
93 /* signed H */
94 if ((r = sshpkt_get_string(ssh, &server_pubkey, &pklen)) != 0 ||
95 (r = sshpkt_get_string(ssh, &signature, &slen)) != 0 ||
96 (r = sshpkt_get_end(ssh)) != 0)
97 goto out;
98 if (pklen != CURVE25519_SIZE) {
99 r = SSH_ERR_SIGNATURE_INVALID;
100 goto out;
101 }
102
103#ifdef DEBUG_KEXECDH
104 dump_digest("server public key:", server_pubkey, CURVE25519_SIZE);
105#endif
106
107 if ((shared_secret = sshbuf_new()) == NULL) {
108 r = SSH_ERR_ALLOC_FAIL;
109 goto out;
110 }
111 if ((r = kexc25519_shared_key(kex->c25519_client_key, server_pubkey,
112 shared_secret)) != 0)
113 goto out;
114
115 /* calc and verify H */
116 hashlen = sizeof(hash);
117 if ((r = kex_c25519_hash(
118 kex->hash_alg,
119 kex->client_version,
120 kex->server_version,
121 sshbuf_ptr(kex->my), sshbuf_len(kex->my),
122 sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
123 server_host_key_blob, sbloblen,
124 kex->c25519_client_pubkey, sizeof(kex->c25519_client_pubkey),
125 server_pubkey, pklen,
126 sshbuf_ptr(shared_secret), sshbuf_len(shared_secret),
127 hash, &hashlen)) != 0)
128 goto out;
129
130 if ((r = sshkey_verify(server_host_key, signature, slen, hash, hashlen,
131 kex->hostkey_alg, ssh->compat)) != 0)
132 goto out;
133
134 if ((r = kex_derive_keys(ssh, hash, hashlen, shared_secret)) == 0)
135 r = kex_send_newkeys(ssh);
136out:
137 explicit_bzero(hash, sizeof(hash));
138 explicit_bzero(kex->c25519_client_key, sizeof(kex->c25519_client_key));
139 free(server_host_key_blob);
140 free(server_pubkey);
141 free(signature);
142 sshkey_free(server_host_key);
143 sshbuf_free(shared_secret);
144 return r;
145}
diff --git a/kexc25519s.c b/kexc25519s.c
deleted file mode 100644
index ace4d5c79..000000000
--- a/kexc25519s.c
+++ /dev/null
@@ -1,136 +0,0 @@
1/* $OpenBSD: kexc25519s.c,v 1.16 2019/01/21 10:20:12 djm Exp $ */
2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved.
5 * Copyright (c) 2013 Aris Adamantiadis. All rights reserved.
6 *
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "includes.h"
28
29#include <sys/types.h>
30#include <stdio.h>
31#include <string.h>
32#include <signal.h>
33
34#include "sshkey.h"
35#include "cipher.h"
36#include "digest.h"
37#include "kex.h"
38#include "log.h"
39#include "packet.h"
40#include "ssh2.h"
41#include "sshbuf.h"
42#include "ssherr.h"
43
44static int input_kex_c25519_init(int, u_int32_t, struct ssh *);
45
46int
47kexc25519_server(struct ssh *ssh)
48{
49 debug("expecting SSH2_MSG_KEX_ECDH_INIT");
50 ssh_dispatch_set(ssh, SSH2_MSG_KEX_ECDH_INIT, &input_kex_c25519_init);
51 return 0;
52}
53
54static int
55input_kex_c25519_init(int type, u_int32_t seq, struct ssh *ssh)
56{
57 struct kex *kex = ssh->kex;
58 struct sshkey *server_host_private, *server_host_public;
59 struct sshbuf *shared_secret = NULL;
60 u_char *server_host_key_blob = NULL, *signature = NULL;
61 u_char server_key[CURVE25519_SIZE];
62 u_char *client_pubkey = NULL;
63 u_char server_pubkey[CURVE25519_SIZE];
64 u_char hash[SSH_DIGEST_MAX_LENGTH];
65 size_t slen, pklen, sbloblen, hashlen;
66 int r;
67
68 /* generate private key */
69 kexc25519_keygen(server_key, server_pubkey);
70#ifdef DEBUG_KEXECDH
71 dump_digest("server private key:", server_key, sizeof(server_key));
72#endif
73 if ((r = kex_load_hostkey(ssh, &server_host_private,
74 &server_host_public)) != 0)
75 goto out;
76 if ((r = sshpkt_get_string(ssh, &client_pubkey, &pklen)) != 0 ||
77 (r = sshpkt_get_end(ssh)) != 0)
78 goto out;
79 if (pklen != CURVE25519_SIZE) {
80 r = SSH_ERR_SIGNATURE_INVALID;
81 goto out;
82 }
83#ifdef DEBUG_KEXECDH
84 dump_digest("client public key:", client_pubkey, CURVE25519_SIZE);
85#endif
86
87 if ((shared_secret = sshbuf_new()) == NULL) {
88 r = SSH_ERR_ALLOC_FAIL;
89 goto out;
90 }
91 if ((r = kexc25519_shared_key(server_key, client_pubkey,
92 shared_secret)) < 0)
93 goto out;
94
95 /* calc H */
96 if ((r = sshkey_to_blob(server_host_public, &server_host_key_blob,
97 &sbloblen)) != 0)
98 goto out;
99 hashlen = sizeof(hash);
100 if ((r = kex_c25519_hash(
101 kex->hash_alg,
102 kex->client_version,
103 kex->server_version,
104 sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
105 sshbuf_ptr(kex->my), sshbuf_len(kex->my),
106 server_host_key_blob, sbloblen,
107 client_pubkey, pklen,
108 server_pubkey, sizeof(server_pubkey),
109 sshbuf_ptr(shared_secret), sshbuf_len(shared_secret),
110 hash, &hashlen)) != 0)
111 goto out;
112
113 /* sign H */
114 if ((r = kex->sign(ssh, server_host_private, server_host_public,
115 &signature, &slen, hash, hashlen, kex->hostkey_alg)) < 0)
116 goto out;
117
118 /* send server hostkey, ECDH pubkey 'Q_S' and signed H */
119 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_REPLY)) != 0 ||
120 (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
121 (r = sshpkt_put_string(ssh, server_pubkey, sizeof(server_pubkey))) != 0 ||
122 (r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
123 (r = sshpkt_send(ssh)) != 0)
124 goto out;
125
126 if ((r = kex_derive_keys(ssh, hash, hashlen, shared_secret)) == 0)
127 r = kex_send_newkeys(ssh);
128out:
129 explicit_bzero(hash, sizeof(hash));
130 explicit_bzero(server_key, sizeof(server_key));
131 free(server_host_key_blob);
132 free(signature);
133 free(client_pubkey);
134 sshbuf_free(shared_secret);
135 return r;
136}
diff --git a/kexkemc.c b/kexkemc.c
index 47f15c30c..13f36a116 100644
--- a/kexkemc.c
+++ b/kexkemc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexkemc.c,v 1.1 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: kexkemc.c,v 1.2 2019/01/21 10:24:09 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2019 Markus Friedl. All rights reserved. 3 * Copyright (c) 2019 Markus Friedl. All rights reserved.
4 * 4 *
@@ -47,7 +47,18 @@ kex_kem_client(struct ssh *ssh)
47 struct kex *kex = ssh->kex; 47 struct kex *kex = ssh->kex;
48 int r; 48 int r;
49 49
50 if ((r = kex_kem_sntrup4591761x25519_keypair(kex)) != 0) 50 switch (kex->kex_type) {
51 case KEX_C25519_SHA256:
52 r = kex_c25519_keypair(kex);
53 break;
54 case KEX_KEM_SNTRUP4591761X25519_SHA512:
55 r = kex_kem_sntrup4591761x25519_keypair(kex);
56 break;
57 default:
58 r = SSH_ERR_INVALID_ARGUMENT;
59 break;
60 }
61 if (r != 0)
51 return r; 62 return r;
52 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_INIT)) != 0 || 63 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_ECDH_INIT)) != 0 ||
53 (r = sshpkt_put_stringb(ssh, kex->kem_client_pub)) != 0 || 64 (r = sshpkt_put_stringb(ssh, kex->kem_client_pub)) != 0 ||
@@ -87,8 +98,19 @@ input_kex_kem_reply(int type, u_int32_t seq, struct ssh *ssh)
87 goto out; 98 goto out;
88 99
89 /* compute shared secret */ 100 /* compute shared secret */
90 if ((r = kex_kem_sntrup4591761x25519_dec(kex, server_pubkey, pklen, 101 switch (kex->kex_type) {
91 &shared_secret)) != 0) 102 case KEX_C25519_SHA256:
103 r = kex_c25519_dec(kex, server_pubkey, pklen, &shared_secret);
104 break;
105 case KEX_KEM_SNTRUP4591761X25519_SHA512:
106 r = kex_kem_sntrup4591761x25519_dec(kex, server_pubkey, pklen,
107 &shared_secret);
108 break;
109 default:
110 r = SSH_ERR_INVALID_ARGUMENT;
111 break;
112 }
113 if (r !=0 )
92 goto out; 114 goto out;
93 115
94 /* calc and verify H */ 116 /* calc and verify H */
diff --git a/kexkems.c b/kexkems.c
index 43cf82018..89237902b 100644
--- a/kexkems.c
+++ b/kexkems.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexkems.c,v 1.1 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: kexkems.c,v 1.2 2019/01/21 10:24:09 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2019 Markus Friedl. All rights reserved. 3 * Copyright (c) 2019 Markus Friedl. All rights reserved.
4 * 4 *
@@ -68,8 +68,20 @@ input_kex_kem_init(int type, u_int32_t seq, struct ssh *ssh)
68 goto out; 68 goto out;
69 69
70 /* compute shared secret */ 70 /* compute shared secret */
71 if ((r = kex_kem_sntrup4591761x25519_enc(kex, client_pubkey, pklen, 71 switch (kex->kex_type) {
72 &server_pubkey, &shared_secret)) != 0) 72 case KEX_C25519_SHA256:
73 r = kex_c25519_enc(kex, client_pubkey, pklen, &server_pubkey,
74 &shared_secret);
75 break;
76 case KEX_KEM_SNTRUP4591761X25519_SHA512:
77 r = kex_kem_sntrup4591761x25519_enc(kex, client_pubkey, pklen,
78 &server_pubkey, &shared_secret);
79 break;
80 default:
81 r = SSH_ERR_INVALID_ARGUMENT;
82 break;
83 }
84 if (r !=0 )
73 goto out; 85 goto out;
74 86
75 /* calc H */ 87 /* calc H */
diff --git a/monitor.c b/monitor.c
index b10fdebf2..9f86d5b75 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: monitor.c,v 1.193 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: monitor.c,v 1.194 2019/01/21 10:24:09 djm Exp $ */
2/* 2/*
3 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 3 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4 * Copyright 2002 Markus Friedl <markus@openbsd.org> 4 * Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -1688,7 +1688,7 @@ monitor_apply_keystate(struct ssh *ssh, struct monitor *pmonitor)
1688 kex->kex[KEX_ECDH_SHA2] = kexecdh_server; 1688 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
1689# endif 1689# endif
1690#endif /* WITH_OPENSSL */ 1690#endif /* WITH_OPENSSL */
1691 kex->kex[KEX_C25519_SHA256] = kexc25519_server; 1691 kex->kex[KEX_C25519_SHA256] = kex_kem_server;
1692 kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server; 1692 kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server;
1693 kex->load_host_public_key=&get_hostkey_public_by_type; 1693 kex->load_host_public_key=&get_hostkey_public_by_type;
1694 kex->load_host_private_key=&get_hostkey_private_by_type; 1694 kex->load_host_private_key=&get_hostkey_private_by_type;
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index 83a768700..9eebc1445 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keyscan.c,v 1.121 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: ssh-keyscan.c,v 1.122 2019/01/21 10:24:09 djm Exp $ */
2/* 2/*
3 * Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>. 3 * Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
4 * 4 *
@@ -271,7 +271,7 @@ keygrab_ssh2(con *c)
271 c->c_ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client; 271 c->c_ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
272# endif 272# endif
273#endif 273#endif
274 c->c_ssh->kex->kex[KEX_C25519_SHA256] = kexc25519_client; 274 c->c_ssh->kex->kex[KEX_C25519_SHA256] = kex_kem_client;
275 c->c_ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client; 275 c->c_ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client;
276 ssh_set_verify_host_key_callback(c->c_ssh, key_print_wrapper); 276 ssh_set_verify_host_key_callback(c->c_ssh, key_print_wrapper);
277 /* 277 /*
diff --git a/ssh_api.c b/ssh_api.c
index 73981aa37..fe9fbf5a7 100644
--- a/ssh_api.c
+++ b/ssh_api.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh_api.c,v 1.11 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: ssh_api.c,v 1.12 2019/01/21 10:24:09 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2012 Markus Friedl. All rights reserved. 3 * Copyright (c) 2012 Markus Friedl. All rights reserved.
4 * 4 *
@@ -110,7 +110,7 @@ ssh_init(struct ssh **sshp, int is_server, struct kex_params *kex_params)
110 ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_server; 110 ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
111# endif 111# endif
112#endif /* WITH_OPENSSL */ 112#endif /* WITH_OPENSSL */
113 ssh->kex->kex[KEX_C25519_SHA256] = kexc25519_server; 113 ssh->kex->kex[KEX_C25519_SHA256] = kex_kem_server;
114 ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server; 114 ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server;
115 ssh->kex->load_host_public_key=&_ssh_host_public_key; 115 ssh->kex->load_host_public_key=&_ssh_host_public_key;
116 ssh->kex->load_host_private_key=&_ssh_host_private_key; 116 ssh->kex->load_host_private_key=&_ssh_host_private_key;
@@ -128,7 +128,7 @@ ssh_init(struct ssh **sshp, int is_server, struct kex_params *kex_params)
128 ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client; 128 ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
129# endif 129# endif
130#endif /* WITH_OPENSSL */ 130#endif /* WITH_OPENSSL */
131 ssh->kex->kex[KEX_C25519_SHA256] = kexc25519_client; 131 ssh->kex->kex[KEX_C25519_SHA256] = kex_kem_client;
132 ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client; 132 ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client;
133 ssh->kex->verify_host_key =&_ssh_verify_host_key; 133 ssh->kex->verify_host_key =&_ssh_verify_host_key;
134 } 134 }
diff --git a/sshconnect2.c b/sshconnect2.c
index 05657fd73..be19722bb 100644
--- a/sshconnect2.c
+++ b/sshconnect2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect2.c,v 1.297 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: sshconnect2.c,v 1.298 2019/01/21 10:24:09 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2008 Damien Miller. All rights reserved. 4 * Copyright (c) 2008 Damien Miller. All rights reserved.
@@ -212,7 +212,7 @@ ssh_kex2(struct ssh *ssh, char *host, struct sockaddr *hostaddr, u_short port)
212 ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client; 212 ssh->kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
213# endif 213# endif
214#endif 214#endif
215 ssh->kex->kex[KEX_C25519_SHA256] = kexc25519_client; 215 ssh->kex->kex[KEX_C25519_SHA256] = kex_kem_client;
216 ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client; 216 ssh->kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_client;
217 ssh->kex->verify_host_key=&verify_host_key_callback; 217 ssh->kex->verify_host_key=&verify_host_key_callback;
218 218
diff --git a/sshd.c b/sshd.c
index 330b8052d..665b22b1e 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.528 2019/01/21 10:20:12 djm Exp $ */ 1/* $OpenBSD: sshd.c,v 1.529 2019/01/21 10:24:09 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -2218,7 +2218,7 @@ do_ssh2_kex(struct ssh *ssh)
2218 kex->kex[KEX_ECDH_SHA2] = kexecdh_server; 2218 kex->kex[KEX_ECDH_SHA2] = kexecdh_server;
2219# endif 2219# endif
2220#endif 2220#endif
2221 kex->kex[KEX_C25519_SHA256] = kexc25519_server; 2221 kex->kex[KEX_C25519_SHA256] = kex_kem_server;
2222 kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server; 2222 kex->kex[KEX_KEM_SNTRUP4591761X25519_SHA512] = kex_kem_server;
2223 kex->load_host_public_key=&get_hostkey_public_by_type; 2223 kex->load_host_public_key=&get_hostkey_public_by_type;
2224 kex->load_host_private_key=&get_hostkey_private_by_type; 2224 kex->load_host_private_key=&get_hostkey_private_by_type;