Skip to content

Commit cf8068d

Browse files
committed
feat(hal): add support for ESP32-P4 ECO5 ECC peripheral
This commit also enabled constant time mode for ECC.
1 parent 4483e26 commit cf8068d

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

components/hal/esp32p4/include/hal/ecc_ll.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
#include <string.h>
1010
#include "hal/assert.h"
1111
#include "hal/ecc_types.h"
12+
#include "hal/efuse_hal.h"
1213
#include "soc/ecc_mult_reg.h"
1314
#include "soc/hp_sys_clkrst_struct.h"
15+
#include "soc/chip_revision.h"
16+
#include "hal/config.h"
1417

1518
#ifdef __cplusplus
1619
extern "C" {
@@ -118,16 +121,15 @@ static inline void ecc_ll_set_mode(ecc_mode_t mode)
118121

119122
static inline void ecc_ll_set_curve(ecc_curve_t curve)
120123
{
121-
switch(curve) {
122-
case ECC_CURVE_SECP256R1:
123-
REG_SET_BIT(ECC_MULT_CONF_REG, ECC_MULT_KEY_LENGTH);
124-
break;
124+
switch (curve) {
125125
case ECC_CURVE_SECP192R1:
126-
REG_CLR_BIT(ECC_MULT_CONF_REG, ECC_MULT_KEY_LENGTH);
126+
case ECC_CURVE_SECP256R1:
127+
case ECC_CURVE_SECP384R1:
128+
case ECC_CURVE_SM2:
129+
REG_SET_FIELD(ECC_MULT_CONF_REG, ECC_MULT_KEY_LENGTH, curve);
127130
break;
128131
default:
129132
HAL_ASSERT(false && "Unsupported curve");
130-
return;
131133
}
132134
}
133135

@@ -242,8 +244,11 @@ static inline void ecc_ll_read_param(ecc_ll_param_t param, uint8_t *buf, uint16_
242244

243245
static inline void ecc_ll_enable_constant_time_point_mul(bool enable)
244246
{
245-
// Not supported for ESP32-P4
246-
(void) enable; //unused
247+
if (enable) {
248+
REG_SET_BIT(ECC_MULT_CONF_REG, ECC_MULT_SECURITY_MODE);
249+
} else {
250+
REG_CLR_BIT(ECC_MULT_CONF_REG, ECC_MULT_SECURITY_MODE);
251+
}
247252
}
248253

249254
#ifdef __cplusplus

components/soc/esp32p4/include/soc/Kconfig.soc_caps.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,10 @@ config SOC_SHA_SUPPORT_SHA512_T
14951495
bool
14961496
default y
14971497

1498+
config SOC_ECC_CONSTANT_TIME_POINT_MUL
1499+
bool
1500+
default y
1501+
14981502
config SOC_ECDSA_SUPPORT_EXPORT_PUBKEY
14991503
bool
15001504
default y

components/soc/esp32p4/include/soc/soc_caps.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@
547547
#define SOC_SHA_SUPPORT_SHA512_256 (1)
548548
#define SOC_SHA_SUPPORT_SHA512_T (1)
549549

550+
/*--------------------------- ECC CAPS ---------------------------------------*/
551+
#define SOC_ECC_CONSTANT_TIME_POINT_MUL 1
552+
550553
/*--------------------------- ECDSA CAPS ---------------------------------------*/
551554
#define SOC_ECDSA_SUPPORT_EXPORT_PUBKEY (1)
552555
#define SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE (1)

0 commit comments

Comments
 (0)