Skip to content

Commit b0f6b87

Browse files
committed
Merge branch 'fix/change_write_protection_bit_of_shared_security_efuses_v5.4' into 'release/v5.4'
Reorder write protection bits of some shared security efuses (v5.4) See merge request espressif/esp-idf!42328
2 parents 2e64a16 + 5fa0347 commit b0f6b87

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

components/bootloader/Kconfig.projbuild

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,9 @@ menu "Security features"
11361136

11371137
config SECURE_FLASH_PSEUDO_ROUND_FUNC
11381138
bool "Permanently enable XTS-AES's pseudo rounds function"
1139-
default y
1140-
depends on SECURE_FLASH_ENCRYPTION_MODE_RELEASE && SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND
1139+
default y if SECURE_FLASH_ENCRYPTION_MODE_RELEASE
1140+
default n
1141+
depends on SECURE_FLASH_ENC_ENABLED && SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND
11411142
help
11421143
If set (default), the bootloader will permanently enable the XTS-AES peripheral's pseudo rounds function.
11431144
Note: Enabling this config would burn an efuse.

components/bootloader_support/include/esp_flash_encrypt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ bool esp_flash_encryption_cfg_verify_release_mode(void);
215215
* It burns:
216216
* - "disable encrypt in dl mode"
217217
* - set FLASH_CRYPT_CNT efuse to max
218+
*
219+
* In case of the targets that support the XTS-AES peripheral's pseudo rounds function,
220+
* this API would configure the pseudo rounds level efuse bit to level low if the efuse bit
221+
* is not set already.
218222
*/
219223
void esp_flash_encryption_set_release_mode(void);
220224

components/bootloader_support/src/esp32h2/flash_encryption_secure_features.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ esp_err_t esp_flash_encryption_enable_secure_features(void)
3636

3737
esp_efuse_write_field_bit(ESP_EFUSE_DIS_DIRECT_BOOT);
3838

39-
#if defined(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE) && defined(SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND)
39+
#if CONFIG_SECURE_FLASH_PSEUDO_ROUND_FUNC
4040
if (spi_flash_encrypt_ll_is_pseudo_rounds_function_supported()) {
4141
ESP_LOGI(TAG, "Enable XTS-AES pseudo rounds function...");
4242
uint8_t xts_pseudo_level = CONFIG_SECURE_FLASH_PSEUDO_ROUND_FUNC_STRENGTH;

components/bootloader_support/src/flash_encrypt.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,13 @@ void esp_flash_encryption_set_release_mode(void)
212212

213213
#ifdef SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND
214214
if (spi_flash_encrypt_ll_is_pseudo_rounds_function_supported()) {
215-
uint8_t xts_pseudo_level = ESP_XTS_AES_PSEUDO_ROUNDS_LOW;
216-
esp_efuse_write_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
215+
uint8_t xts_pseudo_level = 0;
216+
esp_efuse_read_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
217+
218+
if (xts_pseudo_level == ESP_XTS_AES_PSEUDO_ROUNDS_DISABLE) {
219+
xts_pseudo_level = ESP_XTS_AES_PSEUDO_ROUNDS_LOW;
220+
esp_efuse_write_field_blob(ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL, &xts_pseudo_level, ESP_EFUSE_XTS_DPA_PSEUDO_LEVEL[0]->bit_count);
221+
}
217222
}
218223
#endif
219224

components/esp_security/src/init.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include "esp_security_priv.h"
1414
#include "esp_err.h"
1515
#include "hal/efuse_hal.h"
16+
#if SOC_ECDSA_P192_CURVE_DEFAULT_DISABLED
17+
#include "hal/ecdsa_ll.h"
18+
#endif
1619

1720
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY
1821
#include "hal/key_mgr_ll.h"
@@ -42,6 +45,8 @@ ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
4245
esp_crypto_dpa_protection_startup();
4346
#endif
4447

48+
esp_err_t err = ESP_FAIL;
49+
4550
#if CONFIG_ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
4651
bool force_constant_time = true;
4752
#if CONFIG_IDF_TARGET_ESP32H2
@@ -51,7 +56,7 @@ ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
5156
#endif
5257
if (!esp_efuse_read_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME) && force_constant_time) {
5358
ESP_EARLY_LOGD(TAG, "Forcefully enabling ECC constant time operations");
54-
esp_err_t err = esp_efuse_write_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME);
59+
err = esp_efuse_write_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME);
5560
if (err != ESP_OK) {
5661
ESP_EARLY_LOGE(TAG, "Enabling ECC constant time operations forcefully failed.");
5762
return err;
@@ -60,14 +65,25 @@ ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
6065
#endif
6166

6267
#if CONFIG_ESP_ECDSA_ENABLE_P192_CURVE
63-
esp_err_t err;
6468
err = esp_efuse_enable_ecdsa_p192_curve_mode();
6569
if (err != ESP_OK) {
6670
return err;
6771
}
6872
#endif
6973

70-
return ESP_OK;
74+
#if CONFIG_SECURE_BOOT_V2_ENABLED && SOC_ECDSA_P192_CURVE_DEFAULT_DISABLED
75+
// Also write protect the ECDSA_CURVE_MODE efuse bit.
76+
if (ecdsa_ll_is_configurable_curve_supported()) {
77+
err = esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_ECDSA_CURVE_MODE);
78+
if (err != ESP_OK) {
79+
ESP_LOGE(TAG, "Failed to write protect the ECDSA_CURVE_MODE efuse bit.");
80+
return err;
81+
}
82+
}
83+
#endif
84+
85+
err = ESP_OK;
86+
return err;
7187
}
7288

