summaryrefslogtreecommitdiff
path: root/kexecdh.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-01-21 10:35:09 +0000
committerDamien Miller <djm@mindrot.org>2019-01-21 23:13:03 +1100
commit71e67fff946396caa110a7964da23480757258ff (patch)
tree07cae7bce377241a7b61195d0810ec91d953685e /kexecdh.c
parent4b83e2a2cc0c12e671a77eaba1c1245894f4e884 (diff)
upstream: pass values used in KEX hash computation as sshbuf
rather than pointer+len suggested by me; implemented by markus@ ok me OpenBSD-Commit-ID: 994f33c464f4a9e0f1d21909fa3e379f5a0910f0
Diffstat (limited to 'kexecdh.c')
-rw-r--r--kexecdh.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/kexecdh.c b/kexecdh.c
index 263f9fd87..ae9018773 100644
--- a/kexecdh.c
+++ b/kexecdh.c
@@ -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
45static int 45static int
46kex_ecdh_dec_key_group(struct kex *, const u_char *, size_t, EC_KEY *key, 46kex_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
49int 49int
@@ -89,7 +89,7 @@ kex_ecdh_keypair(struct kex *kex)
89} 89}
90 90
91int 91int
92kex_ecdh_enc(struct kex *kex, const u_char *pkblob, size_t pklen, 92kex_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
137static int 137static int
138kex_ecdh_dec_key_group(struct kex *kex, const u_char *pkblob, size_t pklen, 138kex_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
201int 199int
202kex_ecdh_dec(struct kex *kex, const u_char *pkblob, size_t pklen, 200kex_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;