diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 9de60c4e3..99dd77809 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -9391,10 +9391,11 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, return err; #ifndef HAVE_THREAD_LS - if (initMutex == 0) { + if (initMutex == 0) { /* extra sanity check if wolfCrypt_Init not called */ wc_InitMutex(&ecc_fp_lock); initMutex = 1; } + if (wc_LockMutex(&ecc_fp_lock) != 0) return BAD_MUTEX_E; #endif /* HAVE_THREAD_LS */ @@ -9518,7 +9519,7 @@ int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, return MP_INIT_E; #ifndef HAVE_THREAD_LS - if (initMutex == 0) { + if (initMutex == 0) { /* extra sanity check if wolfCrypt_Init not called */ wc_InitMutex(&ecc_fp_lock); initMutex = 1; } @@ -9623,12 +9624,27 @@ static void wc_ecc_fp_free_cache(void) } #endif + +/** Init the Fixed Point cache */ +void wc_ecc_fp_init(void) +{ +#ifndef WOLFSSL_SP_MATH +#ifndef HAVE_THREAD_LS + if (initMutex == 0) { + wc_InitMutex(&ecc_fp_lock); + initMutex = 1; + } +#endif +#endif +} + + /** Free the Fixed Point cache */ void wc_ecc_fp_free(void) { #ifndef WOLFSSL_SP_MATH #ifndef HAVE_THREAD_LS - if (initMutex == 0) { + if (initMutex == 0) { /* extra sanity check if wolfCrypt_Init not called */ wc_InitMutex(&ecc_fp_lock); initMutex = 1; } diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 087807b71..bb847fe94 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -219,6 +219,9 @@ int wolfCrypt_Init(void) #endif #ifdef HAVE_ECC + #ifdef FP_ECC + wc_ecc_fp_init(); + #endif #ifdef ECC_CACHE_CURVE if ((ret = wc_ecc_curve_cache_init()) != 0) { WOLFSSL_MSG("Error creating curve cache"); diff --git a/wolfssl/wolfcrypt/ecc.h b/wolfssl/wolfcrypt/ecc.h index 27f42067f..f67a3930b 100644 --- a/wolfssl/wolfcrypt/ecc.h +++ b/wolfssl/wolfcrypt/ecc.h @@ -521,6 +521,8 @@ WOLFSSL_API int wc_ecc_set_flags(ecc_key* key, word32 flags); WOLFSSL_API void wc_ecc_fp_free(void); +WOLFSSL_LOCAL +void wc_ecc_fp_init(void); WOLFSSL_API int wc_ecc_set_curve(ecc_key* key, int keysize, int curve_id);