7389
void esp_security_init_include_impl(void)

docs/en/security/security-features-enablement-workflows.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ In this workflow we shall use ``espsecure`` tool to generate signing keys and us
485485
:SOC_EFUSE_DIS_USB_JTAG: - ``DIS_USB_JTAG``: Disable USB switch to JTAG.
486486
:SOC_EFUSE_DIS_PAD_JTAG: - ``DIS_PAD_JTAG``: Disable JTAG permanently.
487487
:SOC_EFUSE_REVOKE_BOOT_KEY_DIGESTS: - ``SECURE_BOOT_AGGRESSIVE_REVOKE``: Aggressive revocation of key digests, see :ref:`secure-boot-v2-aggressive-key-revocation` for more details.
488+
:SOC_ECDSA_P192_CURVE_DEFAULT_DISABLED: - ``WR_DIS_ECDSA_CURVE_MODE``: Disable writing to the ECDSA curve mode eFuse bit. As this write protection bit is shared with ``ECC_FORCE_CONST_TIME``, it is recommended to write protect this bit only after configuring the ``ECC_FORCE_CONST_TIME`` eFuse.
488489

489490
The respective eFuses can be burned by running:
490491

docs/zh_CN/security/security-features-enablement-workflows.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ flash 加密指南
485485
:SOC_EFUSE_DIS_USB_JTAG: - ``DIS_USB_JTAG``:禁止从 USB 切换到 JTAG
486486
:SOC_EFUSE_DIS_PAD_JTAG: - ``DIS_PAD_JTAG``:永久禁用 JTAG。
487487
:SOC_EFUSE_REVOKE_BOOT_KEY_DIGESTS: - ``SECURE_BOOT_AGGRESSIVE_REVOKE``:主动吊销密钥摘要。详请请参阅 :ref:`secure-boot-v2-aggressive-key-revocation`。
488+
:SOC_ECDSA_P192_CURVE_DEFAULT_DISABLED: - ``WR_DIS_ECDSA_CURVE_MODE``:禁止写入 ECDSA 曲线模式的 eFuse 位。由于此写保护位与 ``ECC_FORCE_CONST_TIME`` 共享,建议先配置好 ``ECC_FORCE_CONST_TIME`` eFuse 字段后,再设置此写保护位)。
488489

489490
运行以下命令烧录相应的 eFuse:
490491

0 commit comments

Comments
 (0)