@@ -62722,6 +62722,215 @@ static int test_wolfSSL_EVP_X_STATE_LEN(void)
6272262722 return EXPECT_RESULT();
6272362723}
6272462724
62725+ static int test_EVP_PKEY_is_a(void)
62726+ {
62727+ EXPECT_DECLS;
62728+ EVP_PKEY *pkey = NULL;
62729+
62730+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "DH"), 0);
62731+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "RSA"), 0);
62732+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "EC"), 0);
62733+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "DSA"), 0);
62734+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, NULL), 0);
62735+
62736+ #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
62737+
62738+ {
62739+ const unsigned char* key = dh_key_der_2048;
62740+ ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
62741+ sizeof_dh_key_der_2048)));
62742+
62743+ ExpectIntNE(wolfSSL_EVP_PKEY_is_a(pkey, "DH"), 0);
62744+
62745+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "RSA"), 0);
62746+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "EC"), 0);
62747+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "DSA"), 0);
62748+
62749+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, NULL), 0);
62750+
62751+ EVP_PKEY_free(pkey);
62752+ pkey = NULL;
62753+ }
62754+ #endif /* !NO_DH && (!HAVE_FIPS || FIPS_VERSION_GT(2,0)) */
62755+
62756+ #ifndef NO_DSA
62757+ {
62758+ #ifdef USE_CERT_BUFFERS_1024
62759+ const unsigned char* dsaKeyDer = dsa_key_der_1024;
62760+ int dsaKeySz = sizeof_dsa_key_der_1024;
62761+ #elif defined(USE_CERT_BUFFERS_2048)
62762+ const unsigned char* dsaKeyDer = dsa_key_der_2048;
62763+ int dsaKeySz = sizeof_dsa_key_der_2048;
62764+ #endif
62765+ ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &pkey, &dsaKeyDer,
62766+ (long)dsaKeySz));
62767+
62768+ ExpectIntNE(wolfSSL_EVP_PKEY_is_a(pkey, "DSA"), 0);
62769+
62770+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "RSA"), 0);
62771+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "EC"), 0);
62772+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "DH"), 0);
62773+
62774+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, NULL), 0);
62775+
62776+ EVP_PKEY_free(pkey);
62777+ pkey = NULL;
62778+ }
62779+ #endif /* !NO_DSA */
62780+
62781+ #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
62782+ {
62783+
62784+ const unsigned char* server_key =
62785+ (const unsigned char*)server_key_der_2048;
62786+ ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &server_key,
62787+ (long)sizeof_server_key_der_2048));
62788+
62789+ ExpectIntNE(wolfSSL_EVP_PKEY_is_a(pkey, "RSA"), 0);
62790+
62791+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "DSA"), 0);
62792+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "EC"), 0);
62793+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "DH"), 0);
62794+
62795+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, NULL), 0);
62796+
62797+ EVP_PKEY_free(pkey);
62798+ pkey = NULL;
62799+ }
62800+ #endif /* !NO_RSA && USE_CERT_BUFFERS_2048 */
62801+
62802+ #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
62803+ {
62804+ const unsigned char* client_key =
62805+ (const unsigned char*)ecc_clikey_der_256;
62806+ ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &client_key,
62807+ (long)sizeof_ecc_clikey_der_256)));
62808+
62809+ ExpectIntNE(wolfSSL_EVP_PKEY_is_a(pkey, "EC"), 0);
62810+
62811+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "DSA"), 0);
62812+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "RSA"), 0);
62813+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, "DH"), 0);
62814+
62815+ ExpectIntEQ(wolfSSL_EVP_PKEY_is_a(pkey, NULL), 0);
62816+
62817+ EVP_PKEY_free(pkey);
62818+ pkey = NULL;
62819+ }
62820+ #endif /* HAVE_ECC && USE_CERT_BUFFERS_256 */
62821+
62822+ return EXPECT_RESULT();
62823+ }
62824+
62825+ static int test_EVP_CIPHER_key_length(void)
62826+ {
62827+ EXPECT_DECLS;
62828+ #if defined(HAVE_AES_CBC) || defined(HAVE_AESGCM) || \
62829+ defined(WOLFSSL_AES_COUNTER) || defined(HAVE_AES_ECB) || \
62830+ defined(WOLFSSL_AES_OFB) || !defined(NO_RC4) || \
62831+ (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
62832+
62833+ #ifdef HAVE_AES_CBC
62834+ #ifdef WOLFSSL_AES_128
62835+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_128_cbc()), AES_128_KEY_SIZE);
62836+ #endif
62837+ #ifdef WOLFSSL_AES_192
62838+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_192_cbc()), AES_192_KEY_SIZE);
62839+ #endif
62840+ #ifdef WOLFSSL_AES_256
62841+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_256_cbc()), AES_256_KEY_SIZE);
62842+ #endif
62843+ #endif
62844+
62845+ #ifdef HAVE_AESGCM
62846+ #ifdef WOLFSSL_AES_128
62847+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_128_gcm()), AES_128_KEY_SIZE);
62848+ #endif
62849+ #ifdef WOLFSSL_AES_192
62850+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_192_gcm()), AES_192_KEY_SIZE);
62851+ #endif
62852+ #ifdef WOLFSSL_AES_256
62853+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_256_gcm()), AES_256_KEY_SIZE);
62854+ #endif
62855+ #endif
62856+
62857+ #ifdef HAVE_AESCCM
62858+ #ifdef WOLFSSL_AES_128
62859+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_128_ccm()), AES_128_KEY_SIZE);
62860+ #endif
62861+ #ifdef WOLFSSL_AES_192
62862+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_192_ccm()), AES_192_KEY_SIZE);
62863+ #endif
62864+ #ifdef WOLFSSL_AES_256
62865+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_256_ccm()), AES_256_KEY_SIZE);
62866+ #endif
62867+ #endif
62868+
62869+ #ifdef WOLFSSL_AES_COUNTER
62870+ #ifdef WOLFSSL_AES_128
62871+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_128_ctr()), AES_128_KEY_SIZE);
62872+ #endif
62873+ #ifdef WOLFSSL_AES_192
62874+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_192_ctr()), AES_192_KEY_SIZE);
62875+ #endif
62876+ #ifdef WOLFSSL_AES_256
62877+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_256_ctr()), AES_256_KEY_SIZE);
62878+ #endif
62879+ #endif
62880+
62881+ #ifdef HAVE_AES_ECB
62882+ #ifdef WOLFSSL_AES_128
62883+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_128_ecb()), AES_128_KEY_SIZE);
62884+ #endif
62885+ #ifdef WOLFSSL_AES_192
62886+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_192_ecb()), AES_192_KEY_SIZE);
62887+ #endif
62888+ #ifdef WOLFSSL_AES_256
62889+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_256_ecb()), AES_256_KEY_SIZE);
62890+ #endif
62891+ #endif
62892+
62893+ #ifdef WOLFSSL_AES_OFB
62894+ #ifdef WOLFSSL_AES_128
62895+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_128_ofb()), AES_128_KEY_SIZE);
62896+ #endif
62897+ #ifdef WOLFSSL_AES_192
62898+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_192_ofb()), AES_192_KEY_SIZE);
62899+ #endif
62900+ #ifdef WOLFSSL_AES_256
62901+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_aes_256_ofb()), AES_256_KEY_SIZE);
62902+ #endif
62903+ #endif
62904+
62905+ #ifndef NO_RC4
62906+ ExpectIntEQ(EVP_CIPHER_key_length(wolfSSL_EVP_rc4()), RC4_KEY_SIZE);
62907+ #endif
62908+
62909+ #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
62910+ ExpectIntEQ(EVP_CIPHER_key_length(wolfSSL_EVP_chacha20_poly1305()),
62911+ CHACHA20_POLY1305_AEAD_KEYSIZE);
62912+ #endif
62913+ #endif
62914+
62915+ #ifdef WOLFSSL_SM4_ECB
62916+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_sm4_ecb()), SM4_KEY_SIZE);
62917+ #endif
62918+ #ifdef WOLFSSL_SM4_CBC
62919+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_sm4_cbc()), SM4_KEY_SIZE);
62920+ #endif
62921+ #ifdef WOLFSSL_SM4_CTR
62922+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_sm4_ctr()), SM4_KEY_SIZE);
62923+ #endif
62924+ #ifdef WOLFSSL_SM4_GCM
62925+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_sm4_gcm()), SM4_KEY_SIZE);
62926+ #endif
62927+ #ifdef WOLFSSL_SM4_CCM
62928+ ExpectIntEQ(EVP_CIPHER_key_length(EVP_sm4_ccm()), SM4_KEY_SIZE);
62929+ #endif
62930+
62931+ return EXPECT_RESULT();
62932+ }
62933+
6272562934static int test_wolfSSL_EVP_CIPHER_block_size(void)
6272662935{
6272762936 EXPECT_DECLS;
@@ -85139,6 +85348,8 @@ TEST_CASE testCases[] = {
8513985348 TEST_DECL(test_wolfSSL_EVP_CIPHER_iv_length),
8514085349 TEST_DECL(test_wolfSSL_EVP_X_STATE),
8514185350 TEST_DECL(test_wolfSSL_EVP_X_STATE_LEN),
85351+ TEST_DECL(test_EVP_PKEY_is_a),
85352+ TEST_DECL(test_EVP_CIPHER_key_length),
8514285353 TEST_DECL(test_wolfSSL_EVP_BytesToKey),
8514385354#endif
8514485355
0 commit comments