mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 20:41:14 +00:00
Merge branch 'fix/crypto_periphs_use_rcc_atomic_blocks' into 'master'
Use rcc atomic blocks to enable/reset crypto peripherals See merge request espressif/esp-idf!25811
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "soc/hwcrypto_reg.h"
|
||||
#include "soc/hp_sys_clkrst_struct.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/ds_types.h"
|
||||
|
||||
@@ -24,6 +25,35 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for DS peripheral module
|
||||
*
|
||||
* @param true to enable the module, false to disable the module
|
||||
*/
|
||||
static inline void ds_ll_enable_bus_clock(bool enable)
|
||||
{
|
||||
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_ds_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define ds_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; ds_ll_enable_bus_clock(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Reset the DS peripheral module
|
||||
*/
|
||||
static inline void ds_ll_reset_register(void)
|
||||
{
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ds = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ds = 0;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define ds_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; ds_ll_reset_register(__VA_ARGS__)
|
||||
|
||||
static inline void ds_ll_start(void)
|
||||
{
|
||||
REG_WRITE(DS_SET_START_REG, 1);
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "hal/assert.h"
|
||||
#include "hal/ecc_types.h"
|
||||
#include "soc/ecc_mult_reg.h"
|
||||
#include "soc/hp_sys_clkrst_struct.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -24,6 +25,38 @@ typedef enum {
|
||||
ECC_PARAM_QZ,
|
||||
} ecc_ll_param_t;
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for ECC peripheral module
|
||||
*
|
||||
* @param true to enable the module, false to disable the module
|
||||
*/
|
||||
static inline void ecc_ll_enable_bus_clock(bool enable)
|
||||
{
|
||||
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_ecc_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define ecc_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; ecc_ll_enable_bus_clock(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Reset the ECC peripheral module
|
||||
*/
|
||||
static inline void ecc_ll_reset_register(void)
|
||||
{
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ecc = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ecc = 0;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 0;
|
||||
|
||||
// Clear reset on ECDSA, otherwise ECC is held in reset
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ecdsa = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define ecc_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; ecc_ll_reset_register(__VA_ARGS__)
|
||||
|
||||
static inline void ecc_ll_enable_interrupt(void)
|
||||
{
|
||||
REG_SET_FIELD(ECC_MULT_INT_ENA_REG, ECC_MULT_CALC_DONE_INT_ENA, 1);
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include <string.h>
|
||||
#include "hal/assert.h"
|
||||
#include "soc/ecdsa_reg.h"
|
||||
#include "soc/hp_sys_clkrst_struct.h"
|
||||
#include "hal/ecdsa_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -70,6 +71,31 @@ typedef enum {
|
||||
ECDSA_MODE_SHA_CONTINUE
|
||||
} ecdsa_ll_sha_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for ECDSA peripheral module
|
||||
*
|
||||
* @param true to enable the module, false to disable the module
|
||||
*/
|
||||
static inline void ecdsa_ll_enable_bus_clock(bool enable)
|
||||
{
|
||||
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_ecdsa_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define ecdsa_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; ecdsa_ll_enable_bus_clock(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Reset the ECDSA peripheral module
|
||||
*/
|
||||
static inline void ecdsa_ll_reset_register(void)
|
||||
{
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ecdsa = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ecdsa = 0;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable interrupt of a given type
|
||||
*
|
||||
|
@@ -13,9 +13,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "soc/system_reg.h"
|
||||
#include "soc/hwcrypto_reg.h"
|
||||
#include "soc/hp_sys_clkrst_struct.h"
|
||||
#include "hal/hmac_hal.h"
|
||||
|
||||
#define SHA256_BLOCK_SZ 64
|
||||
@@ -30,6 +32,35 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for HMAC peripheral module
|
||||
*
|
||||
* @param true to enable the module, false to disable the module
|
||||
*/
|
||||
static inline void hmac_ll_enable_bus_clock(bool enable)
|
||||
{
|
||||
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_hmac_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define hmac_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; hmac_ll_enable_bus_clock(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Reset the HMAC peripheral module
|
||||
*/
|
||||
static inline void hmac_ll_reset_register(void)
|
||||
{
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_hmac = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_hmac = 0;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define hmac_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; hmac_ll_reset_register(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Makes the peripheral ready for use, after enabling it.
|
||||
*/
|
||||
|
@@ -10,13 +10,46 @@
|
||||
#include <sys/param.h>
|
||||
#include "hal/assert.h"
|
||||
#include "hal/mpi_types.h"
|
||||
#include "soc/rsa_reg.h"
|
||||
#include "soc/hp_sys_clkrst_struct.h"
|
||||
#include "soc/mpi_periph.h"
|
||||
#include "soc/rsa_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for MPI peripheral module
|
||||
*
|
||||
* @param enable true to enable the module, false to disable the module
|
||||
*/
|
||||
static inline void mpi_ll_enable_bus_clock(bool enable)
|
||||
{
|
||||
HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_rsa_clk_en = enable;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define mpi_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; mpi_ll_enable_bus_clock(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Reset the MPI peripheral module
|
||||
*/
|
||||
static inline void mpi_ll_reset_register(void)
|
||||
{
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_rsa = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_rsa = 0;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 1;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 0;
|
||||
|
||||
// Clear reset on digital signature and ECDSA, otherwise RSA is held in reset
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ds = 0;
|
||||
HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_ecdsa = 0;
|
||||
}
|
||||
|
||||
/// use a macro to wrap the function, force the caller to use it in a critical section
|
||||
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
|
||||
#define mpi_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; mpi_ll_reset_register(__VA_ARGS__)
|
||||
|
||||
static inline size_t mpi_ll_calculate_hardware_words(size_t words)
|
||||
{
|
||||
|
Reference in New Issue
Block a user