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
release/v5.0
Mahavir Jain 2023-10-20 15:57:16 +08:00
commit f333925342
6 zmienionych plików z 85 dodań i 6 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -63,6 +63,18 @@ void esp_crypto_mpi_lock_acquire(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
}
#endif

Wyświetl plik

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

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -12,6 +12,7 @@
SHA: peripheral independent, but DMA is shared with AES
AES: peripheral independent, but DMA is shared with SHA
MPI/RSA: independent
ECC: independent
HMAC: needs SHA
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 */
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)
{
_lock_acquire(&s_crypto_hmac_lock);
@ -73,3 +77,13 @@ void esp_crypto_mpi_lock_release(void)
{
_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);
}

Wyświetl plik

@ -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
*/
@ -7,15 +7,14 @@
#include <string.h>
#include <stdio.h>
#include "esp_crypto_lock.h"
#include "esp_private/periph_ctrl.h"
#include "ecc_impl.h"
#include "hal/ecc_hal.h"
static _lock_t s_crypto_ecc_lock;
static void esp_ecc_acquire_hardware(void)
{
_lock_acquire(&s_crypto_ecc_lock);
esp_crypto_ecc_lock_acquire();
periph_module_enable(PERIPH_ECC_MODULE);
}
@ -24,7 +23,7 @@ static void esp_ecc_release_hardware(void)
{
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)