summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
index 051c812781..890f991df9 100644
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ b/src/lib/libcrypto/dsa/dsa_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_key.c,v 1.32 2022/11/26 16:08:52 tb Exp $ */ 1/* $OpenBSD: dsa_key.c,v 1.33 2023/01/11 04:35:26 jsing 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 *
@@ -82,39 +82,38 @@ DSA_generate_key(DSA *dsa)
82static int 82static int
83dsa_builtin_keygen(DSA *dsa) 83dsa_builtin_keygen(DSA *dsa)
84{ 84{
85 int ok = 0;
86 BN_CTX *ctx = NULL;
87 BIGNUM *pub_key = NULL, *priv_key = NULL; 85 BIGNUM *pub_key = NULL, *priv_key = NULL;
86 BN_CTX *ctx = NULL;
87 int ok = 0;
88 88
89 if ((ctx = BN_CTX_new()) == NULL) 89 if ((priv_key = BN_new()) == NULL)
90 goto err;
91 if ((pub_key = BN_new()) == NULL)
90 goto err; 92 goto err;
91 93
92 if ((priv_key = dsa->priv_key) == NULL) { 94 if ((ctx = BN_CTX_new()) == NULL)
93 if ((priv_key = BN_new()) == NULL) 95 goto err;
94 goto err;
95 }
96 96
97 if (!bn_rand_interval(priv_key, BN_value_one(), dsa->q)) 97 if (!bn_rand_interval(priv_key, BN_value_one(), dsa->q))
98 goto err; 98 goto err;
99
100 if ((pub_key = dsa->pub_key) == NULL) {
101 if ((pub_key = BN_new()) == NULL)
102 goto err;
103 }
104
105 if (!BN_mod_exp_ct(pub_key, dsa->g, priv_key, dsa->p, ctx)) 99 if (!BN_mod_exp_ct(pub_key, dsa->g, priv_key, dsa->p, ctx))
106 goto err; 100 goto err;
107 101
102 BN_free(dsa->priv_key);
108 dsa->priv_key = priv_key; 103 dsa->priv_key = priv_key;
104 priv_key = NULL;
105
106 BN_free(dsa->pub_key);
109 dsa->pub_key = pub_key; 107 dsa->pub_key = pub_key;
108 pub_key = NULL;
109
110 ok = 1; 110 ok = 1;
111 111
112 err: 112 err:
113 if (dsa->pub_key == NULL) 113 BN_free(pub_key);
114 BN_free(pub_key); 114 BN_free(priv_key);
115 if (dsa->priv_key == NULL)
116 BN_free(priv_key);
117 BN_CTX_free(ctx); 115 BN_CTX_free(ctx);
116
118 return ok; 117 return ok;
119} 118}
120#endif 119#endif