Skip to content

Commit d6c1184

Browse files
committed
fix(bootloader_support): Reorder write protection bits of some shared security efuses
1 parent 79c69cf commit d6c1184

File tree

7 files changed

+68
-9
lines changed

7 files changed

+68
-9
lines changed

components/bootloader/Kconfig.projbuild

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,24 @@ menu "Security features"
972972
so that the bootloader would not need to enable secure boot and thus you could avoid its revocation
973973
strategy.
974974

975+
config SECURE_BOOT_SKIP_WRITE_PROTECTION_SCA
976+
bool "Skip write-protection of SECURE_FLASH_PSEUDO_ROUND_FUNC_STRENGTH"
977+
default y if SECURE_FLASH_PSEUDO_ROUND_FUNC
978+
default n
979+
depends on SOC_ECDSA_SUPPORT_CURVE_P384 && SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND
980+
help
981+
If not set (default, recommended), on the first boot when Secure Boot is enabled for
982+
targets that support Secure Boot using ECDSA-P384, the bootloader will burn the write-protection bit of
983+
of SECURE_BOOT_SHA384_EN that could be shared by multiple other efuse bits like
984+
SECURE_FLASH_PSEUDO_ROUND_FUNC_STRENGTH / XTS_DPA_PSEUDO_LEVEL.
985+
986+
Once this efuse bit is write-protected you cannot update the values of the shared efuses, for example,
987+
the security strength value of XTS_DPA_PSEUDO_LEVEL or setting ECC_FORCE_CONST_TIME.
988+
989+
List of eFuses with the same write protection bit:
990+
991+
ESP32-C5: XTS_DPA_PSEUDO_LEVEL and ECC_FORCE_CONST_TIME
992+
975993
config SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC
976994
bool "Leave UART bootloader encryption enabled"
977995
depends on SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
@@ -1055,6 +1073,7 @@ menu "Security features"
10551073
ESP32-S3: DIS_ICACHE, DIS_DCACHE, DIS_DOWNLOAD_ICACHE, DIS_DOWNLOAD_DCACHE,
10561074
DIS_FORCE_DOWNLOAD, DIS_USB_OTG, DIS_TWAI, DIS_APP_CPU, DIS_PAD_JTAG,
10571075
DIS_DOWNLOAD_MANUAL_ENCRYPT, DIS_USB_JTAG, DIS_USB_SERIAL_JTAG, STRAP_JTAG_SEL, USB_PHY_SEL.
1076+
10581077
endmenu # Potentially Insecure
10591078

10601079
config SECURE_FLASH_ENCRYPT_ONLY_IMAGE_LEN_IN_APP_PART
@@ -1101,6 +1120,12 @@ menu "Security features"
11011120
The strength of the pseudo rounds functions can be configured to low, medium and high,
11021121
each denoting the values that would be stored in the efuses field.
11031122
By default the value to set to low.
1123+
1124+
It is recommended that the required strength of the pseudo rounds function should be set during the
1125+
first boot itself. If your workflow needs to update the function's strength after the first boot,
1126+
you should enable CONFIG_SECURE_BOOT_SKIP_WRITE_PROTECTION_SCA to avoid write protecting this
1127+
bit during the boot up for targets that support Secure Boot using ECDSA-P384.
1128+
11041129
You can configure the strength of the pseudo rounds functions according to your use cases,
11051130
for example, increasing the strength would provide higher security but would slow down the
11061131
flash encryption/decryption operations.

components/bootloader_support/src/esp32c5/secure_boot_secure_features.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ esp_err_t esp_secure_boot_enable_secure_features(void)
5353
esp_efuse_write_field_bit(ESP_EFUSE_SECURE_BOOT_SHA384_EN);
5454
#endif
5555

56-
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_SECURE_BOOT_SHA384_EN);
57-
5856
esp_efuse_write_field_bit(ESP_EFUSE_SECURE_BOOT_EN);
5957

