mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(mbedtls): validate ECDSA signature range and harden ECC memory power-down
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "soc/ecc_mult_reg.h"
|
#include "soc/ecc_mult_reg.h"
|
||||||
#include "soc/pcr_struct.h"
|
#include "soc/pcr_struct.h"
|
||||||
#include "soc/pcr_reg.h"
|
#include "soc/pcr_reg.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -47,11 +48,17 @@ static inline void ecc_ll_reset_register(void)
|
|||||||
PCR.ecdsa_conf.ecdsa_rst_en = 0;
|
PCR.ecdsa_conf.ecdsa_rst_en = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void ecc_ll_clear_force_pd(void)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_power_up(void)
|
static inline void ecc_ll_power_up(void)
|
||||||
{
|
{
|
||||||
/* Power up the ECC peripheral (default state is power-down) */
|
/* Power up the ECC peripheral (default state is power-down) */
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
ESP_FAULT_ASSERT(REG_GET_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_power_down(void)
|
static inline void ecc_ll_power_down(void)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2020-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "soc/ecc_mult_reg.h"
|
#include "soc/ecc_mult_reg.h"
|
||||||
#include "soc/pcr_struct.h"
|
#include "soc/pcr_struct.h"
|
||||||
#include "soc/pcr_reg.h"
|
#include "soc/pcr_reg.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -46,6 +47,7 @@ static inline void ecc_ll_power_up(void)
|
|||||||
{
|
{
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
ESP_FAULT_ASSERT(REG_GET_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_power_down(void)
|
static inline void ecc_ll_power_down(void)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "soc/ecc_mult_reg.h"
|
#include "soc/ecc_mult_reg.h"
|
||||||
#include "soc/pcr_struct.h"
|
#include "soc/pcr_struct.h"
|
||||||
#include "soc/pcr_reg.h"
|
#include "soc/pcr_reg.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -49,9 +50,10 @@ static inline void ecc_ll_reset_register(void)
|
|||||||
|
|
||||||
static inline void ecc_ll_power_up(void)
|
static inline void ecc_ll_power_up(void)
|
||||||
{
|
{
|
||||||
/* Power up the ECC peripheral (default state is power-down) */
|
/* Power up the ECC peripheral (default state is power-up) */
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
ESP_FAULT_ASSERT(REG_GET_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_power_down(void)
|
static inline void ecc_ll_power_down(void)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "soc/ecc_mult_reg.h"
|
#include "soc/ecc_mult_reg.h"
|
||||||
#include "soc/pcr_struct.h"
|
#include "soc/pcr_struct.h"
|
||||||
#include "soc/pcr_reg.h"
|
#include "soc/pcr_reg.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
#include "soc/chip_revision.h"
|
#include "soc/chip_revision.h"
|
||||||
#include "hal/efuse_hal.h"
|
#include "hal/efuse_hal.h"
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@ static inline void ecc_ll_power_up(void)
|
|||||||
{
|
{
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
ESP_FAULT_ASSERT(REG_GET_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_power_down(void)
|
static inline void ecc_ll_power_down(void)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "soc/ecc_mult_reg.h"
|
#include "soc/ecc_mult_reg.h"
|
||||||
#include "soc/pcr_struct.h"
|
#include "soc/pcr_struct.h"
|
||||||
#include "soc/pcr_reg.h"
|
#include "soc/pcr_reg.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -52,6 +53,7 @@ static inline void ecc_ll_power_up(void)
|
|||||||
{
|
{
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_PD);
|
||||||
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
REG_CLR_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
ESP_FAULT_ASSERT(REG_GET_BIT(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_power_down(void)
|
static inline void ecc_ll_power_down(void)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "soc/ecc_mult_reg.h"
|
#include "soc/ecc_mult_reg.h"
|
||||||
#include "soc/pcr_struct.h"
|
#include "soc/pcr_struct.h"
|
||||||
#include "soc/pcr_reg.h"
|
#include "soc/pcr_reg.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -50,9 +51,11 @@ static inline void ecc_ll_reset_register(void)
|
|||||||
static inline void ecc_ll_power_up(void)
|
static inline void ecc_ll_power_up(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Power up the ECC peripheral (default state is power-down) */
|
/* Power up the ECC peripheral (default state is power-up) */
|
||||||
REG_CLR_BIT(PCR_ECC_MEM_LP_CTRL_REG, PCR_ECC_MEM_LP_EN);
|
REG_CLR_BIT(PCR_ECC_MEM_LP_CTRL_REG, PCR_ECC_MEM_LP_EN);
|
||||||
REG_CLR_BIT(PCR_ECC_MEM_LP_CTRL_REG, PCR_ECC_MEM_FORCE_CTRL);
|
REG_SET_BIT(PCR_ECC_MEM_LP_CTRL_REG, PCR_ECC_MEM_FORCE_CTRL);
|
||||||
|
ESP_FAULT_ASSERT(REG_GET_BIT(PCR_ECC_MEM_LP_CTRL_REG, PCR_ECC_MEM_LP_EN) == 0 &&
|
||||||
|
REG_GET_BIT(PCR_ECC_MEM_LP_CTRL_REG, PCR_ECC_MEM_FORCE_CTRL) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_power_down(void)
|
static inline void ecc_ll_power_down(void)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -12,8 +12,10 @@
|
|||||||
#include "hal/efuse_hal.h"
|
#include "hal/efuse_hal.h"
|
||||||
#include "soc/ecc_mult_reg.h"
|
#include "soc/ecc_mult_reg.h"
|
||||||
#include "soc/hp_sys_clkrst_struct.h"
|
#include "soc/hp_sys_clkrst_struct.h"
|
||||||
|
#include "soc/hp_system_reg.h"
|
||||||
#include "soc/chip_revision.h"
|
#include "soc/chip_revision.h"
|
||||||
#include "hal/config.h"
|
#include "hal/config.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -65,8 +67,20 @@ static inline void ecc_ll_reset_register(void)
|
|||||||
ecc_ll_reset_register(__VA_ARGS__); \
|
ecc_ll_reset_register(__VA_ARGS__); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
static inline void ecc_ll_power_up(void) {}
|
static inline void ecc_ll_power_up(void)
|
||||||
static inline void ecc_ll_power_down(void) {}
|
{
|
||||||
|
/* Power up the ECC peripheral (default state is power-up) */
|
||||||
|
REG_CLR_BIT(HP_SYSTEM_ECC_PD_CTRL_REG, HP_SYSTEM_ECC_MEM_PD);
|
||||||
|
REG_CLR_BIT(HP_SYSTEM_ECC_PD_CTRL_REG, HP_SYSTEM_ECC_MEM_FORCE_PD);
|
||||||
|
ESP_FAULT_ASSERT(REG_GET_BIT(HP_SYSTEM_ECC_PD_CTRL_REG, HP_SYSTEM_ECC_MEM_FORCE_PD) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void ecc_ll_power_down(void)
|
||||||
|
{
|
||||||
|
/* Power down the ECC peripheral */
|
||||||
|
REG_CLR_BIT(HP_SYSTEM_ECC_PD_CTRL_REG, HP_SYSTEM_ECC_MEM_FORCE_PU);
|
||||||
|
REG_SET_BIT(HP_SYSTEM_ECC_PD_CTRL_REG, HP_SYSTEM_ECC_MEM_PD);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_enable_interrupt(void)
|
static inline void ecc_ll_enable_interrupt(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#include "hal/ecc_types.h"
|
#include "hal/ecc_types.h"
|
||||||
#include "soc/ecc_mult_reg.h"
|
#include "soc/ecc_mult_reg.h"
|
||||||
#include "soc/hp_sys_clkrst_struct.h"
|
#include "soc/hp_sys_clkrst_struct.h"
|
||||||
|
#include "soc/hp_system_reg.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -62,8 +64,21 @@ static inline void ecc_ll_reset_register(void)
|
|||||||
ecc_ll_reset_register(__VA_ARGS__); \
|
ecc_ll_reset_register(__VA_ARGS__); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
static inline void ecc_ll_power_up(void) {}
|
static inline void ecc_ll_power_up(void)
|
||||||
static inline void ecc_ll_power_down(void) {}
|
{
|
||||||
|
/* Power up the ECC peripheral (default state is power-up) */
|
||||||
|
REG_CLR_BIT(HP_SYSTEM_ECC_MEM_LP_CTRL_REG, HP_SYSTEM_ECC_MEM_LP_EN);
|
||||||
|
REG_SET_BIT(HP_SYSTEM_ECC_MEM_LP_CTRL_REG, HP_SYSTEM_ECC_MEM_LP_FORCE_CTRL);
|
||||||
|
/* Anti-FI: confirm the clears took effect. */
|
||||||
|
ESP_FAULT_ASSERT(REG_GET_BIT(HP_SYSTEM_ECC_MEM_LP_CTRL_REG, HP_SYSTEM_ECC_MEM_LP_EN) == 0 &&
|
||||||
|
REG_GET_BIT(HP_SYSTEM_ECC_MEM_LP_CTRL_REG, HP_SYSTEM_ECC_MEM_LP_FORCE_CTRL) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void ecc_ll_power_down(void)
|
||||||
|
{
|
||||||
|
/* Power down the ECC peripheral */
|
||||||
|
REG_SET_BIT(HP_SYSTEM_ECC_MEM_LP_CTRL_REG, HP_SYSTEM_ECC_MEM_LP_EN);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void ecc_ll_enable_interrupt(void)
|
static inline void ecc_ll_enable_interrupt(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ void esp_system_reset_modules_on_exit(void)
|
|||||||
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
||||||
SET_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
SET_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
|
CLEAR_PERI_REG_MASK(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
|
||||||
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
||||||
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ void esp_system_reset_modules_on_exit(void)
|
|||||||
CLEAR_PERI_REG_MASK(PCR_HMAC_CONF_REG, PCR_HMAC_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_HMAC_CONF_REG, PCR_HMAC_RST_EN);
|
||||||
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
||||||
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
|
CLEAR_PERI_REG_MASK(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
|
||||||
CLEAR_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
|
||||||
|
|
||||||
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ void esp_system_reset_modules_on_exit(void)
|
|||||||
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
||||||
SET_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
SET_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
|
CLEAR_PERI_REG_MASK(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
|
||||||
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
||||||
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ void esp_system_reset_modules_on_exit(void)
|
|||||||
CLEAR_PERI_REG_MASK(PCR_HMAC_CONF_REG, PCR_HMAC_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_HMAC_CONF_REG, PCR_HMAC_RST_EN);
|
||||||
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
||||||
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
|
CLEAR_PERI_REG_MASK(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
|
||||||
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
||||||
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ void esp_system_reset_modules_on_exit(void)
|
|||||||
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
|
||||||
SET_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
SET_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
|
CLEAR_PERI_REG_MASK(PCR_ECC_PD_CTRL_REG, PCR_ECC_MEM_FORCE_PD);
|
||||||
|
|
||||||
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
||||||
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ void esp_system_reset_modules_on_exit(void)
|
|||||||
CLEAR_PERI_REG_MASK(PCR_HMAC_CONF_REG, PCR_HMAC_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_HMAC_CONF_REG, PCR_HMAC_RST_EN);
|
||||||
SET_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
SET_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
|
||||||
|
CLEAR_PERI_REG_MASK(PCR_ECC_MEM_LP_CTRL_REG, PCR_ECC_MEM_LP_EN);
|
||||||
|
SET_PERI_REG_MASK(PCR_ECC_MEM_LP_CTRL_REG, PCR_ECC_MEM_FORCE_CTRL);
|
||||||
|
|
||||||
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
|
||||||
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ void esp_system_reset_modules_on_exit(void)
|
|||||||
CLEAR_PERI_REG_MASK(HP_SYS_CLKRST_HP_RST_EN2_REG, HP_SYS_CLKRST_REG_RST_EN_KM);
|
CLEAR_PERI_REG_MASK(HP_SYS_CLKRST_HP_RST_EN2_REG, HP_SYS_CLKRST_REG_RST_EN_KM);
|
||||||
CLEAR_PERI_REG_MASK(HP_SYS_CLKRST_HP_RST_EN2_REG, HP_SYS_CLKRST_REG_RST_EN_RSA);
|
CLEAR_PERI_REG_MASK(HP_SYS_CLKRST_HP_RST_EN2_REG, HP_SYS_CLKRST_REG_RST_EN_RSA);
|
||||||
CLEAR_PERI_REG_MASK(HP_SYS_CLKRST_HP_RST_EN2_REG, HP_SYS_CLKRST_REG_RST_EN_SHA);
|
CLEAR_PERI_REG_MASK(HP_SYS_CLKRST_HP_RST_EN2_REG, HP_SYS_CLKRST_REG_RST_EN_SHA);
|
||||||
|
CLEAR_PERI_REG_MASK(HP_SYSTEM_ECC_PD_CTRL_REG, HP_SYSTEM_ECC_MEM_FORCE_PD);
|
||||||
|
|
||||||
#if CONFIG_ESP32P4_REV_MIN_FULL < 101
|
#if CONFIG_ESP32P4_REV_MIN_FULL < 101
|
||||||
if (efuse_hal_chip_revision() < 101) {
|
if (efuse_hal_chip_revision() < 101) {
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ void esp_system_reset_modules_on_exit(void)
|
|||||||
esp_rom_output_tx_wait_idle(i);
|
esp_rom_output_tx_wait_idle(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CLEAR_PERI_REG_MASK(HP_SYSTEM_ECC_MEM_LP_CTRL_REG, HP_SYSTEM_ECC_MEM_LP_EN);
|
||||||
|
SET_PERI_REG_MASK(HP_SYSTEM_ECC_MEM_LP_CTRL_REG, HP_SYSTEM_ECC_MEM_LP_FORCE_CTRL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IRAM_ATTR __attribute__((noinline, noreturn)) esp_restart_noos_inner(void)
|
static void IRAM_ATTR __attribute__((noinline, noreturn)) esp_restart_noos_inner(void)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "mbedtls/bignum.h"
|
#include "mbedtls/bignum.h"
|
||||||
|
|
||||||
#include "esp_assert.h"
|
#include "esp_assert.h"
|
||||||
|
#include "esp_fault.h"
|
||||||
#include "esp_crypto_lock.h"
|
#include "esp_crypto_lock.h"
|
||||||
#include "esp_crypto_periph_clk.h"
|
#include "esp_crypto_periph_clk.h"
|
||||||
|
|
||||||
@@ -353,13 +354,22 @@ static psa_status_t check_ecdsa_signature_range(const uint8_t *signature, size_t
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 1 <= scalar <= n-1: equivalently scalar > 0 and scalar < n. */
|
/* 1 <= scalar <= n-1: that is, scalar > 0 and scalar < n. */
|
||||||
if (mbedtls_mpi_cmp_int(&r, 0) <= 0 ||
|
#define RANGE_OK 0x6A6A6A6AU
|
||||||
mbedtls_mpi_cmp_mpi(&r, &grp.N) >= 0 ||
|
#define RANGE_FAIL 0x95959595U
|
||||||
mbedtls_mpi_cmp_int(&s, 0) <= 0 ||
|
volatile uint32_t verdict = RANGE_FAIL;
|
||||||
mbedtls_mpi_cmp_mpi(&s, &grp.N) >= 0) {
|
if (mbedtls_mpi_cmp_int(&r, 0) > 0 &&
|
||||||
|
mbedtls_mpi_cmp_mpi(&r, &grp.N) < 0 &&
|
||||||
|
mbedtls_mpi_cmp_int(&s, 0) > 0 &&
|
||||||
|
mbedtls_mpi_cmp_mpi(&s, &grp.N) < 0) {
|
||||||
|
verdict = RANGE_OK;
|
||||||
|
}
|
||||||
|
if (verdict != RANGE_OK) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
ESP_FAULT_ASSERT(verdict == RANGE_OK);
|
||||||
|
#undef RANGE_OK
|
||||||
|
#undef RANGE_FAIL
|
||||||
|
|
||||||
status = PSA_SUCCESS;
|
status = PSA_SUCCESS;
|
||||||
|
|
||||||
@@ -562,6 +572,8 @@ psa_status_t esp_ecdsa_transparent_verify_hash_complete(esp_ecdsa_transparent_ve
|
|||||||
return PSA_ERROR_INVALID_SIGNATURE;
|
return PSA_ERROR_INVALID_SIGNATURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ESP_FAULT_ASSERT(ret == 0);
|
||||||
|
|
||||||
return PSA_SUCCESS;
|
return PSA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
|
||||||
|
#include "mbedtls/private/ecp.h"
|
||||||
|
#include "mbedtls/private/bignum.h"
|
||||||
#include "psa/crypto.h"
|
#include "psa/crypto.h"
|
||||||
#include "psa_crypto_driver_esp_ecdsa_contexts.h"
|
#include "psa_crypto_driver_esp_ecdsa_contexts.h"
|
||||||
#include "psa_crypto_driver_esp_ecdsa.h"
|
#include "psa_crypto_driver_esp_ecdsa.h"
|
||||||
@@ -334,6 +337,16 @@ TEST_CASE("mbedtls ECDSA signature verification performance on SECP384R1", "[mbe
|
|||||||
#define ECDSA_RANGE_CHECK_REJECT_STATUS PSA_ERROR_INVALID_SIGNATURE
|
#define ECDSA_RANGE_CHECK_REJECT_STATUS PSA_ERROR_INVALID_SIGNATURE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Curve order N in big-endian, taken from mbedtls instead of a hard-coded table. */
|
||||||
|
static void ecdsa_get_curve_order_be(mbedtls_ecp_group_id id, uint8_t *n_be, size_t len)
|
||||||
|
{
|
||||||
|
mbedtls_ecp_group grp;
|
||||||
|
mbedtls_ecp_group_init(&grp);
|
||||||
|
TEST_ASSERT_EQUAL(0, mbedtls_ecp_group_load(&grp, id));
|
||||||
|
TEST_ASSERT_EQUAL(0, mbedtls_mpi_write_binary(&grp.N, n_be, len));
|
||||||
|
mbedtls_ecp_group_free(&grp);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("mbedtls ECDSA signature verification rejects out-of-range r, s on SECP256R1", "[mbedtls]")
|
TEST_CASE("mbedtls ECDSA signature verification rejects out-of-range r, s on SECP256R1", "[mbedtls]")
|
||||||
{
|
{
|
||||||
#if SOC_ECDSA_SUPPORTED
|
#if SOC_ECDSA_SUPPORTED
|
||||||
@@ -341,24 +354,17 @@ TEST_CASE("mbedtls ECDSA signature verification rejects out-of-range r, s on SEC
|
|||||||
TEST_IGNORE_MESSAGE("ECDSA is not supported");
|
TEST_IGNORE_MESSAGE("ECDSA is not supported");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Case A: r = 0, s = 0 -- caught by 'r > 0' / 's > 0' check. */
|
|
||||||
static const uint8_t zero32[32] = { 0 };
|
static const uint8_t zero32[32] = { 0 };
|
||||||
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha,
|
uint8_t p256_n_be[32];
|
||||||
zero32, zero32,
|
ecdsa_get_curve_order_be(MBEDTLS_ECP_DP_SECP256R1, p256_n_be, sizeof(p256_n_be));
|
||||||
ecdsa256_pub_x, ecdsa256_pub_y,
|
|
||||||
ECDSA_RANGE_CHECK_REJECT_STATUS);
|
|
||||||
|
|
||||||
/* Case B: r = N (SECP256R1 curve order), s = valid -- caught by 'r < N' check. */
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha, zero32, zero32, ecdsa256_pub_x, ecdsa256_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=0, s=0 */
|
||||||
static const uint8_t p256_n_be[32] = {
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha, zero32, p256_n_be, ecdsa256_pub_x, ecdsa256_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=0, s=N */
|
||||||
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha, p256_n_be, zero32, ecdsa256_pub_x, ecdsa256_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=N, s=0 */
|
||||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha, p256_n_be, p256_n_be, ecdsa256_pub_x, ecdsa256_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=N, s=N */
|
||||||
0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha, ecdsa256_r, zero32, ecdsa256_pub_x, ecdsa256_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=valid, s=0 */
|
||||||
0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha, ecdsa256_r, p256_n_be, ecdsa256_pub_x, ecdsa256_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=valid, s=N */
|
||||||
};
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha, p256_n_be, ecdsa256_s, ecdsa256_pub_x, ecdsa256_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=N, s=valid */
|
||||||
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP256R1, sha,
|
|
||||||
p256_n_be, ecdsa256_s,
|
|
||||||
ecdsa256_pub_x, ecdsa256_pub_y,
|
|
||||||
ECDSA_RANGE_CHECK_REJECT_STATUS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SOC_ECDSA_SUPPORT_CURVE_P384
|
#ifdef SOC_ECDSA_SUPPORT_CURVE_P384
|
||||||
@@ -369,26 +375,17 @@ TEST_CASE("mbedtls ECDSA signature verification rejects out-of-range r, s on SEC
|
|||||||
TEST_IGNORE_MESSAGE("ECDSA is not supported");
|
TEST_IGNORE_MESSAGE("ECDSA is not supported");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Case A: r = 0, s = 0 */
|
|
||||||
static const uint8_t zero48[48] = { 0 };
|
static const uint8_t zero48[48] = { 0 };
|
||||||
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha,
|
uint8_t p384_n_be[48];
|
||||||
zero48, zero48,
|
ecdsa_get_curve_order_be(MBEDTLS_ECP_DP_SECP384R1, p384_n_be, sizeof(p384_n_be));
|
||||||
ecdsa384_pub_x, ecdsa384_pub_y,
|
|
||||||
ECDSA_RANGE_CHECK_REJECT_STATUS);
|
|
||||||
|
|
||||||
/* Case B: r = N (SECP384R1 curve order), s = valid */
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha, zero48, zero48, ecdsa384_pub_x, ecdsa384_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=0, s=0 */
|
||||||
static const uint8_t p384_n_be[48] = {
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha, zero48, p384_n_be, ecdsa384_pub_x, ecdsa384_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=0, s=N */
|
||||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha, p384_n_be, zero48, ecdsa384_pub_x, ecdsa384_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=N, s=0 */
|
||||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha, p384_n_be, p384_n_be, ecdsa384_pub_x, ecdsa384_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=N, s=N */
|
||||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha, ecdsa384_r, zero48, ecdsa384_pub_x, ecdsa384_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=valid, s=0 */
|
||||||
0xc7, 0x63, 0x4d, 0x81, 0xf4, 0x37, 0x2d, 0xdf,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha, ecdsa384_r, p384_n_be, ecdsa384_pub_x, ecdsa384_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=valid, s=N */
|
||||||
0x58, 0x1a, 0x0d, 0xb2, 0x48, 0xb0, 0xa7, 0x7a,
|
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha, p384_n_be, ecdsa384_s, ecdsa384_pub_x, ecdsa384_pub_y, ECDSA_RANGE_CHECK_REJECT_STATUS); /* r=N, s=valid */
|
||||||
0xec, 0xec, 0x19, 0x6a, 0xcc, 0xc5, 0x29, 0x73,
|
|
||||||
};
|
|
||||||
test_ecdsa_verify(ESP_ECDSA_CURVE_SECP384R1, sha,
|
|
||||||
p384_n_be, ecdsa384_s,
|
|
||||||
ecdsa384_pub_x, ecdsa384_pub_y,
|
|
||||||
ECDSA_RANGE_CHECK_REJECT_STATUS);
|
|
||||||
}
|
}
|
||||||
#endif /* SOC_ECDSA_SUPPORT_CURVE_P384 */
|
#endif /* SOC_ECDSA_SUPPORT_CURVE_P384 */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user