-/* $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.
*/
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