From b46f87ffe6b9a8a92195136e1ed6684714b34637 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Tue, 13 Oct 2020 14:43:32 -0600 Subject: [PATCH 1/9] Added unit test for evp.c --- tests/api.c | 740 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 740 insertions(+) diff --git a/tests/api.c b/tests/api.c index 6d064c537..65ebd7d6c 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33265,7 +33265,718 @@ static void test_wolfSSL_EVP_PKEY_assign(void) printf(resultFmt, passed); #endif /* OPENSSL_ALL */ } +static void test_wolfSSL_EVP_PKEY_base_id(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_PKEY* pkey; + printf(testingFmt, "wolfSSL_EVP_PKEY_base_id"); + + AssertNotNull(pkey = wolfSSL_EVP_PKEY_new()); + + AssertIntEQ(wolfSSL_EVP_PKEY_base_id(NULL), NID_undef); + + AssertIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), 6); + + EVP_PKEY_free(pkey); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_PKEY_id(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_PKEY* pkey; + + printf(testingFmt, "wolfSSL_EVP_PKEY_id"); + + AssertNotNull(pkey = wolfSSL_EVP_PKEY_new()); + + AssertIntEQ(wolfSSL_EVP_PKEY_id(NULL), 0); + + AssertIntEQ(wolfSSL_EVP_PKEY_id(pkey), 6); + + EVP_PKEY_free(pkey); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_PKEY_keygen(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_PKEY* pkey; + EVP_PKEY_CTX *ctx; + + printf(testingFmt, "wolfSSL_EVP_PKEY_keygen"); + + AssertNotNull(pkey = wolfSSL_EVP_PKEY_new()); + AssertNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL)); + + /* Bad cases */ + AssertIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, &pkey), BAD_FUNC_ARG); + AssertIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, NULL), BAD_FUNC_ARG); + AssertIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, NULL), BAD_FUNC_ARG); + + /* Good case */ + AssertIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, &pkey), 0); + + + EVP_PKEY_CTX_free(ctx); + EVP_PKEY_free(pkey); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_PKEY_keygen_init(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_PKEY* pkey; + EVP_PKEY_CTX *ctx; + + printf(testingFmt, "wolfSSL_EVP_PKEY_keygen_init"); + + AssertNotNull(pkey = wolfSSL_EVP_PKEY_new()); + AssertNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL)); + + AssertIntEQ(wolfSSL_EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS); + + + EVP_PKEY_CTX_free(ctx); + EVP_PKEY_free(pkey); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_PKEY_missing_parameters(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_PKEY* pkey; + + printf(testingFmt, "wolfSSL_EVP_PKEY_missing_parameters"); + + AssertNotNull(pkey = wolfSSL_EVP_PKEY_new()); + + AssertIntEQ(wolfSSL_EVP_PKEY_missing_parameters(pkey), 0); + + EVP_PKEY_free(pkey); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_PKEY* pkey; + EVP_PKEY_CTX *ctx; + int bits = 2048; + + + printf(testingFmt, "wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits"); + + AssertNotNull(pkey = wolfSSL_EVP_PKEY_new()); + AssertNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL)); + + AssertIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits), + WOLFSSL_SUCCESS); + + + EVP_PKEY_CTX_free(ctx); + EVP_PKEY_free(pkey); + + printf(resultFmt, passed); +#endif +} + +static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) +{ +#if defined(OPENSSL_ALL) + + byte key[AES_BLOCK_SIZE] = {0}; + byte iv[AES_BLOCK_SIZE] = {0}; + int i, enumlen; + + int enumArray[] = { + + #ifdef HAVE_AES_CBC + NID_aes_128_cbc, + #endif + #ifdef HAVE_AESGCM + NID_aes_128_gcm, + #endif + #ifdef WOLFSSL_AES_COUNTER + NID_aes_128_ctr, + #endif + #ifndef NO_DES3 + NID_des_cbc, + #endif + #ifndef NO_DES3 + NID_des_cbc, + NID_des_ede3_ecb, + #endif + #ifdef HAVE_IDEA + NID_idea_cbc, + #endif + }; + int iv_lengths[] = { + + #ifdef HAVE_AES_CBC + 16, + #endif + #ifdef HAVE_AESGCM + 12, + #endif + #ifdef WOLFSSL_AES_COUNTER + 16, + #endif + #ifndef NO_DES3 + 8, + #endif + #ifndef NO_DES3 + 8, + #endif + #ifdef WOLFSSL_DES_ECB + 0, + #endif + #ifdef HAVE_IDEA + 8, + #endif + }; + + + printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_iv_length"); + enumlen = (sizeof(enumArray)/sizeof(int)); + for(i = 0; i < enumlen; i++) + { + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + const EVP_CIPHER *init = wolfSSL_EVP_get_cipherbynid(enumArray[i]); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]); + + + EVP_CIPHER_CTX_free(ctx); + } + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_CIPHER_CTX_key_length(void) +{ +#if defined(OPENSSL_ALL) && !defined(NO_DES3) + byte key[AES_BLOCK_SIZE] = {0}; + byte iv[AES_BLOCK_SIZE] = {0}; + + printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_key_length"); + + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + const EVP_CIPHER *init = EVP_des_ede3_cbc(); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_key_length(ctx), 24); + + EVP_CIPHER_CTX_free(ctx); + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_CIPHER_CTX_set_key_length(void) +{ +#if defined(OPENSSL_ALL) && !defined(NO_DES3) + byte key[AES_BLOCK_SIZE] = {0}; + byte iv[AES_BLOCK_SIZE] = {0}; + int keylen; + + printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_set_key_length"); + + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + const EVP_CIPHER *init = EVP_des_ede3_cbc(); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + keylen = wolfSSL_EVP_CIPHER_CTX_key_length(ctx); + + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, keylen), + WOLFSSL_SUCCESS); + + EVP_CIPHER_CTX_free(ctx); + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_CIPHER_CTX_set_iv(void) +{ +#if defined(OPENSSL_ALL) && defined(HAVE_AESGCM) && !defined(NO_DES3) &&\ + !defined(NO_DES3) + byte key[AES_BLOCK_SIZE] = {0}; + byte iv[AES_BLOCK_SIZE] = {0}; + int ivLen, keyLen; + + printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_set_iv"); + + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + const EVP_CIPHER *init = EVP_des_ede3_cbc(); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + ivLen = wolfSSL_EVP_CIPHER_CTX_iv_length(ctx); + keyLen = wolfSSL_EVP_CIPHER_CTX_key_length(ctx); + + /* Bad cases */ + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, iv, ivLen), WOLFSSL_FAILURE); + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, NULL, ivLen), WOLFSSL_FAILURE); + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, 0), WOLFSSL_FAILURE); + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, NULL, 0), WOLFSSL_FAILURE); + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, keyLen), WOLFSSL_FAILURE); + + /* Good case */ + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, ivLen), 1); + + + EVP_CIPHER_CTX_free(ctx); + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_PKEY_CTX_new_id(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_ENGINE* e = 0; + int id = 0; + + printf(testingFmt, "wolfSSL_EVP_PKEY_CTX_new_id"); + + AssertNotNull(wolfSSL_EVP_PKEY_CTX_new_id(id, e)); + + + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_rc4(void) +{ +#if defined(OPENSSL_ALL) && !defined(NO_RC4) + + printf(testingFmt, "wolfSSL_EVP_rc4"); + + AssertNotNull(wolfSSL_EVP_rc4()); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_enc_null(void) +{ +#if defined(OPENSSL_ALL) + + printf(testingFmt, "wolfSSL_EVP_enc_null"); + + AssertNotNull(wolfSSL_EVP_enc_null()); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_rc2_cbc(void) +{ +#if defined(OPENSSL_ALL) && defined(WOLFSSL_QT) && !defined(NO_WOLFSSL_STUB) + + printf(testingFmt, "wolfSSL_EVP_rc2_cbc"); + + AssertNull(wolfSSL_EVP_rc2_cbc()); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_mdc2(void) +{ +#if defined(OPENSSL_ALL) + + printf(testingFmt, "wolfSSL_EVP_mdc2"); + + AssertNull(wolfSSL_EVP_mdc2()); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_md4(void) +{ +#if defined(OPENSSL_ALL) && !defined(NO_MD4) + + printf(testingFmt, "wolfSSL_EVP_md4"); + + AssertNotNull(wolfSSL_EVP_md4()); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_aes_256_gcm(void) +{ +#if defined(OPENSSL_ALL) + + printf(testingFmt, "wolfSSL_EVP_aes_256_gcm"); + + AssertNotNull(wolfSSL_EVP_aes_256_gcm()); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_aes_192_gcm(void) +{ +#if defined(OPENSSL_ALL) + + printf(testingFmt, "wolfSSL_EVP_aes_192_gcm"); + + AssertNotNull(wolfSSL_EVP_aes_192_gcm()); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_ripemd160(void) +{ +#if defined(OPENSSL_ALL) + + printf(testingFmt, "wolfSSL_EVP_ripemd160"); + + AssertNull(wolfSSL_EVP_ripemd160()); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_get_digestbynid(void) +{ +#if defined(OPENSSL_ALL) + + printf(testingFmt, "wolfSSL_EVP_get_digestbynid"); + + AssertNotNull(wolfSSL_EVP_get_digestbynid(4)); /* NID_md5 */ + AssertNotNull(wolfSSL_EVP_get_digestbynid(64)); /* NID_sha1 */ + AssertNull(wolfSSL_EVP_get_digestbynid(0)); /* default */ + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_PKEY_get0_EC_KEY(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_PKEY* pkey; + + + printf(testingFmt, "wolfSSL_EVP_PKEY_get0_EC_KEY"); + + AssertNotNull(pkey = wolfSSL_EVP_PKEY_new()); + AssertNull(wolfSSL_EVP_PKEY_get0_EC_KEY(pkey)); + + EVP_PKEY_free(pkey); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_X_STATE(void) +{ +#if defined(OPENSSL_ALL) && !defined(NO_DES3) + + byte key[AES_BLOCK_SIZE] = {0}; + byte iv[AES_BLOCK_SIZE] = {0}; + EVP_CIPHER_CTX *ctx; + const EVP_CIPHER *init; + + printf(testingFmt, "wolfSSL_EVP_X_STATE"); + + /* Bad test cases */ + ctx = EVP_CIPHER_CTX_new(); + init = EVP_des_ede3_cbc(); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + AssertNull(wolfSSL_EVP_X_STATE(NULL)); + AssertNull(wolfSSL_EVP_X_STATE(ctx)); + EVP_CIPHER_CTX_free(ctx); + + /* Good test case */ + ctx = EVP_CIPHER_CTX_new(); + init = wolfSSL_EVP_rc4(); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + AssertNotNull(wolfSSL_EVP_X_STATE(ctx)); + EVP_CIPHER_CTX_free(ctx); + + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_X_STATE_LEN(void) +{ +#if defined(OPENSSL_ALL) && !defined(NO_DES3) + + byte key[AES_BLOCK_SIZE] = {0}; + byte iv[AES_BLOCK_SIZE] = {0}; + EVP_CIPHER_CTX *ctx; + const EVP_CIPHER *init; + + printf(testingFmt, "wolfSSL_EVP_X_STATE_LEN"); + + /* Bad test cases */ + ctx = EVP_CIPHER_CTX_new(); + init = EVP_des_ede3_cbc(); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + AssertIntEQ(wolfSSL_EVP_X_STATE_LEN(NULL), 0); + AssertIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), 0); + EVP_CIPHER_CTX_free(ctx); + + /* Good test case */ + ctx = EVP_CIPHER_CTX_new(); + init = wolfSSL_EVP_rc4(); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + AssertIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), 272); + EVP_CIPHER_CTX_free(ctx); + + + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_CIPHER_iv_length(void) +{ +#if defined(OPENSSL_ALL) + int i, enumlen; + + + int enumArray[] = { + + #ifdef HAVE_AES_CBC + NID_aes_128_cbc, + #endif + #ifdef WOLFSSL_AES_192 + NID_aes_192_cbc, + #endif + #ifdef WOLFSSL_AES_256 + NID_aes_256_cbc, + #endif + #ifdef HAVE_AESGCM + NID_aes_128_gcm, + #endif + #ifdef WOLFSSL_AES_192 + NID_aes_192_gcm, + #endif + #ifdef WOLFSSL_AES_256 + NID_aes_256_gcm, + #endif + #ifdef WOLFSSL_AES_COUNTER + NID_aes_128_ctr, + #endif + #ifdef WOLFSSL_AES_192 + NID_aes_192_ctr, + #endif + #ifdef WOLFSSL_AES_256 + NID_aes_256_ctr, + #endif + #ifndef NO_DES3 + NID_des_cbc, + NID_des_ede3_ecb, + #endif + #ifdef HAVE_IDEA + NID_idea_cbc, + #endif + }; + int iv_lengths[] = { + #ifdef HAVE_AES_CBC + 16, + #endif + #ifdef WOLFSSL_AES_192 + 16, + #endif + #ifdef WOLFSSL_AES_256 + 16, + #endif + #ifdef HAVE_AESGCM + 12, + #endif + #ifdef WOLFSSL_AES_192 + 12, + #endif + #ifdef WOLFSSL_AES_256 + 12, + #endif + #ifdef WOLFSSL_AES_COUNTER + 16, + #endif + #ifdef WOLFSSL_AES_192 + 16, + #endif + #ifdef WOLFSSL_AES_256 + 16, + #endif + #ifndef NO_DES3 + 8, + 0, + #endif + #ifdef HAVE_IDEA + 8, + #endif + }; + + printf(testingFmt, "wolfSSL_EVP_CIPHER_iv_length"); + enumlen = (sizeof(enumArray)/sizeof(int)); + for(i = 0; i < enumlen; i++) + { + const EVP_CIPHER *c = wolfSSL_EVP_get_cipherbynid(enumArray[i]); + AssertIntEQ(wolfSSL_EVP_CIPHER_iv_length(c), iv_lengths[i]); + } + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_SignInit_ex(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_MD_CTX mdCtx; + WOLFSSL_ENGINE* e = 0; + const EVP_MD* md; + md = "SHA256"; + + printf(testingFmt, "wolfSSL_EVP_SignInit_ex"); + + wolfSSL_EVP_MD_CTX_init(&mdCtx); + AssertIntEQ(wolfSSL_EVP_SignInit_ex(&mdCtx, md, e), WOLFSSL_SUCCESS); + + AssertIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_DigestFinal_ex(void) +{ +#if defined(OPENSSL_ALL) + WOLFSSL_EVP_MD_CTX mdCtx; + unsigned int s = 5; + unsigned char md; + + printf(testingFmt, "wolfSSL_EVP_DigestFinal_ex"); + + wolfSSL_EVP_MD_CTX_init(&mdCtx); + AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, &md, &s), 0); + + AssertIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 0); + + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_PKEY_assign_DH(void) +{ +#if defined(OPENSSL_ALL) && !defined(NO_DH) + FILE* f = NULL; + unsigned char buf[4096]; + const unsigned char* pt = buf; + const char* params1 = "./certs/dh2048.der"; + long len = 0; + WOLFSSL_DH* dh = NULL; + WOLFSSL_EVP_PKEY* pkey; + XMEMSET(buf, 0, sizeof(buf)); + + + f = XFOPEN(params1, "rb"); + AssertTrue(f != XBADFILE); + len = (long)XFREAD(buf, 1, sizeof(buf), f); + XFCLOSE(f); + + + printf(testingFmt, "wolfSSL_EVP_PKEY_assign_DH"); + + AssertNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len)); + AssertIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS); + + AssertNotNull(pkey = wolfSSL_EVP_PKEY_new()); + + /* Bad cases */ + AssertIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, dh), WOLFSSL_FAILURE); + AssertIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, NULL), WOLFSSL_FAILURE); + AssertIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, NULL), WOLFSSL_FAILURE); + + /* Good case */ + AssertIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, dh), WOLFSSL_SUCCESS); + + + EVP_PKEY_free(pkey); + printf(resultFmt, passed); +#endif +} +static void test_wolfSSL_EVP_BytesToKey(void) +{ +#if defined(OPENSSL_ALL) && !defined(NO_DES3) + byte key[AES_BLOCK_SIZE] = {0}; + byte iv[AES_BLOCK_SIZE] = {0}; + int sz = 5; + int count = 0; + const EVP_MD* md; + md = "SHA256"; + const EVP_CIPHER *type; + const unsigned char *salt = (unsigned char *)"salt1234"; + const byte data[] = { + 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f, + 0x72,0x6c,0x64 + }; + + type = wolfSSL_EVP_get_cipherbynid(NID_aes_128_cbc); + + printf(testingFmt, "wolfSSL_EVP_BytesToKey"); + + /* Bad cases */ + AssertIntEQ(wolfSSL_EVP_BytesToKey(NULL, md, salt, data, sz, count, key, iv), + 0); + AssertIntEQ(wolfSSL_EVP_BytesToKey(type, md, salt, NULL, sz, count, key, iv), + 16); + md = "2"; + AssertIntEQ(wolfSSL_EVP_BytesToKey(type, md, salt, data, sz, count, key, iv), + WOLFSSL_FAILURE); + + /* Good case */ + md = "SHA256"; + AssertIntEQ(wolfSSL_EVP_BytesToKey(type, md, salt, data, sz, count, key, iv), + 16); + + printf(resultFmt, passed); +#endif +} +static void test_IncCtr(void) +{ +#if defined(OPENSSL_ALL) && defined(HAVE_AESGCM) && !defined(NO_DES3) &&\ + !defined(NO_DES3) + byte key[AES_BLOCK_SIZE] = {0}; + byte iv[AES_BLOCK_SIZE] = {0}; + int type = EVP_CTRL_GCM_IV_GEN; + int arg = 0; + void *ptr; + ptr = NULL; + + printf(testingFmt, "IncCtr"); + + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + const EVP_CIPHER *init = EVP_des_ede3_cbc(); + + wolfSSL_EVP_CIPHER_CTX_init(ctx); + AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); + + + ctx->cipher.aes.keylen = 128; + + AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_ctrl(ctx, type, arg, ptr), 0); + + + EVP_CIPHER_CTX_free(ctx); + printf(resultFmt, passed); +#endif +} static void test_wolfSSL_OBJ_ln(void) { const int nid_set[] = { @@ -37906,6 +38617,35 @@ void ApiTest(void) test_wolfSSL_CTX_ctrl(); test_wolfSSL_DH_check(); test_wolfSSL_EVP_PKEY_assign(); + test_wolfSSL_EVP_PKEY_base_id(); + test_wolfSSL_EVP_PKEY_id(); + test_wolfSSL_EVP_PKEY_keygen(); + test_wolfSSL_EVP_PKEY_keygen_init(); + test_wolfSSL_EVP_PKEY_missing_parameters(); + test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(); + test_wolfSSL_EVP_CIPHER_CTX_iv_length(); + test_wolfSSL_EVP_CIPHER_CTX_key_length(); + test_wolfSSL_EVP_CIPHER_CTX_set_key_length(); + test_wolfSSL_EVP_CIPHER_CTX_set_iv(); + test_wolfSSL_EVP_PKEY_CTX_new_id(); + test_wolfSSL_EVP_rc4(); + test_wolfSSL_EVP_enc_null(); + test_wolfSSL_EVP_rc2_cbc(); + test_wolfSSL_EVP_mdc2(); + test_wolfSSL_EVP_md4(); + test_wolfSSL_EVP_aes_256_gcm(); + test_wolfSSL_EVP_aes_192_gcm(); + test_wolfSSL_EVP_ripemd160(); + test_wolfSSL_EVP_get_digestbynid(); + test_wolfSSL_EVP_PKEY_get0_EC_KEY(); + test_wolfSSL_EVP_X_STATE(); + test_wolfSSL_EVP_X_STATE_LEN(); + test_wolfSSL_EVP_CIPHER_iv_length(); + test_wolfSSL_EVP_SignInit_ex(); + test_wolfSSL_EVP_DigestFinal_ex(); + test_wolfSSL_EVP_PKEY_assign_DH(); + test_wolfSSL_EVP_BytesToKey(); + test_IncCtr(); test_wolfSSL_OBJ_ln(); test_wolfSSL_OBJ_sn(); From 8122c031bf30a1f8ede67e83813d22a225ce1d41 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Thu, 15 Oct 2020 14:44:44 -0600 Subject: [PATCH 2/9] Added ifdef's, changed key sizes to relevant sizes --- tests/api.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/tests/api.c b/tests/api.c index 65ebd7d6c..6cf8d604c 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33391,9 +33391,15 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) { #if defined(OPENSSL_ALL) - byte key[AES_BLOCK_SIZE] = {0}; + /* This is large enough to be used for all key sizes */ + byte key[AES_256_KEY_SIZE] = {0}; byte iv[AES_BLOCK_SIZE] = {0}; int i, enumlen; + EVP_CIPHER_CTX *ctx; + const EVP_CIPHER *init; + + + int enumArray[] = { @@ -33409,8 +33415,7 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) #ifndef NO_DES3 NID_des_cbc, #endif - #ifndef NO_DES3 - NID_des_cbc, + #ifndef WOLFSSL_DES_ECB NID_des_ede3_ecb, #endif #ifdef HAVE_IDEA @@ -33431,14 +33436,11 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) #ifndef NO_DES3 8, #endif - #ifndef NO_DES3 - 8, - #endif #ifdef WOLFSSL_DES_ECB - 0, + 8, #endif #ifdef HAVE_IDEA - 8, + 16, #endif }; @@ -33447,16 +33449,15 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) enumlen = (sizeof(enumArray)/sizeof(int)); for(i = 0; i < enumlen; i++) { - EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); - const EVP_CIPHER *init = wolfSSL_EVP_get_cipherbynid(enumArray[i]); + ctx = EVP_CIPHER_CTX_new(); + init = wolfSSL_EVP_get_cipherbynid(enumArray[i]); wolfSSL_EVP_CIPHER_CTX_init(ctx); AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); - AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]); - +//wolfSSL_EVP_CIPHER_CTX_cleanup EVP_CIPHER_CTX_free(ctx); } @@ -33466,7 +33467,7 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) static void test_wolfSSL_EVP_CIPHER_CTX_key_length(void) { #if defined(OPENSSL_ALL) && !defined(NO_DES3) - byte key[AES_BLOCK_SIZE] = {0}; + byte key[AES_256_KEY_SIZE] = {0}; byte iv[AES_BLOCK_SIZE] = {0}; printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_key_length"); @@ -33486,7 +33487,7 @@ static void test_wolfSSL_EVP_CIPHER_CTX_key_length(void) static void test_wolfSSL_EVP_CIPHER_CTX_set_key_length(void) { #if defined(OPENSSL_ALL) && !defined(NO_DES3) - byte key[AES_BLOCK_SIZE] = {0}; + byte key[AES_256_KEY_SIZE] = {0}; byte iv[AES_BLOCK_SIZE] = {0}; int keylen; @@ -33511,8 +33512,8 @@ static void test_wolfSSL_EVP_CIPHER_CTX_set_iv(void) { #if defined(OPENSSL_ALL) && defined(HAVE_AESGCM) && !defined(NO_DES3) &&\ !defined(NO_DES3) - byte key[AES_BLOCK_SIZE] = {0}; - byte iv[AES_BLOCK_SIZE] = {0}; + byte key[DES3_KEY_SIZE] = {0}; + byte iv[DES_IV_SIZE] = {0}; int ivLen, keyLen; printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_set_iv"); @@ -33591,7 +33592,7 @@ static void test_wolfSSL_EVP_rc2_cbc(void) } static void test_wolfSSL_EVP_mdc2(void) { -#if defined(OPENSSL_ALL) +#if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_STUB) printf(testingFmt, "wolfSSL_EVP_mdc2"); @@ -33677,8 +33678,8 @@ static void test_wolfSSL_EVP_X_STATE(void) { #if defined(OPENSSL_ALL) && !defined(NO_DES3) - byte key[AES_BLOCK_SIZE] = {0}; - byte iv[AES_BLOCK_SIZE] = {0}; + byte key[DES3_KEY_SIZE] = {0}; + byte iv[DES_IV_SIZE] = {0}; EVP_CIPHER_CTX *ctx; const EVP_CIPHER *init; @@ -33713,8 +33714,8 @@ static void test_wolfSSL_EVP_X_STATE_LEN(void) { #if defined(OPENSSL_ALL) && !defined(NO_DES3) - byte key[AES_BLOCK_SIZE] = {0}; - byte iv[AES_BLOCK_SIZE] = {0}; + byte key[DES3_KEY_SIZE] = {0}; + byte iv[DES_IV_SIZE] = {0}; EVP_CIPHER_CTX *ctx; const EVP_CIPHER *init; @@ -33773,6 +33774,7 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) NID_aes_256_gcm, #endif #ifdef WOLFSSL_AES_COUNTER + #ifdef WOLFSSL_AES_128 NID_aes_128_ctr, #endif #ifdef WOLFSSL_AES_192 @@ -33781,6 +33783,7 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #ifdef WOLFSSL_AES_256 NID_aes_256_ctr, #endif + #endif #ifndef NO_DES3 NID_des_cbc, NID_des_ede3_ecb, @@ -33809,6 +33812,7 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) 12, #endif #ifdef WOLFSSL_AES_COUNTER + #ifdef WOLFSSL_AES_128 16, #endif #ifdef WOLFSSL_AES_192 @@ -33817,6 +33821,7 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #ifdef WOLFSSL_AES_256 16, #endif + #endif #ifndef NO_DES3 8, 0, @@ -33952,8 +33957,8 @@ static void test_IncCtr(void) { #if defined(OPENSSL_ALL) && defined(HAVE_AESGCM) && !defined(NO_DES3) &&\ !defined(NO_DES3) - byte key[AES_BLOCK_SIZE] = {0}; - byte iv[AES_BLOCK_SIZE] = {0}; + byte key[DES3_KEY_SIZE] = {0}; + byte iv[DES_IV_SIZE] = {0}; int type = EVP_CTRL_GCM_IV_GEN; int arg = 0; void *ptr; From 74123744963b8537b393324254cef384b411c90c Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Wed, 21 Oct 2020 14:12:37 -0600 Subject: [PATCH 3/9] Changed from hardcoded values, changed types and deleted comments --- tests/api.c | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/tests/api.c b/tests/api.c index 6cf8d604c..321c7d23e 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33398,9 +33398,6 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) EVP_CIPHER_CTX *ctx; const EVP_CIPHER *init; - - - int enumArray[] = { #ifdef HAVE_AES_CBC @@ -33414,9 +33411,7 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) #endif #ifndef NO_DES3 NID_des_cbc, - #endif - #ifndef WOLFSSL_DES_ECB - NID_des_ede3_ecb, + NID_des_ede3_cbc, #endif #ifdef HAVE_IDEA NID_idea_cbc, @@ -33425,22 +33420,20 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) int iv_lengths[] = { #ifdef HAVE_AES_CBC - 16, + AES_BLOCK_SIZE, #endif #ifdef HAVE_AESGCM - 12, + GCM_NONCE_MID_SZ, #endif #ifdef WOLFSSL_AES_COUNTER - 16, + AES_BLOCK_SIZE, #endif #ifndef NO_DES3 - 8, - #endif - #ifdef WOLFSSL_DES_ECB - 8, + DES_BLOCK_SIZE, + DES_BLOCK_SIZE, #endif #ifdef HAVE_IDEA - 16, + IDEA_BLOCK_SIZE, #endif }; @@ -33457,7 +33450,6 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]); -//wolfSSL_EVP_CIPHER_CTX_cleanup EVP_CIPHER_CTX_free(ctx); } @@ -33547,12 +33539,13 @@ static void test_wolfSSL_EVP_PKEY_CTX_new_id(void) #if defined(OPENSSL_ALL) WOLFSSL_ENGINE* e = 0; int id = 0; + EVP_PKEY_CTX *ctx; printf(testingFmt, "wolfSSL_EVP_PKEY_CTX_new_id"); - AssertNotNull(wolfSSL_EVP_PKEY_CTX_new_id(id, e)); - + AssertNotNull(ctx = wolfSSL_EVP_PKEY_CTX_new_id(id, e)); + EVP_PKEY_CTX_free(ctx); printf(resultFmt, passed); #endif @@ -33786,7 +33779,7 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #endif #ifndef NO_DES3 NID_des_cbc, - NID_des_ede3_ecb, + NID_des_ede3_cbc, #endif #ifdef HAVE_IDEA NID_idea_cbc, @@ -33794,40 +33787,40 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) }; int iv_lengths[] = { #ifdef HAVE_AES_CBC - 16, + AES_BLOCK_SIZE, #endif #ifdef WOLFSSL_AES_192 - 16, + AES_BLOCK_SIZE, #endif #ifdef WOLFSSL_AES_256 - 16, + AES_BLOCK_SIZE, #endif #ifdef HAVE_AESGCM - 12, + GCM_NONCE_MID_SZ, #endif #ifdef WOLFSSL_AES_192 - 12, + GCM_NONCE_MID_SZ, #endif #ifdef WOLFSSL_AES_256 - 12, + GCM_NONCE_MID_SZ, #endif #ifdef WOLFSSL_AES_COUNTER #ifdef WOLFSSL_AES_128 - 16, + AES_BLOCK_SIZE, #endif #ifdef WOLFSSL_AES_192 - 16, + AES_BLOCK_SIZE, #endif #ifdef WOLFSSL_AES_256 - 16, + AES_BLOCK_SIZE, #endif #endif #ifndef NO_DES3 - 8, - 0, + DES_BLOCK_SIZE, + DES_BLOCK_SIZE, #endif #ifdef HAVE_IDEA - 8, + IDEA_BLOCK_SIZE, #endif }; From 251f3e15d4cdaa13c751a1f5115ffc334cb789c1 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Thu, 22 Oct 2020 14:01:01 -0600 Subject: [PATCH 4/9] Added fips check for specific size --- tests/api.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/tests/api.c b/tests/api.c index 321c7d23e..667185f80 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33403,9 +33403,12 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) #ifdef HAVE_AES_CBC NID_aes_128_cbc, #endif + #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)) #ifdef HAVE_AESGCM NID_aes_128_gcm, #endif + #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */ #ifdef WOLFSSL_AES_COUNTER NID_aes_128_ctr, #endif @@ -33422,9 +33425,12 @@ static void test_wolfSSL_EVP_CIPHER_CTX_iv_length(void) #ifdef HAVE_AES_CBC AES_BLOCK_SIZE, #endif + #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)) #ifdef HAVE_AESGCM GCM_NONCE_MID_SZ, #endif + #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */ #ifdef WOLFSSL_AES_COUNTER AES_BLOCK_SIZE, #endif @@ -33757,15 +33763,20 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #ifdef WOLFSSL_AES_256 NID_aes_256_cbc, #endif + #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)) #ifdef HAVE_AESGCM - NID_aes_128_gcm, - #endif - #ifdef WOLFSSL_AES_192 - NID_aes_192_gcm, - #endif - #ifdef WOLFSSL_AES_256 - NID_aes_256_gcm, - #endif + #ifdef WOLFSSL_AES_128 + NID_aes_128_gcm, + #endif + #ifdef WOLFSSL_AES_192 + NID_aes_192_gcm, + #endif + #ifdef WOLFSSL_AES_256 + NID_aes_256_gcm, + #endif + #endif /* HAVE_AESGCM */ + #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */ #ifdef WOLFSSL_AES_COUNTER #ifdef WOLFSSL_AES_128 NID_aes_128_ctr, @@ -33795,15 +33806,20 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #ifdef WOLFSSL_AES_256 AES_BLOCK_SIZE, #endif + #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \ + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)) #ifdef HAVE_AESGCM + #ifdef WOLFSSL_AES_128 GCM_NONCE_MID_SZ, - #endif - #ifdef WOLFSSL_AES_192 + #endif + #ifdef WOLFSSL_AES_192 GCM_NONCE_MID_SZ, - #endif - #ifdef WOLFSSL_AES_256 + #endif + #ifdef WOLFSSL_AES_256 GCM_NONCE_MID_SZ, - #endif + #endif + #endif /* HAVE_AESGCM */ + #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */ #ifdef WOLFSSL_AES_COUNTER #ifdef WOLFSSL_AES_128 AES_BLOCK_SIZE, From 05d01dcccd70b49401956e77fc9daaf234370606 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Fri, 23 Oct 2020 13:18:09 -0600 Subject: [PATCH 5/9] Added if defined checks for rc4 and fips --- tests/api.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/api.c b/tests/api.c index 667185f80..64b91794c 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33675,7 +33675,7 @@ static void test_wolfSSL_EVP_PKEY_get0_EC_KEY(void) } static void test_wolfSSL_EVP_X_STATE(void) { -#if defined(OPENSSL_ALL) && !defined(NO_DES3) +#if defined(OPENSSL_ALL) && !defined(NO_DES3) && !defined(NO_RC4) byte key[DES3_KEY_SIZE] = {0}; byte iv[DES_IV_SIZE] = {0}; @@ -33711,7 +33711,7 @@ static void test_wolfSSL_EVP_X_STATE(void) } static void test_wolfSSL_EVP_X_STATE_LEN(void) { -#if defined(OPENSSL_ALL) && !defined(NO_DES3) +#if defined(OPENSSL_ALL) && !defined(NO_DES3) && !defined(NO_RC4) byte key[DES3_KEY_SIZE] = {0}; byte iv[DES_IV_SIZE] = {0}; @@ -33888,7 +33888,8 @@ static void test_wolfSSL_EVP_DigestFinal_ex(void) } static void test_wolfSSL_EVP_PKEY_assign_DH(void) { -#if defined(OPENSSL_ALL) && !defined(NO_DH) +#if defined(OPENSSL_ALL) && !defined(NO_DH) && \ + !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)) FILE* f = NULL; unsigned char buf[4096]; const unsigned char* pt = buf; From cf05a060f7646ab2765727580c033ea914e980da Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Mon, 2 Nov 2020 14:16:02 -0700 Subject: [PATCH 6/9] Removed cases that caused fips test to fail --- tests/api.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/api.c b/tests/api.c index 64b91794c..5668c9afb 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33790,7 +33790,6 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #endif #ifndef NO_DES3 NID_des_cbc, - NID_des_ede3_cbc, #endif #ifdef HAVE_IDEA NID_idea_cbc, @@ -33833,7 +33832,6 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #endif #ifndef NO_DES3 DES_BLOCK_SIZE, - DES_BLOCK_SIZE, #endif #ifdef HAVE_IDEA IDEA_BLOCK_SIZE, From 813a94ab9a83dcdeb234d2a01257eceae19c176b Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Tue, 3 Nov 2020 14:23:32 -0700 Subject: [PATCH 7/9] Added bad and good case to EVP_DigestFinal_ex test --- tests/api.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/api.c b/tests/api.c index 5668c9afb..4e9e7d600 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33790,6 +33790,7 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #endif #ifndef NO_DES3 NID_des_cbc, + NID_des_ede3_cbc, #endif #ifdef HAVE_IDEA NID_idea_cbc, @@ -33832,6 +33833,7 @@ static void test_wolfSSL_EVP_CIPHER_iv_length(void) #endif #ifndef NO_DES3 DES_BLOCK_SIZE, + DES_BLOCK_SIZE, #endif #ifdef HAVE_IDEA IDEA_BLOCK_SIZE, @@ -33871,16 +33873,24 @@ static void test_wolfSSL_EVP_DigestFinal_ex(void) { #if defined(OPENSSL_ALL) WOLFSSL_EVP_MD_CTX mdCtx; - unsigned int s = 5; + unsigned int s = 0; unsigned char md; printf(testingFmt, "wolfSSL_EVP_DigestFinal_ex"); + + /* Bad Case */ wolfSSL_EVP_MD_CTX_init(&mdCtx); AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, &md, &s), 0); - AssertIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 0); + /* Good Case */ + wolfSSL_EVP_MD_CTX_init(&mdCtx); + AssertIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "MD5"), WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, &md, &s), WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS); + + printf(resultFmt, passed); #endif } From 0aee4b78cd26581ae1e816397184b9d7dbc53a6e Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Thu, 5 Nov 2020 14:04:32 -0700 Subject: [PATCH 8/9] Changed md5 to sha256 in DigestFinal_ex function --- tests/api.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/api.c b/tests/api.c index 4e9e7d600..a082f68f4 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33871,23 +33871,35 @@ static void test_wolfSSL_EVP_SignInit_ex(void) } static void test_wolfSSL_EVP_DigestFinal_ex(void) { -#if defined(OPENSSL_ALL) +#if defined(OPENSSL_ALL) && !defined(NO_SHA256) WOLFSSL_EVP_MD_CTX mdCtx; unsigned int s = 0; - unsigned char md; + unsigned char md[WC_SHA256_DIGEST_SIZE]; + unsigned char md2[WC_SHA256_DIGEST_SIZE]; + printf(testingFmt, "wolfSSL_EVP_DigestFinal_ex"); /* Bad Case */ +#if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)) + wolfSSL_EVP_MD_CTX_init(&mdCtx); - AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, &md, &s), 0); + AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), 0); AssertIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 0); +#else + + wolfSSL_EVP_MD_CTX_init(&mdCtx); + AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS); + +#endif + /* Good Case */ wolfSSL_EVP_MD_CTX_init(&mdCtx); - AssertIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "MD5"), WOLFSSL_SUCCESS); - AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, &md, &s), WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA256"), WOLFSSL_SUCCESS); + AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md2, &s), WOLFSSL_SUCCESS); AssertIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS); From a6e0d3eb292dce24a76e7b6ac88fdc86e50cdef8 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Fri, 6 Nov 2020 14:04:27 -0700 Subject: [PATCH 9/9] Changed hardcoded values to variables, changed where some variables were defined, etc --- tests/api.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/tests/api.c b/tests/api.c index a082f68f4..88112efef 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33276,7 +33276,7 @@ static void test_wolfSSL_EVP_PKEY_base_id(void) AssertIntEQ(wolfSSL_EVP_PKEY_base_id(NULL), NID_undef); - AssertIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), 6); + AssertIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), EVP_PKEY_RSA); EVP_PKEY_free(pkey); @@ -33294,7 +33294,7 @@ static void test_wolfSSL_EVP_PKEY_id(void) AssertIntEQ(wolfSSL_EVP_PKEY_id(NULL), 0); - AssertIntEQ(wolfSSL_EVP_PKEY_id(pkey), 6); + AssertIntEQ(wolfSSL_EVP_PKEY_id(pkey), EVP_PKEY_RSA); EVP_PKEY_free(pkey); @@ -33467,11 +33467,11 @@ static void test_wolfSSL_EVP_CIPHER_CTX_key_length(void) #if defined(OPENSSL_ALL) && !defined(NO_DES3) byte key[AES_256_KEY_SIZE] = {0}; byte iv[AES_BLOCK_SIZE] = {0}; + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + const EVP_CIPHER *init = EVP_des_ede3_cbc(); printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_key_length"); - EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); - const EVP_CIPHER *init = EVP_des_ede3_cbc(); wolfSSL_EVP_CIPHER_CTX_init(ctx); AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); @@ -33488,11 +33488,12 @@ static void test_wolfSSL_EVP_CIPHER_CTX_set_key_length(void) byte key[AES_256_KEY_SIZE] = {0}; byte iv[AES_BLOCK_SIZE] = {0}; int keylen; + EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); + const EVP_CIPHER *init = EVP_des_ede3_cbc(); printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_set_key_length"); - EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); - const EVP_CIPHER *init = EVP_des_ede3_cbc(); + wolfSSL_EVP_CIPHER_CTX_init(ctx); AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); @@ -33508,17 +33509,15 @@ static void test_wolfSSL_EVP_CIPHER_CTX_set_key_length(void) } static void test_wolfSSL_EVP_CIPHER_CTX_set_iv(void) { -#if defined(OPENSSL_ALL) && defined(HAVE_AESGCM) && !defined(NO_DES3) &&\ - !defined(NO_DES3) +#if defined(OPENSSL_ALL) && defined(HAVE_AESGCM) && !defined(NO_DES3) byte key[DES3_KEY_SIZE] = {0}; byte iv[DES_IV_SIZE] = {0}; int ivLen, keyLen; - - printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_set_iv"); - EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); const EVP_CIPHER *init = EVP_des_ede3_cbc(); + printf(testingFmt, "wolfSSL_EVP_CIPHER_CTX_set_iv"); + wolfSSL_EVP_CIPHER_CTX_init(ctx); AssertIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS); @@ -33543,7 +33542,7 @@ static void test_wolfSSL_EVP_CIPHER_CTX_set_iv(void) static void test_wolfSSL_EVP_PKEY_CTX_new_id(void) { #if defined(OPENSSL_ALL) - WOLFSSL_ENGINE* e = 0; + WOLFSSL_ENGINE* e = NULL; int id = 0; EVP_PKEY_CTX *ctx; @@ -33650,9 +33649,9 @@ static void test_wolfSSL_EVP_get_digestbynid(void) printf(testingFmt, "wolfSSL_EVP_get_digestbynid"); - AssertNotNull(wolfSSL_EVP_get_digestbynid(4)); /* NID_md5 */ - AssertNotNull(wolfSSL_EVP_get_digestbynid(64)); /* NID_sha1 */ - AssertNull(wolfSSL_EVP_get_digestbynid(0)); /* default */ + AssertNotNull(wolfSSL_EVP_get_digestbynid(NID_md5)); + AssertNotNull(wolfSSL_EVP_get_digestbynid(NID_sha1)); + AssertNull(wolfSSL_EVP_get_digestbynid(0)); printf(resultFmt, passed); #endif @@ -33882,7 +33881,7 @@ static void test_wolfSSL_EVP_DigestFinal_ex(void) /* Bad Case */ -#if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)) +#if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)) wolfSSL_EVP_MD_CTX_init(&mdCtx); AssertIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), 0); @@ -33909,7 +33908,7 @@ static void test_wolfSSL_EVP_DigestFinal_ex(void) static void test_wolfSSL_EVP_PKEY_assign_DH(void) { #if defined(OPENSSL_ALL) && !defined(NO_DH) && \ - !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)) + !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)) FILE* f = NULL; unsigned char buf[4096]; const unsigned char* pt = buf; @@ -33985,8 +33984,7 @@ static void test_wolfSSL_EVP_BytesToKey(void) } static void test_IncCtr(void) { -#if defined(OPENSSL_ALL) && defined(HAVE_AESGCM) && !defined(NO_DES3) &&\ - !defined(NO_DES3) +#if defined(OPENSSL_ALL) && defined(HAVE_AESGCM) && !defined(NO_DES3) byte key[DES3_KEY_SIZE] = {0}; byte iv[DES_IV_SIZE] = {0}; int type = EVP_CTRL_GCM_IV_GEN;