init FP mutex on wolfCrypt init

This commit is contained in:
JacobBarthelmeh
2020-05-13 13:59:35 -07:00
parent 6c9a0e440e
commit 1876fe1c22
3 changed files with 17 additions and 11 deletions

View File

@ -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 */

View File

@ -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");

View File

@ -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);