From 57adb6f5b8ba033d717e5aced9355b600dd0db71 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 26 Jul 2023 09:25:36 +1200 Subject: [PATCH 1/5] Instrumented --- src/internal.c | 4 ++++ src/ssl.c | 2 ++ src/tls13.c | 4 ++-- wolfcrypt/src/port/Espressif/esp32_sha.c | 9 +++++++-- wolfcrypt/src/sha256.c | 3 ++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/internal.c b/src/internal.c index 73fbc66269..893476b040 100644 --- a/src/internal.c +++ b/src/internal.c @@ -9746,6 +9746,7 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) if (IsAtLeastTLSv1_2(ssl)) { #ifndef NO_SHA256 + printf("%s, %d: wc_Sha256Update of WC_ESP32SHA @ %0xd\n", __FUNCTION__, __LINE__, (unsigned)&ssl->hsHashes->hashSha256.ctx); ret = wc_Sha256Update(&ssl->hsHashes->hashSha256, data, sz); if (ret != 0) return ret; @@ -9766,6 +9767,7 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) #endif #endif #ifdef WOLFSSL_SHA512 + printf("%s, %d: wc_Sha512Update of WC_ESP32SHA @ %0xd\n", __FUNCTION__, __LINE__, (unsigned)&ssl->hsHashes->hashSha512.ctx); ret = wc_Sha512Update(&ssl->hsHashes->hashSha512, data, sz); if (ret != 0) return ret; @@ -9789,11 +9791,13 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) ((defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)) || \ (defined(HAVE_ED25519) && !defined(NO_ED25519_CLIENT_AUTH)) || \ (defined(HAVE_ED448) && !defined(NO_ED448_CLIENT_AUTH))) + printf("%s, %d: EdDSA_Update\n", __FUNCTION__, __LINE__); ret = EdDSA_Update(ssl, data, sz); if (ret != 0) return ret; #endif } + printf("%s, %d\n", __FUNCTION__, __LINE__); return ret; } diff --git a/src/ssl.c b/src/ssl.c index cbc269cab8..0347249278 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -1487,8 +1487,10 @@ WOLFSSL_ABI void wolfSSL_free(WOLFSSL* ssl) { WOLFSSL_ENTER("wolfSSL_free"); + printf("Free SSL: %0xd\n", (unsigned)ssl); if (ssl) FreeSSL(ssl, ssl->ctx->heap); + WOLFSSL_LEAVE("wolfSSL_free", 0); } diff --git a/src/tls13.c b/src/tls13.c index 0262062a13..7dd377d600 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -4180,7 +4180,6 @@ int SendTls13ClientHello(WOLFSSL* ssl) tls12minor = DTLSv1_2_MINOR; } #endif /* WOLFSSL_DTLS */ - #ifdef HAVE_SESSION_TICKET if (ssl->options.resuming && (ssl->session->version.major != ssl->version.major || @@ -4345,7 +4344,6 @@ int SendTls13ClientHello(WOLFSSL* ssl) args->length = args->preXLength; } #endif - /* Include length of TLS extensions. */ ret = TLSX_GetRequestSize(ssl, client_hello, &args->length); if (ret != 0) @@ -4532,10 +4530,12 @@ int SendTls13ClientHello(WOLFSSL* ssl) ret = EchHashHelloInner(ssl, args->ech); } #endif + printf("Client hello %d\n", __LINE__); /* compute the outer hash */ if (ret == 0) ret = HashOutput(ssl, args->output, args->idx, 0); + printf("Client hello %d\n", __LINE__); } } if (ret != 0) diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index e159a1ad04..a850be7931 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -644,6 +644,7 @@ int esp_unroll_sha_module_enable(WC_ESP32SHA* ctx) ** periph_module_disable() or threading not working properly. **/ ESP_LOGW(TAG, "warning lockDepth mismatch."); + printf("Bad lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); } ctx->lockDepth = 0; ctx->mode = ESP32_SHA_INIT; @@ -752,12 +753,13 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) ESP_LOGW(TAG, "WARNING: Hardware Mode " "interesting lock depth = %d, %x", ctx->lockDepth, (int)ctx->initializer); - } + printf("Bad lock depth @ %d: %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); + } } else { /* We should have otherwise anticipated this; how did we get here? ** This code should rarely, ideally never be reached. */ - ESP_LOGI(TAG, "\nHardware in use; Mode REVERT to ESP32_SHA_SW\n"); + ESP_LOGI(TAG, "\nHardware in use for WC_ESP32SHA @ 0x%0xd; Mode REVERT to ESP32_SHA_SW\n", (unsigned)ctx); ctx->mode = ESP32_SHA_SW; return 0; /* success, but revert to SW */ } @@ -774,6 +776,7 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) #else if (ret == 0) { ctx->lockDepth++; /* depth for THIS ctx (there could be others!) */ + printf("Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); periph_module_enable(PERIPH_SHA_MODULE); ctx->mode = ESP32_SHA_HW; } @@ -805,12 +808,14 @@ int esp_sha_hw_unlock(WC_ESP32SHA* ctx) * and periph_module_disable() need to be unwound. * * see ref_counts[periph] in file: periph_ctrl.c */ + printf("Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); if (ctx->lockDepth > 0) { ctx->lockDepth--; } else { ctx->lockDepth = 0; } + printf("Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); #if defined(SINGLE_THREADED) InUse = 0; diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index b93529b50c..9c5c02c645 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -1854,7 +1854,8 @@ void wc_Sha256Free(wc_Sha256* sha256) * the unexpected. by the time free is called, the hardware * should have already been released (lockDepth = 0) */ - (void)InitSha256(sha256); /* unlock mutex, set mode to ESP32_SHA_INIT */ + printf("Bad lock depth @ %d = %d for %0xd\n", __LINE__, sha256->ctx.lockDepth, (unsigned)(&sha256->ctx)); + (void)InitSha256(sha256); /* unlock mutex, set mode to ESP32_SHA_INIT */ ESP_LOGV(TAG, "Alert: hardware unlock needed in wc_Sha256Free."); } else { From 97a8a3baf60e089e66d883fe5624b8d8309a8d5e Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 29 Jul 2023 14:48:35 +1200 Subject: [PATCH 2/5] Concept to resolve issue 6637. --- wolfcrypt/src/port/Espressif/esp32_sha.c | 93 +++++++++++++++++------- 1 file changed, 68 insertions(+), 25 deletions(-) diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index a850be7931..ffa798a25f 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -60,10 +60,9 @@ static const char* TAG = "wolf_hw_sha"; #define WC_SHA_DIGEST_SIZE 20 #endif -/* RTOS mutex or just InUse variable */ -#if defined(SINGLE_THREADED) - static int InUse = 0; -#else +static int InUse = 0; +/* If not single threaded, protect InUse with mutex */ +#if !defined(SINGLE_THREADED) static wolfSSL_Mutex sha_mutex = NULL; #endif @@ -665,6 +664,55 @@ int esp_unroll_sha_module_enable(WC_ESP32SHA* ctx) ** lock HW engine. ** this should be called before using engine. */ +int InitMutex() +{ + int ret; + ESP_LOGV(TAG, "Initializing sha_mutex"); + + /* created, but not yet locked */ + ret = esp_CryptHwMutexInit(&sha_mutex); + if (ret == 0) { + ESP_LOGV(TAG, "esp_CryptHwMutexInit sha_mutex init success."); + } + else { + ESP_LOGE(TAG, "esp_CryptHwMutexInit sha_mutex failed."); + sha_mutex = 0; + } + return ret; +} + +bool TryAcquireHardware() +{ + bool bCanUseHardware = false; + if (0 == esp_CryptHwMutexLock(&sha_mutex, (TickType_t)0)) + { + if (!InUse) + { + InUse = 1; + bCanUseHardware = true; + } + esp_CryptHwMutexUnLock(&sha_mutex); + } + + return bCanUseHardware; +} + +void ReleaseHardware() +{ + if (0 == esp_CryptHwMutexLock(&sha_mutex, (TickType_t)0)) + { + if (InUse) + { + InUse = 0; + } + else + { + assert(false); // bug: releasing hardware when not in use!! + } + esp_CryptHwMutexUnLock(&sha_mutex); + } +} + int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) { int ret = 0; @@ -715,22 +763,10 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) ** */ - if (sha_mutex == NULL) { - ESP_LOGV(TAG, "Initializing sha_mutex"); - - /* created, but not yet locked */ - ret = esp_CryptHwMutexInit(&sha_mutex); - if (ret == 0) { - ESP_LOGV(TAG, "esp_CryptHwMutexInit sha_mutex init success."); - } - else { - ESP_LOGE(TAG, "esp_CryptHwMutexInit sha_mutex failed."); - sha_mutex = 0; - - ESP_LOGI(TAG, "Revert to ctx->mode = ESP32_SHA_SW."); - ctx->mode = ESP32_SHA_SW; - return 0; /* success, just not using HW */ - } + if (sha_mutex == NULL && 0 != InitMutex()) { + ESP_LOGI(TAG, "Revert to ctx->mode = ESP32_SHA_SW."); + ctx->mode = ESP32_SHA_SW; + return 0; /* success, just not using HW */ } /* check if this SHA has been operated as SW or HW, or not yet init */ @@ -741,7 +777,9 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) /* we don't wait: ** either the engine is free, or we fall back to SW **/ - if (esp_CryptHwMutexLock(&sha_mutex, (TickType_t)0) == 0) { + if (TryAcquireHardware()) { + ctx->mode = ESP32_SHA_HW; // present in single threaded, but not here. not sure why? + /* check to see if we had a prior fail and need to unroll enables */ ret = esp_unroll_sha_module_enable(ctx); ESP_LOGV(TAG, "Hardware Mode, lock depth = %d, %x", @@ -801,7 +839,9 @@ int esp_sha_hw_unlock(WC_ESP32SHA* ctx) /* ESP32-C3 RISC-V TODO */ #else /* Disable AES hardware */ - periph_module_disable(PERIPH_SHA_MODULE); + // Note: Jim, is there any cost associated with enable/disable hardware here? This seems like + // a power saving feature that could be handled at a different level than per-calculation. + periph_module_disable(PERIPH_SHA_MODULE); #endif /* we'll keep track of our lock depth. * in case of unexpected results, all the periph_module_disable() calls @@ -817,12 +857,15 @@ int esp_sha_hw_unlock(WC_ESP32SHA* ctx) } printf("Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); + if (0 == ctx->lockDepth) // should we only unlock if depth is 0? + { #if defined(SINGLE_THREADED) - InUse = 0; + InUse = 0; #else - /* unlock HW engine for next use */ - esp_CryptHwMutexUnLock(&sha_mutex); + /* unlock HW engine for next use */ + ReleaseHardware(); #endif + } ESP_LOGV(TAG, "leave esp_sha_hw_unlock, %x", (int)ctx->initializer); return 0; } /* esp_sha_hw_unlock */ From 2d6c3e516b384aa229bd317c62656c63cd8508cc Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 29 Jul 2023 15:08:10 +1200 Subject: [PATCH 3/5] Switched to critical section to protect InUse. --- wolfcrypt/src/port/Espressif/esp32_sha.c | 41 ++++-------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index ffa798a25f..714679ba94 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -61,9 +61,9 @@ static const char* TAG = "wolf_hw_sha"; #endif static int InUse = 0; -/* If not single threaded, protect InUse with mutex */ +/* If not single threaded, protect InUse with a critical section */ #if !defined(SINGLE_THREADED) - static wolfSSL_Mutex sha_mutex = NULL; + static portMUX_TYPE sha_crit_sect = portMUX_INITIALIZER_UNLOCKED; #endif #if defined(DEBUG_WOLFSSL) @@ -664,43 +664,23 @@ int esp_unroll_sha_module_enable(WC_ESP32SHA* ctx) ** lock HW engine. ** this should be called before using engine. */ -int InitMutex() -{ - int ret; - ESP_LOGV(TAG, "Initializing sha_mutex"); - - /* created, but not yet locked */ - ret = esp_CryptHwMutexInit(&sha_mutex); - if (ret == 0) { - ESP_LOGV(TAG, "esp_CryptHwMutexInit sha_mutex init success."); - } - else { - ESP_LOGE(TAG, "esp_CryptHwMutexInit sha_mutex failed."); - sha_mutex = 0; - } - return ret; -} - bool TryAcquireHardware() { - bool bCanUseHardware = false; - if (0 == esp_CryptHwMutexLock(&sha_mutex, (TickType_t)0)) - { + bool bCanUseHardware = false; + taskENTER_CRITICAL(&sha_crit_sect); if (!InUse) { InUse = 1; bCanUseHardware = true; } - esp_CryptHwMutexUnLock(&sha_mutex); - } + taskEXIT_CRITICAL(&sha_crit_sect); return bCanUseHardware; } void ReleaseHardware() { - if (0 == esp_CryptHwMutexLock(&sha_mutex, (TickType_t)0)) - { + taskENTER_CRITICAL(&sha_crit_sect); if (InUse) { InUse = 0; @@ -709,8 +689,7 @@ void ReleaseHardware() { assert(false); // bug: releasing hardware when not in use!! } - esp_CryptHwMutexUnLock(&sha_mutex); - } + taskEXIT_CRITICAL(&sha_crit_sect); } int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) @@ -763,12 +742,6 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) ** */ - if (sha_mutex == NULL && 0 != InitMutex()) { - ESP_LOGI(TAG, "Revert to ctx->mode = ESP32_SHA_SW."); - ctx->mode = ESP32_SHA_SW; - return 0; /* success, just not using HW */ - } - /* check if this SHA has been operated as SW or HW, or not yet init */ if (ctx->mode == ESP32_SHA_INIT) { /* try to lock the HW engine */ From 373c05b29f926f14032e2fc6252621a0ff86980b Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 9 Aug 2023 17:48:19 +1200 Subject: [PATCH 4/5] commented out lock tracking (marked with PJM). --- src/internal.c | 8 ++++---- src/ssl.c | 2 +- src/tls13.c | 4 ++-- wolfcrypt/src/port/Espressif/esp32_sha.c | 10 +++++----- wolfcrypt/src/sha256.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/internal.c b/src/internal.c index 893476b040..df3e0587d4 100644 --- a/src/internal.c +++ b/src/internal.c @@ -9746,7 +9746,7 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) if (IsAtLeastTLSv1_2(ssl)) { #ifndef NO_SHA256 - printf("%s, %d: wc_Sha256Update of WC_ESP32SHA @ %0xd\n", __FUNCTION__, __LINE__, (unsigned)&ssl->hsHashes->hashSha256.ctx); + //printf("PJM - %s, %d: wc_Sha256Update of WC_ESP32SHA @ %0xd\n", __FUNCTION__, __LINE__, (unsigned)&ssl->hsHashes->hashSha256.ctx); ret = wc_Sha256Update(&ssl->hsHashes->hashSha256, data, sz); if (ret != 0) return ret; @@ -9767,7 +9767,7 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) #endif #endif #ifdef WOLFSSL_SHA512 - printf("%s, %d: wc_Sha512Update of WC_ESP32SHA @ %0xd\n", __FUNCTION__, __LINE__, (unsigned)&ssl->hsHashes->hashSha512.ctx); + //printf("PJM - %s, %d: wc_Sha512Update of WC_ESP32SHA @ %0xd\n", __FUNCTION__, __LINE__, (unsigned)&ssl->hsHashes->hashSha512.ctx); ret = wc_Sha512Update(&ssl->hsHashes->hashSha512, data, sz); if (ret != 0) return ret; @@ -9791,13 +9791,13 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) ((defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)) || \ (defined(HAVE_ED25519) && !defined(NO_ED25519_CLIENT_AUTH)) || \ (defined(HAVE_ED448) && !defined(NO_ED448_CLIENT_AUTH))) - printf("%s, %d: EdDSA_Update\n", __FUNCTION__, __LINE__); + //printf("PJM - %s, %d: EdDSA_Update\n", __FUNCTION__, __LINE__); ret = EdDSA_Update(ssl, data, sz); if (ret != 0) return ret; #endif } - printf("%s, %d\n", __FUNCTION__, __LINE__); + //printf("PJM - %s, %d\n", __FUNCTION__, __LINE__); return ret; } diff --git a/src/ssl.c b/src/ssl.c index 0347249278..02b9491a68 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -1487,7 +1487,7 @@ WOLFSSL_ABI void wolfSSL_free(WOLFSSL* ssl) { WOLFSSL_ENTER("wolfSSL_free"); - printf("Free SSL: %0xd\n", (unsigned)ssl); + if (ssl) FreeSSL(ssl, ssl->ctx->heap); diff --git a/src/tls13.c b/src/tls13.c index 7dd377d600..8d3b94aa1b 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -4530,12 +4530,12 @@ int SendTls13ClientHello(WOLFSSL* ssl) ret = EchHashHelloInner(ssl, args->ech); } #endif - printf("Client hello %d\n", __LINE__); + //printf("PJM - Client hello %d\n", __LINE__); /* compute the outer hash */ if (ret == 0) ret = HashOutput(ssl, args->output, args->idx, 0); - printf("Client hello %d\n", __LINE__); + //printf("PJM - Client hello %d\n", __LINE__); } } if (ret != 0) diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index 714679ba94..cd32c1ae72 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -643,7 +643,7 @@ int esp_unroll_sha_module_enable(WC_ESP32SHA* ctx) ** periph_module_disable() or threading not working properly. **/ ESP_LOGW(TAG, "warning lockDepth mismatch."); - printf("Bad lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); + //printf("PJM - Bad lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); } ctx->lockDepth = 0; ctx->mode = ESP32_SHA_INIT; @@ -764,7 +764,7 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) ESP_LOGW(TAG, "WARNING: Hardware Mode " "interesting lock depth = %d, %x", ctx->lockDepth, (int)ctx->initializer); - printf("Bad lock depth @ %d: %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); + //printf("PJM - Bad lock depth @ %d: %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); } } else { @@ -787,7 +787,7 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) #else if (ret == 0) { ctx->lockDepth++; /* depth for THIS ctx (there could be others!) */ - printf("Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); + // printf("PJM - Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); periph_module_enable(PERIPH_SHA_MODULE); ctx->mode = ESP32_SHA_HW; } @@ -821,14 +821,14 @@ int esp_sha_hw_unlock(WC_ESP32SHA* ctx) * and periph_module_disable() need to be unwound. * * see ref_counts[periph] in file: periph_ctrl.c */ - printf("Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); + //printf("PJM - Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); if (ctx->lockDepth > 0) { ctx->lockDepth--; } else { ctx->lockDepth = 0; } - printf("Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); + //printf("PJM - Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); if (0 == ctx->lockDepth) // should we only unlock if depth is 0? { diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 9c5c02c645..0721a66b44 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -1854,7 +1854,7 @@ void wc_Sha256Free(wc_Sha256* sha256) * the unexpected. by the time free is called, the hardware * should have already been released (lockDepth = 0) */ - printf("Bad lock depth @ %d = %d for %0xd\n", __LINE__, sha256->ctx.lockDepth, (unsigned)(&sha256->ctx)); + //printf("PJM - Bad lock depth @ %d = %d for %0xd\n", __LINE__, sha256->ctx.lockDepth, (unsigned)(&sha256->ctx)); (void)InitSha256(sha256); /* unlock mutex, set mode to ESP32_SHA_INIT */ ESP_LOGV(TAG, "Alert: hardware unlock needed in wc_Sha256Free."); } From 52f54ebc7af294227a1c9fff1db2607904c17204 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 9 Sep 2023 19:47:40 +1200 Subject: [PATCH 5/5] Removed tracing --- src/internal.c | 4 ---- src/tls13.c | 2 -- wolfcrypt/src/port/Espressif/esp32_sha.c | 5 ----- wolfcrypt/src/sha256.c | 1 - 4 files changed, 12 deletions(-) diff --git a/src/internal.c b/src/internal.c index 29f6682cb4..0fc869cb35 100644 --- a/src/internal.c +++ b/src/internal.c @@ -9746,7 +9746,6 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) if (IsAtLeastTLSv1_2(ssl)) { #ifndef NO_SHA256 - //printf("PJM - %s, %d: wc_Sha256Update of WC_ESP32SHA @ %0xd\n", __FUNCTION__, __LINE__, (unsigned)&ssl->hsHashes->hashSha256.ctx); ret = wc_Sha256Update(&ssl->hsHashes->hashSha256, data, sz); if (ret != 0) return ret; @@ -9767,7 +9766,6 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) #endif #endif #ifdef WOLFSSL_SHA512 - //printf("PJM - %s, %d: wc_Sha512Update of WC_ESP32SHA @ %0xd\n", __FUNCTION__, __LINE__, (unsigned)&ssl->hsHashes->hashSha512.ctx); ret = wc_Sha512Update(&ssl->hsHashes->hashSha512, data, sz); if (ret != 0) return ret; @@ -9791,13 +9789,11 @@ int HashRaw(WOLFSSL* ssl, const byte* data, int sz) ((defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)) || \ (defined(HAVE_ED25519) && !defined(NO_ED25519_CLIENT_AUTH)) || \ (defined(HAVE_ED448) && !defined(NO_ED448_CLIENT_AUTH))) - //printf("PJM - %s, %d: EdDSA_Update\n", __FUNCTION__, __LINE__); ret = EdDSA_Update(ssl, data, sz); if (ret != 0) return ret; #endif } - //printf("PJM - %s, %d\n", __FUNCTION__, __LINE__); return ret; } diff --git a/src/tls13.c b/src/tls13.c index d414f66c4c..46789c2c8d 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -4530,12 +4530,10 @@ int SendTls13ClientHello(WOLFSSL* ssl) ret = EchHashHelloInner(ssl, args->ech); } #endif - //printf("PJM - Client hello %d\n", __LINE__); /* compute the outer hash */ if (ret == 0) ret = HashOutput(ssl, args->output, args->idx, 0); - //printf("PJM - Client hello %d\n", __LINE__); } } if (ret != 0) diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index cd32c1ae72..ad860ad3e6 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -643,7 +643,6 @@ int esp_unroll_sha_module_enable(WC_ESP32SHA* ctx) ** periph_module_disable() or threading not working properly. **/ ESP_LOGW(TAG, "warning lockDepth mismatch."); - //printf("PJM - Bad lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); } ctx->lockDepth = 0; ctx->mode = ESP32_SHA_INIT; @@ -764,7 +763,6 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) ESP_LOGW(TAG, "WARNING: Hardware Mode " "interesting lock depth = %d, %x", ctx->lockDepth, (int)ctx->initializer); - //printf("PJM - Bad lock depth @ %d: %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); } } else { @@ -787,7 +785,6 @@ int esp_sha_try_hw_lock(WC_ESP32SHA* ctx) #else if (ret == 0) { ctx->lockDepth++; /* depth for THIS ctx (there could be others!) */ - // printf("PJM - Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); periph_module_enable(PERIPH_SHA_MODULE); ctx->mode = ESP32_SHA_HW; } @@ -821,14 +818,12 @@ int esp_sha_hw_unlock(WC_ESP32SHA* ctx) * and periph_module_disable() need to be unwound. * * see ref_counts[periph] in file: periph_ctrl.c */ - //printf("PJM - Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); if (ctx->lockDepth > 0) { ctx->lockDepth--; } else { ctx->lockDepth = 0; } - //printf("PJM - Lock depth @ %d = %d for WC_ESP32SHA @ %0xd\n", __LINE__, ctx->lockDepth, (unsigned)ctx); if (0 == ctx->lockDepth) // should we only unlock if depth is 0? { diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 70dec40807..e0734ebcbb 100644 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -1809,7 +1809,6 @@ void wc_Sha256Free(wc_Sha256* sha256) * the unexpected. by the time free is called, the hardware * should have already been released (lockDepth = 0) */ - //printf("PJM - Bad lock depth @ %d = %d for %0xd\n", __LINE__, sha256->ctx.lockDepth, (unsigned)(&sha256->ctx)); (void)InitSha256(sha256); /* unlock mutex, set mode to ESP32_SHA_INIT */ ESP_LOGV(TAG, "Alert: hardware unlock needed in wc_Sha256Free."); }