diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 22db7f167..f27ee2192 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -9385,10 +9385,6 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, return err; #ifndef HAVE_THREAD_LS - if (initMutex == 0) { - wc_InitMutex(&ecc_fp_lock); - initMutex = 1; - } if (wc_LockMutex(&ecc_fp_lock) != 0) return BAD_MUTEX_E; #endif /* HAVE_THREAD_LS */ @@ -9512,11 +9508,6 @@ 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) { - wc_InitMutex(&ecc_fp_lock); - initMutex = 1; - } - if (wc_LockMutex(&ecc_fp_lock) != 0) return BAD_MUTEX_E; #endif /* HAVE_THREAD_LS */ @@ -9616,8 +9607,9 @@ static void wc_ecc_fp_free_cache(void) } #endif -/** Free the Fixed Point cache */ -void wc_ecc_fp_free(void) + +/** Init the Fixed Point cache */ +void wc_ecc_fp_init(void) { #ifndef WOLFSSL_SP_MATH #ifndef HAVE_THREAD_LS @@ -9625,7 +9617,16 @@ void wc_ecc_fp_free(void) 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 (wc_LockMutex(&ecc_fp_lock) == 0) { #endif /* HAVE_THREAD_LS */ 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);