File tree Expand file tree Collapse file tree 3 files changed +50
-4
lines changed
Expand file tree Collapse file tree 3 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,10 @@ WC_RNG* wp_provctx_get_rng(WOLFPROV_CTX* provCtx);
160160#ifndef WP_SINGLE_THREADED
161161int wp_provctx_lock_rng (WOLFPROV_CTX * provCtx );
162162void wp_provctx_unlock_rng (WOLFPROV_CTX * provCtx );
163+
164+ #ifdef HAVE_FIPS
165+ wolfSSL_Mutex * wp_get_cast_mutex (void );
166+ #endif
163167#endif
164168
165169int wolfssl_prov_get_capabilities (void * provctx , const char * capability ,
Original file line number Diff line number Diff line change 3030#include <wolfssl/wolfcrypt/rsa.h>
3131#include <wolfssl/wolfcrypt/pwdbased.h>
3232
33+ #if defined(HAVE_FIPS ) && (!defined(WP_SINGLE_THREADED ))
34+ static wolfSSL_Mutex castMutex ;
35+
36+ /**
37+ * Initialize the cast mutex on library load.
38+ *
39+ * This constructor runs when libwolfprov.so is loaded via dlopen() or at
40+ * program startup. It ensures the castMutex is initialized under lock.
41+ */
42+ __attribute__((constructor ))
43+ static void wolfprov_init_cast_mutex (void )
44+ {
45+ wc_InitMutex (& castMutex );
46+ }
47+
48+ wolfSSL_Mutex * wp_get_cast_mutex ()
49+ {
50+ return & castMutex ;
51+ }
52+ #endif
53+
3354/**
3455 * Get the wolfSSL random number generator from the provider context.
3556 *
Original file line number Diff line number Diff line change @@ -214,10 +214,6 @@ static WOLFPROV_CTX* wolfssl_prov_ctx_new(void)
214214{
215215 WOLFPROV_CTX * ctx ;
216216
217- #ifdef WC_RNG_SEED_CB
218- wc_SetSeed_Cb (wc_GenerateSeed );
219- #endif
220-
221217 ctx = (WOLFPROV_CTX * )OPENSSL_zalloc (sizeof (WOLFPROV_CTX ));
222218 if ((ctx != NULL ) && (wc_InitRng (& ctx -> rng ) != 0 )) {
223219 OPENSSL_free (ctx );
@@ -1312,6 +1308,31 @@ int wolfssl_provider_init(const OSSL_CORE_HANDLE* handle,
13121308 }
13131309 }
13141310
1311+ if (ok ) {
1312+ #ifdef WC_RNG_SEED_CB
1313+ wc_SetSeed_Cb (wc_GenerateSeed );
1314+ #endif
1315+ #if defined(HAVE_FIPS ) && (!defined(WP_SINGLE_THREADED ))
1316+ /* To avoid multi-threading issues in FIPS CAST tests, run all tests
1317+ * under a lock now */
1318+ if (wp_lock (wp_get_cast_mutex ()) != 1 ) {
1319+ WOLFPROV_ERROR_MSG (WP_LOG_COMP_PROVIDER ,
1320+ "Fatal Error: unable to acquire FIPS CAST lock" );
1321+ ok = 0 ;
1322+ }
1323+ if (ok ) {
1324+ if (wc_RunAllCast_fips () != 0 ) {
1325+ WOLFPROV_ERROR_MSG (WP_LOG_COMP_PROVIDER ,
1326+ "Fatal Error: FIPS algo selftest failure" );
1327+ ok = 0 ;
1328+ }
1329+ if (wp_unlock (wp_get_cast_mutex ()) != 1 ) {
1330+ ok = 0 ;
1331+ }
1332+ }
1333+ #endif
1334+ }
1335+
13151336 if (ok ) {
13161337 /* Create a new provider context. */
13171338 * provCtx = wolfssl_prov_ctx_new ();
You can’t perform that action at this time.
0 commit comments