mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
Merge branch 'feature/esp32h2_eco5_ecc_v5.2' into 'release/v5.2'
feat(ecc): enable ECC constant time mode for ESP32-H2 ECO5 (v5.2) See merge request espressif/esp-idf!36586
This commit is contained in:
@@ -44,6 +44,14 @@ int esp_ecc_point_multiply(const ecc_point_t *point, const uint8_t *scalar, ecc_
|
||||
|
||||
ecc_hal_write_mul_param(scalar, point->x, point->y, len);
|
||||
ecc_hal_set_mode(work_mode);
|
||||
|
||||
/*
|
||||
* Enable constant-time point multiplication operations for the ECC hardware accelerator,
|
||||
* if supported for the given target. This protects the ECC multiplication operation from
|
||||
* timing attacks. This increases the time taken (by almost 50%) for some point
|
||||
* multiplication operations performed by the ECC hardware accelerator.
|
||||
*/
|
||||
ecc_hal_enable_constant_time_point_mul(true);
|
||||
ecc_hal_start_calc();
|
||||
|
||||
memset(result, 0, sizeof(ecc_point_t));
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#if CONFIG_MBEDTLS_HARDWARE_ECDSA_SIGN_CONSTANT_TIME_CM
|
||||
#include "esp_timer.h"
|
||||
#include "soc/chip_revision.h"
|
||||
#include "hal/efuse_hal.h"
|
||||
|
||||
#if CONFIG_ESP_CRYPTO_DPA_PROTECTION_LEVEL_HIGH
|
||||
/*
|
||||
@@ -316,9 +318,11 @@ static int esp_ecdsa_sign(mbedtls_ecp_group *grp, mbedtls_mpi* r, mbedtls_mpi* s
|
||||
#endif
|
||||
ecdsa_hal_gen_signature(&conf, sha_le, r_le, s_le, len);
|
||||
#if CONFIG_MBEDTLS_HARDWARE_ECDSA_SIGN_CONSTANT_TIME_CM
|
||||
sig_time = esp_timer_get_time() - sig_time;
|
||||
if (sig_time < ECDSA_CM_FIXED_SIG_TIME) {
|
||||
esp_rom_delay_us(ECDSA_CM_FIXED_SIG_TIME - sig_time);
|
||||
if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 102)) {
|
||||
sig_time = esp_timer_get_time() - sig_time;
|
||||
if (sig_time < ECDSA_CM_FIXED_SIG_TIME) {
|
||||
esp_rom_delay_us(ECDSA_CM_FIXED_SIG_TIME - sig_time);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
process_again = !ecdsa_hal_get_operation_result()
|
||||
|
||||
Reference in New Issue
Block a user