diff options
Diffstat (limited to 'kexecdh.c')
-rw-r--r-- | kexecdh.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: kexecdh.c,v 1.8 2019/01/21 10:29:56 djm Exp $ */ | 1 | /* $OpenBSD: kexecdh.c,v 1.9 2019/01/21 10:35:09 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2010 Damien Miller. All rights reserved. | 3 | * Copyright (c) 2010 Damien Miller. All rights reserved. |
4 | * Copyright (c) 2019 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2019 Markus Friedl. All rights reserved. |
@@ -43,7 +43,7 @@ | |||
43 | #include "ssherr.h" | 43 | #include "ssherr.h" |
44 | 44 | ||
45 | static int | 45 | static int |
46 | kex_ecdh_dec_key_group(struct kex *, const u_char *, size_t, EC_KEY *key, | 46 | kex_ecdh_dec_key_group(struct kex *, const struct sshbuf *, EC_KEY *key, |
47 | const EC_GROUP *, struct sshbuf **); | 47 | const EC_GROUP *, struct sshbuf **); |
48 | 48 | ||
49 | int | 49 | int |
@@ -89,7 +89,7 @@ kex_ecdh_keypair(struct kex *kex) | |||
89 | } | 89 | } |
90 | 90 | ||
91 | int | 91 | int |
92 | kex_ecdh_enc(struct kex *kex, const u_char *pkblob, size_t pklen, | 92 | kex_ecdh_enc(struct kex *kex, const struct sshbuf *client_blob, |
93 | struct sshbuf **server_blobp, struct sshbuf **shared_secretp) | 93 | struct sshbuf **server_blobp, struct sshbuf **shared_secretp) |
94 | { | 94 | { |
95 | const EC_GROUP *group; | 95 | const EC_GROUP *group; |
@@ -123,7 +123,7 @@ kex_ecdh_enc(struct kex *kex, const u_char *pkblob, size_t pklen, | |||
123 | if ((r = sshbuf_put_ec(server_blob, pub_key, group)) != 0 || | 123 | if ((r = sshbuf_put_ec(server_blob, pub_key, group)) != 0 || |
124 | (r = sshbuf_get_u32(server_blob, NULL)) != 0) | 124 | (r = sshbuf_get_u32(server_blob, NULL)) != 0) |
125 | goto out; | 125 | goto out; |
126 | if ((r = kex_ecdh_dec_key_group(kex, pkblob, pklen, server_key, group, | 126 | if ((r = kex_ecdh_dec_key_group(kex, client_blob, server_key, group, |
127 | shared_secretp)) != 0) | 127 | shared_secretp)) != 0) |
128 | goto out; | 128 | goto out; |
129 | *server_blobp = server_blob; | 129 | *server_blobp = server_blob; |
@@ -135,7 +135,7 @@ kex_ecdh_enc(struct kex *kex, const u_char *pkblob, size_t pklen, | |||
135 | } | 135 | } |
136 | 136 | ||
137 | static int | 137 | static int |
138 | kex_ecdh_dec_key_group(struct kex *kex, const u_char *pkblob, size_t pklen, | 138 | kex_ecdh_dec_key_group(struct kex *kex, const struct sshbuf *ec_blob, |
139 | EC_KEY *key, const EC_GROUP *group, struct sshbuf **shared_secretp) | 139 | EC_KEY *key, const EC_GROUP *group, struct sshbuf **shared_secretp) |
140 | { | 140 | { |
141 | struct sshbuf *buf = NULL; | 141 | struct sshbuf *buf = NULL; |
@@ -151,10 +151,8 @@ kex_ecdh_dec_key_group(struct kex *kex, const u_char *pkblob, size_t pklen, | |||
151 | r = SSH_ERR_ALLOC_FAIL; | 151 | r = SSH_ERR_ALLOC_FAIL; |
152 | goto out; | 152 | goto out; |
153 | } | 153 | } |
154 | if ((r = sshbuf_put_u32(buf, pklen)) != 0 || | 154 | if ((r = sshbuf_put_stringb(buf, ec_blob)) != 0) |
155 | (r = sshbuf_put(buf, pkblob, pklen)) != 0) { | ||
156 | goto out; | 155 | goto out; |
157 | } | ||
158 | if ((dh_pub = EC_POINT_new(group)) == NULL) { | 156 | if ((dh_pub = EC_POINT_new(group)) == NULL) { |
159 | r = SSH_ERR_ALLOC_FAIL; | 157 | r = SSH_ERR_ALLOC_FAIL; |
160 | goto out; | 158 | goto out; |
@@ -199,12 +197,12 @@ kex_ecdh_dec_key_group(struct kex *kex, const u_char *pkblob, size_t pklen, | |||
199 | } | 197 | } |
200 | 198 | ||
201 | int | 199 | int |
202 | kex_ecdh_dec(struct kex *kex, const u_char *pkblob, size_t pklen, | 200 | kex_ecdh_dec(struct kex *kex, const struct sshbuf *server_blob, |
203 | struct sshbuf **shared_secretp) | 201 | struct sshbuf **shared_secretp) |
204 | { | 202 | { |
205 | int r; | 203 | int r; |
206 | 204 | ||
207 | r = kex_ecdh_dec_key_group(kex, pkblob, pklen, kex->ec_client_key, | 205 | r = kex_ecdh_dec_key_group(kex, server_blob, kex->ec_client_key, |
208 | kex->ec_group, shared_secretp); | 206 | kex->ec_group, shared_secretp); |
209 | EC_KEY_free(kex->ec_client_key); | 207 | EC_KEY_free(kex->ec_client_key); |
210 | kex->ec_client_key = NULL; | 208 | kex->ec_client_key = NULL; |