summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-12-28 21:58:12 +0000
committertb <>2023-12-28 21:58:12 +0000
commit56a4cf214f97ca08f80790c161f0b3d472017eeb (patch)
treece2a3e06d40f5b9382679d1f6a95b6e61dbe9af8 /src/lib
parent4018894af11650d6af70fa1bbae4115a256be079 (diff)
downloadopenbsd-56a4cf214f97ca08f80790c161f0b3d472017eeb.tar.gz
openbsd-56a4cf214f97ca08f80790c161f0b3d472017eeb.tar.bz2
openbsd-56a4cf214f97ca08f80790c161f0b3d472017eeb.zip
Rework rsa_priv_decode()
Turn the function into single exit and error check EVP_PKEY_assign() for style. ok jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/rsa/rsa_ameth.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c
index b2f6b2f79b..a43bcf9f9a 100644
--- a/src/lib/libcrypto/rsa/rsa_ameth.c
+++ b/src/lib/libcrypto/rsa/rsa_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_ameth.c,v 1.52 2023/12/28 21:57:08 tb Exp $ */ 1/* $OpenBSD: rsa_ameth.c,v 1.53 2023/12/28 21:58:12 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 */
@@ -264,24 +264,27 @@ static int
264rsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) 264rsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)
265{ 265{
266 const unsigned char *p; 266 const unsigned char *p;
267 RSA *rsa; 267 RSA *rsa = NULL;
268 int pklen; 268 int pklen;
269 const X509_ALGOR *alg; 269 const X509_ALGOR *alg;
270 int ret = 0;
270 271
271 if (!PKCS8_pkey_get0(NULL, &p, &pklen, &alg, p8)) 272 if (!PKCS8_pkey_get0(NULL, &p, &pklen, &alg, p8))
272 return 0; 273 goto err;
273 rsa = d2i_RSAPrivateKey(NULL, &p, pklen); 274 if ((rsa = d2i_RSAPrivateKey(NULL, &p, pklen)) == NULL)
274 if (rsa == NULL) { 275 goto err;
275 RSAerror(ERR_R_RSA_LIB); 276 if (!rsa_param_decode(rsa, alg))
276 return 0; 277 goto err;
277 } 278 if (!EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa))
278 if (!rsa_param_decode(rsa, alg)) { 279 goto err;
279 RSA_free(rsa); 280 rsa = NULL;
280 return 0;
281 }
282 EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa);
283 281
284 return 1; 282 ret = 1;
283
284 err:
285 RSA_free(rsa);
286
287 return ret;
285} 288}
286 289
287static int 290static int