Skip to content

Commit

Permalink
wolfcrypt/src/evp.c: add wolfSSL_EVP_PKEY_is_a().
Browse files Browse the repository at this point in the history
  • Loading branch information
douzzer committed Jul 29, 2024
1 parent b1765ca commit bb4266c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions wolfcrypt/src/evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 wolfSSL_EVP_PKEY_is_a(const WOLFSSL_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
Expand Down
3 changes: 3 additions & 0 deletions wolfssl/openssl/evp.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ 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 wolfSSL_EVP_PKEY_is_a(const WOLFSSL_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
Expand Down Expand Up @@ -1111,6 +1113,7 @@ WOLFSSL_API int wolfSSL_EVP_SignInit_ex(WOLFSSL_EVP_MD_CTX* ctx,
#define EVP_PKEY_keygen wolfSSL_EVP_PKEY_keygen
#define EVP_PKEY_keygen_init wolfSSL_EVP_PKEY_keygen_init
#define EVP_PKEY_bits wolfSSL_EVP_PKEY_bits
#define EVP_PKEY_is_a wolfSSL_EVP_PKEY_is_a
#define EVP_PKEY_CTX_free wolfSSL_EVP_PKEY_CTX_free
#define EVP_PKEY_CTX_new wolfSSL_EVP_PKEY_CTX_new
#define EVP_PKEY_CTX_set_rsa_padding wolfSSL_EVP_PKEY_CTX_set_rsa_padding
Expand Down

0 comments on commit bb4266c

Please sign in to comment.