diff --git a/components/esp_hw_support/port/esp32h2/esp_crypto_lock.c b/components/esp_hw_support/port/esp32h2/esp_crypto_lock.c index 209866fe4f..9569637346 100644 --- a/components/esp_hw_support/port/esp32h2/esp_crypto_lock.c +++ b/components/esp_hw_support/port/esp32h2/esp_crypto_lock.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +7,7 @@ #include #include "esp_crypto_lock.h" +#include "hal/ecdsa_ll.h" /* Lock overview: SHA: peripheral independent, but DMA is shared with AES @@ -96,12 +97,18 @@ void esp_crypto_ecdsa_lock_acquire(void) { _lock_acquire(&s_crypto_ecdsa_lock); esp_crypto_ecc_lock_acquire(); - esp_crypto_mpi_lock_acquire(); + + if (ecdsa_ll_is_mpi_required()) { + esp_crypto_mpi_lock_acquire(); + } } void esp_crypto_ecdsa_lock_release(void) { - esp_crypto_mpi_lock_release(); + if (ecdsa_ll_is_mpi_required()) { + esp_crypto_mpi_lock_release(); + } + esp_crypto_ecc_lock_release(); _lock_release(&s_crypto_ecdsa_lock); } diff --git a/components/esp_hw_support/port/esp32p4/esp_crypto_lock.c b/components/esp_hw_support/port/esp32p4/esp_crypto_lock.c index e8687c7f02..c62fd0b870 100644 --- a/components/esp_hw_support/port/esp32p4/esp_crypto_lock.c +++ b/components/esp_hw_support/port/esp32p4/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 */ @@ -7,6 +7,7 @@ #include #include "esp_crypto_lock.h" +#include "hal/ecdsa_ll.h" /* Lock overview: SHA: peripheral independent, but DMA is shared with AES @@ -99,12 +100,18 @@ void esp_crypto_ecdsa_lock_acquire(void) { _lock_acquire(&s_crypto_ecdsa_lock); esp_crypto_ecc_lock_acquire(); - esp_crypto_mpi_lock_acquire(); + + if (ecdsa_ll_is_mpi_required()) { + esp_crypto_mpi_lock_acquire(); + } } void esp_crypto_ecdsa_lock_release(void) { - esp_crypto_mpi_lock_release(); + if (ecdsa_ll_is_mpi_required()) { + esp_crypto_mpi_lock_release(); + } + 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 f3429cf1b2..d439f1d539 100644 --- a/components/hal/esp32p4/include/hal/ecdsa_ll.h +++ b/components/hal/esp32p4/include/hal/ecdsa_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -432,6 +432,14 @@ static inline int ecdsa_ll_check_k_value(void) return REG_GET_BIT(ECDSA_RESULT_REG, ECDSA_K_VALUE_WARNING); } +/** + * @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 9e2d341770..130ac044cd 100644 --- a/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c +++ b/components/hal/test_apps/crypto/main/ecdsa/test_ecdsa.c @@ -43,9 +43,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 } @@ -53,8 +55,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 89bc215e03..a083a96170 100644 --- a/components/mbedtls/port/ecdsa/ecdsa_alt.c +++ b/components/mbedtls/port/ecdsa/ecdsa_alt.c @@ -68,9 +68,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 */ } @@ -87,8 +89,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 */