Skip to content

Commit f19e8e6

Browse files
nileshkale123mahavirj
authored andcommitted
fix: re-enabled ecdsa support for esp32c5-eco2
1 parent 8c67e3e commit f19e8e6

File tree

20 files changed

+117
-833
lines changed

20 files changed

+117
-833
lines changed

components/hal/ecdsa_hal.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void configure_ecdsa_periph(ecdsa_hal_config_t *conf)
2626
{
2727

2828
if (conf->use_km_key == 0) {
29-
efuse_hal_set_ecdsa_key(conf->efuse_key_blk);
29+
efuse_hal_set_ecdsa_key(conf->curve, conf->efuse_key_blk);
3030

3131
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY
3232
// Force Key Manager to use eFuse key for XTS-AES operation
@@ -49,9 +49,11 @@ static void configure_ecdsa_periph(ecdsa_hal_config_t *conf)
4949
#if SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE
5050
ecdsa_ll_set_k_type(conf->sign_type);
5151

52+
#if !SOC_ECDSA_SUPPORT_HW_DETERMINISTIC_LOOP
5253
if (conf->sign_type == ECDSA_K_TYPE_DETERMINISITIC) {
5354
ecdsa_ll_set_deterministic_loop(conf->loop_number);
5455
}
56+
#endif /* !SOC_ECDSA_SUPPORT_HW_DETERMINISTIC_LOOP */
5557
#endif
5658
}
5759

@@ -224,11 +226,9 @@ void ecdsa_hal_export_pubkey(ecdsa_hal_config_t *conf, uint8_t *pub_x, uint8_t *
224226
}
225227
#endif /* SOC_ECDSA_SUPPORT_EXPORT_PUBKEY */
226228

227-
#ifdef SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE
228-
229+
#if SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE && !SOC_ECDSA_SUPPORT_HW_DETERMINISTIC_LOOP
229230
bool ecdsa_hal_det_signature_k_check(void)
230231
{
231232
return (ecdsa_ll_check_k_value() == 0);
232233
}
233-
234-
#endif /* SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE */
234+
#endif /* SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE && !SOC_ECDSA_SUPPORT_HW_DETERMINISTIC_LOOP */

components/hal/efuse_hal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ IRAM_ATTR bool efuse_hal_flash_encryption_enabled(void)
5757
}
5858

5959
#if SOC_EFUSE_ECDSA_KEY
60-
void efuse_hal_set_ecdsa_key(int efuse_blk)
60+
void efuse_hal_set_ecdsa_key(ecdsa_curve_t curve, int efuse_blk)
6161
{
62-
efuse_ll_set_ecdsa_key_blk(efuse_blk);
62+
efuse_ll_set_ecdsa_key_blk(curve, efuse_blk);
6363

6464
efuse_ll_rs_bypass_update();
6565

components/hal/esp32c5/include/hal/ecdsa_ll.h

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -194,11 +194,11 @@ static inline void ecdsa_ll_set_mode(ecdsa_mode_t mode)
194194
static inline void ecdsa_ll_set_curve(ecdsa_curve_t curve)
195195
{
196196
switch (curve) {
197-
case ECDSA_CURVE_SECP256R1:
198-
REG_SET_BIT(ECDSA_CONF_REG, ECDSA_ECC_CURVE);
199-
break;
200197
case ECDSA_CURVE_SECP192R1:
201-
REG_CLR_BIT(ECDSA_CONF_REG, ECDSA_ECC_CURVE);
198+
case ECDSA_CURVE_SECP256R1:
199+
case ECDSA_CURVE_SECP384R1:
200+
case ECDSA_CURVE_SM2:
201+
REG_SET_FIELD(ECDSA_CONF_REG, ECDSA_ECC_CURVE, curve);
202202
break;
203203
default:
204204
HAL_ASSERT(false && "Unsupported curve");
@@ -248,16 +248,6 @@ static inline void ecdsa_ll_set_k_type(ecdsa_sign_type_t type)
248248
}
249249
}
250250

251-
/**
252-
* @brief Set the loop number value that is used for deterministic derivation of K
253-
*
254-
* @param loop_number Loop number for deterministic K
255-
*/
256-
static inline void ecdsa_ll_set_deterministic_loop(uint16_t loop_number)
257-
{
258-
REG_SET_FIELD(ECDSA_CONF_REG, ECDSA_DETERMINISTIC_LOOP, loop_number);
259-
}
260-
261251
/**
262252
* @brief Set the stage of ECDSA operation
263253
*
@@ -415,17 +405,6 @@ static inline int ecdsa_ll_get_operation_result(void)
415405
return REG_GET_BIT(ECDSA_RESULT_REG, ECDSA_OPERATION_RESULT);
416406
}
417407

418-
/**
419-
* @brief Check if the k value is greater than the curve order.
420-
*
421-
* @return 0, k value is not greater than the curve order. In this case, the k value is the set k value.
422-
* @return 1, k value is greater than than the curve order. In this case, the k value is the set (k mod n).
423-
*/
424-
static inline int ecdsa_ll_check_k_value(void)
425-
{
426-
return REG_GET_BIT(ECDSA_RESULT_REG, ECDSA_K_VALUE_WARNING);
427-
}
428-
429408
#ifdef __cplusplus
430409
}
431410
#endif

components/hal/esp32c5/include/hal/efuse_ll.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "soc/efuse_periph.h"
1414
#include "hal/assert.h"
1515
#include "rom/efuse.h"
16+
#include "hal/ecdsa_types.h"
1617

