Added unit tests for Random.c

This commit is contained in:
Ethan Looney
2020-07-15 12:55:19 -07:00
parent 4938baa892
commit 7a642e2b78

View File

@ -9018,7 +9018,7 @@ static int test_wc_Sha3_512_Copy (void)
/* /*
* Unit test function for wc_Sha3_GetFlags() * Unit test function for wc_Sha3_GetFlags()
*/ */
static int test_wc_Sha3_GetFlags (void) static int test_wc_Sha3_GetFlags (void)
{ {
int ret = 0; int ret = 0;
#if defined(WOLFSSL_SHA3) && \ #if defined(WOLFSSL_SHA3) && \
@ -9026,9 +9026,9 @@ static int test_wc_Sha3_GetFlags (void)
wc_Sha3 sha3; wc_Sha3 sha3;
word32 flags = 0; word32 flags = 0;
printf(testingFmt, "wc_Sha3_GetFlags()"); printf(testingFmt, "wc_Sha3_GetFlags()");
/* Initialize */ /* Initialize */
ret = wc_InitSha3_224(&sha3, HEAP_HINT, devId); ret = wc_InitSha3_224(&sha3, HEAP_HINT, devId);
if (ret != 0) { if (ret != 0) {
@ -9042,7 +9042,7 @@ static int test_wc_Sha3_GetFlags (void)
ret = 0; ret = 0;
} }
} }
wc_Sha3_224_Free(&sha3); wc_Sha3_224_Free(&sha3);
printf(resultFmt, ret == 0 ? passed : failed); printf(resultFmt, ret == 0 ? passed : failed);
@ -9199,7 +9199,7 @@ static int test_wc_Shake256_Final (void)
/* /*
* Testing wc_Shake256_Copy() * Testing wc_Shake256_Copy()
*/ */
static int test_wc_Shake256_Copy (void) static int test_wc_Shake256_Copy (void)
{ {
int ret = 0; int ret = 0;
#if defined(WOLFSSL_SHAKE256) && !defined(WOLFSSL_NO_SHAKE256) #if defined(WOLFSSL_SHAKE256) && !defined(WOLFSSL_NO_SHAKE256)
@ -9255,7 +9255,7 @@ static int test_wc_Shake256_Copy (void)
} }
wc_Shake256_Free(&shake); wc_Shake256_Free(&shake);
printf(resultFmt, ret == 0 ? passed : failed); printf(resultFmt, ret == 0 ? passed : failed);
#endif #endif
return ret; return ret;
@ -33358,6 +33358,58 @@ static int test_wc_RNG_GenerateBlock(void)
return ret; return ret;
} }
/*
* Testing wc_InitRngNonce
*/
static int test_wc_InitRngNonce(void)
{
int ret;
WC_RNG rng;
byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
"\x45\xAC\x13\x7A\xE1\x48\xAF\x16";;
word32 nonceSz = sizeof(nonce);
printf(testingFmt, "wc_InitRngNonce()");
ret = wc_InitRng(&rng);
if (ret == 0){
ret = wc_InitRngNonce(&rng, nonce, nonceSz);
}
wc_FreeRng(&rng);
printf(resultFmt, ret == 0 ? passed : failed);
return ret;
}/* End test_wc_InitRngNonce*/
/*
* Testing wc_InitRngNonce_ex
*/
static int test_wc_InitRngNonce_ex(void)
{
int ret;
WC_RNG rng;
byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
"\x45\xAC\x13\x7A\xE1\x48\xAF\x16";;
word32 nonceSz = sizeof(nonce);
printf(testingFmt, "wc_InitRngNonce_ex()");
ret = wc_InitRng(&rng);
if (ret == 0){
ret = wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, devId);
}
wc_FreeRng(&rng);
printf(resultFmt, ret == 0 ? passed : failed);
return ret;
}/*End test_wc_InitRngNonce_ex*/
#endif #endif
static void test_wolfSSL_X509_CRL(void) static void test_wolfSSL_X509_CRL(void)
@ -35109,7 +35161,7 @@ void ApiTest(void)
AssertIntEQ(test_wc_Sha3_256_Copy(), 0); AssertIntEQ(test_wc_Sha3_256_Copy(), 0);
AssertIntEQ(test_wc_Sha3_384_Copy(), 0); AssertIntEQ(test_wc_Sha3_384_Copy(), 0);
AssertIntEQ(test_wc_Sha3_512_Copy(), 0); AssertIntEQ(test_wc_Sha3_512_Copy(), 0);
AssertIntEQ(test_wc_Sha3_GetFlags(), 0); AssertIntEQ(test_wc_Sha3_GetFlags(), 0);
AssertIntEQ(test_wc_InitShake256(), 0); AssertIntEQ(test_wc_InitShake256(), 0);
AssertIntEQ(testing_wc_Shake256_Update(), 0); AssertIntEQ(testing_wc_Shake256_Update(), 0);
AssertIntEQ(test_wc_Shake256_Final(), 0); AssertIntEQ(test_wc_Shake256_Final(), 0);
@ -35228,6 +35280,8 @@ void ApiTest(void)
AssertIntEQ(test_wc_RNG_GenerateBlock_Reseed(), 0); AssertIntEQ(test_wc_RNG_GenerateBlock_Reseed(), 0);
#endif #endif
AssertIntEQ(test_wc_RNG_GenerateBlock(), 0); AssertIntEQ(test_wc_RNG_GenerateBlock(), 0);
AssertIntEQ(test_wc_InitRngNonce(), 0);
AssertIntEQ(test_wc_InitRngNonce_ex(), 0);
#endif #endif
AssertIntEQ(test_wc_ed25519_make_key(), 0); AssertIntEQ(test_wc_ed25519_make_key(), 0);