mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
feat(esp_hw_support): Added locking mechanism for the ECDSA and ECC peripheral
This commit is contained in:
parent
aa4783519a
commit
6a7caa7b8e
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -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
|
||||
|
@ -63,6 +63,34 @@ 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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Acquire lock for ECDSA cryptography peripheral
|
||||
*
|
||||
* Internally also locks the ECC and MPI peripheral, as the ECDSA depends on these peripherals
|
||||
*/
|
||||
void esp_crypto_ecdsa_lock_acquire(void);
|
||||
|
||||
/**
|
||||
* @brief Release lock for ECDSA cryptography peripheral
|
||||
*
|
||||
* Internally also releases the ECC and MPI peripheral, as the ECDSA depends on these peripherals
|
||||
*/
|
||||
void esp_crypto_ecdsa_lock_release(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -63,6 +63,34 @@ 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);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Acquire lock for ECDSA cryptography peripheral
|
||||
*
|
||||
* Internally also locks the ECC and MPI peripheral, as the ECDSA depends on these peripherals
|
||||
*/
|
||||
void esp_crypto_ecdsa_lock_acquire(void);
|
||||
|
||||
/**
|
||||
* @brief Release lock for ECDSA cryptography peripheral
|
||||
*
|
||||
* Internally also releases the ECC and MPI peripheral, as the ECDSA depends on these peripherals
|
||||
*/
|
||||
void esp_crypto_ecdsa_lock_release(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -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);
|
||||
}
|
||||
|
@ -12,8 +12,10 @@
|
||||
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
|
||||
ECDSA: needs ECC and MPI
|
||||
*/
|
||||
|
||||
/* Lock for DS peripheral */
|
||||
@ -28,6 +30,12 @@ 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;
|
||||
|
||||
/* Lock for ECDSA peripheral */
|
||||
static _lock_t s_crypto_ecdsa_lock;
|
||||
|
||||
void esp_crypto_hmac_lock_acquire(void)
|
||||
{
|
||||
_lock_acquire(&s_crypto_hmac_lock);
|
||||
@ -73,3 +81,27 @@ 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);
|
||||
}
|
||||
|
||||
void esp_crypto_ecdsa_lock_acquire(void)
|
||||
{
|
||||
_lock_acquire(&s_crypto_ecdsa_lock);
|
||||
esp_crypto_ecc_lock_acquire();
|
||||
esp_crypto_mpi_lock_acquire();
|
||||
}
|
||||
|
||||
void esp_crypto_ecdsa_lock_release(void)
|
||||
{
|
||||
esp_crypto_mpi_lock_release();
|
||||
esp_crypto_ecc_lock_release();
|
||||
_lock_release(&s_crypto_ecdsa_lock);
|
||||
}
|
||||
|
@ -12,8 +12,10 @@
|
||||
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
|
||||
ECDSA: needs ECC and MPI
|
||||
*/
|
||||
|
||||
/* Lock for DS peripheral */
|
||||
@ -28,6 +30,12 @@ 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;
|
||||
|
||||
/* Lock for ECDSA peripheral */
|
||||
static _lock_t s_crypto_ecdsa_lock;
|
||||
|
||||
void esp_crypto_hmac_lock_acquire(void)
|
||||
{
|
||||
_lock_acquire(&s_crypto_hmac_lock);
|
||||
@ -73,3 +81,27 @@ 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);
|
||||
}
|
||||
|
||||
void esp_crypto_ecdsa_lock_acquire(void)
|
||||
{
|
||||
_lock_acquire(&s_crypto_ecdsa_lock);
|
||||
esp_crypto_ecc_lock_acquire();
|
||||
esp_crypto_mpi_lock_acquire();
|
||||
}
|
||||
|
||||
void esp_crypto_ecdsa_lock_release(void)
|
||||
{
|
||||
esp_crypto_mpi_lock_release();
|
||||
esp_crypto_ecc_lock_release();
|
||||
_lock_release(&s_crypto_ecdsa_lock);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "hal/ecdsa_hal.h"
|
||||
#include "esp_crypto_lock.h"
|
||||
#include "esp_efuse.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/ecdsa.h"
|
||||
@ -19,11 +20,9 @@
|
||||
|
||||
__attribute__((unused)) static const char *TAG = "ecdsa_alt";
|
||||
|
||||
static _lock_t s_crypto_ecdsa_lock;
|
||||
|
||||
static void esp_ecdsa_acquire_hardware(void)
|
||||
{
|
||||
_lock_acquire(&s_crypto_ecdsa_lock);
|
||||
esp_crypto_ecdsa_lock_acquire();
|
||||
|
||||
periph_module_enable(PERIPH_ECDSA_MODULE);
|
||||
}
|
||||
@ -32,7 +31,7 @@ static void esp_ecdsa_release_hardware(void)
|
||||
{
|
||||
periph_module_disable(PERIPH_ECDSA_MODULE);
|
||||
|
||||
_lock_release(&s_crypto_ecdsa_lock);
|
||||
esp_crypto_ecdsa_lock_release();
|
||||
}
|
||||
|
||||
static void ecdsa_be_to_le(const uint8_t* be_point, uint8_t *le_point, uint8_t len)
|
||||
|
Loading…
x
Reference in New Issue
Block a user