summaryrefslogtreecommitdiff
path: root/kexdhc.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-01-21 10:00:23 +0000
committerDamien Miller <djm@mindrot.org>2019-01-21 21:47:28 +1100
commite93bd98eab79b9a78f64ee8dd4dffc4d3979c7ae (patch)
treeb02f3b1ca965cfa9fbbf3fbf4b8a3b56d93088cd /kexdhc.c
parent5ae3f6d314465026d028af82609c1d49ad197655 (diff)
upstream: factor out DH keygen; it's identical between the client
and the server from markus@ ok djm@ OpenBSD-Commit-ID: 2be57f6a0d44f1ab2c8de2b1b5d6f530c387fae9
Diffstat (limited to 'kexdhc.c')
-rw-r--r--kexdhc.c28
1 files changed, 3 insertions, 25 deletions
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 ||