Skip to content

Commit 5408118

Browse files
authored
Merge pull request #7298 from douzzer/20240304-wolfcrypttest-fixes
20240304-wolfcrypttest-fixes
2 parents ee39a8f + 321a72c commit 5408118

3 files changed

Lines changed: 58 additions & 14 deletions

File tree

src/ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6805,7 +6805,7 @@ static int ProcessBufferTryDecodeEd25519(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
68056805
ssl->buffers.keyType = ed25519_sa_algo;
68066806
ssl->buffers.keySz = *keySz;
68076807
}
6808-
else if (ctx) {
6808+
else {
68096809
ctx->privateKeyType = ed25519_sa_algo;
68106810
ctx->privateKeySz = *keySz;
68116811
}

tests/api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28015,7 +28015,7 @@ static int test_wc_PKCS7_VerifySignedData_RSA(void)
2801528015
XFILE signedBundle = XBADFILE;
2801628016
int signedBundleSz = 0;
2801728017
int chunkSz = 1;
28018-
int i, rc;
28018+
int i, rc = 0;
2801928019
byte* buf = NULL;
2802028020

2802128021
ExpectTrue((signedBundle = XFOPEN("./certs/test-stream-sign.p7b",

wolfcrypt/test/test.c

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,6 +3198,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
31983198
byte i_hashcopy[WC_SHA256_DIGEST_SIZE];
31993199
testVector interleave_test_sha[4];
32003200
wc_Sha256 i_sha, i_shaCopy;
3201+
#endif
3202+
#ifndef NO_LARGE_HASH_TEST
3203+
#define LARGE_HASH_TEST_INPUT_SZ 1024
3204+
#ifdef WOLFSSL_SMALL_STACK
3205+
byte *large_input = NULL;
3206+
#else
3207+
byte large_input[LARGE_HASH_TEST_INPUT_SZ];
3208+
#endif
32013209
#endif
32023210

32033211
int times = sizeof(test_sha) / sizeof(struct testVector), i;
@@ -3339,17 +3347,26 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
33393347

33403348
#ifndef NO_LARGE_HASH_TEST
33413349
/* BEGIN LARGE HASH TEST */ {
3342-
byte large_input[1024];
33433350
#ifdef HASH_SIZE_LIMIT
3344-
const char* large_digest =
3351+
WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
33453352
"\xa4\x75\x9e\x7a\xa2\x03\x38\x32\x88\x66\xa2\xea\x17\xea\xf8\xc7"
33463353
"\xfe\x4e\xc6\xbb\xe3\xbb\x71\xce\xe7\xdf\x7c\x04\x61\xb3\xc2\x2f";
33473354
#else
3348-
const char* large_digest =
3355+
WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
33493356
"\x27\x78\x3e\x87\x96\x3a\x4e\xfb\x68\x29\xb5\x31\xc9\xba\x57\xb4"
33503357
"\x4f\x45\x79\x7f\x67\x70\xbd\x63\x7f\xbf\x0d\x80\x7c\xbd\xba\xe0";
33513358
#endif
3352-
for (i = 0; i < (int)sizeof(large_input); i++) {
3359+
3360+
#ifdef WOLFSSL_SMALL_STACK
3361+
large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
3362+
DYNAMIC_TYPE_TMP_BUFFER);
3363+
3364+
if (large_input == NULL) {
3365+
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
3366+
}
3367+
#endif
3368+
3369+
for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
33533370
large_input[i] = (byte)(i & 0xFF);
33543371
}
33553372
#ifdef HASH_SIZE_LIMIT
@@ -3358,11 +3375,11 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
33583375
times = 100;
33593376
#endif
33603377
#ifdef WOLFSSL_PIC32MZ_HASH
3361-
wc_Sha256SizeSet(&sha, times * sizeof(large_input));
3378+
wc_Sha256SizeSet(&sha, times * LARGE_HASH_TEST_INPUT_SZ);
33623379
#endif
33633380
for (i = 0; i < times; ++i) {
33643381
ret = wc_Sha256Update(&sha, (byte*)large_input,
3365-
(word32)sizeof(large_input));
3382+
LARGE_HASH_TEST_INPUT_SZ);
33663383
if (ret != 0)
33673384
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
33683385
}
@@ -3372,10 +3389,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
33723389
if (XMEMCMP(hash, large_digest, WC_SHA256_DIGEST_SIZE) != 0)
33733390
ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
33743391
} /* END LARGE HASH TEST */
3392+
#undef LARGE_HASH_TEST_INPUT_SZ
33753393
#endif /* NO_LARGE_HASH_TEST */
33763394

33773395
exit:
33783396

3397+
#if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
3398+
XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
3399+
#endif
33793400
wc_Sha256Free(&sha);
33803401
wc_Sha256Free(&shaCopy);
33813402
#ifndef NO_WOLFSSL_SHA256_INTERLEAVE
@@ -3405,6 +3426,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
34053426
byte i_hash[WC_SHA512_DIGEST_SIZE];
34063427
byte i_hashcopy[WC_SHA512_DIGEST_SIZE];
34073428
testVector interleave_test_sha[3];
3429+
#endif
3430+
#ifndef NO_LARGE_HASH_TEST
3431+
#define LARGE_HASH_TEST_INPUT_SZ 1024
3432+
#ifdef WOLFSSL_SMALL_STACK
3433+
byte *large_input = NULL;
3434+
#else
3435+
byte large_input[LARGE_HASH_TEST_INPUT_SZ];
3436+
#endif
34083437
#endif
34093438

34103439
int times = sizeof(test_sha) / sizeof(struct testVector), i;
@@ -3539,22 +3568,30 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
35393568

35403569
#ifndef NO_LARGE_HASH_TEST
35413570
/* BEGIN LARGE HASH TEST */ {
3542-
byte large_input[1024];
35433571
#ifdef HASH_SIZE_LIMIT
3544-
const char* large_digest =
3572+
WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
35453573
"\x30\x9B\x96\xA6\xE9\x43\x78\x30\xA3\x71\x51\x61\xC1\xEB\xE1\xBE"
35463574
"\xC8\xA5\xF9\x13\x5A\xD6\x6D\x9E\x46\x31\x31\x67\x8D\xE2\xC0\x0B"
35473575
"\x2A\x1A\x03\xE1\xF3\x48\xA7\x33\xBD\x49\xF8\xFF\xF1\xC2\xC2\x95"
35483576
"\xCB\xF0\xAF\x87\x61\x85\x58\x63\x6A\xCA\x70\x9C\x8B\x83\x3F\x5D";
35493577
#else
3550-
const char* large_digest =
3578+
WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
35513579
"\x5a\x1f\x73\x90\xbd\x8c\xe4\x63\x54\xce\xa0\x9b\xef\x32\x78\x2d"
35523580
"\x2e\xe7\x0d\x5e\x2f\x9d\x15\x1b\xdd\x2d\xde\x65\x0c\x7b\xfa\x83"
35533581
"\x5e\x80\x02\x13\x84\xb8\x3f\xff\x71\x62\xb5\x09\x89\x63\xe1\xdc"
35543582
"\xa5\xdc\xfc\xfa\x9d\x1a\x4d\xc0\xfa\x3a\x14\xf6\x01\x51\x90\xa4";
35553583
#endif
35563584

3557-
for (i = 0; i < (int)sizeof(large_input); i++) {
3585+
#ifdef WOLFSSL_SMALL_STACK
3586+
large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
3587+
DYNAMIC_TYPE_TMP_BUFFER);
3588+
3589+
if (large_input == NULL) {
3590+
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
3591+
}
3592+
#endif
3593+
3594+
for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
35583595
large_input[i] = (byte)(i & 0xFF);
35593596
}
35603597
#ifdef HASH_SIZE_LIMIT
@@ -3564,7 +3601,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
35643601
#endif
35653602
for (i = 0; i < times; ++i) {
35663603
ret = wc_Sha512Update(&sha, (byte*)large_input,
3567-
(word32)sizeof(large_input));
3604+
LARGE_HASH_TEST_INPUT_SZ);
35683605
if (ret != 0)
35693606
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
35703607
}
@@ -3578,16 +3615,21 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
35783615
/* Unaligned memory access test */
35793616
for (i = 1; i < 16; i++) {
35803617
ret = wc_Sha512Update(&sha, (byte*)large_input + i,
3581-
(word32)sizeof(large_input) - i);
3618+
LARGE_HASH_TEST_INPUT_SZ - i);
35823619
if (ret != 0)
35833620
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
35843621
ret = wc_Sha512Final(&sha, hash);
35853622
}
35863623
#endif
35873624
} /* END LARGE HASH TEST */
3625+
#undef LARGE_HASH_TEST_INPUT_SZ
35883626
#endif /* NO_LARGE_HASH_TEST */
35893627

35903628
exit:
3629+
3630+
#if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
3631+
XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
3632+
#endif
35913633
wc_Sha512Free(&sha);
35923634
wc_Sha512Free(&shaCopy);
35933635
#ifndef NO_WOLFSSL_SHA256_INTERLEAVE
@@ -24356,7 +24398,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void)
2435624398
return WC_TEST_RET_ENC_NC;
2435724399
#endif
2435824400
#else
24401+
#ifdef SCRYPT_TEST_ALL
2435924402
(void)verify4;
24403+
#endif
2436024404
#endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */
2436124405

2436224406
#if !defined(BENCH_EMBEDDED)

0 commit comments

Comments
 (0)