forked from espressif/esp-idf
feat(esp_hw_support): Added locking mechanism for the ECDSA and ECC peripheral
This commit is contained in:
@@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -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
|
||||||
|
@@ -63,6 +63,34 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
@@ -12,8 +12,10 @@
|
|||||||
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
|
||||||
|
ECDSA: needs ECC and MPI
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Lock for DS peripheral */
|
/* 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 */
|
/* 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;
|
||||||
|
|
||||||
|
/* Lock for ECDSA peripheral */
|
||||||
|
static _lock_t s_crypto_ecdsa_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 +81,27 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
* 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)
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "hal/ecdsa_hal.h"
|
#include "hal/ecdsa_hal.h"
|
||||||
|
#include "esp_crypto_lock.h"
|
||||||
#include "esp_efuse.h"
|
#include "esp_efuse.h"
|
||||||
#include "mbedtls/ecp.h"
|
#include "mbedtls/ecp.h"
|
||||||
#include "mbedtls/ecdsa.h"
|
#include "mbedtls/ecdsa.h"
|
||||||
@@ -18,11 +19,9 @@
|
|||||||
|
|
||||||
__attribute__((unused)) static const char *TAG = "ecdsa_alt";
|
__attribute__((unused)) static const char *TAG = "ecdsa_alt";
|
||||||
|
|
||||||
static _lock_t s_crypto_ecdsa_lock;
|
|
||||||
|
|
||||||
static void esp_ecdsa_acquire_hardware(void)
|
static void esp_ecdsa_acquire_hardware(void)
|
||||||
{
|
{
|
||||||
_lock_acquire(&s_crypto_ecdsa_lock);
|
esp_crypto_ecdsa_lock_acquire();
|
||||||
|
|
||||||
periph_module_enable(PERIPH_ECDSA_MODULE);
|
periph_module_enable(PERIPH_ECDSA_MODULE);
|
||||||
}
|
}
|
||||||
@@ -31,7 +30,7 @@ static void esp_ecdsa_release_hardware(void)
|
|||||||
{
|
{
|
||||||
periph_module_disable(PERIPH_ECDSA_MODULE);
|
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)
|
static void ecdsa_be_to_le(const uint8_t* be_point, uint8_t *le_point, uint8_t len)
|
||||||
|
Reference in New Issue
Block a user