es256: fix es256_pk_from_EVP_PKEY() using OpenSSL 3.0

use EVP_PKEY_get0_EC_KEY to get the underlying EC_KEY when building
with OpenSSL 3.0. we typically prefer EVP_PKEY_get0 (since that
is const-safe in both OpenSSL 1.1 and 3.0) but EVP_PKEY_get0
returns NULL in OpenSSL 3.0.
This commit is contained in:
pedro martelletto
2022-03-22 15:02:29 +01:00
committed by Konstantinos Georgantas
parent 800ee4c3ca
commit 73b27d8c65
+8 -2
View File
@@ -11,6 +11,12 @@
#include "fido.h"
#include "fido/es256.h"
#if OPENSSL_VERSION_NUMBER >= 0x30000000
#define get0_EC_KEY(x) EVP_PKEY_get0_EC_KEY((x))
#else
#define get0_EC_KEY(x) EVP_PKEY_get0((x))
#endif
static int
decode_coord(const cbor_item_t *item, void *xy, size_t xy_len)
{
@@ -366,10 +372,10 @@ fail:
int
es256_pk_from_EVP_PKEY(es256_pk_t *pk, const EVP_PKEY *pkey)
{
EC_KEY *ec;
const EC_KEY *ec;
if (EVP_PKEY_base_id(pkey) != EVP_PKEY_EC ||
(ec = EVP_PKEY_get0(pkey)) == NULL)
(ec = get0_EC_KEY(pkey)) == NULL)
return (FIDO_ERR_INVALID_ARGUMENT);
return (es256_pk_from_EC_KEY(pk, ec));