@@ -209,7 +209,7 @@ int esp_set_hw(WC_ESP32SHA* ctx)
209209*/
210210int esp_sha_need_byte_reversal (WC_ESP32SHA * ctx )
211211{
212- int ret = TRUE ; /* Assume we'll need reversal, look for exceptions. */
212+ int ret = 1 ; /* Assume we'll need reversal, look for exceptions. */
213213 CTX_STACK_CHECK (ctx );
214214#if defined(CONFIG_IDF_TARGET_ESP32C2 ) || \
215215 defined(CONFIG_IDF_TARGET_ESP8684 ) || \
@@ -227,10 +227,10 @@ int esp_sha_need_byte_reversal(WC_ESP32SHA* ctx)
227227 #endif
228228 if (ctx -> mode == ESP32_SHA_HW ) {
229229 ESP_LOGV (TAG , " No reversal, ESP32_SHA_HW" );
230- ret = FALSE ;
230+ ret = 0 ;
231231 }
232232 else {
233- ret = TRUE ;
233+ ret = 1 ;
234234 ESP_LOGV (TAG , " Need byte reversal, %d" , ctx -> mode );
235235 /* Return true for SW; only HW C3 skips reversal at this time. */
236236 #ifdef WOLFSSL_HW_METRICS
@@ -400,7 +400,7 @@ int esp_sha_init_ctx(WC_ESP32SHA* ctx)
400400
401401 /* Reminder: always start isfirstblock = 1 (true) when using HW engine. */
402402 /* We're always on the first block at init time. (not zero-based!) */
403- ctx -> isfirstblock = true ;
403+ ctx -> isfirstblock = 1 ;
404404 ctx -> lockDepth = 0 ; /* new objects will always start with lock depth = 0 */
405405
406406#if defined(MUTEX_DURING_INIT )
@@ -824,7 +824,7 @@ static int wc_esp_wait_until_idle(void)
824824 defined(CONFIG_IDF_TARGET_ESP32C3 ) || \
825825 defined(CONFIG_IDF_TARGET_ESP32C6 )
826826 /* ESP32-C3 and ESP32-C6 RISC-V */
827- while ((sha_ll_busy () == true ) && (loop_ct > 0 )) {
827+ while ((sha_ll_busy () == 1 ) && (loop_ct > 0 )) {
828828 loop_ct -- ;
829829 /* do nothing while waiting. */
830830 }
@@ -948,20 +948,22 @@ int esp_unroll_sha_module_enable(WC_ESP32SHA* ctx)
948948 return ret ;
949949} /* esp_unroll_sha_module_enable */
950950
951- int esp_sha_set_stray (WC_ESP32SHA * ctx )
951+ /* Set and return a stray ctx value stray_ctx. Useful for multi-task debugging.
952+ * Returns zero if not debugging. */
953+ uintptr_t esp_sha_set_stray (WC_ESP32SHA * ctx )
952954{
953- int ret = 0 ;
955+ uintptr_t ret = 0 ;
954956 CTX_STACK_CHECK (ctx );
955957
956958#ifdef WOLFSSL_DEBUG_MUTEX
957959 stray_ctx = ctx ;
958- ret = (int )stray_ctx ;
960+ ret = (uintptr_t )stray_ctx ;
959961#endif
960962 CTX_STACK_CHECK (ctx );
961963 return ret ;
962964}
963965
964- /* Return 1 if the SHA HW is in use, 0 otherwise*/
966+ /* Return 1 if the SHA HW is in use, 0 otherwise. */
965967int esp_sha_hw_in_use ()
966968{
967969 int ret ;
@@ -974,6 +976,7 @@ int esp_sha_hw_in_use()
974976 ESP_LOGV (TAG , "esp_sha_hw_in_use is %d" , ret );
975977 return ret ;
976978}
979+
977980/*
978981** return HW lock owner, otherwise zero if not locked.
979982**
@@ -1057,10 +1060,13 @@ uintptr_t esp_sha_hw_islocked(WC_ESP32SHA* ctx)
10571060 * The HW is typically unlocked when the SHA hash wc_Sha[nn]Final() is called.
10581061 * However, in the case of TLS connections the in-progress hash may at times be
10591062 * abandoned. Thus this function should be called at free time. See internal.c
1063+ *
1064+ * Returns the owner of the current lock, typically used for debugging.
1065+ * Returns zero if there was no unfinished lock found to clean up.
10601066 */
1061- int esp_sha_release_unfinished_lock (WC_ESP32SHA * ctx )
1067+ uintptr_t esp_sha_release_unfinished_lock (WC_ESP32SHA * ctx )
10621068{
1063- int ret = 0 ;
1069+ uintptr_t ret = 0 ;
10641070 CTX_STACK_CHECK (ctx );
10651071
10661072 ret = esp_sha_hw_islocked (ctx ); /* get the owner of the current lock */
@@ -1075,7 +1081,7 @@ int esp_sha_release_unfinished_lock(WC_ESP32SHA* ctx)
10751081 #endif
10761082 if (ret == (uintptr_t )ctx ) {
10771083 /* found a match for this object */
1078- if (ret == ( uintptr_t )( ctx -> initializer ) ) {
1084+ if (ret == ctx -> initializer ) {
10791085 /* confirmed match*/
10801086 ESP_LOGW (TAG , "New mutex_ctx_owner = NULL" );
10811087 #ifdef ESP_MONITOR_HW_TASK_LOCK
@@ -1087,7 +1093,7 @@ int esp_sha_release_unfinished_lock(WC_ESP32SHA* ctx)
10871093 else {
10881094 /* the only mismatch expected may be in a multi-thread RTOS */
10891095 ESP_LOGE (TAG , "ERROR: Release unfinished lock for %x but "
1090- "found %x" , ret , ( uintptr_t )( ctx -> initializer ) );
1096+ "found %x" , ret , ctx -> initializer );
10911097 }
10921098 #ifdef WOLFSSL_DEBUG_MUTEX
10931099 ESP_LOGE (TAG , "\n>>>> esp_sha_release_unfinished_lock %x\n" , ret );
@@ -1605,7 +1611,7 @@ static int esp_sha_start_process(WC_ESP32SHA* sha)
16051611 ESP_LOGV (TAG , "SHA1 SHA_START_REG" );
16061612 if (sha -> isfirstblock ) {
16071613 sha_ll_start_block (SHA2_256 );
1608- sha -> isfirstblock = false ;
1614+ sha -> isfirstblock = 0 ;
16091615
16101616 ESP_LOGV (TAG , " set sha->isfirstblock = 0" );
16111617
@@ -1658,7 +1664,7 @@ static int esp_sha_start_process(WC_ESP32SHA* sha)
16581664
16591665 if (sha -> isfirstblock ) {
16601666 REG_WRITE (SHA_START_REG , 1 );
1661- sha -> isfirstblock = false ;
1667+ sha -> isfirstblock = 0 ;
16621668
16631669 ESP_LOGV (TAG , " set sha->isfirstblock = 0" );
16641670
@@ -1709,7 +1715,7 @@ static int esp_sha_start_process(WC_ESP32SHA* sha)
17091715 break ;
17101716 }
17111717
1712- sha -> isfirstblock = false ;
1718+ sha -> isfirstblock = 0 ;
17131719 ESP_LOGV (TAG , " set sha->isfirstblock = 0" );
17141720
17151721 #if defined(DEBUG_WOLFSSL )
@@ -1976,7 +1982,7 @@ int wc_esp_digest_state(WC_ESP32SHA* ctx, byte* hash)
19761982 }
19771983
19781984#if defined(CONFIG_IDF_TARGET_ESP32S2 ) || defined(CONFIG_IDF_TARGET_ESP32S3 )
1979- if (ctx -> isfirstblock == true ) {
1985+ if (ctx -> isfirstblock == 1 ) {
19801986 /* no hardware use yet. Nothing to do yet */
19811987 return ESP_OK ;
19821988 }
@@ -2064,7 +2070,7 @@ int wc_esp_digest_state(WC_ESP32SHA* ctx, byte* hash)
20642070 return ESP_FAIL ;
20652071 }
20662072
2067- if (ctx -> isfirstblock == true ) {
2073+ if (ctx -> isfirstblock == 1 ) {
20682074 /* no hardware use yet. Nothing to do yet */
20692075 return ESP_OK ;
20702076 }
0 commit comments