Skip to content

Commit fd7d9c9

Browse files
committed
Merge branch 'fix/key_mgr_use_default_efuse_key' into 'master'
Configure the Key Manager to use XTS-AES efuse key by-default Closes IDFCI-3135 and IDFCI-3136 See merge request espressif/esp-idf!42032
2 parents 76b28d8 + 8b663eb commit fd7d9c9

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

components/esp_security/src/init.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#if SOC_KEY_MANAGER_SUPPORT_KEY_DEPLOYMENT
2222
#include "hal/key_mgr_ll.h"
23+
#include "hal/key_mgr_types.h"
2324
#endif /* SOC_KEY_MANAGER_SUPPORT_KEY_DEPLOYMENT */
2425

2526
#if SOC_ECDSA_P192_CURVE_DEFAULT_DISABLED
@@ -31,14 +32,24 @@ __attribute__((unused)) static const char *TAG = "esp_security";
3132
static void esp_key_mgr_init(void)
3233
{
3334
// The following code initializes the key manager.
35+
// When Flash Encryption is already enabled, Key Manager is initialized by the
36+
// ROM, and when Flash Encryption is enabled during boot up, Key Manager is
37+
// initialized by the bootloader.
3438
#if SOC_KEY_MANAGER_SUPPORT_KEY_DEPLOYMENT
35-
// Enable key manager clock
36-
// Using ll APIs which do not require critical section
37-
_key_mgr_ll_enable_bus_clock(true);
38-
_key_mgr_ll_enable_peripheral_clock(true);
39-
_key_mgr_ll_reset_register();
40-
while (key_mgr_ll_get_state() != ESP_KEY_MGR_STATE_IDLE) {
41-
};
39+
if (!efuse_hal_flash_encryption_enabled()) {
40+
// Enable key manager clock
41+
key_mgr_ll_power_up();
42+
// Using ll APIs which do not require critical section
43+
_key_mgr_ll_enable_bus_clock(true);
44+
_key_mgr_ll_enable_peripheral_clock(true);
45+
_key_mgr_ll_reset_register();
46+
47+
while (key_mgr_ll_get_state() != ESP_KEY_MGR_STATE_IDLE) {
48+
};
49+
50+
// Force Key Manager to use eFuse key by-default for an XTS-AES operation.
51+
key_mgr_ll_set_key_usage(ESP_KEY_MGR_XTS_AES_128_KEY, ESP_KEY_MGR_USE_EFUSE_KEY);
52+
}
4253
#endif /* SOC_KEY_MANAGER_SUPPORT_KEY_DEPLOYMENT */
4354
}
4455

components/hal/esp32p4/include/hal/key_mgr_ll.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
extern "C" {
2626
#endif
2727

28+
static inline void key_mgr_ll_power_up(void)
29+
{
30+
// TODO: IDF-13524
31+
}
32+
33+
static inline void key_mgr_ll_power_down(void)
34+
{
35+
// TODO: IDF-13524
36+
}
37+
2838
/**
2939
* @brief Enable the bus clock for Key Manager peripheral
3040
* Note: Please use key_mgr_ll_enable_bus_clock which requires the critical section

0 commit comments

Comments
 (0)