fix(mbedtls/ecdsa): Fix dependant peripheral's enable and reset

This commit is contained in:
harshal.patil
2024-03-28 19:33:23 +05:30
parent 85186042c3
commit bd826801ba
6 changed files with 70 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: CC0-1.0 * SPDX-License-Identifier: CC0-1.0
*/ */
@ -14,6 +14,9 @@
#include "hal/ecdsa_hal.h" #include "hal/ecdsa_hal.h"
#include "hal/ecdsa_ll.h" #include "hal/ecdsa_ll.h"
#include "hal/ecdsa_types.h" #include "hal/ecdsa_types.h"
#include "hal/ecc_ll.h"
#include "hal/mpi_ll.h"
#include "soc/soc_caps.h"
#include "memory_checks.h" #include "memory_checks.h"
#include "unity_fixture.h" #include "unity_fixture.h"
@ -26,10 +29,32 @@ static void ecdsa_enable_and_reset(void)
ecdsa_ll_enable_bus_clock(true); ecdsa_ll_enable_bus_clock(true);
ecdsa_ll_reset_register(); ecdsa_ll_reset_register();
} }
ECC_RCC_ATOMIC() {
ecc_ll_enable_bus_clock(true);
ecc_ll_reset_register();
}
#ifdef SOC_ECDSA_USES_MPI
MPI_RCC_ATOMIC() {
mpi_ll_enable_bus_clock(true);
mpi_ll_reset_register();
}
#endif
} }
static void ecdsa_disable(void) static void ecdsa_disable(void)
{ {
#ifdef SOC_ECDSA_USES_MPI
MPI_RCC_ATOMIC() {
mpi_ll_enable_bus_clock(false);
}
#endif
ECC_RCC_ATOMIC() {
ecc_ll_enable_bus_clock(false);
}
ECDSA_RCC_ATOMIC() { ECDSA_RCC_ATOMIC() {
ecdsa_ll_enable_bus_clock(false); ecdsa_ll_enable_bus_clock(false);
} }

View File

@ -1,11 +1,13 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <string.h> #include <string.h>
#include "hal/ecdsa_ll.h" #include "hal/ecdsa_ll.h"
#include "hal/ecdsa_hal.h" #include "hal/ecdsa_hal.h"
#include "hal/ecc_ll.h"
#include "hal/mpi_ll.h"
#include "esp_crypto_lock.h" #include "esp_crypto_lock.h"
#include "esp_efuse.h" #include "esp_efuse.h"
#include "esp_private/esp_crypto_lock_internal.h" #include "esp_private/esp_crypto_lock_internal.h"
@ -14,6 +16,7 @@
#include "mbedtls/asn1write.h" #include "mbedtls/asn1write.h"
#include "mbedtls/platform_util.h" #include "mbedtls/platform_util.h"
#include "ecdsa/ecdsa_alt.h" #include "ecdsa/ecdsa_alt.h"
#include "soc/soc_caps.h"
#define ECDSA_KEY_MAGIC (short) 0xECD5A #define ECDSA_KEY_MAGIC (short) 0xECD5A
#define ECDSA_SHA_LEN 32 #define ECDSA_SHA_LEN 32
@ -29,6 +32,21 @@ static void esp_ecdsa_acquire_hardware(void)
ecdsa_ll_enable_bus_clock(true); ecdsa_ll_enable_bus_clock(true);
ecdsa_ll_reset_register(); ecdsa_ll_reset_register();
} }
ECC_RCC_ATOMIC() {
ecc_ll_enable_bus_clock(true);
ecc_ll_reset_register();
}
#ifdef SOC_ECDSA_USES_MPI
/* 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();
}
#endif /* SOC_ECDSA_USES_MPI */
} }
static void esp_ecdsa_release_hardware(void) static void esp_ecdsa_release_hardware(void)
@ -37,6 +55,16 @@ static void esp_ecdsa_release_hardware(void)
ecdsa_ll_enable_bus_clock(false); ecdsa_ll_enable_bus_clock(false);
} }
ECC_RCC_ATOMIC() {
ecc_ll_enable_bus_clock(false);
}
#ifdef SOC_ECDSA_USES_MPI
MPI_RCC_ATOMIC() {
mpi_ll_enable_bus_clock(false);
}
#endif /* SOC_ECDSA_USES_MPI */
esp_crypto_ecdsa_lock_release(); esp_crypto_ecdsa_lock_release();
} }

