summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kex.h3
-rw-r--r--kexdh.c28
-rw-r--r--kexdhc.c28
-rw-r--r--kexdhs.c35
4 files changed, 37 insertions, 57 deletions
diff --git a/kex.h b/kex.h
index 085e60b52..4394e100b 100644
--- a/kex.h
+++ b/kex.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.h,v 1.94 2019/01/19 21:43:56 djm Exp $ */ 1/* $OpenBSD: kex.h,v 1.95 2019/01/21 10:00:23 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.
@@ -202,6 +202,7 @@ int kexecdh_server(struct ssh *);
202int kexc25519_client(struct ssh *); 202int kexc25519_client(struct ssh *);
203int kexc25519_server(struct ssh *); 203int kexc25519_server(struct ssh *);
204 204
205int kex_dh_keygen(struct kex *);
205int kex_dh_hash(int, const struct sshbuf *, const struct sshbuf *, 206int kex_dh_hash(int, const struct sshbuf *, const struct sshbuf *,
206 const u_char *, size_t, const u_char *, size_t, const u_char *, size_t, 207 const u_char *, size_t, const u_char *, size_t, const u_char *, size_t,
207 const BIGNUM *, const BIGNUM *, const BIGNUM *, u_char *, size_t *); 208 const BIGNUM *, const BIGNUM *, const BIGNUM *, u_char *, size_t *);
diff --git a/kexdh.c b/kexdh.c
index 34c55ef9f..916036994 100644
--- a/kexdh.c
+++ b/kexdh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexdh.c,v 1.27 2018/12/27 03:25:25 djm Exp $ */ 1/* $OpenBSD: kexdh.c,v 1.28 2019/01/21 10:00:23 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -39,11 +39,37 @@
39#include "sshkey.h" 39#include "sshkey.h"
40#include "cipher.h" 40#include "cipher.h"
41#include "kex.h" 41#include "kex.h"
42#include "dh.h"
42#include "ssherr.h" 43#include "ssherr.h"
43#include "sshbuf.h" 44#include "sshbuf.h"
44#include "digest.h" 45#include "digest.h"
45 46
46int 47int
48kex_dh_keygen(struct kex *kex)
49{
50 switch (kex->kex_type) {
51 case KEX_DH_GRP1_SHA1:
52 kex->dh = dh_new_group1();
53 break;
54 case KEX_DH_GRP14_SHA1:
55 case KEX_DH_GRP14_SHA256:
56 kex->dh = dh_new_group14();
57 break;
58 case KEX_DH_GRP16_SHA512:
59 kex->dh = dh_new_group16();
60 break;
61 case KEX_DH_GRP18_SHA512:
62 kex->dh = dh_new_group18();
63 break;
64 default:
65 return SSH_ERR_INVALID_ARGUMENT;
66 }
67 if (kex->dh == NULL)
68 return SSH_ERR_ALLOC_FAIL;
69 return (dh_gen_key(kex->dh, kex->we_need * 8));
70}
71
72int
47kex_dh_hash( 73kex_dh_hash(
48 int hash_alg, 74 int hash_alg,
49 const struct sshbuf *client_version, 75 const struct sshbuf *client_version,
diff --git a/kexdhc.c b/kexdhc.c
index a37452abd..a7ea0baad 100644
--- a/kexdhc.c
+++ b/kexdhc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexdhc.c,v 1.26 2019/01/21 09:55:52 djm Exp $ */ 1/* $OpenBSD: kexdhc.c,v 1.27 2019/01/21 10:00:23 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -41,10 +41,10 @@
41#include "sshkey.h" 41#include "sshkey.h"
42#include "cipher.h" 42#include "cipher.h"
43#include "digest.h" 43#include "digest.h"
44#include "dh.h"
44#include "kex.h" 45#include "kex.h"
45#include "log.h" 46#include "log.h"
46#include "packet.h" 47#include "packet.h"
47#include "dh.h"
48#include "ssh2.h" 48#include "ssh2.h"
49#include "dispatch.h" 49#include "dispatch.h"
50#include "compat.h" 50#include "compat.h"
@@ -61,31 +61,9 @@ kexdh_client(struct ssh *ssh)
61 const BIGNUM *pub_key; 61 const BIGNUM *pub_key;
62 62
63 /* generate and send 'e', client DH public key */ 63 /* generate and send 'e', client DH public key */
64 switch (kex->kex_type) { 64 if ((r = kex_dh_keygen(kex)) != 0)
65 case KEX_DH_GRP1_SHA1:
66 kex->dh = dh_new_group1();
67 break;
68 case KEX_DH_GRP14_SHA1:
69 case KEX_DH_GRP14_SHA256:
70 kex->dh = dh_new_group14();
71 break;
72 case KEX_DH_GRP16_SHA512:
73 kex->dh = dh_new_group16();
74 break;
75 case KEX_DH_GRP18_SHA512:
76 kex->dh = dh_new_group18();
77 break;
78 default:
79 r = SSH_ERR_INVALID_ARGUMENT;
80 goto out;
81 }
82 if (kex->dh == NULL) {
83 r = SSH_ERR_ALLOC_FAIL;
84 goto out; 65 goto out;
85 }
86 debug("sending SSH2_MSG_KEXDH_INIT"); 66 debug("sending SSH2_MSG_KEXDH_INIT");
87 if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
88 goto out;
89 DH_get0_key(kex->dh, &pub_key, NULL); 67 DH_get0_key(kex->dh, &pub_key, NULL);
90 if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_INIT)) != 0 || 68 if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_INIT)) != 0 ||
91 (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 || 69 (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||
diff --git a/kexdhs.c b/kexdhs.c
index b7b64a82a..cd2e52e00 100644
--- a/kexdhs.c
+++ b/kexdhs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexdhs.c,v 1.32 2019/01/21 09:55:52 djm Exp $ */ 1/* $OpenBSD: kexdhs.c,v 1.33 2019/01/21 10:00:23 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -40,10 +40,10 @@
40#include "sshkey.h" 40#include "sshkey.h"
41#include "cipher.h" 41#include "cipher.h"
42#include "digest.h" 42#include "digest.h"
43#include "dh.h"
43#include "kex.h" 44#include "kex.h"
44#include "log.h" 45#include "log.h"
45#include "packet.h" 46#include "packet.h"
46#include "dh.h"
47#include "ssh2.h" 47#include "ssh2.h"
48 48
49#include "dispatch.h" 49#include "dispatch.h"
@@ -60,36 +60,11 @@ kexdh_server(struct ssh *ssh)
60 int r; 60 int r;
61 61
62 /* generate server DH public key */ 62 /* generate server DH public key */
63 switch (kex->kex_type) { 63 if ((r = kex_dh_keygen(kex)) != 0)
64 case KEX_DH_GRP1_SHA1: 64 return r;
65 kex->dh = dh_new_group1();
66 break;
67 case KEX_DH_GRP14_SHA1:
68 case KEX_DH_GRP14_SHA256:
69 kex->dh = dh_new_group14();
70 break;
71 case KEX_DH_GRP16_SHA512:
72 kex->dh = dh_new_group16();
73 break;
74 case KEX_DH_GRP18_SHA512:
75 kex->dh = dh_new_group18();
76 break;
77 default:
78 r = SSH_ERR_INVALID_ARGUMENT;
79 goto out;
80 }
81 if (kex->dh == NULL) {
82 r = SSH_ERR_ALLOC_FAIL;
83 goto out;
84 }
85 if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
86 goto out;
87
88 debug("expecting SSH2_MSG_KEXDH_INIT"); 65 debug("expecting SSH2_MSG_KEXDH_INIT");
89 ssh_dispatch_set(ssh, SSH2_MSG_KEXDH_INIT, &input_kex_dh_init); 66 ssh_dispatch_set(ssh, SSH2_MSG_KEXDH_INIT, &input_kex_dh_init);
90 r = 0; 67 return 0;
91 out:
92 return r;
93} 68}
94 69
95int 70int