Skip to content

Commit

Permalink
large input sync w/upstream & update
Browse files Browse the repository at this point in the history
  • Loading branch information
gojimmypi committed Oct 9, 2024
1 parent d760da6 commit f2c773a
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ typedef struct testVector {
size_t outLen;
} testVector;

#ifndef NO_LARGE_HASH_TEST
#ifndef LARGE_HASH_TEST_INPUT_SZ
#define LARGE_HASH_TEST_INPUT_SZ 1024
#endif
#endif

#ifndef WOLFSSL_TEST_SUBROUTINE
#define WOLFSSL_TEST_SUBROUTINE
#endif
Expand Down Expand Up @@ -5945,7 +5951,6 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
wc_Sha256 i_sha, i_shaCopy;
#endif
#ifndef NO_LARGE_HASH_TEST
#define LARGE_HASH_TEST_INPUT_SZ 1024
#ifdef WOLFSSL_SMALL_STACK
byte *large_input = NULL;
#else
Expand Down Expand Up @@ -6183,6 +6188,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)

exit:

#if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#endif
wc_Sha256Free(&sha);
wc_Sha256Free(&shaCopy);
#ifndef NO_WOLFSSL_SHA256_INTERLEAVE
Expand Down Expand Up @@ -6212,6 +6220,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
byte i_hash[WC_SHA512_DIGEST_SIZE];
byte i_hashcopy[WC_SHA512_DIGEST_SIZE];
testVector interleave_test_sha[3];
#endif
#ifndef NO_LARGE_HASH_TEST
#ifdef WOLFSSL_SMALL_STACK
byte *large_input = NULL;
#else
byte large_input[LARGE_HASH_TEST_INPUT_SZ];
#endif
#endif

int times = sizeof(test_sha) / sizeof(struct testVector), i;
Expand Down Expand Up @@ -6350,7 +6365,6 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)

#ifndef NO_LARGE_HASH_TEST
/* BEGIN LARGE HASH TEST */ {
byte large_input[1024];
#ifdef HASH_SIZE_LIMIT
WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
"\x30\x9B\x96\xA6\xE9\x43\x78\x30\xA3\x71\x51\x61\xC1\xEB\xE1\xBE"
Expand All @@ -6365,7 +6379,16 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
"\xa5\xdc\xfc\xfa\x9d\x1a\x4d\xc0\xfa\x3a\x14\xf6\x01\x51\x90\xa4";
#endif

for (i = 0; i < (int)sizeof(large_input); i++) {
#ifdef WOLFSSL_SMALL_STACK
large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER);

if (large_input == NULL) {
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
}
#endif

for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
large_input[i] = (byte)(i & 0xFF);
}
#ifdef HASH_SIZE_LIMIT
Expand All @@ -6375,7 +6398,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
#endif
for (i = 0; i < times; ++i) {
ret = wc_Sha512Update(&sha, (byte*)large_input,
(word32)sizeof(large_input));
LARGE_HASH_TEST_INPUT_SZ);
if (ret != 0)
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
#ifndef NO_WOLFSSL_SHA512_INTERLEAVE
Expand Down Expand Up @@ -6416,6 +6439,10 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
#endif /* NO_LARGE_HASH_TEST */

exit:

#if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#endif
wc_Sha512Free(&sha);
wc_Sha512Free(&shaCopy);
#ifndef NO_WOLFSSL_SHA256_INTERLEAVE
Expand Down

0 comments on commit f2c773a

Please sign in to comment.