View File

@ -1135,6 +1135,10 @@ config SOC_CRYPTO_DPA_PROTECTION_SUPPORTED
bool bool
default y default y
config SOC_ECDSA_USES_MPI
bool
default y
config SOC_UART_NUM config SOC_UART_NUM
int int
default 2 default 2

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -215,7 +215,7 @@
// Support to hold a single digital I/O when the digital domain is powered off // Support to hold a single digital I/O when the digital domain is powered off
#define SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP (1) #define SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP (1)
// The Clock Out singnal is route to the pin by GPIO matrix // The Clock Out signal is route to the pin by GPIO matrix
#define SOC_GPIO_CLOCKOUT_BY_GPIO_MATRIX (1) #define SOC_GPIO_CLOCKOUT_BY_GPIO_MATRIX (1)
/*-------------------------- RTCIO CAPS --------------------------------------*/ /*-------------------------- RTCIO CAPS --------------------------------------*/
@ -460,6 +460,9 @@
/*------------------------ Anti DPA (Security) CAPS --------------------------*/ /*------------------------ Anti DPA (Security) CAPS --------------------------*/
#define SOC_CRYPTO_DPA_PROTECTION_SUPPORTED 1 #define SOC_CRYPTO_DPA_PROTECTION_SUPPORTED 1
/*------------------------- ECDSA CAPS -------------------------*/
#define SOC_ECDSA_USES_MPI (1)
/*-------------------------- UART CAPS ---------------------------------------*/ /*-------------------------- UART CAPS ---------------------------------------*/
// ESP32-H2 has 2 UARTs // ESP32-H2 has 2 UARTs
#define SOC_UART_NUM (2) #define SOC_UART_NUM (2)
@ -489,7 +492,7 @@
/*-------------------------- Power Management CAPS ----------------------------*/ /*-------------------------- Power Management CAPS ----------------------------*/
#define SOC_PM_SUPPORT_BT_WAKEUP (1) #define SOC_PM_SUPPORT_BT_WAKEUP (1)
#define SOC_PM_SUPPORT_EXT1_WAKEUP (1) #define SOC_PM_SUPPORT_EXT1_WAKEUP (1)
#define SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN (1) /*!<Supports one bit per pin to configue the EXT1 trigger level */ #define SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN (1) /*!<Supports one bit per pin to configure the EXT1 trigger level */
#define SOC_PM_SUPPORT_CPU_PD (1) #define SOC_PM_SUPPORT_CPU_PD (1)
#define SOC_PM_SUPPORT_MODEM_PD (1) /*!<modem includes BLE and 15.4 */ #define SOC_PM_SUPPORT_MODEM_PD (1) /*!<modem includes BLE and 15.4 */
#define SOC_PM_SUPPORT_XTAL32K_PD (1) #define SOC_PM_SUPPORT_XTAL32K_PD (1)

View File

@ -859,6 +859,10 @@ config SOC_ECDSA_SUPPORT_EXPORT_PUBKEY
bool bool
default y default y
config SOC_ECDSA_USES_MPI
bool
default y
config SOC_SDM_GROUPS config SOC_SDM_GROUPS
int int
default 1 default 1

View File

@ -391,6 +391,7 @@
/*--------------------------- ECDSA CAPS ---------------------------------------*/ /*--------------------------- ECDSA CAPS ---------------------------------------*/
#define SOC_ECDSA_SUPPORT_EXPORT_PUBKEY (1) #define SOC_ECDSA_SUPPORT_EXPORT_PUBKEY (1)
#define SOC_ECDSA_USES_MPI (1)
/*-------------------------- Sigma Delta Modulator CAPS -----------------*/ /*-------------------------- Sigma Delta Modulator CAPS -----------------*/
#define SOC_SDM_GROUPS 1U #define SOC_SDM_GROUPS 1U