summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2018-11-09 23:49:19 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2018-11-09 23:49:19 +0000
commit36522e01eb3e59fb58b59a85316f66570dc61ad1 (patch)
tree6a83a2db60b89511d92dd15d8706073deacf193e
parent5e224b438c66a72bd532a84f4ecf1fb9e4b57410 (diff)
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--lib/libcrypto/dh/dh_key.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/libcrypto/dh/dh_key.c b/lib/libcrypto/dh/dh_key.c
index 790b7061348..694200a7c48 100644
--- a/lib/libcrypto/dh/dh_key.c
+++ b/lib/libcrypto/dh/dh_key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dh_key.c,v 1.34 2018/11/06 07:02:33 tb Exp $ */
+/* $OpenBSD: dh_key.c,v 1.35 2018/11/09 23:49:18 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -102,11 +102,10 @@ static int
generate_key(DH *dh)
{
int ok = 0;
- int generate_new_key = 0;
unsigned l;
BN_CTX *ctx;
BN_MONT_CTX *mont = NULL;
- BIGNUM *pub_key = dh->pub_key, *priv_key = dh->priv_key, *two = NULL;
+ BIGNUM *pub_key = NULL, *priv_key = NULL, *two = NULL;
if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
DHerror(DH_R_MODULUS_TOO_LARGE);
@@ -117,10 +116,9 @@ generate_key(DH *dh)
if (ctx == NULL)
goto err;
- if (priv_key == NULL) {
+ if ((priv_key = dh->priv_key) == NULL) {
if ((priv_key = BN_new()) == NULL)
goto err;
- generate_new_key = 1;
}
if (pub_key == NULL) {
@@ -135,7 +133,7 @@ generate_key(DH *dh)
goto err;
}
- if (generate_new_key) {
+ if (dh->priv_key == NULL) {
if (dh->q) {
if ((two = BN_new()) == NULL)
goto err;