Skip to content

Commit f5543f6

Browse files
committed
wolfcrypt/test/test.c: in wolfcrypt_test_main(), install myFipsCb if applicable, and save failed wolfCrypt retvals to args.return_code to assure error exit. fixes FIPS integrity failure message with wolfEntropy.
1 parent 4fda088 commit f5543f6

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,9 +3055,19 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
30553055
args.argc = argc;
30563056
args.argv = argv;
30573057
#endif
3058+
3059+
#if defined(HAVE_FIPS) && defined(HAVE_ENTROPY_MEMUSE) && \
3060+
!defined(WOLFSSL_KERNEL_MODE)
3061+
/* wolfEntropy's Entropy_Init() calls wc_InitSha3_256(), which
3062+
* ultimately fails if the FIPS integrity hash is wrong.
3063+
*/
3064+
wolfCrypt_SetCb_fips(myFipsCb);
3065+
#endif
3066+
30583067
if ((ret = wolfCrypt_Init()) != 0) {
30593068
printf("wolfCrypt_Init failed %d\n", (int)ret);
3060-
err_sys("Error with wolfCrypt_Init!\n", WC_TEST_RET_ENC_EC(ret));
3069+
args.return_code = WC_TEST_RET_ENC_EC(ret);
3070+
err_sys("Error with wolfCrypt_Init!\n", args.return_code);
30613071
}
30623072

30633073
#ifdef HAVE_WC_INTROSPECTION
@@ -3074,13 +3084,16 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
30743084

30753085
if ((ret = wolfCrypt_Cleanup()) != 0) {
30763086
printf("wolfCrypt_Cleanup failed %d\n", (int)ret);
3077-
err_sys("Error with wolfCrypt_Cleanup!\n", WC_TEST_RET_ENC_EC(ret));
3087+
args.return_code = WC_TEST_RET_ENC_EC(ret);
3088+
err_sys("Error with wolfCrypt_Cleanup!\n", args.return_code);
30783089
}
30793090

30803091
#ifdef HAVE_WNR
3081-
if ((ret = wc_FreeNetRandom()) < 0)
3092+
if ((ret = wc_FreeNetRandom()) < 0) {
3093+
args.return_code = WC_TEST_RET_ENC_EC(ret);
30823094
err_sys("Failed to free netRandom context",
3083-
WC_TEST_RET_ENC_EC(ret));
3095+
args.return_code);
3096+
}
30843097
#endif /* HAVE_WNR */
30853098
#ifdef DOLPHIN_EMULATOR
30863099
/* Returning from main panics the emulator. Just hang

0 commit comments

Comments
 (0)