From b615dbe9d5dbd88920fc2571a3404d8796b7f29b Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 15 May 2020 11:50:05 -0600 Subject: [PATCH] add additional FP_ECC lock sanity check for case where wolfCrypt_Init is not called --- wolfcrypt/src/ecc.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index f27ee2192..900b8c30c 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -9385,6 +9385,11 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, return err; #ifndef HAVE_THREAD_LS + 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 */ @@ -9508,6 +9513,11 @@ 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) { /* 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 */ @@ -9627,6 +9637,11 @@ void wc_ecc_fp_free(void) { #ifndef WOLFSSL_SP_MATH #ifndef HAVE_THREAD_LS + 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) { #endif /* HAVE_THREAD_LS */