Skip to content

Commit 74d14d9

Browse files
committed
wolfcrypt/test/test.c: fix for FIPS <6.0.0 with WOLFSSL_SMALL_STACK.
1 parent 64a359c commit 74d14d9

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,38 @@ static void myFipsCb(int ok, int err, const char* hash)
920920
}
921921
#endif /* HAVE_FIPS && !WOLFSSL_LINUXKM */
922922

923+
#if defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
924+
925+
#ifndef NO_AES
926+
static struct Aes *wc_AesNew(void *heap, int thisDevId) {
927+
Aes* aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_AES);
928+
if (aes != NULL) {
929+
if (wc_AesInit(aes, heap, thisDevId) != 0) {
930+
XFREE(aes, heap, DYNAMIC_TYPE_AES);
931+
aes = NULL;
932+
}
933+
}
934+
return aes;
935+
}
936+
#endif
937+
938+
#ifndef NO_RSA
939+
static RsaKey* wc_NewRsaKey(void* heap, int thisDevId)
940+
{
941+
RsaKey* key = (RsaKey*)XMALLOC(sizeof(RsaKey), heap, DYNAMIC_TYPE_RSA);
942+
if (key != NULL) {
943+
if (wc_InitRsaKey_ex(key, heap, thisDevId) != 0) {
944+
XFREE(key, heap, DYNAMIC_TYPE_RSA);
945+
key = NULL;
946+
}
947+
}
948+
return key;
949+
}
950+
#endif
951+
952+
#endif /* FIPS_VERSION3_LT(6,0,0) */
953+
954+
923955
#ifdef WOLFSSL_STATIC_MEMORY
924956
#if defined(WOLFSSL_STATIC_MEMORY_TEST_SZ)
925957
static byte gTestMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
@@ -9491,8 +9523,15 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
94919523
out:
94929524

94939525
wc_AesFree(enc);
9526+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
9527+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
9528+
#endif
9529+
94949530
#ifdef HAVE_AES_DECRYPT
94959531
wc_AesFree(dec);
9532+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
9533+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
9534+
#endif
94969535
#endif
94979536
#endif /* WOLFSSL_AES_256 */
94989537

@@ -9812,8 +9851,14 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
98129851
out:
98139852

98149853
wc_AesFree(enc);
9854+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
9855+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
9856+
#endif
98159857
#ifdef HAVE_AES_DECRYPT
98169858
wc_AesFree(dec);
9859+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
9860+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
9861+
#endif
98179862
#endif
98189863

98199864
return ret;
@@ -10066,8 +10111,14 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
1006610111
out:
1006710112

1006810113
wc_AesFree(enc);
10114+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
10115+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
10116+
#endif
1006910117
#ifdef HAVE_AES_DECRYPT
1007010118
wc_AesFree(dec);
10119+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
10120+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
10121+
#endif
1007110122
#endif
1007210123

1007310124
return ret;
@@ -10270,8 +10321,14 @@ static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
1027010321
out:
1027110322

1027210323
wc_AesFree(enc);
10324+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
10325+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
10326+
#endif
1027310327
#ifdef HAVE_AES_DECRYPT
1027410328
wc_AesFree(dec);
10329+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
10330+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
10331+
#endif
1027510332
#endif
1027610333

1027710334
return ret;
@@ -10407,6 +10464,9 @@ static wc_test_ret_t aes_key_size_test(void)
1040710464
out:
1040810465

1040910466
wc_AesFree(aes);
10467+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
10468+
XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
10469+
#endif
1041010470

1041110471
return ret;
1041210472
}
@@ -13444,8 +13504,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void)
1344413504

1344513505
out:
1344613506
wc_AesFree(enc);
13507+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
13508+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
13509+
#endif
1344713510
#ifdef HAVE_AES_DECRYPT
1344813511
wc_AesFree(dec);
13512+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
13513+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
13514+
#endif
1344913515
#endif
1345013516
return ret;
1345113517
}
@@ -14010,8 +14076,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void)
1401014076
out:
1401114077

1401214078
wc_AesFree(enc);
14079+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14080+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
14081+
#endif
1401314082
#ifdef HAVE_AES_DECRYPT
1401414083
wc_AesFree(dec);
14084+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14085+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
14086+
#endif
1401514087
#endif
1401614088

1401714089
return ret;
@@ -14080,7 +14152,13 @@ static wc_test_ret_t aes_ecb_direct_test(void)
1408014152
out:
1408114153

1408214154
wc_AesFree(enc);
14155+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14156+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
14157+
#endif
1408314158
wc_AesFree(dec);
14159+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14160+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
14161+
#endif
1408414162

1408514163
return ret;
1408614164
}
@@ -14272,8 +14350,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
1427214350
out:
1427314351

1427414352
wc_AesFree(enc);
14353+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14354+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
14355+
#endif
1427514356
#ifdef HAVE_AES_DECRYPT
1427614357
wc_AesFree(dec);
14358+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14359+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
14360+
#endif
1427714361
#endif
1427814362
#endif /* HAVE_AES_CBC */
1427914363

@@ -14471,8 +14555,14 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
1447114555
out:
1447214556

1447314557
wc_AesFree(enc);
14558+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14559+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
14560+
#endif
1447414561
#ifdef HAVE_AES_DECRYPT
1447514562
wc_AesFree(dec);
14563+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14564+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
14565+
#endif
1447614566
#endif
1447714567
#endif /* HAVE_AES_CBC */
1447814568

@@ -14600,7 +14690,13 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv,
1460014690
out:
1460114691

1460214692
wc_AesFree(enc);
14693+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14694+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
14695+
#endif
1460314696
wc_AesFree(dec);
14697+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
14698+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
14699+
#endif
1460414700

1460514701
return ret;
1460614702
}
@@ -15532,7 +15628,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
1553215628
#endif
1553315629

1553415630
wc_AesFree(enc);
15631+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
15632+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
15633+
#endif
1553515634
wc_AesFree(dec);
15635+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
15636+
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
15637+
#endif
1553615638

1553715639
return ret;
1553815640
}
@@ -15751,6 +15853,9 @@ static wc_test_ret_t aesccm_256_test(void)
1575115853
#endif
1575215854

1575315855
wc_AesFree(aes);
15856+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
15857+
XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
15858+
#endif
1575415859

1575515860
return ret;
1575615861
}
@@ -15914,6 +16019,9 @@ static wc_test_ret_t aesccm_128_test(void)
1591416019
XMEMSET(iv2, 0, sizeof(iv2));
1591516020

1591616021
wc_AesFree(enc);
16022+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
16023+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
16024+
#endif
1591716025
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
1591816026
enc = wc_AesNew(HEAP_HINT, devId);
1591916027
if (enc == NULL)
@@ -16047,6 +16155,9 @@ static wc_test_ret_t aesccm_128_test(void)
1604716155
out:
1604816156

1604916157
wc_AesFree(enc);
16158+
#if defined(WOLFSSL_SMALL_STACK) && defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0)
16159+
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
16160+
#endif
1605016161

1605116162
return ret;
1605216163
}

0 commit comments

Comments
 (0)