OpenSSL: crypto_ec_key_get_private_key() using new EVP_PKEY API

Implement crypto_ec_key_get_private_key() without the deprecated EC_KEY
API when using OpenSSL 3.0.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2022-05-26 16:40:18 +03:00
parent 177ebfe109
commit 5b97395b3e

View file

@ -3438,6 +3438,14 @@ struct crypto_bignum *
crypto_ec_key_get_private_key(struct crypto_ec_key *key)
{
EVP_PKEY *pkey = (EVP_PKEY *) key;
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
BIGNUM *bn = NULL;
if (!EVP_PKEY_is_a(pkey, "EC") ||
EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_PRIV_KEY, &bn) != 1)
return NULL;
return (struct crypto_bignum *) bn;
#else /* OpenSSL version >= 3.0 */
const EC_KEY *eckey;
const BIGNUM *bn;
@ -3448,6 +3456,7 @@ crypto_ec_key_get_private_key(struct crypto_ec_key *key)
if (!bn)
return NULL;
return (struct crypto_bignum *) BN_dup(bn);
#endif /* OpenSSL version >= 3.0 */
}