summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-12-28 22:10:33 +0000
committertb <>2023-12-28 22:10:33 +0000
commitd038647e3a4f1ef5e7535103a39d0cdc628ed9e0 (patch)
tree5f51006dacb8444f05ca8f1046265f008a1075f2
parentd02de88bb0448555210074070ff438d090c4c115 (diff)
downloadopenbsd-d038647e3a4f1ef5e7535103a39d0cdc628ed9e0.tar.gz
openbsd-d038647e3a4f1ef5e7535103a39d0cdc628ed9e0.tar.bz2
openbsd-d038647e3a4f1ef5e7535103a39d0cdc628ed9e0.zip
Rework pkey_dh_paramgen()
Similar to pkey_rsa_paramgen() this function does some strange dances with the pkey_gencb and initialization plus missing error checks. Fix all that and use the idiom established in previous commits. ok jsing
-rw-r--r--src/lib/libcrypto/dh/dh_pmeth.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/lib/libcrypto/dh/dh_pmeth.c b/src/lib/libcrypto/dh/dh_pmeth.c
index 5a43acceff..5b43214448 100644
--- a/src/lib/libcrypto/dh/dh_pmeth.c
+++ b/src/lib/libcrypto/dh/dh_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_pmeth.c,v 1.14 2023/12/28 22:06:41 tb Exp $ */ 1/* $OpenBSD: dh_pmeth.c,v 1.15 2023/12/28 22:10:33 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -189,25 +189,28 @@ out_of_range:
189static int 189static int
190pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 190pkey_dh_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
191{ 191{
192 DH *dh = NULL; 192 DH *dh;
193 DH_PKEY_CTX *dctx = ctx->data; 193 DH_PKEY_CTX *dctx = ctx->data;
194 BN_GENCB *pcb, cb; 194 BN_GENCB *pcb = NULL;
195 int ret; 195 BN_GENCB cb = {0};
196 int ret = 0;
196 197
197 if (ctx->pkey_gencb) { 198 if ((dh = DH_new()) == NULL)
199 goto err;
200 if (ctx->pkey_gencb != NULL) {
198 pcb = &cb; 201 pcb = &cb;
199 evp_pkey_set_cb_translate(pcb, ctx); 202 evp_pkey_set_cb_translate(pcb, ctx);
200 } else 203 }
201 pcb = NULL; 204 if (!DH_generate_parameters_ex(dh, dctx->prime_len, dctx->generator, pcb))
202 dh = DH_new(); 205 goto err;
203 if (!dh) 206 if (!EVP_PKEY_assign_DH(pkey, dh))
204 return 0; 207 goto err;
205 ret = DH_generate_parameters_ex(dh, dctx->prime_len, dctx->generator, 208 dh = NULL;
206 pcb); 209
207 if (ret) 210 ret = 1;
208 EVP_PKEY_assign_DH(pkey, dh); 211 err:
209 else 212 DH_free(dh);
210 DH_free(dh); 213
211 return ret; 214 return ret;
212} 215}
213 216