summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/evp/pmeth_gn.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/libcrypto/evp/pmeth_gn.c b/src/lib/libcrypto/evp/pmeth_gn.c
index 2711ba1a9e..b86ecc6811 100644
--- a/src/lib/libcrypto/evp/pmeth_gn.c
+++ b/src/lib/libcrypto/evp/pmeth_gn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_gn.c,v 1.16 2024/04/09 13:52:41 beck Exp $ */ 1/* $OpenBSD: pmeth_gn.c,v 1.17 2024/04/12 02:56:15 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 */
@@ -141,7 +141,7 @@ EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
141{ 141{
142 int ret; 142 int ret;
143 143
144 if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) { 144 if (ctx == NULL || ctx->pmeth == NULL || ctx->pmeth->keygen == NULL) {
145 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); 145 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
146 return -2; 146 return -2;
147 } 147 }
@@ -150,17 +150,19 @@ EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
150 return -1; 150 return -1;
151 } 151 }
152 152
153 if (!ppkey) 153 if (ppkey == NULL)
154 return -1; 154 return -1;
155 155
156 if (!*ppkey) 156 if (*ppkey == NULL)
157 *ppkey = EVP_PKEY_new(); 157 *ppkey = EVP_PKEY_new();
158 if (*ppkey == NULL)
159 return -1;
158 160
159 ret = ctx->pmeth->keygen(ctx, *ppkey); 161 if ((ret = ctx->pmeth->keygen(ctx, *ppkey)) <= 0) {
160 if (ret <= 0) {
161 EVP_PKEY_free(*ppkey); 162 EVP_PKEY_free(*ppkey);
162 *ppkey = NULL; 163 *ppkey = NULL;
163 } 164 }
165
164 return ret; 166 return ret;
165} 167}
166LCRYPTO_ALIAS(EVP_PKEY_keygen); 168LCRYPTO_ALIAS(EVP_PKEY_keygen);