Skip to content

Commit 33fc601

Browse files
committed
tweaks from PRBs results:
tests/api.c: * remove inapt SSL_library_init() in test_wolfSSL_EVP_Cipher_extra(); * move TEST_X509_DECLS to follow TEST_DECL(test_wolfSSL_Init); tests/api/test_random.c: enlarge seed buffer in test_wc_RNG_TestSeed() to accommodate amdrand block size; tests/quic.c: wrap exercises in wolfSSL_Init()...wolfSSL_Cleanup(); tests/unit.c: in unit_test(), add several more fflush(stdout)s, report error from wolfSSL_Cleanup(), and fix line length; wolfcrypt/test/test.c: omit reseed test in _rng_test() if HAVE_INTEL_RDRAND or old FIPS, and use simplified random_test() if HAVE_INTEL_RDRAND; wolfssl/wolfcrypt/mem_track.h: add memList pointer in struct memoryStats, and set it in InitMemoryTracker(); wolfssl/wolfcrypt/settings.h: undefine WOLFSSL_SMALL_STACK_CACHE if WOLFSSL_SMALL_STACK is undefined; .github/workflows/trackmemory.yml: add --enable-intelrdseed scenario.
1 parent e159c65 commit 33fc601

File tree

8 files changed

+54
-15
lines changed

8 files changed

+54
-15
lines changed

.github/workflows/trackmemory.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
#
2828
# Note, don't combine wolfEntropy with the full TLS cipher suite test -- the implicit wc_InitRng()s in each suite have an enormous CPU footprint.
2929
'--enable-wolfEntropy --enable-smallstackcache --enable-smallstack --enable-all CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY -DNO_WOLFSSL_CIPHER_SUITE_TEST"',
30+
'--enable-intelrdseed --enable-smallstackcache --enable-smallstack --enable-all CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY -DNO_WOLFSSL_CIPHER_SUITE_TEST"',
3031
'--enable-amdrand --enable-smallstackcache --enable-smallstack --enable-all CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY -DNO_WOLFSSL_CIPHER_SUITE_TEST"',
3132
'--disable-asm --enable-wolfEntropy --enable-smallstackcache --enable-smallstack --enable-all CFLAGS="-DWC_RNG_SEED_CB -DWOLFSSL_TRACK_MEMORY -DWOLFSSL_DEBUG_MEMORY -DNO_WOLFSSL_CIPHER_SUITE_TEST"'
3233
]

tests/api.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22832,8 +22832,6 @@ static int test_wolfSSL_EVP_Cipher_extra(void)
2283222832

2283322833
set_plain(plain, BUFFSZ * RECORDS);
2283422834

22835-
SSL_library_init();
22836-
2283722835
ExpectNotNull(evp = EVP_CIPHER_CTX_new());
2283822836
ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
2283922837

@@ -41503,8 +41501,6 @@ TEST_CASE testCases[] = {
4150341501
TEST_MLDSA_DECLS,
4150441502
/* Signature API */
4150541503
TEST_SIGNATURE_DECLS,
41506-
/* x509 */
41507-
TEST_X509_DECLS,
4150841504

4150941505
/* ASN */
4151041506
TEST_ASN_DECLS,
@@ -41562,6 +41558,9 @@ TEST_CASE testCases[] = {
4156241558

4156341559
TEST_DECL(test_wolfSSL_Init),
4156441560

41561+
/* x509 -- must appear after test_wolfSSL_Init(). */
41562+
TEST_X509_DECLS,
41563+
4156541564
TEST_DECL(test_dual_alg_support),
4156641565
TEST_DECL(test_dual_alg_crit_ext_support),
4156741566

tests/api/test_random.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ int test_wc_RNG_TestSeed(void)
327327
#if defined(HAVE_HASHDRBG) && \
328328
(!(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
329329
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
330-
byte seed[16];
330+
byte seed[32];
331331
byte i;
332332

333333
#ifdef TEST_WC_RNG_TESTSEED_BAD_PARAMS

tests/quic.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,12 @@ int QuicTest(void)
18921892
int ret = 0;
18931893
#ifdef WOLFSSL_QUIC
18941894
int verbose = 0;
1895+
1896+
if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
1897+
printf("wolfSSL_Init() failed in QuicTest().");
1898+
return -1;
1899+
}
1900+
18951901
printf(" Begin QUIC Tests\n");
18961902

18971903
if ((ret = test_set_quic_method()) != TEST_SUCCESS) goto leave;
@@ -1917,6 +1923,8 @@ int QuicTest(void)
19171923
printf(" FAILED: some tests did not pass.\n");
19181924
}
19191925
printf(" End QUIC Tests\n");
1926+
1927+
(void)wolfSSL_Cleanup();
19201928
#endif
19211929
return ret == TEST_SUCCESS ? 0 : -1;
19221930
}

tests/unit.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ int unit_test(int argc, char** argv)
273273
}
274274

