forked from espressif/esp-idf
feat(esp_security): Config to forcefully enable ECC constant-time operations during bootup
This commit is contained in:
@@ -37,4 +37,17 @@ menu "ESP Security Specific"
|
|||||||
default 3 if ESP_CRYPTO_DPA_PROTECTION_LEVEL_HIGH
|
default 3 if ESP_CRYPTO_DPA_PROTECTION_LEVEL_HIGH
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
config ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
|
||||||
|
bool "Forcfully enable ECC constant time point multiplication operations"
|
||||||
|
depends on SOC_ECC_CONSTANT_TIME_POINT_MUL
|
||||||
|
default N
|
||||||
|
help
|
||||||
|
If enabled, the app startup code will burn the ECC_FORCE_CONST_TIME efuse bit to force the
|
||||||
|
ECC peripheral to always perform constant time point multiplication operations,
|
||||||
|
irrespective of the ECC_MULT_SECURITY_MODE status bit that is present in the ECC_MULT_CONF_REG
|
||||||
|
register. By default, ESP-IDF configures the ECC peripheral to perform constant time point
|
||||||
|
multiplication operations, so enabling this config would provide security enhancement only in
|
||||||
|
the cases when trusted boot is not enabled and the attacker tries carrying out non-constant
|
||||||
|
time point multiplication operations by changing the default ESP-IDF configurations.
|
||||||
|
Performing constant time operations protect the ECC multiplication operations from timing attacks.
|
||||||
endmenu
|
endmenu
|
||||||
|
@@ -7,7 +7,12 @@
|
|||||||
#include "esp_private/startup_internal.h"
|
#include "esp_private/startup_internal.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "esp_crypto_clk.h"
|
#include "esp_crypto_clk.h"
|
||||||
|
#include "esp_efuse.h"
|
||||||
|
#include "esp_efuse_table.h"
|
||||||
#include "esp_security_priv.h"
|
#include "esp_security_priv.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
|
||||||
|
__attribute__((unused)) static const char *TAG = "esp_security";
|
||||||
|
|
||||||
ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
|
ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
|
||||||
{
|
{
|
||||||
@@ -15,6 +20,17 @@ ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
|
|||||||
#if CONFIG_ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP
|
#if CONFIG_ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP
|
||||||
esp_crypto_dpa_protection_startup();
|
esp_crypto_dpa_protection_startup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
|
||||||
|
if (!esp_efuse_read_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME)) {
|
||||||
|
ESP_EARLY_LOGD(TAG, "Forcefully enabling ECC constant time operations");
|
||||||
|
esp_err_t err = esp_efuse_write_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_EARLY_LOGE(TAG, "Enabling ECC constant time operations forcefully failed.");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user