From f5543f6b95ef2d7d7abc56166774bef163b25448 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Tue, 25 Nov 2025 20:21:37 -0600 Subject: [PATCH] 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. --- wolfcrypt/test/test.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 6680c284f..8e6a8ed10 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -3055,9 +3055,19 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ args.argc = argc; args.argv = argv; #endif + +#if defined(HAVE_FIPS) && defined(HAVE_ENTROPY_MEMUSE) && \ + !defined(WOLFSSL_KERNEL_MODE) + /* wolfEntropy's Entropy_Init() calls wc_InitSha3_256(), which + * ultimately fails if the FIPS integrity hash is wrong. + */ + wolfCrypt_SetCb_fips(myFipsCb); +#endif + if ((ret = wolfCrypt_Init()) != 0) { printf("wolfCrypt_Init failed %d\n", (int)ret); - err_sys("Error with wolfCrypt_Init!\n", WC_TEST_RET_ENC_EC(ret)); + args.return_code = WC_TEST_RET_ENC_EC(ret); + err_sys("Error with wolfCrypt_Init!\n", args.return_code); } #ifdef HAVE_WC_INTROSPECTION @@ -3074,13 +3084,16 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ if ((ret = wolfCrypt_Cleanup()) != 0) { printf("wolfCrypt_Cleanup failed %d\n", (int)ret); - err_sys("Error with wolfCrypt_Cleanup!\n", WC_TEST_RET_ENC_EC(ret)); + args.return_code = WC_TEST_RET_ENC_EC(ret); + err_sys("Error with wolfCrypt_Cleanup!\n", args.return_code); } #ifdef HAVE_WNR - if ((ret = wc_FreeNetRandom()) < 0) + if ((ret = wc_FreeNetRandom()) < 0) { + args.return_code = WC_TEST_RET_ENC_EC(ret); err_sys("Failed to free netRandom context", - WC_TEST_RET_ENC_EC(ret)); + args.return_code); + } #endif /* HAVE_WNR */ #ifdef DOLPHIN_EMULATOR /* Returning from main panics the emulator. Just hang