275275
printf("wolfCrypt unit test completed successfully.\n\n");
276+
fflush(stdout);
276277
}
277278
#endif
278279

@@ -282,6 +283,7 @@ int unit_test(int argc, char** argv)
282283
{
283284
if (apiTesting) {
284285
ret = ApiTest();
286+
fflush(stdout);
285287
if (ret != 0)
286288
goto exit;
287289
}
@@ -291,20 +293,25 @@ int unit_test(int argc, char** argv)
291293
}
292294

293295
#ifdef WOLFSSL_W64_WRAPPER
294-
if ((ret = w64wrapper_test()) != 0) {
296+
ret = w64wrapper_test();
297+
fflush(stdout);
298+
if (ret != 0) {
295299
fprintf(stderr, "w64wrapper test failed with %d\n", ret);
296300
goto exit;
297301
}
298302
#endif /* WOLFSSL_W64_WRAPPER */
299303

300304
#ifdef WOLFSSL_QUIC
301-
if ((ret = QuicTest()) != 0) {
305+
ret = QuicTest();
306+
fflush(stdout);
307+
if (ret != 0) {
302308
fprintf(stderr, "quic test failed with %d\n", ret);
303309
goto exit;
304310
}
305311
#endif
306312

307313
SrpTest();
314+
fflush(stdout);
308315
}
309316

310317
#if !defined(NO_WOLFSSL_CIPHER_SUITE_TEST) && \
@@ -326,10 +333,18 @@ int unit_test(int argc, char** argv)
326333

327334
#ifdef WOLFSSL_TRACK_MEMORY
328335
if (ret == 0) {
329-
(void)wolfSSL_Cleanup();
336+
ret = wolfSSL_Cleanup(); /* no-op in a successful full run. */
337+
338+
if (ret == WOLFSSL_SUCCESS)
339+
ret = 0;
340+
else
341+
fprintf(stderr, "wolfSSL_Cleanup() returned %d\n", ret);
342+
330343
if (wc_MemStats_Ptr->currentBytes > 0)
331344
{
332-
fprintf(stderr, "WOLFSSL_TRACK_MEMORY: currentBytes after cleanup is %ld\n", wc_MemStats_Ptr->currentBytes);
345+
fprintf(stderr,
346+
"WOLFSSL_TRACK_MEMORY: currentBytes after cleanup is %ld\n",
347+
wc_MemStats_Ptr->currentBytes);
333348
ret = MEMORY_E;
334349
}
335350
}

wolfcrypt/test/test.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19693,7 +19693,9 @@ static wc_test_ret_t _rng_test(WC_RNG* rng)
1969319693
return WC_TEST_RET_ENC_EC(ret);
1969419694
}
1969519695

19696-
#if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
19696+
#if defined(HAVE_HASHDRBG) && !defined(HAVE_INTEL_RDRAND) && \
19697+
!defined(CUSTOM_RAND_GENERATE_BLOCK) && \
19698+
!defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(5,0,0))
1969719699
/* Test periodic reseed dynamics. */
1969819700

1969919701
((struct DRBG_internal *)rng->drbg)->reseedCtr = WC_RESEED_INTERVAL;
@@ -19704,7 +19706,7 @@ static wc_test_ret_t _rng_test(WC_RNG* rng)
1970419706

