mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(ecdsa): remove unused k_mode from the ECDSA HAL/LL API
For ESP32-H2 case, the hardware k mode is always enforced through efuse settings (done in startup code). For ESP32-P4 case, the software k mode is not supported in the peripheral itself and code was redundant.
This commit is contained in:
parent
0ccfa4b0c2
commit
2cd1635b86
@ -18,21 +18,16 @@ static void configure_ecdsa_periph(ecdsa_hal_config_t *conf)
|
||||
|
||||
ecdsa_ll_set_mode(conf->mode);
|
||||
ecdsa_ll_set_curve(conf->curve);
|
||||
ecdsa_ll_set_k_mode(conf->k_mode);
|
||||
ecdsa_ll_set_z_mode(conf->sha_mode);
|
||||
}
|
||||
|
||||
void ecdsa_hal_gen_signature(ecdsa_hal_config_t *conf, const uint8_t *k, const uint8_t *hash,
|
||||
void ecdsa_hal_gen_signature(ecdsa_hal_config_t *conf, const uint8_t *hash,
|
||||
uint8_t *r_out, uint8_t *s_out, uint16_t len)
|
||||
{
|
||||
if (len != ECDSA_HAL_P192_COMPONENT_LEN && len != ECDSA_HAL_P256_COMPONENT_LEN) {
|
||||
HAL_ASSERT(false && "Incorrect length");
|
||||
}
|
||||
|
||||
if (conf->k_mode == ECDSA_K_USER_PROVIDED && k == NULL) {
|
||||
HAL_ASSERT(false && "Mismatch in K configuration");
|
||||
}
|
||||
|
||||
if (conf->sha_mode == ECDSA_Z_USER_PROVIDED && hash == NULL) {
|
||||
HAL_ASSERT(false && "Mismatch in SHA configuration");
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ typedef enum {
|
||||
ECDSA_PARAM_R,
|
||||
ECDSA_PARAM_S,
|
||||
ECDSA_PARAM_Z,
|
||||
ECDSA_PARAM_K,
|
||||
ECDSA_PARAM_QAX,
|
||||
ECDSA_PARAM_QAY
|
||||
} ecdsa_ll_param_t;
|
||||
@ -170,26 +169,6 @@ static inline void ecdsa_ll_set_curve(ecdsa_curve_t curve)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the source of `K`
|
||||
*
|
||||
* @param mode Mode of K generation
|
||||
*/
|
||||
static inline void ecdsa_ll_set_k_mode(ecdsa_k_mode_t mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case ECDSA_K_USE_TRNG:
|
||||
REG_CLR_BIT(ECDSA_CONF_REG, ECDSA_SOFTWARE_SET_K);
|
||||
break;
|
||||
case ECDSA_K_USER_PROVIDED:
|
||||
REG_SET_BIT(ECDSA_CONF_REG, ECDSA_SOFTWARE_SET_K);
|
||||
break;
|
||||
default:
|
||||
HAL_ASSERT(false && "Unsupported curve");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the source of `Z` (SHA message)
|
||||
*
|
||||
@ -315,7 +294,6 @@ static inline void ecdsa_ll_write_param(ecdsa_ll_param_t param, const uint8_t *b
|
||||
case ECDSA_PARAM_Z:
|
||||
reg = ECDSA_Z_MEM;
|
||||
break;
|
||||
case ECDSA_PARAM_K:
|
||||
case ECDSA_PARAM_QAX:
|
||||
reg = ECDSA_QAX_MEM;
|
||||
break;
|
||||
@ -353,7 +331,6 @@ static inline void ecdsa_ll_read_param(ecdsa_ll_param_t param, uint8_t *buf, uin
|
||||
case ECDSA_PARAM_Z:
|
||||
reg = ECDSA_Z_MEM;
|
||||
break;
|
||||
case ECDSA_PARAM_K:
|
||||
case ECDSA_PARAM_QAX:
|
||||
reg = ECDSA_QAX_MEM;
|
||||
break;
|
||||
|
@ -25,7 +25,6 @@ extern "C" {
|
||||
typedef struct {
|
||||
ecdsa_mode_t mode; /* Mode of operation */
|
||||
ecdsa_curve_t curve; /* Curve to use for operation */
|
||||
ecdsa_k_mode_t k_mode; /* Source of K */
|
||||
ecdsa_sha_mode_t sha_mode; /* Source of SHA that needs to be signed */
|
||||
int efuse_key_blk; /* Efuse block to use as ECDSA key (The purpose of the efuse block must be ECDSA_KEY) */
|
||||
} ecdsa_hal_config_t;
|
||||
@ -34,13 +33,12 @@ typedef struct {
|
||||
* @brief Generate ECDSA signature
|
||||
*
|
||||
* @param conf Configuration for ECDSA operation, see ``ecdsa_hal_config_t``
|
||||
* @param k Value of K used internally. Set this to NULL if K is generated by hardware
|
||||
* @param hash Hash that is to be signed
|
||||
* @param r_out Buffer that will contain `R` component of ECDSA signature
|
||||
* @param s_out Buffer that will contain `S` component of ECDSA signature
|
||||
* @param len Length of the r_out and s_out buffer (32 bytes for SECP256R1, 24 for SECP192R1)
|
||||
*/
|
||||
void ecdsa_hal_gen_signature(ecdsa_hal_config_t *conf, const uint8_t *k, const uint8_t *hash,
|
||||
void ecdsa_hal_gen_signature(ecdsa_hal_config_t *conf, const uint8_t *hash,
|
||||
uint8_t *r_out, uint8_t *s_out, uint16_t len);
|
||||
|
||||
/**
|
||||
|
@ -25,14 +25,6 @@ typedef enum {
|
||||
ECDSA_CURVE_SECP256R1,
|
||||
} ecdsa_curve_t;
|
||||
|
||||
/**
|
||||
* @brief Source of 'K' used internally for generating signature
|
||||
*/
|
||||
typedef enum {
|
||||
ECDSA_K_USE_TRNG,
|
||||
ECDSA_K_USER_PROVIDED,
|
||||
} ecdsa_k_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Source of SHA message that is to be signed/verified
|
||||
*/
|
||||
|
@ -139,12 +139,11 @@ static int esp_ecdsa_sign(mbedtls_ecp_group *grp, mbedtls_mpi* r, mbedtls_mpi* s
|
||||
ecdsa_hal_config_t conf = {
|
||||
.mode = ECDSA_MODE_SIGN_GEN,
|
||||
.curve = curve,
|
||||
.k_mode = ECDSA_K_USE_TRNG,
|
||||
.sha_mode = ECDSA_Z_USER_PROVIDED,
|
||||
.efuse_key_blk = d->MBEDTLS_PRIVATE(n),
|
||||
};
|
||||
|
||||
ecdsa_hal_gen_signature(&conf, NULL, sha_le, r_le, s_le, len);
|
||||
ecdsa_hal_gen_signature(&conf, sha_le, r_le, s_le, len);
|
||||
} while (!memcmp(r_le, zeroes, len) || !memcmp(s_le, zeroes, len));
|
||||
|
||||
esp_ecdsa_release_hardware();
|
||||
@ -364,7 +363,6 @@ static int esp_ecdsa_verify(mbedtls_ecp_group *grp,
|
||||
ecdsa_hal_config_t conf = {
|
||||
.mode = ECDSA_MODE_SIGN_VERIFY,
|
||||
.curve = curve,
|
||||
.k_mode = ECDSA_K_USE_TRNG,
|
||||
.sha_mode = ECDSA_Z_USER_PROVIDED,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user