From d50593834b2f62c34e0210bd35b9f67a8622fc62 Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Fri, 19 Sep 2025 12:04:46 -0700 Subject: [PATCH] Add fix for SHA HW on ESP-IDF v6 --- wolfcrypt/src/port/Espressif/esp32_sha.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index 474a0c571..3f07c1da3 100644 --- a/wolfcrypt/src/port/Espressif/esp32_sha.c +++ b/wolfcrypt/src/port/Espressif/esp32_sha.c @@ -55,6 +55,9 @@ #include #include + #if ESP_IDF_VERSION_MAJOR >= 6 + #include "sha/sha_core.h" + #endif #elif defined(CONFIG_IDF_TARGET_ESP32) || \ defined(CONFIG_IDF_TARGET_ESP32S2) || \ defined(CONFIG_IDF_TARGET_ESP32S3) @@ -1928,6 +1931,24 @@ static int wc_esp_process_block(WC_ESP32SHA* ctx, /* see ctx->sha_type */ } if (ctx->isfirstblock) { ets_sha_enable(); /* will clear initial digest */ +#if ESP_IDF_VERSION_MAJOR >= 6 + /* Beginning ESP-IDF v6, the mode needs to be explicitly set. */ + sha_hal_wait_idle(); + switch (ctx->sha_type) { + case SHA1: + sha_hal_set_mode(SHA1); + break; + case SHA2_224: + esp_sha_set_mode(SHA2_224); + break; + case SHA2_256: + esp_sha_set_mode(SHA2_256); + break; + default: + /* Unsupported SHA mode. */ + ESP_LOGW(TAG, "Unexpected sha_type", ctx->sha_type); + } +#endif #if defined(DEBUG_WOLFSSL) { this_block_num = 1; /* one-based counter, just for debug info */