6058
#ifndef CONFIG_SECURE_BOOT_V2_ALLOW_EFUSE_RD_DIS

components/bootloader_support/src/secure_boot.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ bool esp_secure_boot_cfg_verify_release_mode(void)
429429
}
430430

431431
#if SOC_ECDSA_SUPPORT_CURVE_P384
432+
#if CONFIG_SECURE_BOOT_ECDSA_KEY_LEN_384_BITS
433+
secure = esp_efuse_read_field_bit(ESP_EFUSE_SECURE_BOOT_SHA384_EN);
434+
result &= secure;
435+
if (!secure) {
436+
ESP_LOGW(TAG, "Not enabled Secure Boot using SHA-384 mode (set SECURE_BOOT_SHA384_EN->1)");
437+
}
438+
#else
432439
/* When using Secure Boot with SHA-384, the efuse bit representing Secure Boot with SHA-384 would already be programmed.
433440
* But in the case of the existing Secure Boot V2 schemes using SHA-256, the efuse bit representing
434441
* Secure Boot with SHA-384 needs to be write-protected, so that an attacker cannot perform a denial-of-service
@@ -439,6 +446,7 @@ bool esp_secure_boot_cfg_verify_release_mode(void)
439446
if (!secure) {
440447
ESP_LOGW(TAG, "Not write-protected secure boot using SHA-384 mode (set WR_DIS_SECURE_BOOT_SHA384_EN->1)");
441448
}
449+
#endif
442450
#endif
443451

444452
secure = (num_keys != 0);

components/esp_security/Kconfig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ menu "ESP Security Specific"
4040
config ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
4141
bool "Forcefully enable ECC constant time point multiplication operations"
4242
depends on SOC_ECC_CONSTANT_TIME_POINT_MUL
43-
default N
43+
default n
4444
help
4545
If enabled, the app startup code will burn the ECC_FORCE_CONST_TIME efuse bit to force the
4646
ECC peripheral to always perform constant time point multiplication operations,
@@ -51,10 +51,16 @@ menu "ESP Security Specific"
5151
time point multiplication operations by changing the default ESP-IDF configurations.
5252
Performing constant time operations protect the ECC multiplication operations from timing attacks.
5353

54+
For targets that support Secure Boot using ECDSA-P384, the write-protection bit of the efuse
55+
bit could be shared by multiple other efuse bits and can be programmed by the application when
56+
Secure Boot is enabled.
57+
Thus, you could select CONFIG_SECURE_BOOT_SKIP_WRITE_PROTECTION_SCA, in case you would like
58+
to skip the write-protection of the efuse bit.
59+
5460
config ESP_ECDSA_ENABLE_P192_CURVE
5561
bool "Enable ECDSA 192-curve operations"
5662
depends on SOC_ECDSA_P192_CURVE_DEFAULT_DISABLED
57-
default N
63+
default n
5864
help
5965
By default, only the 256-bit curve operations are allowed. If this configuration is enabled,
6066
it will set the eFuse to allow ECDSA operations using both the 192-bit and 256-bit curves.

components/esp_security/src/init.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
4646
esp_crypto_dpa_protection_startup();
4747
#endif
4848

49+
esp_err_t err = ESP_FAIL;
50+
4951
#if CONFIG_ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
5052
bool force_constant_time = true;
5153
#if CONFIG_IDF_TARGET_ESP32H2
@@ -55,7 +57,7 @@ ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
5557
#endif
5658
if (!esp_efuse_read_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME) && force_constant_time) {
5759
ESP_EARLY_LOGD(TAG, "Forcefully enabling ECC constant time operations");
58-
esp_err_t err = esp_efuse_write_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME);
60+
err = esp_efuse_write_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME);
5961
if (err != ESP_OK) {
6062
ESP_EARLY_LOGE(TAG, "Enabling ECC constant time operations forcefully failed.");
6163
return err;
@@ -64,13 +66,30 @@ ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
6466
#endif
6567

6668
#if CONFIG_ESP_ECDSA_ENABLE_P192_CURVE
67-
esp_err_t err = esp_efuse_enable_ecdsa_p192_curve_mode();
69+
err = esp_efuse_enable_ecdsa_p192_curve_mode();
70+
if (err != ESP_OK) {
71+
return err;
72+
}
73+
#endif
74+
75+
#if CONFIG_SECURE_BOOT_V2_ENABLED
76+
#if !CONFIG_SECURE_BOOT_SKIP_WRITE_PROTECTION_SCA
77+
// C5
78+
#if SOC_ECDSA_SUPPORT_CURVE_P384 && !CONFIG_SECURE_BOOT_ECDSA_KEY_LEN_384_BITS
79+
// Since SECURE_BOOT_SHA384_EN, XTS_DPA_PSEUDO_LEVEL, and ECC_FORCE_CONST_TIME share the
80+
// same write-protection bit, these efuses should only be write-protected after all of
81+
// them have been programmed.
82+
err = esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_SECURE_BOOT_SHA384_EN);
6883
if (err != ESP_OK) {
84+
ESP_LOGE(TAG, "Failed to write protect the SECURE_BOOT_SHA384_EN efuse bit.");
6985
return err;
7086
}
87+
#endif
88+
#endif
7189
#endif
7290

73-
return ESP_OK;
91+
err = ESP_OK;
92+
return err;
7493
}
7594

7695
void esp_security_init_include_impl(void)

docs/en/security/flash-encryption.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,10 @@ It is recommended to use flash encryption in combination with Secure Boot. Howev
876876

877877
- :ref:`Re-flashing via Pregenerated Flash Encryption Key <pregenerated-flash-encryption-key>` is still possible, provided the bootloader is not re-flashed. Re-flashing the bootloader requires the same :ref:`Re-flashable <CONFIG_SECURE_BOOTLOADER_MODE>` option to be enabled in the Secure Boot config.
878878

879+
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_SUPPORT_PSEUDO_ROUND and SOC_ECDSA_SUPPORT_CURVE_P384
880+
881+
- It is recommended that the required :ref: `strength of the pseudo rounds function <xts-aes-pseudo-round-func>` should be set during the first boot itself when flash encryption release mode is enabled. If your workflow needs to update the function's strength after the first boot, you should enable :ref:`CONFIG_SECURE_BOOT_SKIP_WRITE_PROTECTION_SCA` to avoid write protecting this bit during the boot up.
882+
879883
.. _flash-encryption-advanced-features:
880884

881885
Advanced Features

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ In this workflow we shall use ``espsecure`` tool to generate signing keys and us
500500
:SOC_EFUSE_DIS_USB_JTAG: - ``DIS_USB_JTAG``: Disable USB switch to JTAG.
501501
:SOC_EFUSE_DIS_PAD_JTAG: - ``DIS_PAD_JTAG``: Disable JTAG permanently.
502502
: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.
503-
:SOC_ECDSA_P192_CURVE_DEFAULT_DISABLED: - ``WR_DIS_ECDSA_CURVE_MODE``: Disable writing to the ECDSA curve mode eFuse bit.
504-
:SOC_ECDSA_SUPPORT_CURVE_P384: - ``WR_DIS_SECURE_BOOT_SHA384_EN``: Disable writing to the SHA-384 secure boot eFuse bit.
503+
:SOC_ECDSA_SUPPORT_CURVE_P384: - ``WR_DIS_SECURE_BOOT_SHA384_EN``: Disable writing to the SHA-384 secure boot eFuse bit (As this write protection bit is shared with XTS_DPA_PSEUDO_LEVEL and ECC_FORCE_CONST_TIME, it is recommended to write protect this bit only after configuring all the other shared efuses).
505504

506505
The respective eFuses can be burned by running:
507506

0 commit comments

Comments
 (0)