From 93473a055855d717876902a42507adede2f478ff Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Fri, 8 Aug 2025 17:28:25 +0530 Subject: [PATCH] change(mbedtls/ecdsa): The ECDSA module of ESP32-H2 ECO5 does not use MPI module --- components/esp_security/src/esp_crypto_lock.c | 13 ++++++++++--- components/hal/esp32h2/include/hal/ecdsa_ll.h | 8 ++++++++ components/hal/esp32p4/include/hal/ecdsa_ll.h | 8 ++++++++ .../hal/test_apps/crypto/main/ecdsa/test_ecdsa.c | 14 +++++++++----- components/mbedtls/port/ecdsa/ecdsa_alt.c | 14 +++++++++----- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/components/esp_security/src/esp_crypto_lock.c b/components/esp_security/src/esp_crypto_lock.c index 0712c1acbb..1dd15473a9 100644 --- a/components/esp_security/src/esp_crypto_lock.c +++ b/components/esp_security/src/esp_crypto_lock.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -46,6 +46,9 @@ static _lock_t s_crypto_ecc_lock; #ifdef SOC_ECDSA_SUPPORTED /* Lock for ECDSA peripheral */ static _lock_t s_crypto_ecdsa_lock; +#if SOC_ECDSA_USES_MPI +#include "hal/ecdsa_ll.h" +#endif /* SOC_ECDSA_USES_MPI */ #endif /* SOC_ECDSA_SUPPORTED */ #ifdef SOC_KEY_MANAGER_SUPPORTED @@ -137,14 +140,18 @@ void esp_crypto_ecdsa_lock_acquire(void) _lock_acquire(&s_crypto_ecdsa_lock); esp_crypto_ecc_lock_acquire(); #ifdef SOC_ECDSA_USES_MPI - esp_crypto_mpi_lock_acquire(); + if (ecdsa_ll_is_mpi_required()) { + esp_crypto_mpi_lock_acquire(); + } #endif /* SOC_ECDSA_USES_MPI */ } void esp_crypto_ecdsa_lock_release(void) { #ifdef SOC_ECDSA_USES_MPI - esp_crypto_mpi_lock_release(); + if (ecdsa_ll_is_mpi_required()) { + esp_crypto_mpi_lock_release(); + } #endif /* SOC_ECDSA_USES_MPI */ esp_crypto_ecc_lock_release(); _lock_release(&s_crypto_ecdsa_lock); diff --git a/components/hal/esp32h2/include/hal/ecdsa_ll.h b/components/hal/esp32h2/include/hal/ecdsa_ll.h index 65299c1219..842e5b4d97 100644 --- a/components/hal/esp32h2/include/hal/ecdsa_ll.h +++ b/components/hal/esp32h2/include/hal/ecdsa_ll.h @@ -418,6 +418,14 @@ static inline bool ecdsa_ll_is_deterministic_mode_supported(void) return ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 102); } +/** + * @brief Check if the ECDSA peripheral uses MPI module's memory + */ +static inline bool ecdsa_ll_is_mpi_required(void) +{ + return !ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 102); +} + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32p4/include/hal/ecdsa_ll.h b/components/hal/esp32p4/include/hal/ecdsa_ll.h index 1e8a713f75..b7d16aae0e 100644 --- a/components/hal/esp32p4/include/hal/ecdsa_ll.h +++ b/components/hal/esp32p4/include/hal/ecdsa_ll.h @@ -440,6 +440,14 @@ static inline bool ecdsa_ll_is_deterministic_mode_supported(void) return true; } +/** + * @brief Check if the ECDSA peripheral uses MPI module's memory + */ +static inline bool ecdsa_ll_is_mpi_required(void) +{ + return true; // TODO: IDF-13523 +} + #ifdef __cplusplus } #endif diff --git a/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c b/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c index c7ddbeecd7..3e96c9a1e4 100644 --- a/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c +++ b/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c @@ -45,9 +45,11 @@ static void ecdsa_enable_and_reset(void) } #ifdef SOC_ECDSA_USES_MPI - MPI_RCC_ATOMIC() { - mpi_ll_enable_bus_clock(true); - mpi_ll_reset_register(); + if (ecdsa_ll_is_mpi_required()) { + MPI_RCC_ATOMIC() { + mpi_ll_enable_bus_clock(true); + mpi_ll_reset_register(); + } } #endif } @@ -55,8 +57,10 @@ static void ecdsa_enable_and_reset(void) static void ecdsa_disable(void) { #ifdef SOC_ECDSA_USES_MPI - MPI_RCC_ATOMIC() { - mpi_ll_enable_bus_clock(false); + if (ecdsa_ll_is_mpi_required()) { + MPI_RCC_ATOMIC() { + mpi_ll_enable_bus_clock(false); + } } #endif diff --git a/components/mbedtls/port/ecdsa/ecdsa_alt.c b/components/mbedtls/port/ecdsa/ecdsa_alt.c index 96a14e7930..b6db8b0ae6 100644 --- a/components/mbedtls/port/ecdsa/ecdsa_alt.c +++ b/components/mbedtls/port/ecdsa/ecdsa_alt.c @@ -70,9 +70,11 @@ static void esp_ecdsa_acquire_hardware(void) /* We need to reset the MPI peripheral because ECDSA peripheral * of some targets use the MPI peripheral as well. */ - MPI_RCC_ATOMIC() { - mpi_ll_enable_bus_clock(true); - mpi_ll_reset_register(); + if (ecdsa_ll_is_mpi_required()) { + MPI_RCC_ATOMIC() { + mpi_ll_enable_bus_clock(true); + mpi_ll_reset_register(); + } } #endif /* SOC_ECDSA_USES_MPI */ } @@ -89,8 +91,10 @@ static void esp_ecdsa_release_hardware(void) } #ifdef SOC_ECDSA_USES_MPI - MPI_RCC_ATOMIC() { - mpi_ll_enable_bus_clock(false); + if (ecdsa_ll_is_mpi_required()) { + MPI_RCC_ATOMIC() { + mpi_ll_enable_bus_clock(false); + } } #endif /* SOC_ECDSA_USES_MPI */