summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/rsa/rsa_pmeth.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_pmeth.c b/src/lib/libcrypto/rsa/rsa_pmeth.c
index cb82b0908f..9be9079613 100644
--- a/src/lib/libcrypto/rsa/rsa_pmeth.c
+++ b/src/lib/libcrypto/rsa/rsa_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_pmeth.c,v 1.39 2023/07/08 12:26:45 beck Exp $ */ 1/* $OpenBSD: rsa_pmeth.c,v 1.40 2023/12/28 21:59:07 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 */
@@ -756,32 +756,36 @@ pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
756{ 756{
757 RSA *rsa = NULL; 757 RSA *rsa = NULL;
758 RSA_PKEY_CTX *rctx = ctx->data; 758 RSA_PKEY_CTX *rctx = ctx->data;
759 BN_GENCB *pcb, cb; 759 BN_GENCB *pcb = NULL;
760 int ret; 760 BN_GENCB cb = {0};
761 int ret = 0;
761 762
762 if (rctx->pub_exp == NULL) { 763 if (rctx->pub_exp == NULL) {
763 if ((rctx->pub_exp = BN_new()) == NULL) 764 if ((rctx->pub_exp = BN_new()) == NULL)
764 return 0; 765 goto err;
765 if (!BN_set_word(rctx->pub_exp, RSA_F4)) 766 if (!BN_set_word(rctx->pub_exp, RSA_F4))
766 return 0; 767 goto err;
767 } 768 }
769
768 if ((rsa = RSA_new()) == NULL) 770 if ((rsa = RSA_new()) == NULL)
769 return 0; 771 goto err;
770 if (ctx->pkey_gencb != NULL) { 772 if (ctx->pkey_gencb != NULL) {
771 pcb = &cb; 773 pcb = &cb;
772 evp_pkey_set_cb_translate(pcb, ctx); 774 evp_pkey_set_cb_translate(pcb, ctx);
773 } else {
774 pcb = NULL;
775 } 775 }
776 ret = RSA_generate_key_ex(rsa, rctx->nbits, rctx->pub_exp, pcb); 776 if (!RSA_generate_key_ex(rsa, rctx->nbits, rctx->pub_exp, pcb))
777 if (ret > 0 && !rsa_set_pss_param(rsa, ctx)) { 777 goto err;
778 RSA_free(rsa); 778 if (!rsa_set_pss_param(rsa, ctx))
779 return 0; 779 goto err;
780 } 780 if (!EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, rsa))
781 if (ret > 0) 781 goto err;
782 EVP_PKEY_assign(pkey, ctx->pmeth->pkey_id, rsa); 782 rsa = NULL;
783 else 783
784 RSA_free(rsa); 784 ret = 1;
785
786 err:
787 RSA_free(rsa);
788
785 return ret; 789 return ret;
786} 790}
787 791