Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/wolfprovider/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ WC_RNG* wp_provctx_get_rng(WOLFPROV_CTX* provCtx);
#ifndef WP_SINGLE_THREADED
int wp_provctx_lock_rng(WOLFPROV_CTX* provCtx);
void wp_provctx_unlock_rng(WOLFPROV_CTX* provCtx);

#ifdef HAVE_FIPS
wolfSSL_Mutex *wp_get_cast_mutex(void);
#endif
#endif

int wolfssl_prov_get_capabilities(void *provctx, const char *capability,
Expand Down
21 changes: 21 additions & 0 deletions src/wp_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@
#include <wolfssl/wolfcrypt/rsa.h>
#include <wolfssl/wolfcrypt/pwdbased.h>

#if defined(HAVE_FIPS) && (!defined(WP_SINGLE_THREADED))
static wolfSSL_Mutex castMutex;

/**
* Initialize the cast mutex on library load.
*
* This constructor runs when libwolfprov.so is loaded via dlopen() or at
* program startup. It ensures the castMutex is initialized under lock.
*/
__attribute__((constructor))
static void wolfprov_init_cast_mutex(void)
{
wc_InitMutex(&castMutex);
}

wolfSSL_Mutex *wp_get_cast_mutex()
{
return &castMutex;
}
#endif

/**
* Get the wolfSSL random number generator from the provider context.
*
Expand Down
23 changes: 19 additions & 4 deletions src/wp_wolfprov.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ static WOLFPROV_CTX* wolfssl_prov_ctx_new(void)
{
WOLFPROV_CTX* ctx;

#ifdef WC_RNG_SEED_CB
wc_SetSeed_Cb(wc_GenerateSeed);
#endif

ctx = (WOLFPROV_CTX*)OPENSSL_zalloc(sizeof(WOLFPROV_CTX));
if ((ctx != NULL) && (wc_InitRng(&ctx->rng) != 0)) {
OPENSSL_free(ctx);
Expand Down Expand Up @@ -1312,6 +1308,25 @@ int wolfssl_provider_init(const OSSL_CORE_HANDLE* handle,
}
}

if (ok) {
#ifdef WC_RNG_SEED_CB
wc_SetSeed_Cb(wc_GenerateSeed);
#endif
#if defined(HAVE_FIPS) && (!defined(WP_SINGLE_THREADED))
/* To avoid multi-threading issues in FIPS CAST tests, run all tests
* under a lock now */
if (wp_lock(wp_get_cast_mutex()) != 1) {
ok = 0;
}
if (ok) {
if (wc_RunAllCast_fips() != 0) {
ok = 0;
}
wp_unlock(wp_get_cast_mutex());
}
#endif
}

if (ok) {
/* Create a new provider context. */
*provCtx = wolfssl_prov_ctx_new();
Expand Down
Loading