From 56a4cf214f97ca08f80790c161f0b3d472017eeb Mon Sep 17 00:00:00 2001 From: tb <> Date: Thu, 28 Dec 2023 21:58:12 +0000 Subject: Rework rsa_priv_decode() Turn the function into single exit and error check EVP_PKEY_assign() for style. ok jsing --- src/lib/libcrypto/rsa/rsa_ameth.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/lib') 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 @@ -/* $OpenBSD: rsa_ameth.c,v 1.52 2023/12/28 21:57:08 tb Exp $ */ +/* $OpenBSD: rsa_ameth.c,v 1.53 2023/12/28 21:58:12 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -264,24 +264,27 @@ static int rsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) { const unsigned char *p; - RSA *rsa; + RSA *rsa = NULL; int pklen; const X509_ALGOR *alg; + int ret = 0; if (!PKCS8_pkey_get0(NULL, &p, &pklen, &alg, p8)) - return 0; - rsa = d2i_RSAPrivateKey(NULL, &p, pklen); - if (rsa == NULL) { - RSAerror(ERR_R_RSA_LIB); - return 0; - } - if (!rsa_param_decode(rsa, alg)) { - RSA_free(rsa); - return 0; - } - EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa); + goto err; + if ((rsa = d2i_RSAPrivateKey(NULL, &p, pklen)) == NULL) + goto err; + if (!rsa_param_decode(rsa, alg)) + goto err; + if (!EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa)) + goto err; + rsa = NULL; - return 1; + ret = 1; + + err: + RSA_free(rsa); + + return ret; } static int -- cgit v1.2.3-55-g6feb