From 7f413c914df482f02fc957f12f2d802414147da2 Mon Sep 17 00:00:00 2001 From: "nilesh.kale" Date: Fri, 24 Apr 2026 11:17:19 +0530 Subject: [PATCH] feat(sha): add SM3 hardware support Enable hardware SM3 digest support on ESP32-H4, ESP32-S31 and ESP32-C5 via the SHA peripheral (mode 14). --- components/esp_hal_security/sha_hal.c | 3 +++ components/esp_rom/esp32c5/include/esp32c5/rom/sha.h | 1 + components/esp_rom/esp32h4/include/esp32h4/rom/sha.h | 1 + components/esp_rom/esp32s31/include/esp32s31/rom/sha.h | 1 + components/soc/esp32c5/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32c5/include/soc/soc_caps.h | 1 + components/soc/esp32h4/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32h4/include/soc/soc_caps.h | 1 + components/soc/esp32s31/include/soc/Kconfig.soc_caps.in | 4 ++++ components/soc/esp32s31/include/soc/soc_caps.h | 1 + 10 files changed, 21 insertions(+) diff --git a/components/esp_hal_security/sha_hal.c b/components/esp_hal_security/sha_hal.c index d7da7f4fe6a..b2d567bbbbc 100644 --- a/components/esp_hal_security/sha_hal.c +++ b/components/esp_hal_security/sha_hal.c @@ -44,6 +44,9 @@ inline static size_t state_length(esp_sha_type type) return SHA1_STATE_LEN_WORDS; case SHA2_224: case SHA2_256: +#if SOC_SHA_SUPPORT_SM3 + case SM3: +#endif return SHA256_STATE_LEN_WORDS; #if SOC_SHA_SUPPORT_SHA384 case SHA2_384: diff --git a/components/esp_rom/esp32c5/include/esp32c5/rom/sha.h b/components/esp_rom/esp32c5/include/esp32c5/rom/sha.h index be03f8ab107..b2e90a67aee 100644 --- a/components/esp_rom/esp32c5/include/esp32c5/rom/sha.h +++ b/components/esp_rom/esp32c5/include/esp32c5/rom/sha.h @@ -23,6 +23,7 @@ typedef enum { SHA2_512224, SHA2_512256, SHA2_512T, + SM3 = 14, SHA_TYPE_MAX } SHA_TYPE; diff --git a/components/esp_rom/esp32h4/include/esp32h4/rom/sha.h b/components/esp_rom/esp32h4/include/esp32h4/rom/sha.h index 0d4a84c105a..995fdc99690 100644 --- a/components/esp_rom/esp32h4/include/esp32h4/rom/sha.h +++ b/components/esp_rom/esp32h4/include/esp32h4/rom/sha.h @@ -23,6 +23,7 @@ typedef enum { SHA2_512224, SHA2_512256, SHA2_512T, + SM3 = 14, SHA_TYPE_MAX } SHA_TYPE; diff --git a/components/esp_rom/esp32s31/include/esp32s31/rom/sha.h b/components/esp_rom/esp32s31/include/esp32s31/rom/sha.h index 0d4a84c105a..995fdc99690 100644 --- a/components/esp_rom/esp32s31/include/esp32s31/rom/sha.h +++ b/components/esp_rom/esp32s31/include/esp32s31/rom/sha.h @@ -23,6 +23,7 @@ typedef enum { SHA2_512224, SHA2_512256, SHA2_512T, + SM3 = 14, SHA_TYPE_MAX } SHA_TYPE; diff --git a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in index 87cb0251cbc..e21a6f8f312 100644 --- a/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c5/include/soc/Kconfig.soc_caps.in @@ -911,6 +911,10 @@ config SOC_SHA_SUPPORT_SHA512_T bool default y +config SOC_SHA_SUPPORT_SM3 + bool + default y + config SOC_ECC_CONSTANT_TIME_POINT_MUL bool default y diff --git a/components/soc/esp32c5/include/soc/soc_caps.h b/components/soc/esp32c5/include/soc/soc_caps.h index f4bed4b404c..367780f1886 100644 --- a/components/soc/esp32c5/include/soc/soc_caps.h +++ b/components/soc/esp32c5/include/soc/soc_caps.h @@ -375,6 +375,7 @@ #define SOC_SHA_SUPPORT_SHA512_224 (1) #define SOC_SHA_SUPPORT_SHA512_256 (1) #define SOC_SHA_SUPPORT_SHA512_T (1) +#define SOC_SHA_SUPPORT_SM3 (1) /*--------------------------- ECC CAPS ---------------------------------------*/ #define SOC_ECC_CONSTANT_TIME_POINT_MUL 1 diff --git a/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in index c49cd55822f..de6395d1eca 100644 --- a/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h4/include/soc/Kconfig.soc_caps.in @@ -815,6 +815,10 @@ config SOC_SHA_SUPPORT_SHA512_T bool default y +config SOC_SHA_SUPPORT_SM3 + bool + default y + config SOC_ECC_CONSTANT_TIME_POINT_MUL bool default y diff --git a/components/soc/esp32h4/include/soc/soc_caps.h b/components/soc/esp32h4/include/soc/soc_caps.h index 68c13ee8d3f..fb0ff754086 100644 --- a/components/soc/esp32h4/include/soc/soc_caps.h +++ b/components/soc/esp32h4/include/soc/soc_caps.h @@ -352,6 +352,7 @@ #define SOC_SHA_SUPPORT_SHA384 (1) #define SOC_SHA_SUPPORT_SHA512 (1) #define SOC_SHA_SUPPORT_SHA512_T (1) +#define SOC_SHA_SUPPORT_SM3 (1) /*--------------------------- ECC CAPS ---------------------------------------*/ #define SOC_ECC_CONSTANT_TIME_POINT_MUL 1 diff --git a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in index d5f62e19a50..5dfba7b53aa 100644 --- a/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s31/include/soc/Kconfig.soc_caps.in @@ -1091,6 +1091,10 @@ config SOC_SHA_SUPPORT_SHA512_T bool default y +config SOC_SHA_SUPPORT_SM3 + bool + default y + config SOC_MPI_MEM_BLOCKS_NUM int default 4 diff --git a/components/soc/esp32s31/include/soc/soc_caps.h b/components/soc/esp32s31/include/soc/soc_caps.h index 0dc1f8a43eb..22d1dacd0b5 100644 --- a/components/soc/esp32s31/include/soc/soc_caps.h +++ b/components/soc/esp32s31/include/soc/soc_caps.h @@ -401,6 +401,7 @@ #define SOC_SHA_SUPPORT_SHA512_224 (1) #define SOC_SHA_SUPPORT_SHA512_256 (1) #define SOC_SHA_SUPPORT_SHA512_T (1) +#define SOC_SHA_SUPPORT_SM3 (1) /*--------------------------- MPI CAPS ---------------------------------------*/ #define SOC_MPI_MEM_BLOCKS_NUM (4)