diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index b53d6eca97..07526231aa 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -283,6 +283,35 @@ static const struct s_ent { static const char EVP_NULL[] = "NULL"; +static const struct pkey_type_name_ent { + int type; + const char *name; +} pkey_type_names[] = +{ + { EVP_PKEY_RSA, "RSA" }, + { EVP_PKEY_EC, "EC" }, + { EVP_PKEY_DH, "DH" }, + { EVP_PKEY_DSA, "DSA" } +}; + +static int pkey_type_by_name(const char *name) { + unsigned int i; + if (name == NULL) + return 0; + for (i = 0; i < XELEM_CNT(pkey_type_names); ++i) { + if (XSTRCMP(name, pkey_type_names[i].name)) + return pkey_type_names[i].type; + } + return 0; +} + +int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name) { + int type = pkey_type_by_name(name); + if (type == 0) + return 0; + return (pkey->type == type); +} + #define EVP_CIPHER_TYPE_MATCHES(x, y) (XSTRCMP(x,y) == 0) #define EVP_PKEY_PRINT_LINE_WIDTH_MAX 80 diff --git a/wolfssl/openssl/evp.h b/wolfssl/openssl/evp.h index f2387478d3..e889a39054 100644 --- a/wolfssl/openssl/evp.h +++ b/wolfssl/openssl/evp.h @@ -722,6 +722,7 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_keygen_init(WOLFSSL_EVP_PKEY_CTX *ctx); WOLFSSL_API int wolfSSL_EVP_PKEY_keygen(WOLFSSL_EVP_PKEY_CTX *ctx, WOLFSSL_EVP_PKEY **ppkey); WOLFSSL_API int wolfSSL_EVP_PKEY_bits(const WOLFSSL_EVP_PKEY *pkey); +WOLFSSL_API int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name); #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L WOLFSSL_API void wolfSSL_EVP_PKEY_CTX_free(WOLFSSL_EVP_PKEY_CTX *ctx); #else