Merge branch 'feature/locking_layer_for_ecdsa_v5.0' into 'release/v5.0'

feat(esp_hw_support): Added locking mechanism for the ECC peripheral (v5.0)

See merge request espressif/esp-idf!26287
This commit is contained in:
Mahavir Jain
2023-10-20 15:57:16 +08:00
6 changed files with 85 additions and 6 deletions

View File

@ -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 ECC cryptography peripheral.
*
*/
void esp_crypto_ecc_lock_acquire(void);
/**
* @brief Release lock for the ECC cryptography peripheral.
*
*/
void esp_crypto_ecc_lock_release(void);
#ifdef __cplusplus
}
#endif

View File

@ -63,6 +63,18 @@ void esp_crypto_mpi_lock_acquire(void);
*/ */
void esp_crypto_mpi_lock_release(void); void esp_crypto_mpi_lock_release(void);
/**
* @brief Acquire lock for the ECC cryptography peripheral.
*
*/
void esp_crypto_ecc_lock_acquire(void);
/**
* @brief Release lock for the ECC cryptography peripheral.
*
*/
void esp_crypto_ecc_lock_release(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -9,7 +9,8 @@ set(srcs "rtc_clk_init.c"
if(NOT BOOTLOADER_BUILD) if(NOT BOOTLOADER_BUILD)
list(APPEND srcs "sar_periph_ctrl.c") list(APPEND srcs "esp_crypto_lock.c"
"sar_periph_ctrl.c")
endif() endif()

View File

@ -0,0 +1,26 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sys/lock.h>
#include "esp_crypto_lock.h"
/* Lock overview:
ECC: independent
*/
/* Lock for ECC peripheral */
static _lock_t s_crypto_ecc_lock;
void esp_crypto_ecc_lock_acquire(void)
{
_lock_acquire(&s_crypto_ecc_lock);
}
void esp_crypto_ecc_lock_release(void)
{
_lock_release(&s_crypto_ecc_lock);
}

View File

@ -12,6 +12,7 @@
SHA: peripheral independent, but DMA is shared with AES SHA: peripheral independent, but DMA is shared with AES
AES: peripheral independent, but DMA is shared with SHA AES: peripheral independent, but DMA is shared with SHA
MPI/RSA: independent MPI/RSA: independent
ECC: independent
HMAC: needs SHA HMAC: needs SHA
DS: needs HMAC (which needs SHA), AES and MPI DS: needs HMAC (which needs SHA), AES and MPI
*/ */
@ -28,6 +29,9 @@ static _lock_t s_crypto_mpi_lock;
/* Single lock for SHA and AES, sharing a reserved GDMA channel */ /* Single lock for SHA and AES, sharing a reserved GDMA channel */
static _lock_t s_crypto_sha_aes_lock; static _lock_t s_crypto_sha_aes_lock;
/* Lock for ECC peripheral */
static _lock_t s_crypto_ecc_lock;
void esp_crypto_hmac_lock_acquire(void) void esp_crypto_hmac_lock_acquire(void)
{ {
_lock_acquire(&s_crypto_hmac_lock); _lock_acquire(&s_crypto_hmac_lock);
@ -73,3 +77,13 @@ void esp_crypto_mpi_lock_release(void)
{ {
_lock_release(&s_crypto_mpi_lock); _lock_release(&s_crypto_mpi_lock);
} }
void esp_crypto_ecc_lock_acquire(void)
{
_lock_acquire(&s_crypto_ecc_lock);
}
void esp_crypto_ecc_lock_release(void)
{
_lock_release(&s_crypto_ecc_lock);
}

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -7,15 +7,14 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "esp_crypto_lock.h"
#include "esp_private/periph_ctrl.h" #include "esp_private/periph_ctrl.h"
#include "ecc_impl.h" #include "ecc_impl.h"
#include "hal/ecc_hal.h" #include "hal/ecc_hal.h"
static _lock_t s_crypto_ecc_lock;
static void esp_ecc_acquire_hardware(void) static void esp_ecc_acquire_hardware(void)
{ {
_lock_acquire(&s_crypto_ecc_lock); esp_crypto_ecc_lock_acquire();
periph_module_enable(PERIPH_ECC_MODULE); periph_module_enable(PERIPH_ECC_MODULE);
} }
@ -24,7 +23,7 @@ static void esp_ecc_release_hardware(void)
{ {
periph_module_disable(PERIPH_ECC_MODULE); periph_module_disable(PERIPH_ECC_MODULE);
_lock_release(&s_crypto_ecc_lock); esp_crypto_ecc_lock_release();
} }
int esp_ecc_point_multiply(const ecc_point_t *point, const uint8_t *scalar, ecc_point_t *result, bool verify_first) int esp_ecc_point_multiply(const ecc_point_t *point, const uint8_t *scalar, ecc_point_t *result, bool verify_first)