diff --git a/components/esp_hal_security/esp32/include/hal/sha_ll.h b/components/esp_hal_security/esp32/include/hal/sha_ll.h index 18b4e775e43..42b2402d67f 100644 --- a/components/esp_hal_security/esp32/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -195,6 +195,18 @@ static inline void sha_ll_read_digest(esp_sha_type sha_type, void *digest_state, } } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32c2/include/hal/sha_ll.h b/components/esp_hal_security/esp32c2/include/hal/sha_ll.h index a353e70d197..3dc6780df34 100644 --- a/components/esp_hal_security/esp32c2/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32c2/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -180,6 +180,18 @@ static inline void sha_ll_write_digest(esp_sha_type sha_type, void *digest_state } } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32c3/include/hal/sha_ll.h b/components/esp_hal_security/esp32c3/include/hal/sha_ll.h index 6970f1ccbea..700f8ab7600 100644 --- a/components/esp_hal_security/esp32c3/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32c3/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -184,6 +184,18 @@ static inline void sha_ll_write_digest(esp_sha_type sha_type, void *digest_state } } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32c5/include/hal/sha_ll.h b/components/esp_hal_security/esp32c5/include/hal/sha_ll.h index 28c66a0bcc1..62f550a150a 100644 --- a/components/esp_hal_security/esp32c5/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32c5/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -191,6 +191,18 @@ static inline void sha_ll_t_len_set(uint8_t t_len) REG_WRITE(SHA_T_LENGTH_REG, t_len); } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no eFuse that disables SM3, so the mode is always available. + * + * @return true + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return true; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32c6/include/hal/sha_ll.h b/components/esp_hal_security/esp32c6/include/hal/sha_ll.h index 1c727408d45..9ed487d4733 100644 --- a/components/esp_hal_security/esp32c6/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32c6/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -170,6 +170,18 @@ static inline void sha_ll_write_digest(esp_sha_type sha_type, void *digest_state } } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32c61/include/hal/sha_ll.h b/components/esp_hal_security/esp32c61/include/hal/sha_ll.h index c1e90c4e0ef..dc699b40edf 100644 --- a/components/esp_hal_security/esp32c61/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32c61/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -169,6 +169,18 @@ static inline void sha_ll_write_digest(esp_sha_type sha_type, void *digest_state } } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32h2/include/hal/sha_ll.h b/components/esp_hal_security/esp32h2/include/hal/sha_ll.h index 32ece1b085b..6df20e0d052 100644 --- a/components/esp_hal_security/esp32h2/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32h2/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -171,6 +171,18 @@ static inline void sha_ll_write_digest(esp_sha_type sha_type, void *digest_state } } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32h21/include/hal/sha_ll.h b/components/esp_hal_security/esp32h21/include/hal/sha_ll.h index 2b6dc3d6aa4..bfb4df5f5d5 100644 --- a/components/esp_hal_security/esp32h21/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32h21/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -171,6 +171,18 @@ static inline void sha_ll_write_digest(esp_sha_type sha_type, void *digest_state } } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32p4/include/hal/sha_ll.h b/components/esp_hal_security/esp32p4/include/hal/sha_ll.h index 49ec3f72870..bb61650b794 100644 --- a/components/esp_hal_security/esp32p4/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32p4/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -206,6 +206,18 @@ static inline void sha_ll_t_len_set(uint8_t t_len) REG_WRITE(SHA_T_LENGTH_REG, t_len); } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32s2/include/hal/sha_ll.h b/components/esp_hal_security/esp32s2/include/hal/sha_ll.h index 1f13e1d01bc..3bc6574b8f2 100644 --- a/components/esp_hal_security/esp32s2/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32s2/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -223,6 +223,18 @@ static inline void sha_ll_t_len_set(uint8_t t_len) REG_WRITE(SHA_T_LENGTH_REG, t_len); } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32s3/include/hal/sha_ll.h b/components/esp_hal_security/esp32s3/include/hal/sha_ll.h index 357ff5980eb..2072db67274 100644 --- a/components/esp_hal_security/esp32s3/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32s3/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -201,6 +201,18 @@ static inline void sha_ll_t_len_set(uint8_t t_len) REG_WRITE(SHA_T_LENGTH_REG, t_len); } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no SM3 hardware. + * + * @return false + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return false; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/esp32s31/include/hal/sha_ll.h b/components/esp_hal_security/esp32s31/include/hal/sha_ll.h index ca6151d9e5f..97e329c7b13 100644 --- a/components/esp_hal_security/esp32s31/include/hal/sha_ll.h +++ b/components/esp_hal_security/esp32s31/include/hal/sha_ll.h @@ -9,6 +9,7 @@ #include "hal/sha_types.h" #include "soc/hp_sys_clkrst_struct.h" #include "soc/hwcrypto_reg.h" +#include "soc/efuse_struct.h" /* ESP32-S31 SHA register header uses SHA_2_SM_3_H_MEM/M_MEM naming * instead of SHA_H_MEM/M_MEM. Define compatibility macros. */ @@ -211,6 +212,20 @@ static inline void sha_ll_t_len_set(uint8_t t_len) REG_WRITE(SHA_T_LENGTH_REG, t_len); } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * The DIS_SM_CRYPT eFuse disables SM2 and SM3 permanently. The function reads + * the eFuse shadow register directly, so it reports the real chip state also + * when CONFIG_EFUSE_VIRTUAL is enabled. + * + * @return true if SM3 is available, false if the eFuse disables it + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return !EFUSE.rd_repeat_data1.dis_sm_crypt; +} + #ifdef __cplusplus } #endif diff --git a/components/esp_hal_security/include/hal/sha_hal.h b/components/esp_hal_security/include/hal/sha_hal.h index c6c11d6cebe..a1d7be76f5e 100644 --- a/components/esp_hal_security/include/hal/sha_hal.h +++ b/components/esp_hal_security/include/hal/sha_hal.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -73,6 +73,14 @@ void sha_hal_write_digest(esp_sha_type sha_type, void *digest_state); void sha_hal_hash_dma(size_t num_blocks, bool first_block); #endif +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * @return true if SM3 is available. false if the chip has no SM3 hardware + * or if an eFuse disables it. + */ +bool sha_hal_is_sm3_supported(void); + #if SOC_SHA_SUPPORT_SHA512_T /** * @brief Calculates and sets the initial digiest for SHA512_t diff --git a/components/esp_hal_security/sha_hal.c b/components/esp_hal_security/sha_hal.c index b2d567bbbbc..95e8c087c2a 100644 --- a/components/esp_hal_security/sha_hal.c +++ b/components/esp_hal_security/sha_hal.c @@ -139,6 +139,11 @@ void sha_hal_write_digest(esp_sha_type sha_type, void *digest_state) } #endif //SOC_SHA_SUPPORT_RESUME +bool sha_hal_is_sm3_supported(void) +{ + return sha_ll_is_sm3_supported(); +} + #if SOC_SHA_SUPPORT_SHA512_T /* Calculates and sets the initial digiest for SHA512_t */ diff --git a/components/hal/esp32h4/include/hal/sha_ll.h b/components/hal/esp32h4/include/hal/sha_ll.h index 53fd27b8eeb..e263e2a5151 100644 --- a/components/hal/esp32h4/include/hal/sha_ll.h +++ b/components/hal/esp32h4/include/hal/sha_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -189,6 +189,18 @@ static inline void sha_ll_t_len_set(uint8_t t_len) REG_WRITE(SHA_T_LENGTH_REG, t_len); } +/** + * @brief Check whether the SHA peripheral can run the SM3 mode. + * + * This chip has no eFuse that disables SM3, so the mode is always available. + * + * @return true + */ +static inline bool sha_ll_is_sm3_supported(void) +{ + return true; +} + #ifdef __cplusplus } #endif