1970519707
if (((struct DRBG_internal *)rng->drbg)->reseedCtr == WC_RESEED_INTERVAL)
1970619708
return WC_TEST_RET_ENC_NC;
19707-
#endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
19709+
#endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK && !HAVE_SELFTEST */
1970819710

1970919711
#if defined(WOLFSSL_TRACK_MEMORY) && defined(WOLFSSL_SMALL_STACK_CACHE)
1971019712
/* wc_RNG_GenerateBlock() must not allocate any memory in
@@ -19797,7 +19799,8 @@ static wc_test_ret_t random_rng_test(void)
1979719799
return ret;
1979819800
}
1979919801

19800-
#if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
19802+
#if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK) && \
19803+
!defined(HAVE_INTEL_RDRAND)
1980119804

1980219805
#if defined(WC_RNG_SEED_CB) && \
1980319806
!(defined(ENTROPY_SCALE_FACTOR) || defined(SEED_BLOCK_SZ))
@@ -19940,7 +19943,7 @@ static wc_test_ret_t rng_seed_test(void)
1994019943
out:
1994119944
return ret;
1994219945
}
19943-
#endif /* WC_RNG_SEED_CB) && !(ENTROPY_SCALE_FACTOR || SEED_BLOCK_SZ) */
19946+
#endif /* WC_RNG_SEED_CB && !(ENTROPY_SCALE_FACTOR || SEED_BLOCK_SZ) */
1994419947

1994519948

1994619949
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
@@ -20060,7 +20063,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
2006020063
return 0;
2006120064
}
2006220065

20063-
#else
20066+
#else /* !HAVE_HASHDRBG || CUSTOM_RAND_GENERATE_BLOCK || HAVE_INTEL_RDRAND */
2006420067

2006520068
WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
2006620069
{
@@ -20070,7 +20073,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
2007020073
return random_rng_test();
2007120074
}
2007220075

20073-
#endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
20076+
#endif /* !HAVE_HASHDRBG || CUSTOM_RAND_GENERATE_BLOCK || HAVE_INTEL_RDRAND */
2007420077
#endif /* WC_NO_RNG */
2007520078

2007620079
#ifndef MEM_TEST_SZ

wolfssl/wolfcrypt/mem_track.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
#define DO_MEM_LIST
8484
#endif
8585

86+
struct memoryList;
87+
8688
typedef struct memoryStats {
8789
long totalAllocs; /* number of allocations */
8890
long totalDeallocs; /* number of deallocations */
@@ -98,6 +100,9 @@ typedef struct memoryStats {
98100
* by wolfCrypt_heap_peak_checkpoint()
99101
*/
100102
#endif
103+
#ifdef DO_MEM_LIST
104+
struct memoryList *memList;
105+
#endif
101106
} memoryStats;
102107

103108
typedef struct memHint {
@@ -380,6 +385,7 @@ static WC_INLINE int InitMemoryTracker(void)
380385

381386
#ifdef DO_MEM_LIST
382387
XMEMSET(&ourMemList, 0, sizeof(ourMemList));
388+
ourMemStats.memList = &ourMemList;
383389

384390
pthread_mutex_unlock(&memLock);
385391
#endif

wolfssl/wolfcrypt/settings.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,6 +4323,13 @@ extern void uITRON4_free(void *p) ;
43234323
without staticmemory (WOLFSSL_STATIC_MEMORY)
43244324
#endif
43254325

4326+
/* Undefine WOLFSSL_SMALL_STACK_CACHE if WOLFSSL_SMALL_STACK is undefined --
4327+
* they only work together.
4328+
*/
4329+
#if defined(WOLFSSL_SMALL_STACK_CACHE) && !defined(WOLFSSL_SMALL_STACK)
4330+
#undef WOLFSSL_SMALL_STACK_CACHE
4331+
#endif
4332+
43264333
/* If malloc is disabled make sure it is also disabled in SP math */
43274334
#if defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_SP_NO_MALLOC) && \
43284335
(defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL))

0 commit comments

Comments
 (0)