1718
#ifdef __cplusplus
1819
extern "C" {
@@ -93,9 +94,19 @@ __attribute__((always_inline)) static inline uint32_t efuse_ll_get_chip_ver_pkg(
9394
return EFUSE.rd_mac_sys2.pkg_version;
9495
}
9596

96-
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(int efuse_blk)
97+
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(ecdsa_curve_t curve, int efuse_blk)
9798
{
98-
EFUSE.conf.cfg_ecdsa_blk = efuse_blk;
99+
switch (curve) {
100+
case ECDSA_CURVE_SECP192R1:
101+
EFUSE.ecdsa.cfg_ecdsa_p192_blk = efuse_blk;
102+
break;
103+
case ECDSA_CURVE_SECP256R1:
104+
EFUSE.ecdsa.cfg_ecdsa_p256_blk = efuse_blk;
105+
break;
106+
default:
107+
HAL_ASSERT(false && "Unsupported curve");
108+
break;
109+
}
99110
}
100111

101112
__attribute__((always_inline)) static inline uint32_t efuse_ll_get_ocode(void)

components/hal/esp32c61/include/hal/efuse_ll.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "soc/efuse_struct.h"
1414
#include "hal/assert.h"
1515
#include "rom/efuse.h"
16+
#include "hal/ecdsa_types.h"
1617

1718
#ifdef __cplusplus
1819
extern "C" {
@@ -98,8 +99,9 @@ __attribute__((always_inline)) static inline uint32_t efuse_ll_get_ecdsa_key_blk
9899
return EFUSE0.conf.cfg_ecdsa_blk;
99100
}
100101

101-
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(int efuse_blk)
102+
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(ecdsa_curve_t curve, int efuse_blk)
102103
{
104+
(void) curve;
103105
EFUSE0.conf.cfg_ecdsa_blk = efuse_blk;
104106
}
105107

components/hal/esp32h2/include/hal/efuse_ll.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "soc/efuse_periph.h"
1212
#include "hal/assert.h"
1313
#include "rom/efuse.h"
14+
#include "hal/ecdsa_types.h"
1415

1516
#ifdef __cplusplus
1617
extern "C" {
@@ -107,8 +108,9 @@ __attribute__((always_inline)) static inline uint32_t efuse_ll_get_ecdsa_key_blk
107108
return EFUSE.conf.cfg_ecdsa_blk;
108109
}
109110

110-
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(int efuse_blk)
111+
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(ecdsa_curve_t curve, int efuse_blk)
111112
{
113+
(void) curve;
112114
EFUSE.conf.cfg_ecdsa_blk = efuse_blk;
113115
}
114116

components/hal/esp32h21/include/hal/efuse_ll.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "soc/efuse_periph.h"
1212
#include "hal/assert.h"
1313
#include "rom/efuse.h"
14+
#include "hal/ecdsa_types.h"
1415

1516
//TODO: [ESP32H21] IDF-11556, inherit from h2
1617

@@ -114,8 +115,9 @@ __attribute__((always_inline)) static inline uint32_t efuse_ll_get_ecdsa_key_blk
114115
return EFUSE.conf.cfg_ecdsa_blk;
115116
}
116117

117-
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(int efuse_blk)
118+
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(ecdsa_curve_t curve, int efuse_blk)
118119
{
120+
(void) curve;
119121
EFUSE.conf.cfg_ecdsa_blk = efuse_blk;
120122
}
121123

components/hal/esp32h4/include/hal/efuse_ll.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "soc/efuse_periph.h"
1212
#include "hal/assert.h"
1313
#include "rom/efuse.h"
14+
#include "hal/ecdsa_types.h"
1415

1516
//TODO: [ESP32H4] IDF-12322 inherited from verification branch, need check
1617

@@ -96,9 +97,10 @@ __attribute__((always_inline)) static inline uint32_t efuse_ll_get_ecdsa_key_blk
9697
return 0;
9798
}
9899

99-
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(int efuse_blk)
100+
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(ecdsa_curve_t curve, int efuse_blk)
100101
{
101102
//ESP32H4 TODO
103+
(void)curve;
102104
(void)efuse_blk;
103105
}
104106

components/hal/esp32p4/include/hal/efuse_ll.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "soc/efuse_periph.h"
1212
#include "hal/assert.h"
1313
#include "rom/efuse.h"
14+
#include "hal/ecdsa_types.h"
1415

1516
#ifdef __cplusplus
1617
extern "C" {
@@ -91,8 +92,9 @@ __attribute__((always_inline)) static inline uint32_t efuse_ll_get_chip_ver_pkg(
9192
return EFUSE.rd_mac_sys_2.pkg_version;
9293
}
9394

94-
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(int efuse_blk)
95+
__attribute__((always_inline)) static inline void efuse_ll_set_ecdsa_key_blk(ecdsa_curve_t curve, int efuse_blk)
9596
{
97+
(void) curve;
9698
EFUSE.conf.cfg_ecdsa_blk = efuse_blk;
9799
}
98100

components/hal/include/hal/ecdsa_hal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void ecdsa_hal_export_pubkey(ecdsa_hal_config_t *conf, uint8_t *pub_x, uint8_t *
9898
*/
9999
bool ecdsa_hal_get_operation_result(void);
100100

101-
#ifdef SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE
101+
#if SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE && !SOC_ECDSA_SUPPORT_HW_DETERMINISTIC_LOOP
102102
/**
103103
* @brief Check if the K value derived by the peripheral during deterministic signature generation is valid
104104
*
@@ -107,7 +107,7 @@ bool ecdsa_hal_get_operation_result(void);
107107
*/
108108
bool ecdsa_hal_det_signature_k_check(void);
109109

110-
#endif /* SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE */
110+
#endif /* SOC_ECDSA_SUPPORT_DETERMINISTIC_MODE && !SOC_ECDSA_SUPPORT_HW_DETERMINISTIC_LOOP */
111111

112112
#ifdef __cplusplus
113113
}

0 commit comments

Comments
 (0)