diff --git a/components/esp_hw_support/include/soc/esp32/esp_crypto_lock.h b/components/esp_hw_support/include/soc/esp32/esp_crypto_lock.h new file mode 100644 index 0000000000..340278c911 --- /dev/null +++ b/components/esp_hw_support/include/soc/esp32/esp_crypto_lock.h @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Acquire lock for the mpi cryptography peripheral. + * + */ +void esp_crypto_mpi_lock_acquire(void); + +/** + * @brief Release lock for the mpi cryptography peripheral. + * + */ +void esp_crypto_mpi_lock_release(void); + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_hw_support/port/esp32/CMakeLists.txt b/components/esp_hw_support/port/esp32/CMakeLists.txt index 81d3206176..27a9809b21 100644 --- a/components/esp_hw_support/port/esp32/CMakeLists.txt +++ b/components/esp_hw_support/port/esp32/CMakeLists.txt @@ -11,6 +11,7 @@ set(srcs if(NOT BOOTLOADER_BUILD) list(APPEND srcs "cache_sram_mmu.c" + "esp_crypto_lock.c" "sar_periph_ctrl.c") endif() diff --git a/components/esp_hw_support/port/esp32/esp_crypto_lock.c b/components/esp_hw_support/port/esp32/esp_crypto_lock.c new file mode 100644 index 0000000000..3eb303c92b --- /dev/null +++ b/components/esp_hw_support/port/esp32/esp_crypto_lock.c @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "esp_crypto_lock.h" + +/* Lock overview: +MPI/RSA: independent +*/ + +/* Lock for the MPI/RSA peripheral */ + +static _lock_t s_crypto_mpi_lock; + +void esp_crypto_mpi_lock_acquire(void) +{ + _lock_acquire(&s_crypto_mpi_lock); +} + +void esp_crypto_mpi_lock_release(void) +{ + _lock_release(&s_crypto_mpi_lock); +} diff --git a/components/mbedtls/port/bignum/bignum_alt.c b/components/mbedtls/port/bignum/bignum_alt.c index 815b095b1d..f8ae1a1605 100644 --- a/components/mbedtls/port/bignum/bignum_alt.c +++ b/components/mbedtls/port/bignum/bignum_alt.c @@ -3,28 +3,17 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include "esp_crypto_lock.h" #include "esp_private/periph_ctrl.h" #include "bignum_impl.h" #include "mbedtls/bignum.h" -#if CONFIG_IDF_TARGET_ESP32 -#include -static _lock_t mpi_lock; -#else -#include "esp_crypto_lock.h" -#endif - #include "hal/mpi_hal.h" void esp_mpi_enable_hardware_hw_op( void ) { -#if CONFIG_IDF_TARGET_ESP32 - /* newlib locks lazy initialize on ESP-IDF */ - _lock_acquire(&mpi_lock); -#else esp_crypto_mpi_lock_acquire(); -#endif /* Enable RSA hardware */ periph_module_enable(PERIPH_RSA_MODULE); @@ -40,11 +29,7 @@ void esp_mpi_disable_hardware_hw_op( void ) /* Disable RSA hardware */ periph_module_disable(PERIPH_RSA_MODULE); -#if CONFIG_IDF_TARGET_ESP32 - _lock_release(&mpi_lock); -#else esp_crypto_mpi_lock_release(); -#endif } size_t esp_mpi_hardware_words(size_t words)