Skip to content

Commit 8b663eb

Browse files
committed
fix(esp_security): Configure the Key Manager to use XTS-AES efuse key by-default
1 parent 649741f commit 8b663eb

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,21 +20,32 @@
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
__attribute__((unused)) static const char *TAG = "esp_security";
2627

2728
static void esp_key_mgr_init(void)
2829
{
2930
// The following code initializes the key manager.
31+
// When Flash Encryption is already enabled, Key Manager is initialized by the
32+
// ROM, and when Flash Encryption is enabled during boot up, Key Manager is
33+
// initialized by the bootloader.
3034
#if SOC_KEY_MANAGER_SUPPORT_KEY_DEPLOYMENT
31-
// Enable key manager clock
32-
// Using ll APIs which do not require critical section
33-
_key_mgr_ll_enable_bus_clock(true);
34-
_key_mgr_ll_enable_peripheral_clock(true);
35-
_key_mgr_ll_reset_register();
36-
while (key_mgr_ll_get_state() != ESP_KEY_MGR_STATE_IDLE) {
37-
};
35+
if (!efuse_hal_flash_encryption_enabled()) {
36+
// Enable key manager clock
37+
key_mgr_ll_power_up();
38+
// Using ll APIs which do not require critical section
39+
_key_mgr_ll_enable_bus_clock(true);
40+
_key_mgr_ll_enable_peripheral_clock(true);
41+
_key_mgr_ll_reset_register();
42+
43+
while (key_mgr_ll_get_state() != ESP_KEY_MGR_STATE_IDLE) {
44+
};
45+
46+
// Force Key Manager to use eFuse key by-default for an XTS-AES operation.
47+
key_mgr_ll_set_key_usage(ESP_KEY_MGR_XTS_AES_128_KEY, ESP_KEY_MGR_USE_EFUSE_KEY);
48+
}
3849
#endif /* SOC_KEY_MANAGER_SUPPORT_KEY_DEPLOYMENT */
3950
}
4051

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)