Skip to content

Commit e63f109

Browse files
committed
Add fix for SHA HW on ESP-IDF v6
1 parent b90720c commit e63f109

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

wolfcrypt/src/port/Espressif/esp32_sha.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555

5656
#include <hal/sha_ll.h>
5757
#include <hal/clk_gate_ll.h>
58+
#if ESP_IDF_VERSION_MAJOR >= 6
59+
#include "sha/sha_core.h"
60+
#endif
5861
#elif defined(CONFIG_IDF_TARGET_ESP32) || \
5962
defined(CONFIG_IDF_TARGET_ESP32S2) || \
6063
defined(CONFIG_IDF_TARGET_ESP32S3)
@@ -1928,6 +1931,24 @@ static int wc_esp_process_block(WC_ESP32SHA* ctx, /* see ctx->sha_type */
19281931
}
19291932
if (ctx->isfirstblock) {
19301933
ets_sha_enable(); /* will clear initial digest */
1934+
#if ESP_IDF_VERSION_MAJOR >= 6
1935+
/* Beginning ESP-IDF v6, the mode needs to be explictly set. */
1936+
sha_hal_wait_idle();
1937+
switch (ctx->sha_type) {
1938+
case SHA1:
1939+
sha_hal_set_mode(SHA1);
1940+
break;
1941+
case SHA2_224:
1942+
esp_sha_set_mode(SHA2_224);
1943+
break;
1944+
case SHA2_256:
1945+
esp_sha_set_mode(SHA2_256);
1946+
break;
1947+
default:
1948+
/* Unsupported SHA mode. */
1949+
ESP_LOGW(TAG, "Unexpected sha_type", ctx->sha_type);
1950+
}
1951+
#endif
19311952
#if defined(DEBUG_WOLFSSL)
19321953
{
19331954
this_block_num = 1; /* one-based counter, just for debug info */

0 commit comments

Comments
 (0)