diff --git a/tests/api.c b/tests/api.c index d72c50bb1..856434644 100644 --- a/tests/api.c +++ b/tests/api.c @@ -2396,15 +2396,14 @@ static void test_wolfSSL_mcast(void) */ static int test_wc_InitMd5 (void) { + int flag = 0; #ifndef NO_MD5 Md5 md5; - int ret, flag; + int ret; printf(testingFmt, "wc_InitMd5()"); - flag = 0; - /* Test good arg. */ ret = wc_InitMd5(&md5); if (ret != 0) { @@ -2424,7 +2423,7 @@ static int test_wc_InitMd5 (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_InitMd5 */ /* @@ -2432,11 +2431,10 @@ static int test_wc_InitMd5 (void) */ static int test_wc_InitSha(void) { + int flag = 0; #ifndef NO_SHA Sha sha; - int ret, flag; - - flag = 0; + int ret; printf(testingFmt, "wc_InitSha()"); @@ -2459,7 +2457,7 @@ static int test_wc_InitSha(void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_InitSha */ @@ -2468,11 +2466,10 @@ static int test_wc_InitSha(void) */ static int test_wc_InitSha256 (void) { + int flag = 0; #ifndef NO_SHA256 Sha256 sha256; - int ret, flag; - - flag = 0; + int ret; printf(testingFmt, "wc_InitSha256()"); @@ -2495,7 +2492,7 @@ static int test_wc_InitSha256 (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_InitSha256 */ @@ -2504,11 +2501,10 @@ static int test_wc_InitSha256 (void) */ static int test_wc_InitSha512 (void) { + int flag = 0; #ifdef WOLFSSL_SHA512 Sha512 sha512; - int ret, flag; - - flag = 0; + int ret; printf(testingFmt, "wc_InitSha512()"); @@ -2531,7 +2527,7 @@ static int test_wc_InitSha512 (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_InitSha512 */ @@ -2540,11 +2536,10 @@ static int test_wc_InitSha512 (void) */ static int test_wc_InitSha384 (void) { + int flag = 0; #ifdef WOLFSSL_SHA384 Sha384 sha384; - int ret, flag; - - flag = 0; + int ret; printf(testingFmt, "wc_InitSha384()"); @@ -2566,7 +2561,7 @@ static int test_wc_InitSha384 (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_InitSha384 */ /* @@ -2574,11 +2569,10 @@ static int test_wc_InitSha384 (void) */ static int test_wc_InitSha224 (void) { + int flag = 0; #ifdef WOLFSSL_SHA224 Sha224 sha224; - int ret, flag; - - flag = 0; + int ret; printf(testingFmt, "wc_InitSha224()"); @@ -2600,7 +2594,7 @@ static int test_wc_InitSha224 (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_InitSha224 */ @@ -2609,11 +2603,10 @@ static int test_wc_InitSha224 (void) */ static int test_wc_InitRipeMd (void) { + int flag = 0; #ifdef WOLFSSL_RIPEMD RipeMd ripemd; - int ret, flag; - - flag = 0; + int ret; printf(testingFmt, "wc_InitRipeMd()"); @@ -2634,7 +2627,7 @@ static int test_wc_InitRipeMd (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_InitRipeMd */ @@ -2644,13 +2637,12 @@ static int test_wc_InitRipeMd (void) static int test_wc_Md5Update (void) { + int flag = 0; #ifndef NO_MD5 Md5 md5; byte hash[MD5_DIGEST_SIZE]; testVector a, b, c; - int ret, flag; - - flag = 0; + int ret; ret = wc_InitMd5(&md5); if (ret != 0) { @@ -2739,7 +2731,7 @@ static int test_wc_Md5Update (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Md5Update() */ /* @@ -2748,13 +2740,12 @@ static int test_wc_Md5Update (void) static int test_wc_ShaUpdate (void) { + int flag = 0; #ifndef NO_SHA Sha sha; byte hash[SHA_DIGEST_SIZE]; testVector a, b, c; - int ret, flag; - - flag = 0; + int ret; ret = wc_InitSha(&sha); if (ret != 0) { @@ -2843,7 +2834,7 @@ static int test_wc_ShaUpdate (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_ShaUpdate() */ @@ -2853,13 +2844,12 @@ static int test_wc_ShaUpdate (void) */ static int test_wc_Sha256Update (void) { + int flag = 0; #ifndef NO_SHA256 Sha256 sha256; byte hash[SHA256_DIGEST_SIZE]; testVector a, b, c; - int ret, flag; - - flag = 0; + int ret; ret = wc_InitSha256(&sha256); if (ret != 0) { @@ -2949,7 +2939,7 @@ static int test_wc_Sha256Update (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha256Update */ @@ -2959,13 +2949,12 @@ static int test_wc_Sha256Update (void) static int test_wc_Sha384Update (void) { + int flag = 0; #ifdef WOLFSSL_SHA384 Sha384 sha384; byte hash[SHA384_DIGEST_SIZE]; testVector a, b, c; - int ret, flag; - - flag = 0; + int ret; ret = wc_InitSha384(&sha384); if (ret != 0) { @@ -3057,7 +3046,7 @@ static int test_wc_Sha384Update (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha384Update */ /* @@ -3066,13 +3055,12 @@ static int test_wc_Sha384Update (void) static int test_wc_RipeMdUpdate (void) { + int flag = 0; #ifdef WOLFSSL_RIPEMD RipeMd ripemd; byte hash[RIPEMD_DIGEST_SIZE]; testVector a, b, c; - int ret, flag; - - flag = 0; + int ret; ret = wc_InitRipeMd(&ripemd); if (ret != 0) { @@ -3159,7 +3147,7 @@ static int test_wc_RipeMdUpdate (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_RipeMdUdpate */ @@ -3169,13 +3157,12 @@ static int test_wc_RipeMdUpdate (void) static int test_wc_Sha512Update (void) { + int flag = 0; #ifdef WOLFSSL_SHA512 Sha512 sha512; byte hash[SHA512_DIGEST_SIZE]; testVector a, b, c; - int ret, flag; - - flag = 0; + int ret; ret = wc_InitSha512(&sha512); if (ret != 0) { @@ -3268,7 +3255,7 @@ static int test_wc_Sha512Update (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha512Update */ @@ -3277,13 +3264,12 @@ static int test_wc_Sha512Update (void) */ static int test_wc_Sha224Update (void) { + int flag = 0; #ifdef WOLFSSL_SHA224 Sha224 sha224; byte hash[SHA224_DIGEST_SIZE]; testVector a, b, c; - int ret, flag; - - flag = 0; + int ret; ret = wc_InitSha224(&sha224); if (ret != 0) { @@ -3373,7 +3359,7 @@ static int test_wc_Sha224Update (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha224Update */ @@ -3383,6 +3369,7 @@ static int test_wc_Sha224Update (void) static int test_wc_Md5Final (void) { + int flag = 0; #ifndef NO_MD5 /* Instantiate */ Md5 md5; @@ -3390,9 +3377,7 @@ static int test_wc_Md5Final (void) byte hash1[MD5_DIGEST_SIZE]; byte hash2[2*MD5_DIGEST_SIZE]; byte hash3[5*MD5_DIGEST_SIZE]; - int times, i, flag, ret; - - flag = 0; + int times, i, ret; /* Initialize */ ret = wc_InitMd5(&md5); @@ -3447,7 +3432,7 @@ static int test_wc_Md5Final (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* @@ -3455,15 +3440,14 @@ static int test_wc_Md5Final (void) */ static int test_wc_ShaFinal (void) { + int flag = 0; #ifndef NO_SHA Sha sha; byte* hash_test[3]; byte hash1[SHA_DIGEST_SIZE]; byte hash2[2*SHA_DIGEST_SIZE]; byte hash3[5*SHA_DIGEST_SIZE]; - int times, i, ret, flag; - - flag = 0; + int times, i, ret; /*Initialize*/ ret = wc_InitSha(&sha); @@ -3518,7 +3502,7 @@ static int test_wc_ShaFinal (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_ShaFinal */ /* @@ -3526,15 +3510,14 @@ static int test_wc_ShaFinal (void) */ static int test_wc_Sha256Final (void) { + int flag = 0; #ifndef NO_SHA256 Sha256 sha256; byte* hash_test[3]; byte hash1[SHA256_DIGEST_SIZE]; byte hash2[2*SHA256_DIGEST_SIZE]; byte hash3[5*SHA256_DIGEST_SIZE]; - int times, i, ret, flag; - - flag = 0; + int times, i, ret; /* Initialize */ ret = wc_InitSha256(&sha256); @@ -3589,7 +3572,7 @@ static int test_wc_Sha256Final (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha256Final */ @@ -3598,15 +3581,14 @@ static int test_wc_Sha256Final (void) */ static int test_wc_Sha512Final (void) { + int flag = 0; #ifdef WOLFSSL_SHA512 Sha512 sha512; byte* hash_test[3]; byte hash1[SHA512_DIGEST_SIZE]; byte hash2[2*SHA512_DIGEST_SIZE]; byte hash3[5*SHA512_DIGEST_SIZE]; - int times, i, ret, flag; - - flag = 0; + int times, i, ret; /* Initialize */ ret = wc_InitSha512(&sha512); @@ -3659,7 +3641,7 @@ static int test_wc_Sha512Final (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha512Final */ /* @@ -3667,15 +3649,14 @@ static int test_wc_Sha512Final (void) */ static int test_wc_Sha384Final (void) { + int flag = 0; #ifdef WOLFSSL_SHA384 Sha384 sha384; byte* hash_test[3]; byte hash1[SHA384_DIGEST_SIZE]; byte hash2[2*SHA384_DIGEST_SIZE]; byte hash3[5*SHA384_DIGEST_SIZE]; - int times, i, ret, flag; - - flag = 0; + int times, i, ret; /* Initialize */ ret = wc_InitSha384(&sha384); @@ -3730,7 +3711,7 @@ static int test_wc_Sha384Final (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha384Final */ @@ -3739,15 +3720,14 @@ static int test_wc_Sha384Final (void) */ static int test_wc_RipeMdFinal (void) { + int flag = 0; #ifdef WOLFSSL_RIPEMD RipeMd ripemd; byte* hash_test[3]; byte hash1[RIPEMD_DIGEST_SIZE]; byte hash2[2*RIPEMD_DIGEST_SIZE]; byte hash3[5*RIPEMD_DIGEST_SIZE]; - int times, i, ret, flag; - - flag = 0; + int times, i, ret; /* Initialize */ ret = wc_InitRipeMd(&ripemd); @@ -3800,7 +3780,7 @@ static int test_wc_RipeMdFinal (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_RipeMdFinal */ /* @@ -3808,15 +3788,14 @@ static int test_wc_RipeMdFinal (void) */ static int test_wc_Sha224Final (void) { + int flag = 0; #ifdef WOLFSSL_SHA224 Sha224 sha224; byte* hash_test[3]; byte hash1[SHA224_DIGEST_SIZE]; byte hash2[2*SHA224_DIGEST_SIZE]; byte hash3[5*SHA224_DIGEST_SIZE]; - int times, i, ret, flag; - - flag = 0; + int times, i, ret; /* Initialize */ ret = wc_InitSha224(&sha224); @@ -3871,7 +3850,7 @@ static int test_wc_Sha224Final (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha224Final */ /* @@ -3879,6 +3858,7 @@ static int test_wc_Sha224Final (void) */ static int test_wc_IdeaSetKey (void) { + int ret = 0; #ifdef HAVE_IDEA Idea idea; @@ -3887,7 +3867,7 @@ static int test_wc_IdeaSetKey (void) 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37, 0x37 }; - int ret, flag = 0; + int flag = 0; printf(testingFmt, "wc_IdeaSetKey()"); /*IV can be NULL, default value is 0*/ @@ -3924,7 +3904,7 @@ static int test_wc_IdeaSetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_IdeaSetKey */ @@ -3933,9 +3913,9 @@ static int test_wc_IdeaSetKey (void) */ static int test_wc_IdeaSetIV (void) { + int ret = 0; #ifdef HAVE_IDEA Idea idea; - int ret; printf(testingFmt, "wc_IdeaSetIV()"); @@ -3952,7 +3932,7 @@ static int test_wc_IdeaSetIV (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_IdeaSetIV */ @@ -3961,6 +3941,7 @@ static int test_wc_IdeaSetIV (void) */ static int test_wc_IdeaCipher (void) { + int ret = 0; #ifdef HAVE_IDEA Idea idea; const byte key[] = @@ -3974,7 +3955,6 @@ static int test_wc_IdeaCipher (void) }; byte enc[sizeof(plain)]; byte dec[sizeof(enc)]; - int ret; printf(testingFmt, "wc_IdeaCipher()"); @@ -4016,7 +3996,7 @@ static int test_wc_IdeaCipher (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_IdeaCipher */ /* @@ -4024,6 +4004,7 @@ static int test_wc_IdeaCipher (void) */ static int test_wc_IdeaCbcEncyptDecrypt (void) { + int ret = 0; #ifdef HAVE_IDEA Idea idea; const byte key[] = @@ -4034,7 +4015,6 @@ static int test_wc_IdeaCbcEncyptDecrypt (void) const char* message = "International Data Encryption Algorithm"; byte msg_enc[40]; byte msg_dec[40]; - int ret; printf(testingFmt, "wc_IdeaCbcEncrypt()"); @@ -4095,7 +4075,7 @@ static int test_wc_IdeaCbcEncyptDecrypt (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_IdeaCbcEncryptDecrypt */ @@ -4105,14 +4085,17 @@ static int test_wc_IdeaCbcEncyptDecrypt (void) */ static int test_wc_Md5HmacSetKey (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_MD5) Hmac hmac; - int ret, flag, times, itr; + int ret, times, itr; const char* keys[]= { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", - "Jefe", +#ifndef HAVE_FIPS + "Jefe", /* smaller than minumum FIPS key size */ +#endif "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" }; @@ -4155,15 +4138,21 @@ static int test_wc_Md5HmacSetKey (void) if (!flag) { ret = wc_HmacSetKey(&hmac, MD5, (byte*)keys[0], 0); +#ifdef HAVE_FIPS + if (ret != HMAC_MIN_KEYLEN_E) { + flag = SSL_FATAL_ERROR; + } +#else if (ret != 0) { flag = SSL_FATAL_ERROR; } +#endif } printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Md5HmacSetKey */ @@ -4173,15 +4162,18 @@ static int test_wc_Md5HmacSetKey (void) static int test_wc_ShaHmacSetKey (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_SHA) Hmac hmac; - int ret, flag, times, itr; + int ret, times, itr; const char* keys[]= { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" "\x0b\x0b\x0b", - "Jefe", +#ifndef HAVE_FIPS + "Jefe", /* smaller than minumum FIPS key size */ +#endif "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" "\xAA\xAA\xAA" }; @@ -4225,15 +4217,21 @@ static int test_wc_ShaHmacSetKey (void) if (!flag) { ret = wc_HmacSetKey(&hmac, SHA, (byte*)keys[0], 0); +#ifdef HAVE_FIPS + if (ret != HMAC_MIN_KEYLEN_E) { + flag = SSL_FATAL_ERROR; + } +#else if (ret != 0) { flag = SSL_FATAL_ERROR; } +#endif } printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_ShaHmacSetKey() */ /* @@ -4242,15 +4240,18 @@ static int test_wc_ShaHmacSetKey (void) static int test_wc_Sha224HmacSetKey (void) { + int flag = 0; #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224) Hmac hmac; - int ret, flag, times, itr; + int ret, times, itr; const char* keys[]= { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" "\x0b\x0b\x0b", - "Jefe", +#ifndef HAVE_FIPS + "Jefe", /* smaller than minumum FIPS key size */ +#endif "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" "\xAA\xAA\xAA" }; @@ -4294,15 +4295,21 @@ static int test_wc_Sha224HmacSetKey (void) if (!flag) { ret = wc_HmacSetKey(&hmac, SHA224, (byte*)keys[0], 0); +#ifdef HAVE_FIPS + if (ret != HMAC_MIN_KEYLEN_E) { + flag = SSL_FATAL_ERROR; + } +#else if (ret != 0) { flag = SSL_FATAL_ERROR; } +#endif } printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha224HmacSetKey() */ /* @@ -4311,15 +4318,18 @@ static int test_wc_Sha224HmacSetKey (void) static int test_wc_Sha256HmacSetKey (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_SHA256) Hmac hmac; - int ret, flag, times, itr; + int ret, times, itr; const char* keys[]= { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" "\x0b\x0b\x0b", - "Jefe", +#ifndef HAVE_FIPS + "Jefe", /* smaller than minumum FIPS key size */ +#endif "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" "\xAA\xAA\xAA" }; @@ -4363,15 +4373,21 @@ static int test_wc_Sha256HmacSetKey (void) if (!flag) { ret = wc_HmacSetKey(&hmac, SHA256, (byte*)keys[0], 0); +#ifdef HAVE_FIPS + if (ret != HMAC_MIN_KEYLEN_E) { + flag = SSL_FATAL_ERROR; + } +#else if (ret != 0) { flag = SSL_FATAL_ERROR; } +#endif } printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha256HmacSetKey() */ @@ -4380,15 +4396,18 @@ static int test_wc_Sha256HmacSetKey (void) */ static int test_wc_Sha384HmacSetKey (void) { + int flag = 0; #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384) Hmac hmac; - int ret, flag, times, itr; + int ret, times, itr; const char* keys[]= { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" "\x0b\x0b\x0b", - "Jefe", +#ifndef HAVE_FIPS + "Jefe", /* smaller than minumum FIPS key size */ +#endif "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" "\xAA\xAA\xAA" }; @@ -4432,15 +4451,21 @@ static int test_wc_Sha384HmacSetKey (void) if (!flag) { ret = wc_HmacSetKey(&hmac, SHA384, (byte*)keys[0], 0); +#ifdef HAVE_FIPS + if (ret != HMAC_MIN_KEYLEN_E) { + flag = SSL_FATAL_ERROR; + } +#else if (ret != 0) { flag = SSL_FATAL_ERROR; } +#endif } printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha384HmacSetKey() */ @@ -4449,11 +4474,17 @@ static int test_wc_Sha384HmacSetKey (void) */ static int test_wc_Md5HmacUpdate (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_MD5) Hmac hmac; testVector a, b; - int ret, flag; + int ret; +#ifdef HAVE_FIPS + const char* keys = + "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; +#else const char* keys = "Jefe"; +#endif a.input = "what do ya want for nothing?"; a.inLen = XSTRLEN(a.input); @@ -4509,7 +4540,7 @@ static int test_wc_Md5HmacUpdate (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Md5HmacUpdate */ /* @@ -4517,11 +4548,17 @@ static int test_wc_Md5HmacUpdate (void) */ static int test_wc_ShaHmacUpdate (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_SHA) Hmac hmac; testVector a, b; - int ret, flag; + int ret; +#ifdef HAVE_FIPS + const char* keys = + "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; +#else const char* keys = "Jefe"; +#endif a.input = "what do ya want for nothing?"; a.inLen = XSTRLEN(a.input); @@ -4577,7 +4614,7 @@ static int test_wc_ShaHmacUpdate (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_ShaHmacUpdate */ /* @@ -4585,11 +4622,17 @@ static int test_wc_ShaHmacUpdate (void) */ static int test_wc_Sha224HmacUpdate (void) { + int flag = 0; #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224) Hmac hmac; testVector a, b; - int ret, flag; + int ret; +#ifdef HAVE_FIPS + const char* keys = + "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; +#else const char* keys = "Jefe"; +#endif a.input = "what do ya want for nothing?"; a.inLen = XSTRLEN(a.input); @@ -4645,7 +4688,7 @@ static int test_wc_Sha224HmacUpdate (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha224HmacUpdate */ /* @@ -4653,11 +4696,17 @@ static int test_wc_Sha224HmacUpdate (void) */ static int test_wc_Sha256HmacUpdate (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_SHA256) Hmac hmac; testVector a, b; - int ret, flag; + int ret; +#ifdef HAVE_FIPS + const char* keys = + "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; +#else const char* keys = "Jefe"; +#endif a.input = "what do ya want for nothing?"; a.inLen = XSTRLEN(a.input); @@ -4713,7 +4762,7 @@ static int test_wc_Sha256HmacUpdate (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha256HmacUpdate */ /* @@ -4721,11 +4770,17 @@ static int test_wc_Sha256HmacUpdate (void) */ static int test_wc_Sha384HmacUpdate (void) { + int flag = 0; #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384) Hmac hmac; testVector a, b; - int ret, flag; + int ret; +#ifdef HAVE_FIPS + const char* keys = + "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; +#else const char* keys = "Jefe"; +#endif a.input = "what do ya want for nothing?"; a.inLen = XSTRLEN(a.input); @@ -4781,7 +4836,7 @@ static int test_wc_Sha384HmacUpdate (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha384HmacUpdate */ /* @@ -4790,11 +4845,12 @@ static int test_wc_Sha384HmacUpdate (void) static int test_wc_Md5HmacFinal (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_MD5) Hmac hmac; byte hash[MD5_DIGEST_SIZE]; testVector a; - int ret, flag; + int ret; const char* key; key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; @@ -4852,7 +4908,7 @@ static int test_wc_Md5HmacFinal (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Md5HmacFinal */ @@ -4861,11 +4917,12 @@ static int test_wc_Md5HmacFinal (void) */ static int test_wc_ShaHmacFinal (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_SHA) Hmac hmac; byte hash[SHA_DIGEST_SIZE]; testVector a; - int ret, flag; + int ret; const char* key; key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" @@ -4924,7 +4981,7 @@ static int test_wc_ShaHmacFinal (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_ShaHmacFinal */ @@ -4934,11 +4991,12 @@ static int test_wc_ShaHmacFinal (void) */ static int test_wc_Sha224HmacFinal (void) { + int flag = 0; #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224) Hmac hmac; byte hash[SHA224_DIGEST_SIZE]; testVector a; - int ret, flag; + int ret; const char* key; key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" @@ -4997,7 +5055,7 @@ static int test_wc_Sha224HmacFinal (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha224HmacFinal */ /* @@ -5005,11 +5063,12 @@ static int test_wc_Sha224HmacFinal (void) */ static int test_wc_Sha256HmacFinal (void) { + int flag = 0; #if !defined(NO_HMAC) && !defined(NO_SHA256) Hmac hmac; byte hash[SHA256_DIGEST_SIZE]; testVector a; - int ret, flag; + int ret; const char* key; key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" @@ -5069,7 +5128,7 @@ static int test_wc_Sha256HmacFinal (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha256HmacFinal */ /* @@ -5077,11 +5136,12 @@ static int test_wc_Sha256HmacFinal (void) */ static int test_wc_Sha384HmacFinal (void) { + int flag = 0; #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384) Hmac hmac; byte hash[SHA384_DIGEST_SIZE]; testVector a; - int ret, flag; + int ret; const char* key; key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" @@ -5141,7 +5201,7 @@ static int test_wc_Sha384HmacFinal (void) printf(resultFmt, flag == 0 ? passed : failed); #endif - return 0; + return flag; } /* END test_wc_Sha384HmacFinal */ @@ -5151,9 +5211,9 @@ static int test_wc_Sha384HmacFinal (void) */ static int test_wc_Des3_SetIV (void) { + int ret = 0; #ifndef NO_DES3 Des3 des; - int ret; const byte key[] = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, @@ -5179,6 +5239,7 @@ static int test_wc_Des3_SetIV (void) } } +#ifndef HAVE_FIPS /* no sanity checks with FIPS wrapper */ /* Test explicitly wc_Des3_SetIV() */ if (ret == 0) { ret = wc_Des3_SetIV(NULL, iv); @@ -5188,11 +5249,12 @@ static int test_wc_Des3_SetIV (void) ret = SSL_FATAL_ERROR; } } +#endif printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_Des3_SetIV */ @@ -5201,9 +5263,9 @@ static int test_wc_Des3_SetIV (void) */ static int test_wc_Des3_SetKey (void) { + int ret = 0; #ifndef NO_DES3 Des3 des; - int ret; const byte key[] = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, @@ -5246,7 +5308,7 @@ static int test_wc_Des3_SetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_Des3_SetKey */ @@ -5255,11 +5317,11 @@ static int test_wc_Des3_SetKey (void) */ static int test_wc_Des3_CbcEncryptDecrypt (void) { + int ret = 0; #ifndef NO_DES3 Des3 des; byte cipher[24]; byte plain[24]; - int ret; const byte key[] = { @@ -5336,7 +5398,7 @@ static int test_wc_Des3_CbcEncryptDecrypt (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END wc_Des3_CbcEncrypt */ @@ -5345,6 +5407,7 @@ static int test_wc_Des3_CbcEncryptDecrypt (void) */ static int test_wc_Des3_CbcEncryptDecryptWithKey (void) { + int ret = 0; #ifndef NO_DES3 word32 vectorSz, cipherSz; @@ -5372,7 +5435,6 @@ static int test_wc_Des3_CbcEncryptDecryptWithKey (void) 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81 }; - int ret; vectorSz = sizeof(byte) * 24; cipherSz = sizeof(byte) * 24; @@ -5425,7 +5487,7 @@ static int test_wc_Des3_CbcEncryptDecryptWithKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_Des3_CbcEncryptDecryptWithKey */ @@ -5434,6 +5496,7 @@ static int test_wc_Des3_CbcEncryptDecryptWithKey (void) */ static int test_wc_Chacha_SetKey (void) { + int ret = 0; #ifdef HAVE_CHACHA ChaCha ctx; const byte key[] = @@ -5444,7 +5507,6 @@ static int test_wc_Chacha_SetKey (void) 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01 }; byte cipher[128]; - int ret; printf(testingFmt, "wc_Chacha_SetKey()"); @@ -5462,6 +5524,9 @@ static int test_wc_Chacha_SetKey (void) } } printf(resultFmt, ret == 0 ? passed : failed); + if (ret != 0) { + return ret; + } printf(testingFmt, "wc_Chacha_SetIV"); ret = wc_Chacha_SetIV(&ctx, cipher, 0); @@ -5477,7 +5542,7 @@ static int test_wc_Chacha_SetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_Chacha_SetKey */ /* @@ -5485,11 +5550,11 @@ static int test_wc_Chacha_SetKey (void) */ static int test_wc_Chacha_Process (void) { + int ret = 0; #ifdef HAVE_CHACHA ChaCha enc, dec; byte cipher[128]; byte plain[128]; - int ret; const byte key[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -5539,7 +5604,7 @@ static int test_wc_Chacha_Process (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_Chacha_Process */ /* @@ -5547,6 +5612,7 @@ static int test_wc_Chacha_Process (void) */ static int test_wc_ChaCha20Poly1305_aead (void) { + int ret = 0; #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) const byte key[] = { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, @@ -5606,7 +5672,6 @@ static int test_wc_ChaCha20Poly1305_aead (void) byte generatedCiphertext[272]; byte generatedPlaintext[272]; byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE]; - int ret; /* Initialize stack variables. */ XMEMSET(generatedCiphertext, 0, 272); @@ -5652,6 +5717,9 @@ static int test_wc_ChaCha20Poly1305_aead (void) } } printf(resultFmt, ret == 0 ? passed : failed); + if (ret != 0) { + return ret; + } printf(testingFmt, "wc_ChaCha20Poly1305_Decrypt()"); ret = wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher, @@ -5694,7 +5762,7 @@ static int test_wc_ChaCha20Poly1305_aead (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test-wc_ChaCha20Poly1305_EncryptDecrypt */ @@ -5704,6 +5772,7 @@ static int test_wc_ChaCha20Poly1305_aead (void) */ static int test_wc_AesSetIV (void) { + int ret = 0; #ifndef NO_AES Aes aes; byte key16[] = @@ -5713,7 +5782,6 @@ static int test_wc_AesSetIV (void) }; byte iv1[] = "1234567890abcdef"; byte iv2[] = "0987654321fedcba"; - int ret; printf(testingFmt, "wc_AesSetIV()"); @@ -5736,7 +5804,7 @@ static int test_wc_AesSetIV (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* test_wc_AesSetIV */ @@ -5745,6 +5813,7 @@ static int test_wc_AesSetIV (void) */ static int test_wc_AesSetKey (void) { + int ret = 0; #ifndef NO_AES Aes aes; byte key16[] = @@ -5771,7 +5840,6 @@ static int test_wc_AesSetKey (void) 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65 }; byte iv[] = "1234567890abcdef"; - int ret; printf(testingFmt, "wc_AesSetKey()"); @@ -5807,7 +5875,7 @@ static int test_wc_AesSetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_AesSetKey */ @@ -5818,6 +5886,7 @@ static int test_wc_AesSetKey (void) */ static int test_wc_AesCbcEncryptDecrypt (void) { + int ret = 0; #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT) Aes aes; byte key32[] = @@ -5840,7 +5909,6 @@ static int test_wc_AesCbcEncryptDecrypt (void) int cbcD = SSL_FATAL_ERROR; int cbcDWK = SSL_FATAL_ERROR; byte dec2[sizeof(vector)]; - int ret; /* Init stack variables. */ XMEMSET(enc, 0, sizeof(enc)); @@ -5895,6 +5963,9 @@ static int test_wc_AesCbcEncryptDecrypt (void) } } printf(resultFmt, cbcE == 0 ? passed : failed); + if (cbcE != 0) { + return cbcE; + } printf(testingFmt, "wc_AesCbcDecrypt()"); if (cbcD == 0) { @@ -5915,6 +5986,9 @@ static int test_wc_AesCbcEncryptDecrypt (void) } } printf(resultFmt, cbcD == 0 ? passed : failed); + if (cbcD != 0) { + return cbcD; + } printf(testingFmt, "wc_AesCbcDecryptWithKey()"); if (cbcDWK == 0) { @@ -5938,9 +6012,12 @@ static int test_wc_AesCbcEncryptDecrypt (void) cbcDWK = SSL_FATAL_ERROR; } } - printf(resultFmt, cbcDWK == 0 ? passed : failed); + printf(resultFmt, cbcDWK == 0 ? passed : failed); + if (cbcDWK != 0) { + return cbcDWK; + } #endif - return 0; + return ret; } /* END test_wc_AesCbcEncryptDecrypt */ /* @@ -5948,6 +6025,7 @@ static int test_wc_AesCbcEncryptDecrypt (void) */ static int test_wc_AesCtrEncryptDecrypt (void) { + int ret = 0; #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) Aes aesEnc, aesDec; byte key32[] = @@ -5966,7 +6044,6 @@ static int test_wc_AesCtrEncryptDecrypt (void) byte iv[] = "1234567890abcdef"; byte enc[AES_BLOCK_SIZE * 2]; byte dec[AES_BLOCK_SIZE * 2]; - int ret; /* Init stack variables. */ XMEMSET(enc, 0, AES_BLOCK_SIZE * 2); @@ -6017,7 +6094,7 @@ static int test_wc_AesCtrEncryptDecrypt (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_AesCtrEncryptDecrypt */ @@ -6026,6 +6103,7 @@ static int test_wc_AesCtrEncryptDecrypt (void) */ static int test_wc_AesGcmSetKey (void) { + int ret = 0; #if !defined(NO_AES) && defined(HAVE_AESGCM) Aes aes; @@ -6065,7 +6143,6 @@ static int test_wc_AesGcmSetKey (void) 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65 }; - int ret; printf(testingFmt, "wc_AesGcmSetKey()"); @@ -6096,7 +6173,7 @@ static int test_wc_AesGcmSetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_AesGcmSetKey */ /* @@ -6104,6 +6181,7 @@ static int test_wc_AesGcmSetKey (void) */ static int test_wc_AesGcmEncryptDecrypt (void) { + int ret = 0; #if !defined(NO_AES) && defined(HAVE_AESGCM) Aes aes; @@ -6131,7 +6209,6 @@ static int test_wc_AesGcmEncryptDecrypt (void) byte enc[sizeof(vector)]; byte resultT[AES_BLOCK_SIZE]; byte dec[sizeof(vector)]; - int ret; int gcmD = SSL_FATAL_ERROR; int gcmE = SSL_FATAL_ERROR; @@ -6185,6 +6262,10 @@ static int test_wc_AesGcmEncryptDecrypt (void) } /* END wc_AesGcmEncrypt */ printf(resultFmt, gcmE == 0 ? passed : failed); + if (gcmE != 0) { + return gcmE; + } + #ifdef HAVE_AES_DECRYPT printf(testingFmt, "wc_AesGcmDecrypt()"); @@ -6227,7 +6308,7 @@ static int test_wc_AesGcmEncryptDecrypt (void) printf(resultFmt, gcmD == 0 ? passed : failed); #endif /* HAVE_AES_DECRYPT */ #endif - return 0; + return ret; } /* END test_wc_AesGcmEncryptDecrypt */ @@ -6236,6 +6317,7 @@ static int test_wc_AesGcmEncryptDecrypt (void) */ static int test_wc_GmacSetKey (void) { + int ret = 0; #if !defined(NO_AES) && defined(HAVE_AESGCM) Gmac gmac; byte key16[] = @@ -6274,7 +6356,6 @@ static int test_wc_GmacSetKey (void) 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 }; - int ret; printf(testingFmt, "wc_GmacSetKey()"); @@ -6311,7 +6392,7 @@ static int test_wc_GmacSetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_GmacSetKey */ @@ -6320,6 +6401,7 @@ static int test_wc_GmacSetKey (void) */ static int test_wc_GmacUpdate (void) { + int ret = 0; #if !defined(NO_AES) && defined(HAVE_AESGCM) Gmac gmac; const byte key16[] = @@ -6388,7 +6470,6 @@ static int test_wc_GmacUpdate (void) byte tagOut[16]; byte tagOut2[24]; byte tagOut3[32]; - int ret; /* Init stack varaibles. */ XMEMSET(tagOut, 0, sizeof(tagOut)); @@ -6450,7 +6531,7 @@ static int test_wc_GmacUpdate (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_GmacUpdate */ @@ -6460,6 +6541,7 @@ static int test_wc_GmacUpdate (void) */ static int test_wc_CamelliaSetKey (void) { + int ret = 0; #ifdef HAVE_CAMELLIA Camellia camellia; /*128-bit key*/ @@ -6488,7 +6570,6 @@ static int test_wc_CamelliaSetKey (void) 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; - int ret; printf(testingFmt, "wc_CamelliaSetKey()"); @@ -6526,7 +6607,7 @@ static int test_wc_CamelliaSetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_CammeliaSetKey */ @@ -6535,6 +6616,7 @@ static int test_wc_CamelliaSetKey (void) */ static int test_wc_CamelliaSetIV (void) { + int ret = 0; #ifdef HAVE_CAMELLIA Camellia camellia; static const byte iv[] = @@ -6542,7 +6624,6 @@ static int test_wc_CamelliaSetIV (void) 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; - int ret; printf(testingFmt, "wc_CamelliaSetIV()"); @@ -6563,7 +6644,7 @@ static int test_wc_CamelliaSetIV (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /*END test_wc_CamelliaSetIV*/ /* @@ -6571,6 +6652,7 @@ static int test_wc_CamelliaSetIV (void) */ static int test_wc_CamelliaEncryptDecryptDirect (void) { + int ret = 0; #ifdef HAVE_CAMELLIA Camellia camellia; static const byte key24[] = @@ -6593,7 +6675,6 @@ static int test_wc_CamelliaEncryptDecryptDirect (void) byte dec[sizeof(enc)]; int camE = SSL_FATAL_ERROR; int camD = SSL_FATAL_ERROR; - int ret; /*Init stack variables.*/ XMEMSET(enc, 0, 16); @@ -6627,6 +6708,10 @@ static int test_wc_CamelliaEncryptDecryptDirect (void) } printf(resultFmt, camE == 0 ? passed : failed); + if (camE != 0) { + return camE; + } + printf(testingFmt, "wc_CamelliaDecryptDirect()"); if (ret == 0) { @@ -6645,9 +6730,12 @@ static int test_wc_CamelliaEncryptDecryptDirect (void) } printf(resultFmt, camD == 0 ? passed : failed); + if (camD != 0) { + return camD; + } #endif - return 0; + return ret; } /* END test-wc_CamelliaEncryptDecryptDirect */ @@ -6656,6 +6744,7 @@ static int test_wc_CamelliaEncryptDecryptDirect (void) */ static int test_wc_CamelliaCbcEncryptDecrypt (void) { + int ret = 0; #ifdef HAVE_CAMELLIA Camellia camellia; static const byte key24[] = @@ -6673,7 +6762,6 @@ static int test_wc_CamelliaCbcEncryptDecrypt (void) byte dec[CAMELLIA_BLOCK_SIZE]; int camCbcE = SSL_FATAL_ERROR; int camCbcD = SSL_FATAL_ERROR; - int ret; /* Init stack variables. */ XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE); @@ -6716,6 +6804,10 @@ static int test_wc_CamelliaCbcEncryptDecrypt (void) } printf(resultFmt, camCbcE == 0 ? passed : failed); + if (camCbcE != 0) { + return camCbcE; + } + printf(testingFmt, "wc_CamelliaCbcDecrypt()"); if (ret == 0) { @@ -6736,9 +6828,12 @@ static int test_wc_CamelliaCbcEncryptDecrypt (void) } /* END bad args. */ printf(resultFmt, camCbcD == 0 ? passed : failed); + if (camCbcD != 0) { + return camCbcD; + } #endif - return 0; + return ret; } /* END test_wc_CamelliaCbcEncryptDecrypt */ @@ -6747,9 +6842,9 @@ static int test_wc_CamelliaCbcEncryptDecrypt (void) */ static int test_wc_RabbitSetKey (void) { + int ret = 0; #ifndef NO_RABBIT Rabbit rabbit; - int ret; const char* key = "\xAC\xC3\x51\xDC\xF1\x62\xFC\x3B" "\xFE\x36\x3D\x2E\x29\x13\x28\x91"; const char* iv = "\x59\x7E\x26\xC1\x75\xF5\x73\xC3"; @@ -6772,7 +6867,7 @@ static int test_wc_RabbitSetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RabbitSetKey */ @@ -6781,11 +6876,11 @@ static int test_wc_RabbitSetKey (void) */ static int test_wc_RabbitProcess (void) { + int ret = 0; #ifndef NO_RABBIT Rabbit enc, dec; byte cipher[25]; byte plain[25]; - int ret; const char* key = "\xAC\xC3\x51\xDC\xF1\x62\xFC\x3B" "\xFE\x36\x3D\x2E\x29\x13\x28\x91"; const char* iv = "\x59\x7E\x26\xC1\x75\xF5\x73\xC3"; @@ -6832,7 +6927,7 @@ static int test_wc_RabbitProcess (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RabbitProcess */ @@ -6845,6 +6940,7 @@ static int test_wc_RabbitProcess (void) */ static int test_wc_Arc4SetKey (void) { + int ret = 0; #ifndef NO_RC4 Arc4 arc; const char* key[] = @@ -6852,7 +6948,6 @@ static int test_wc_Arc4SetKey (void) "\x01\x23\x45\x67\x89\xab\xcd\xef" }; int keyLen = 8; - int ret; printf(testingFmt, "wc_Arch4SetKey()"); @@ -6874,7 +6969,7 @@ static int test_wc_Arc4SetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_Arc4SetKey */ @@ -6883,13 +6978,13 @@ static int test_wc_Arc4SetKey (void) */ static int test_wc_Arc4Process (void) { + int ret = 0; #ifndef NO_RC4 Arc4 enc, dec; const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef"; const char* input = "\x01\x23\x45\x67\x89\xab\xcd\xef"; byte cipher[8]; byte plain[8]; - int ret; /* Init stack variables */ XMEMSET(cipher, 0, sizeof(cipher)); @@ -6949,7 +7044,7 @@ static int test_wc_Arc4Process (void) wc_Arc4Free(&dec); #endif - return 0; + return ret; }/* END test_wc_Arc4Process */ @@ -6959,9 +7054,9 @@ static int test_wc_Arc4Process (void) */ static int test_wc_InitRsaKey (void) { + int ret = 0; #ifndef NO_RSA RsaKey key; - int ret; printf(testingFmt, "wc_InitRsaKey()"); @@ -6990,7 +7085,7 @@ static int test_wc_InitRsaKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_InitRsaKey */ @@ -6999,12 +7094,12 @@ static int test_wc_InitRsaKey (void) */ static int test_wc_RsaPrivateKeyDecode (void) { + int ret = 0; #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\ || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS) RsaKey key; byte* tmp; word32 idx = 0; - int ret = 0; int bytes = 0; printf(testingFmt, "wc_RsaPrivateKeyDecode()"); @@ -7071,7 +7166,7 @@ static int test_wc_RsaPrivateKeyDecode (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaPrivateKeyDecode */ @@ -7080,13 +7175,13 @@ static int test_wc_RsaPrivateKeyDecode (void) */ static int test_wc_RsaPublicKeyDecode (void) { + int ret = 0; #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\ || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS) RsaKey keyPub; byte* tmp; word32 idx = 0; int bytes = 0; - int ret = 0; tmp = (byte*)XMALLOC(GEN_BUF, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) { @@ -7153,7 +7248,7 @@ static int test_wc_RsaPublicKeyDecode (void) #endif - return 0; + return ret; } /* END test_wc_RsaPublicKeyDecode */ @@ -7162,9 +7257,9 @@ static int test_wc_RsaPublicKeyDecode (void) */ static int test_wc_RsaPublicKeyDecodeRaw (void) { + int ret = 0; #if !defined(NO_RSA) RsaKey key; - int ret; const byte n = 0x23; const byte e = 0x03; int nSz = sizeof(n); @@ -7217,7 +7312,7 @@ static int test_wc_RsaPublicKeyDecodeRaw (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaPublicKeyDecodeRaw */ @@ -7226,11 +7321,11 @@ static int test_wc_RsaPublicKeyDecodeRaw (void) */ static int test_wc_MakeRsaKey (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey genKey; WC_RNG rng; - int ret; printf(testingFmt, "wc_MakeRsaKey()"); @@ -7295,7 +7390,7 @@ static int test_wc_MakeRsaKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_MakeRsaKey */ @@ -7304,9 +7399,9 @@ static int test_wc_MakeRsaKey (void) */ static int test_wc_SetKeyUsage (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_CERT_EXT) && !defined(HAVE_FIPS) Cert myCert; - int ret; ret = wc_InitCert(&myCert); @@ -7351,7 +7446,7 @@ static int test_wc_SetKeyUsage (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_SetKeyUsage */ @@ -7360,11 +7455,11 @@ static int test_wc_SetKeyUsage (void) */ static int test_wc_RsaKeyToDer (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey genKey; WC_RNG rng; byte* der; - int ret = 0; der = (byte*)XMALLOC(610, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { @@ -7446,7 +7541,7 @@ static int test_wc_RsaKeyToDer (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaKeyToDer */ /* @@ -7454,12 +7549,12 @@ static int test_wc_RsaKeyToDer (void) */ static int test_wc_RsaKeyToPublicDer (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey key; WC_RNG rng; byte* der; word32 derLen = 162; - int ret = 0; der = (byte*)XMALLOC(derLen, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (der == NULL) { @@ -7533,7 +7628,7 @@ static int test_wc_RsaKeyToPublicDer (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaKeyToPublicDer */ @@ -7542,6 +7637,7 @@ static int test_wc_RsaKeyToPublicDer (void) */ static int test_wc_RsaPublicEncryptDecrypt (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey key; WC_RNG rng; @@ -7549,7 +7645,6 @@ static int test_wc_RsaPublicEncryptDecrypt (void) word32 cipherLen = 128; word32 plainLen = 25; word32 inLen = (word32)XSTRLEN(inStr); - int ret; DECLARE_VAR_INIT(in, byte, inLen, inStr, NULL); DECLARE_VAR(plain, byte, plainLen, NULL); @@ -7578,6 +7673,9 @@ static int test_wc_RsaPublicEncryptDecrypt (void) /* Pass bad args. */ /* Tests PsaPublicEncryptEx() which, is tested by another fn. No need dup.*/ printf(resultFmt, ret == 0 ? passed : failed); + if (ret != 0) { + return ret; + } /* Decrypt */ printf(testingFmt, "wc_RsaPrivateDecrypt()"); @@ -7610,7 +7708,7 @@ static int test_wc_RsaPublicEncryptDecrypt (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaPublicEncryptDecrypt */ @@ -7619,6 +7717,7 @@ static int test_wc_RsaPublicEncryptDecrypt (void) */ static int test_wc_RsaPublicEncryptDecrypt_ex (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS)\ && !defined(WC_NO_RSA_OAEP) && !defined(HAVE_USER_RSA) RsaKey key; @@ -7628,7 +7727,6 @@ static int test_wc_RsaPublicEncryptDecrypt_ex (void) const word32 cipherSz = 128; const word32 plainSz = 25; byte* res = NULL; - int ret = 0; int idx = 0; DECLARE_VAR_INIT(in, byte, inLen, inStr, NULL); @@ -7662,6 +7760,9 @@ static int test_wc_RsaPublicEncryptDecrypt_ex (void) /*Pass bad args.*/ /* Tests RsaPublicEncryptEx again. No need duplicate. */ printf(resultFmt, ret == 0 ? passed : failed); + if (ret != 0) { + return ret; + } /* Decrypt */ printf(testingFmt, "wc_RsaPrivateDecrypt_ex()"); @@ -7686,6 +7787,9 @@ static int test_wc_RsaPublicEncryptDecrypt_ex (void) /*Pass bad args.*/ /* Tests RsaPrivateDecryptEx() again. No need duplicate. */ printf(resultFmt, ret == 0 ? passed : failed); + if (ret != 0) { + return ret; + } printf(testingFmt, "wc_RsaPrivateDecryptInline_ex()"); if (ret == 0) { @@ -7715,7 +7819,7 @@ static int test_wc_RsaPublicEncryptDecrypt_ex (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaPublicEncryptDecrypt_ex */ @@ -7724,6 +7828,7 @@ static int test_wc_RsaPublicEncryptDecrypt_ex (void) */ static int test_wc_RsaSSL_SignVerify (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey key; WC_RNG rng; @@ -7732,7 +7837,6 @@ static int test_wc_RsaSSL_SignVerify (void) const word32 plainSz = 25; word32 inLen = (word32)XSTRLEN(inStr); word32 idx = 0; - int ret; DECLARE_VAR_INIT(in, byte, inLen, inStr, NULL); DECLARE_VAR(out, byte, outSz, NULL); @@ -7799,6 +7903,9 @@ static int test_wc_RsaSSL_SignVerify (void) } #endif printf(resultFmt, ret == 0 ? passed : failed); + if (ret != 0) { + return ret; + } /* Verify. */ printf(testingFmt, "wc_RsaSSL_Verify()"); @@ -7864,7 +7971,7 @@ static int test_wc_RsaSSL_SignVerify (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaSSL_SignVerify */ @@ -7873,10 +7980,10 @@ static int test_wc_RsaSSL_SignVerify (void) */ static int test_wc_RsaEncryptSize (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey key; WC_RNG rng; - int ret; int enc128 = 128; int enc512 = 512; @@ -7938,7 +8045,7 @@ static int test_wc_RsaEncryptSize (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaEncryptSize*/ @@ -7947,10 +8054,10 @@ static int test_wc_RsaEncryptSize (void) */ static int test_wc_RsaFlattenPublicKey (void) { + int ret = 0; #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) RsaKey key; WC_RNG rng; - int ret; byte e[256]; byte n[256]; word32 eSz = sizeof(e); @@ -8030,7 +8137,7 @@ static int test_wc_RsaFlattenPublicKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_RsaFlattenPublicKey */ @@ -8041,6 +8148,7 @@ static int test_wc_RsaFlattenPublicKey (void) */ static int test_wc_AesCcmSetKey (void) { + int ret = 0; #ifdef HAVE_AESCCM Aes aes; const byte key16[] = @@ -8061,7 +8169,6 @@ static int test_wc_AesCcmSetKey (void) 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 }; - int ret; printf(testingFmt, "wc_AesCcmSetKey()"); @@ -8092,7 +8199,7 @@ static int test_wc_AesCcmSetKey (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_AesCcmSetKey */ @@ -8101,6 +8208,7 @@ static int test_wc_AesCcmSetKey (void) */ static int test_wc_AesCcmEncryptDecrypt (void) { + int ret = 0; #ifdef HAVE_AESCCM Aes aes; const byte key16[] = @@ -8138,7 +8246,6 @@ static int test_wc_AesCcmEncryptDecrypt (void) byte cipherOut[sizeof(plainT)]; byte authTag[sizeof(t)]; int ccmE = SSL_FATAL_ERROR; - int ret; #ifdef HAVE_AES_DECRYPT int ccmD = SSL_FATAL_ERROR; byte plainOut[sizeof(cipherOut)]; @@ -8213,6 +8320,9 @@ static int test_wc_AesCcmEncryptDecrypt (void) } /* End Encrypt */ printf(resultFmt, ccmE == 0 ? passed : failed); + if (ccmE != 0) { + return ccmE; + } #ifdef HAVE_AES_DECRYPT printf(testingFmt, "wc_AesCcmDecrypt()"); @@ -8262,11 +8372,14 @@ static int test_wc_AesCcmEncryptDecrypt (void) } /* END Decrypt */ printf(resultFmt, ccmD == 0 ? passed : failed); + if (ccmD != 0) { + return ccmD; + } #endif #endif /* HAVE_AESCCM */ - return 0; + return ret; } /* END test_wc_AesCcmEncryptDecrypt */ @@ -8277,13 +8390,13 @@ static int test_wc_AesCcmEncryptDecrypt (void) */ static int test_wc_Hc128_SetKey (void) { + int ret = 0; #ifdef HAVE_HC128 HC128 ctx; const char* key = "\x80\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00"; const char* iv = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE" "\x45\xAC\x13\x7A\xE1\x48\xAF\x16"; - int ret; printf(testingFmt, "wc_Hc128_SetKey()"); ret = wc_Hc128_SetKey(&ctx, (byte*)key, (byte*)iv); @@ -8302,7 +8415,7 @@ static int test_wc_Hc128_SetKey (void) #endif - return 0; + return ret; } /* END test_wc_Hc128_SetKey */ @@ -8311,6 +8424,7 @@ static int test_wc_Hc128_SetKey (void) */ static int test_wc_Hc128_Process (void) { + int ret = 0; #ifdef HAVE_HC128 HC128 enc; HC128 dec; @@ -8320,7 +8434,6 @@ static int test_wc_Hc128_Process (void) size_t inlen = XSTRLEN(input); byte cipher[inlen]; byte plain[inlen]; - int ret; printf(testingFmt, "wc_Hc128_Process()"); ret = wc_Hc128_SetKey(&enc, (byte*)key, NULL); @@ -8353,7 +8466,7 @@ static int test_wc_Hc128_Process (void) printf(resultFmt, ret == 0 ? passed : failed); #endif - return 0; + return ret; } /* END test_wc_Hc128_Process */