From b6b8de1f5975f261e9d91f430f82a477cd0670b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Wed, 1 Apr 2026 08:22:28 +0200 Subject: [PATCH 1/5] Add bounds checks for Blake2 digest size --- tests/api/test_blake2.c | 36 ++++++++++++++++++++++++++++++++++++ wolfcrypt/src/blake2b.c | 9 +++++++++ wolfcrypt/src/blake2s.c | 9 +++++++++ 3 files changed, 54 insertions(+) diff --git a/tests/api/test_blake2.c b/tests/api/test_blake2.c index 9cbd11de85d..2067997fa23 100644 --- a/tests/api/test_blake2.c +++ b/tests/api/test_blake2.c @@ -50,6 +50,12 @@ int test_wc_InitBlake2b(void) ExpectIntEQ(wc_InitBlake2b(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_InitBlake2b(NULL, WC_BLAKE2B_DIGEST_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* digestSz values that truncate via (byte) cast to a valid size must be + * rejected: 257 mod 256 = 1, 320 mod 256 = 64 - both within BLAKE2B range */ + ExpectIntEQ(wc_InitBlake2b(&blake, 257), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_InitBlake2b(&blake, 256 + BLAKE2B_OUTBYTES), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Test good arg. */ ExpectIntEQ(wc_InitBlake2b(&blake, WC_BLAKE2B_DIGEST_SIZE), 0); @@ -82,6 +88,12 @@ int test_wc_InitBlake2b_WithKey(void) ExpectIntEQ(wc_InitBlake2b_WithKey(NULL, digestSz, key, keylen), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* digestSz that truncates to a valid byte-sized value must be rejected */ + ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, 257, NULL, keylen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, 256 + BLAKE2B_OUTBYTES, NULL, keylen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* Test good arg. */ ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, NULL, keylen), 0); ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, keylen), 0); @@ -127,8 +139,14 @@ int test_wc_Blake2bFinal(void) ExpectIntEQ(wc_Blake2bFinal(&blake, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_Blake2bFinal(NULL, hash, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* requestSz that truncates to valid byte must be rejected */ + ExpectIntEQ(wc_Blake2bFinal(&blake, hash, 257), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_Blake2bFinal(&blake, hash, 256 + BLAKE2B_OUTBYTES), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Test good args. */ + ExpectIntEQ(wc_InitBlake2b(&blake, WC_BLAKE2B_DIGEST_SIZE), 0); ExpectIntEQ(wc_Blake2bFinal(&blake, hash, WC_BLAKE2B_DIGEST_SIZE), 0); #endif return EXPECT_RESULT(); @@ -322,6 +340,12 @@ int test_wc_InitBlake2s(void) ExpectIntEQ(wc_InitBlake2s(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_InitBlake2s(NULL, WC_BLAKE2S_DIGEST_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* digestSz that truncates via (byte) cast to a valid size must be rejected: + * 257 mod 256 = 1, 288 mod 256 = 32 - both within BLAKE2S range */ + ExpectIntEQ(wc_InitBlake2s(&blake, 257), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_InitBlake2s(&blake, 256 + BLAKE2S_OUTBYTES), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Test good arg. */ ExpectIntEQ(wc_InitBlake2s(&blake, WC_BLAKE2S_DIGEST_SIZE), 0); @@ -352,6 +376,12 @@ int test_wc_InitBlake2s_WithKey(void) ExpectIntEQ(wc_InitBlake2s_WithKey(NULL, digestSz, key, keylen), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* digestSz that truncates to a valid byte-sized value must be rejected */ + ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, 257, NULL, keylen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, 256 + BLAKE2S_OUTBYTES, NULL, keylen), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* Test good arg. */ ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, NULL, keylen), 0); ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, keylen), 0); @@ -397,8 +427,14 @@ int test_wc_Blake2sFinal(void) ExpectIntEQ(wc_Blake2sFinal(&blake, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); ExpectIntEQ(wc_Blake2sFinal(NULL, hash, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + /* requestSz that truncates to valid byte must be rejected */ + ExpectIntEQ(wc_Blake2sFinal(&blake, hash, 257), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_Blake2sFinal(&blake, hash, 256 + BLAKE2S_OUTBYTES), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); /* Test good args. */ + ExpectIntEQ(wc_InitBlake2s(&blake, WC_BLAKE2S_DIGEST_SIZE), 0); ExpectIntEQ(wc_Blake2sFinal(&blake, hash, WC_BLAKE2S_DIGEST_SIZE), 0); #endif return EXPECT_RESULT(); diff --git a/wolfcrypt/src/blake2b.c b/wolfcrypt/src/blake2b.c index 90776bbef1f..7e7b60bab93 100644 --- a/wolfcrypt/src/blake2b.c +++ b/wolfcrypt/src/blake2b.c @@ -426,6 +426,9 @@ int wc_InitBlake2b(Blake2b* b2b, word32 digestSz) if (b2b == NULL){ return BAD_FUNC_ARG; } + if (digestSz == 0 || digestSz > BLAKE2B_OUTBYTES) { + return BAD_FUNC_ARG; + } b2b->digestSz = digestSz; return blake2b_init(b2b->S, (byte)digestSz); @@ -437,6 +440,9 @@ int wc_InitBlake2b_WithKey(Blake2b* b2b, word32 digestSz, const byte *key, word3 if (b2b == NULL){ return BAD_FUNC_ARG; } + if (digestSz == 0 || digestSz > BLAKE2B_OUTBYTES) { + return BAD_FUNC_ARG; + } b2b->digestSz = digestSz; if (keylen >= 256) @@ -478,6 +484,9 @@ int wc_Blake2bFinal(Blake2b* b2b, byte* final, word32 requestSz) } sz = requestSz ? requestSz : b2b->digestSz; + if (sz == 0 || sz > BLAKE2B_OUTBYTES) { + return BAD_FUNC_ARG; + } return blake2b_final(b2b->S, final, (byte)sz); } diff --git a/wolfcrypt/src/blake2s.c b/wolfcrypt/src/blake2s.c index ee105209bb0..ae48b9b3d8b 100644 --- a/wolfcrypt/src/blake2s.c +++ b/wolfcrypt/src/blake2s.c @@ -421,6 +421,9 @@ int wc_InitBlake2s(Blake2s* b2s, word32 digestSz) if (b2s == NULL){ return BAD_FUNC_ARG; } + if (digestSz == 0 || digestSz > BLAKE2S_OUTBYTES) { + return BAD_FUNC_ARG; + } b2s->digestSz = digestSz; return blake2s_init(b2s->S, (byte)digestSz); @@ -433,6 +436,9 @@ int wc_InitBlake2s_WithKey(Blake2s* b2s, word32 digestSz, const byte *key, word3 if (b2s == NULL){ return BAD_FUNC_ARG; } + if (digestSz == 0 || digestSz > BLAKE2S_OUTBYTES) { + return BAD_FUNC_ARG; + } b2s->digestSz = digestSz; if (keylen >= 256) @@ -475,6 +481,9 @@ int wc_Blake2sFinal(Blake2s* b2s, byte* final, word32 requestSz) } sz = requestSz ? requestSz : b2s->digestSz; + if (sz == 0 || sz > BLAKE2S_OUTBYTES) { + return BAD_FUNC_ARG; + } return blake2s_final(b2s->S, final, (byte)sz); } From 6e0624065f5ccac89f699b45d1b2cfbdc1d49ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Wed, 1 Apr 2026 08:57:38 +0200 Subject: [PATCH 2/5] Make sure ECB decrypt function is called in EVP This only makes an actual difference when FREESCALE_MMCAU is defined (otherwise encrypt and decrypt are the same), but better for clarity still. --- wolfcrypt/src/evp.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index fc4f68eb9fc..b802958a9ee 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -695,10 +695,16 @@ static int evpCipherBlock(WOLFSSL_EVP_CIPHER_CTX *ctx, break; #if defined(WOLFSSL_DES_ECB) case WC_DES_ECB_TYPE: - ret = wc_Des_EcbEncrypt(&ctx->cipher.des, out, in, inl); + if (ctx->enc) + ret = wc_Des_EcbEncrypt(&ctx->cipher.des, out, in, inl); + else + ret = wc_Des_EcbDecrypt(&ctx->cipher.des, out, in, inl); break; case WC_DES_EDE3_ECB_TYPE: - ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, out, in, inl); + if (ctx->enc) + ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, out, in, inl); + else + ret = wc_Des3_EcbDecrypt(&ctx->cipher.des3, out, in, inl); break; #endif #endif @@ -8749,13 +8755,19 @@ void wolfSSL_EVP_init(void) #ifdef WOLFSSL_DES_ECB case WC_DES_ECB_TYPE : WOLFSSL_MSG("DES ECB"); - ret = wc_Des_EcbEncrypt(&ctx->cipher.des, dst, src, len); + if (ctx->enc) + ret = wc_Des_EcbEncrypt(&ctx->cipher.des, dst, src, len); + else + ret = wc_Des_EcbDecrypt(&ctx->cipher.des, dst, src, len); if (ret == 0) ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE); break; case WC_DES_EDE3_ECB_TYPE : WOLFSSL_MSG("DES3 ECB"); - ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, dst, src, len); + if (ctx->enc) + ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, dst, src, len); + else + ret = wc_Des3_EcbDecrypt(&ctx->cipher.des3, dst, src, len); if (ret == 0) ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE); break; From da597e30dba22cd1bd020374239d839cafdff495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Wed, 1 Apr 2026 09:04:08 +0200 Subject: [PATCH 3/5] Fix SECO AES GCM return value --- wolfcrypt/src/port/caam/wolfcaam_seco.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfcrypt/src/port/caam/wolfcaam_seco.c b/wolfcrypt/src/port/caam/wolfcaam_seco.c index 374f779aee4..8389d0470d8 100644 --- a/wolfcrypt/src/port/caam/wolfcaam_seco.c +++ b/wolfcrypt/src/port/caam/wolfcaam_seco.c @@ -1075,7 +1075,7 @@ static hsm_err_t wc_SECO_AESGCM(unsigned int args[4], CAAM_BUFFER* buf, int sz) } XFREE(cipherAndTag, NULL, DYNAMIC_TYPE_TMP_BUFFER); (void)sz; - return HSM_NO_ERROR; + return err; } From 8b2c0f7cd2b485ed3937f5708e8db7c0fb956fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Wed, 1 Apr 2026 09:16:55 +0200 Subject: [PATCH 4/5] Make sure ASCON is unusable on big endian --- wolfcrypt/src/ascon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wolfcrypt/src/ascon.c b/wolfcrypt/src/ascon.c index 8c61f00bf03..8bd1e88d4d6 100644 --- a/wolfcrypt/src/ascon.c +++ b/wolfcrypt/src/ascon.c @@ -45,6 +45,9 @@ #ifndef WORD64_AVAILABLE #error "Ascon implementation requires a 64-bit word" #endif +#ifdef BIG_ENDIAN_ORDER + #error "Ascon not yet supported on big-endian systems" +#endif /* Data block size in bytes */ #define ASCON_HASH256_RATE 8 From 22a2290972081f188cf9718f3760a6845513b182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Wed, 1 Apr 2026 10:06:11 +0200 Subject: [PATCH 5/5] Fix TOCTOU issues in SP math code --- wolfcrypt/src/sp_arm32.c | 56 ++++++++++++++++--------------------- wolfcrypt/src/sp_arm64.c | 49 ++++++++++++++------------------ wolfcrypt/src/sp_armthumb.c | 56 ++++++++++++++++--------------------- wolfcrypt/src/sp_c32.c | 28 ++++++++----------- wolfcrypt/src/sp_c64.c | 28 ++++++++----------- wolfcrypt/src/sp_cortexm.c | 56 ++++++++++++++++--------------------- wolfcrypt/src/sp_dsp32.c | 7 ++--- wolfcrypt/src/sp_x86_64.c | 56 ++++++++++++++++--------------------- 8 files changed, 144 insertions(+), 192 deletions(-) diff --git a/wolfcrypt/src/sp_arm32.c b/wolfcrypt/src/sp_arm32.c index 991f5fc4783..62a7376a53a 100644 --- a/wolfcrypt/src/sp_arm32.c +++ b/wolfcrypt/src/sp_arm32.c @@ -75874,10 +75874,6 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_8(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); } @@ -75885,6 +75881,9 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_8(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -76256,10 +76255,6 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_8(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); } @@ -76267,6 +76262,9 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_8(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -93909,10 +93907,6 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_12(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); } @@ -93920,6 +93914,9 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_12(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -94307,10 +94304,6 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_12(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); } @@ -94318,6 +94311,9 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_12(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -121070,10 +121066,6 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_17(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); } @@ -121081,6 +121073,9 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_17(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -121488,10 +121483,6 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_17(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); } @@ -121499,6 +121490,9 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_17(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -150839,10 +150833,6 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_32(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); } @@ -150850,6 +150840,9 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_32(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -151154,10 +151147,6 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_32(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); } @@ -151165,6 +151154,9 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_32(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); diff --git a/wolfcrypt/src/sp_arm64.c b/wolfcrypt/src/sp_arm64.c index f06ad68f74c..402e75a6db0 100644 --- a/wolfcrypt/src/sp_arm64.c +++ b/wolfcrypt/src/sp_arm64.c @@ -24685,10 +24685,6 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_4(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_win_add_sub_4(r, g, k, map, ct, heap); } @@ -24696,6 +24692,9 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_4(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -25074,10 +25073,6 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_4(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_win_add_sub_4(r, g, k, map, ct, heap); } @@ -25085,6 +25080,9 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_4(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -45189,10 +45187,6 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_6(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_win_add_sub_6(r, g, k, map, ct, heap); } @@ -45200,6 +45194,9 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_6(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -45578,10 +45575,6 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_6(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_win_add_sub_6(r, g, k, map, ct, heap); } @@ -45589,6 +45582,9 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_6(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -73181,10 +73177,6 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_9(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); } @@ -73192,6 +73184,9 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_9(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -73588,10 +73583,6 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_9(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); } @@ -73599,6 +73590,9 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_9(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -116668,10 +116662,6 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_16(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_win_add_sub_16(r, g, k, map, ct, heap); } @@ -116679,6 +116669,9 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_16(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); diff --git a/wolfcrypt/src/sp_armthumb.c b/wolfcrypt/src/sp_armthumb.c index 508dbbfd435..88604d693c8 100644 --- a/wolfcrypt/src/sp_armthumb.c +++ b/wolfcrypt/src/sp_armthumb.c @@ -101326,10 +101326,6 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_8(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); } @@ -101337,6 +101333,9 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_8(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -101708,10 +101707,6 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_8(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); } @@ -101719,6 +101714,9 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_8(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -111761,10 +111759,6 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_12(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); } @@ -111772,6 +111766,9 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_12(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -112159,10 +112156,6 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_12(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); } @@ -112170,6 +112163,9 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_12(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -124995,10 +124991,6 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_17(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); } @@ -125006,6 +124998,9 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_17(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -125413,10 +125408,6 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_17(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); } @@ -125424,6 +125415,9 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_17(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -209206,10 +209200,6 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_32(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); } @@ -209217,6 +209207,9 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_32(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -209521,10 +209514,6 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_32(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); } @@ -209532,6 +209521,9 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_32(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); diff --git a/wolfcrypt/src/sp_c32.c b/wolfcrypt/src/sp_c32.c index 137f69cebc2..16889893c91 100644 --- a/wolfcrypt/src/sp_c32.c +++ b/wolfcrypt/src/sp_c32.c @@ -21573,10 +21573,6 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_9(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); } @@ -21584,6 +21580,9 @@ static int sp_256_ecc_mulmod_9(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_9(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -28692,10 +28691,6 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_15(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_win_add_sub_15(r, g, k, map, ct, heap); } @@ -28703,6 +28698,9 @@ static int sp_384_ecc_mulmod_15(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_15(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -35873,10 +35871,6 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_21(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_win_add_sub_21(r, g, k, map, ct, heap); } @@ -35884,6 +35878,9 @@ static int sp_521_ecc_mulmod_21(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_21(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -44014,10 +44011,6 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_42(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_win_add_sub_42(r, g, k, map, ct, heap); } @@ -44025,6 +44018,9 @@ static int sp_1024_ecc_mulmod_42(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_42(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); diff --git a/wolfcrypt/src/sp_c64.c b/wolfcrypt/src/sp_c64.c index e408e871f44..089b8fca839 100644 --- a/wolfcrypt/src/sp_c64.c +++ b/wolfcrypt/src/sp_c64.c @@ -22066,10 +22066,6 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_5(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_win_add_sub_5(r, g, k, map, ct, heap); } @@ -22077,6 +22073,9 @@ static int sp_256_ecc_mulmod_5(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_5(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -28612,10 +28611,6 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_7(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_win_add_sub_7(r, g, k, map, ct, heap); } @@ -28623,6 +28618,9 @@ static int sp_384_ecc_mulmod_7(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_7(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -35631,10 +35629,6 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_9(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); } @@ -35642,6 +35636,9 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_9(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -42954,10 +42951,6 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_18(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_win_add_sub_18(r, g, k, map, ct, heap); } @@ -42965,6 +42958,9 @@ static int sp_1024_ecc_mulmod_18(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_18(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); diff --git a/wolfcrypt/src/sp_cortexm.c b/wolfcrypt/src/sp_cortexm.c index 5cde3aad8ca..a36602d1952 100644 --- a/wolfcrypt/src/sp_cortexm.c +++ b/wolfcrypt/src/sp_cortexm.c @@ -37260,10 +37260,6 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_8(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); } @@ -37271,6 +37267,9 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_8(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -37642,10 +37641,6 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_8(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_fast_8(r, g, k, map, ct, heap); } @@ -37653,6 +37648,9 @@ static int sp_256_ecc_mulmod_8(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_8(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -47215,10 +47213,6 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_12(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); } @@ -47226,6 +47220,9 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_12(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -47613,10 +47610,6 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_12(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_fast_12(r, g, k, map, ct, heap); } @@ -47624,6 +47617,9 @@ static int sp_384_ecc_mulmod_12(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_12(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -59084,10 +59080,6 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_17(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); } @@ -59095,6 +59087,9 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_17(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -59502,10 +59497,6 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_17(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_fast_17(r, g, k, map, ct, heap); } @@ -59513,6 +59504,9 @@ static int sp_521_ecc_mulmod_17(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_17(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -73371,10 +73365,6 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_32(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); } @@ -73382,6 +73372,9 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_32(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -73686,10 +73679,6 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_32(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_fast_32(r, g, k, map, ct, heap); } @@ -73697,6 +73686,9 @@ static int sp_1024_ecc_mulmod_32(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_32(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); diff --git a/wolfcrypt/src/sp_dsp32.c b/wolfcrypt/src/sp_dsp32.c index f040894ef6d..885d57643b6 100644 --- a/wolfcrypt/src/sp_dsp32.c +++ b/wolfcrypt/src/sp_dsp32.c @@ -2710,10 +2710,6 @@ static int sp_256_ecc_mulmod_10(sp_point* r, const sp_point* g, const sp_digit* if (cache->cnt == 2) sp_256_gen_stripe_table_10(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_fast_10(r, g, k, map, heap); } @@ -2721,6 +2717,9 @@ static int sp_256_ecc_mulmod_10(sp_point* r, const sp_point* g, const sp_digit* err = sp_256_ecc_mulmod_stripe_10(r, g, cache->table, k, map, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_lock); +#endif /* HAVE_THREAD_LS */ } return err; diff --git a/wolfcrypt/src/sp_x86_64.c b/wolfcrypt/src/sp_x86_64.c index ab682df02f1..1f7cd9e3961 100644 --- a/wolfcrypt/src/sp_x86_64.c +++ b/wolfcrypt/src/sp_x86_64.c @@ -10488,10 +10488,6 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_4(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_win_add_sub_4(r, g, k, map, ct, heap); } @@ -10499,6 +10495,9 @@ static int sp_256_ecc_mulmod_4(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_4(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -10827,10 +10826,6 @@ static int sp_256_ecc_mulmod_avx2_4(sp_point_256* r, const sp_point_256* g, if (cache->cnt == 2) sp_256_gen_stripe_table_avx2_4(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_256_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_256_ecc_mulmod_win_add_sub_avx2_4(r, g, k, map, ct, heap); } @@ -10838,6 +10833,9 @@ static int sp_256_ecc_mulmod_avx2_4(sp_point_256* r, const sp_point_256* g, err = sp_256_ecc_mulmod_stripe_avx2_4(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_256_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -29240,10 +29238,6 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_6(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_win_add_sub_6(r, g, k, map, ct, heap); } @@ -29251,6 +29245,9 @@ static int sp_384_ecc_mulmod_6(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_6(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -29582,10 +29579,6 @@ static int sp_384_ecc_mulmod_avx2_6(sp_point_384* r, const sp_point_384* g, if (cache->cnt == 2) sp_384_gen_stripe_table_avx2_6(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_384_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_384_ecc_mulmod_win_add_sub_avx2_6(r, g, k, map, ct, heap); } @@ -29593,6 +29586,9 @@ static int sp_384_ecc_mulmod_avx2_6(sp_point_384* r, const sp_point_384* g, err = sp_384_ecc_mulmod_stripe_avx2_6(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_384_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -53694,10 +53690,6 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_9(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_win_add_sub_9(r, g, k, map, ct, heap); } @@ -53705,6 +53697,9 @@ static int sp_521_ecc_mulmod_9(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_9(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -54036,10 +54031,6 @@ static int sp_521_ecc_mulmod_avx2_9(sp_point_521* r, const sp_point_521* g, if (cache->cnt == 2) sp_521_gen_stripe_table_avx2_9(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_521_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_521_ecc_mulmod_win_add_sub_avx2_9(r, g, k, map, ct, heap); } @@ -54047,6 +54038,9 @@ static int sp_521_ecc_mulmod_avx2_9(sp_point_521* r, const sp_point_521* g, err = sp_521_ecc_mulmod_stripe_avx2_9(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_521_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -94467,10 +94461,6 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_16(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_win_add_sub_16(r, g, k, map, ct, heap); } @@ -94478,6 +94468,9 @@ static int sp_1024_ecc_mulmod_16(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_16(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC); @@ -94792,10 +94785,6 @@ static int sp_1024_ecc_mulmod_avx2_16(sp_point_1024* r, const sp_point_1024* g, if (cache->cnt == 2) sp_1024_gen_stripe_table_avx2_16(g, cache->table, tmp, heap); -#ifndef HAVE_THREAD_LS - wc_UnLockMutex(&sp_cache_1024_lock); -#endif /* HAVE_THREAD_LS */ - if (cache->cnt < 2) { err = sp_1024_ecc_mulmod_win_add_sub_avx2_16(r, g, k, map, ct, heap); } @@ -94803,6 +94792,9 @@ static int sp_1024_ecc_mulmod_avx2_16(sp_point_1024* r, const sp_point_1024* g, err = sp_1024_ecc_mulmod_stripe_avx2_16(r, g, cache->table, k, map, ct, heap); } +#ifndef HAVE_THREAD_LS + wc_UnLockMutex(&sp_cache_1024_lock); +#endif /* HAVE_THREAD_LS */ } SP_FREE_VAR(tmp, heap, DYNAMIC_TYPE_ECC);