Skip to content

Commit 748d29b

Browse files
mahavirjespressif-bot
authored andcommitted
feat(ecc): enable ECC constant time mode for ESP32-H2 ECO5
1 parent 2fe702e commit 748d29b

File tree

15 files changed

+58
-23
lines changed

15 files changed

+58
-23
lines changed

components/esp_hw_support/port/esp32h2/Kconfig.hw_support

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ choice ESP32H2_REV_MIN
1515
bool "Rev v0.1 (ECO1)"
1616
config ESP32H2_REV_MIN_2
1717
bool "Rev v0.2 (ECO2)"
18+
config ESP32H2_REV_MIN_102
19+
bool "Rev v1.2 (ECO5)"
1820
endchoice
1921

2022
config ESP32H2_REV_MIN_FULL
2123
int
2224
default 0 if ESP32H2_REV_MIN_0
2325
default 1 if ESP32H2_REV_MIN_1
2426
default 2 if ESP32H2_REV_MIN_2
27+
default 102 if ESP32H2_REV_MIN_102
2528

2629
config ESP_REV_MIN_FULL
2730
int
@@ -31,7 +34,7 @@ config ESP_REV_MIN_FULL
3134
# MAX Revision
3235
#
3336

34-
comment "Maximum Supported ESP32-H2 Revision (Rev v0.99)"
37+
comment "Maximum Supported ESP32-H2 Revision (Rev v1.99)"
3538
# Maximum revision that IDF supports.
3639
# It can not be changed by user.
3740
# Only Espressif can change it when a new version will be supported in IDF.

components/esp_security/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ menu "ESP Security Specific"
3838
endmenu
3939

4040
config ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
41-
bool "Forcfully enable ECC constant time point multiplication operations"
41+
bool "Forcefully enable ECC constant time point multiplication operations"
4242
depends on SOC_ECC_CONSTANT_TIME_POINT_MUL
43+
depends on !(IDF_TARGET_ESP32H2 && ESP32H2_REV_MIN_FULL < 102)
4344
default N
4445
help
4546
If enabled, the app startup code will burn the ECC_FORCE_CONST_TIME efuse bit to force the

components/esp_security/src/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
4040
esp_crypto_dpa_protection_startup();
4141
#endif
4242

43-
#ifdef CONFIG_ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
43+
#if CONFIG_ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
4444
if (!esp_efuse_read_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME)) {
4545
ESP_EARLY_LOGD(TAG, "Forcefully enabling ECC constant time operations");
4646
esp_err_t err = esp_efuse_write_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME);

components/hal/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ menu "Hardware Abstraction Layer (HAL) and Low Level (LL)"
105105

106106
config HAL_ECDSA_GEN_SIG_CM
107107
bool "Enable countermeasure for ECDSA signature generation"
108+
depends on IDF_TARGET_ESP32H2 && ESP32H2_REV_MIN_FULL < 102
108109
default n
109-
# ToDo - IDF-11051
110110
help
111111
Enable this option to apply the countermeasure for ECDSA signature operation
112112
This countermeasure masks the real ECDSA sign operation

components/hal/ecc_hal.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ int ecc_hal_read_mod_op_result(uint8_t *r, uint16_t len)
178178

179179
#endif /* SOC_ECC_EXTENDED_MODES_SUPPORTED */
180180

181-
#ifdef SOC_ECC_CONSTANT_TIME_POINT_MUL
182181
void ecc_hal_enable_constant_time_point_mul(bool enable)
183182
{
184183
ecc_ll_enable_constant_time_point_mul(enable);
185184
}
186-
#endif /* SOC_ECC_CONSTANT_TIME_POINT_MUL */

components/hal/esp32c2/include/hal/ecc_ll.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -171,6 +171,12 @@ static inline void ecc_ll_read_param(ecc_ll_param_t param, uint8_t *buf, uint16_
171171
memcpy(buf, (void *)reg, len);
172172
}
173173

174+
static inline void ecc_ll_enable_constant_time_point_mul(bool enable)
175+
{
176+
// Not supported for ESP32-C2
177+
(void) enable; //unused
178+
}
179+
174180
#ifdef __cplusplus
175181
}
176182
#endif

components/hal/esp32c6/include/hal/ecc_ll.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ static inline void ecc_ll_read_param(ecc_ll_param_t param, uint8_t *buf, uint16_
173173
memcpy(buf, (void *)reg, len);
174174
}
175175

176+
static inline void ecc_ll_enable_constant_time_point_mul(bool enable)
177+
{
178+
// Not supported for ESP32-C6
179+
(void) enable; //unused
180+
}
181+
176182
#ifdef __cplusplus
177183
}
178184
#endif

components/hal/esp32h2/include/hal/ecc_ll.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "soc/ecc_mult_reg.h"
1313
#include "soc/pcr_struct.h"
1414
#include "soc/pcr_reg.h"
15+
#include "soc/chip_revision.h"
16+
#include "hal/efuse_ll.h"
1517

1618
#ifdef __cplusplus
1719
extern "C" {
@@ -211,6 +213,18 @@ static inline ecc_mod_base_t ecc_ll_get_mod_base(void)
211213
return (ecc_mod_base_t)(REG_GET_FIELD(ECC_MULT_CONF_REG, ECC_MULT_MOD_BASE));
212214
}
213215

216+
static inline void ecc_ll_enable_constant_time_point_mul(bool enable)
217+
{
218+
// ECC constant time point multiplication is supported only on rev 1.2 and above
219+
if ((efuse_ll_get_chip_wafer_version_major() >= 1) && (efuse_ll_get_chip_wafer_version_minor() >= 2)) {
220+
if (enable) {
221+
REG_SET_BIT(ECC_MULT_CONF_REG, ECC_MULT_SECURITY_MODE);
222+
} else {
223+
REG_CLR_BIT(ECC_MULT_CONF_REG, ECC_MULT_SECURITY_MODE);
224+
}
225+
}
226+
}
227+
214228
static inline void ecc_ll_read_param(ecc_ll_param_t param, uint8_t *buf, uint16_t len)
215229
{
216230
uint32_t reg;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -240,6 +240,12 @@ static inline void ecc_ll_read_param(ecc_ll_param_t param, uint8_t *buf, uint16_
240240
memcpy(buf, (void *)reg, len);
241241
}
242242

243+
static inline void ecc_ll_enable_constant_time_point_mul(bool enable)
244+
{
245+
// Not supported for ESP32-P4
246+
(void) enable; //unused
247+
}
248+
243249
#ifdef __cplusplus
244250
}
245251
#endif

components/hal/include/hal/ecc_hal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,12 @@ int ecc_hal_read_mod_op_result(uint8_t *r, uint16_t len);
195195

196196
#endif /* SOC_ECC_EXTENDED_MODES_SUPPORTED */
197197

198-
#ifdef SOC_ECC_CONSTANT_TIME_POINT_MUL
199198
/**
200199
* @brief Enable constant time multiplication operations
201200
*
202201
* @param true: enable; false: disable
203202
*/
204203
void ecc_hal_enable_constant_time_point_mul(bool enable);
205-
#endif /* SOC_ECC_CONSTANT_TIME_POINT_MUL */
206204

207205
#ifdef __cplusplus
208206
}

0 commit comments

Comments
 (0)