diff --git a/wolfcrypt/src/port/Espressif/esp32_sha.c b/wolfcrypt/src/port/Espressif/esp32_sha.c index 474a0c5718f..3f07c1da322 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 */