summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2018-11-09 23:49:18 +0000
committertb <>2018-11-09 23:49:18 +0000
commita362bc4bed09c18e7fae16b195f3c9401576da64 (patch)
treed5d6f1936d976f7c0cf2c3d81123d0f49d2ce05d
parentb654209f551ca241f7057a6dd9cc71a79151eb43 (diff)
downloadopenbsd-a362bc4bed09c18e7fae16b195f3c9401576da64.tar.gz
openbsd-a362bc4bed09c18e7fae16b195f3c9401576da64.tar.bz2
openbsd-a362bc4bed09c18e7fae16b195f3c9401576da64.zip
Initialize priv_key and pub_key on first use instead of at the top.
While there, eliminate a flag that was only used once. ok beck jsing mestre
-rw-r--r--src/lib/libcrypto/dh/dh_key.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
index 790b706134..694200a7c4 100644
--- a/src/lib/libcrypto/dh/dh_key.c
+++ b/src/lib/libcrypto/dh/dh_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_key.c,v 1.34 2018/11/06 07:02:33 tb Exp $ */ 1/* $OpenBSD: dh_key.c,v 1.35 2018/11/09 23:49:18 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -102,11 +102,10 @@ static int
102generate_key(DH *dh) 102generate_key(DH *dh)
103{ 103{
104 int ok = 0; 104 int ok = 0;
105 int generate_new_key = 0;
106 unsigned l; 105 unsigned l;
107 BN_CTX *ctx; 106 BN_CTX *ctx;
108 BN_MONT_CTX *mont = NULL; 107 BN_MONT_CTX *mont = NULL;
109 BIGNUM *pub_key = dh->pub_key, *priv_key = dh->priv_key, *two = NULL; 108 BIGNUM *pub_key = NULL, *priv_key = NULL, *two = NULL;
110 109
111 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { 110 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
112 DHerror(DH_R_MODULUS_TOO_LARGE); 111 DHerror(DH_R_MODULUS_TOO_LARGE);
@@ -117,10 +116,9 @@ generate_key(DH *dh)
117 if (ctx == NULL) 116 if (ctx == NULL)
118 goto err; 117 goto err;
119 118
120 if (priv_key == NULL) { 119 if ((priv_key = dh->priv_key) == NULL) {
121 if ((priv_key = BN_new()) == NULL) 120 if ((priv_key = BN_new()) == NULL)
122 goto err; 121 goto err;
123 generate_new_key = 1;
124 } 122 }
125 123
126 if (pub_key == NULL) { 124 if (pub_key == NULL) {
@@ -135,7 +133,7 @@ generate_key(DH *dh)
135 goto err; 133 goto err;
136 } 134 }
137 135
138 if (generate_new_key) { 136 if (dh->priv_key == NULL) {
139 if (dh->q) { 137 if (dh->q) {
140 if ((two = BN_new()) == NULL) 138 if ((two = BN_new()) == NULL)
141 goto err; 139 goto err;