|
6 | 6 |
|
7 | 7 | #include "esp_private/startup_internal.h" |
8 | 8 | #include "sdkconfig.h" |
| 9 | +#include "soc/soc_caps.h" |
9 | 10 | #include "esp_crypto_clk.h" |
10 | 11 | #include "esp_efuse.h" |
11 | 12 | #include "esp_efuse_table.h" |
12 | 13 | #include "esp_security_priv.h" |
13 | 14 | #include "esp_err.h" |
| 15 | +#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY |
| 16 | +#include "hal/key_mgr_ll.h" |
| 17 | +#endif |
14 | 18 |
|
15 | 19 | __attribute__((unused)) static const char *TAG = "esp_security"; |
16 | 20 |
|
| 21 | +static void esp_key_mgr_init(void) |
| 22 | +{ |
| 23 | + // The following operation makes the Key Manager to use eFuse key for ECDSA and XTS-AES operation by default |
| 24 | + // This is to keep the default behavior same as the other chips |
| 25 | + // If the Key Manager configuration is already locked then following operation does not have any effect |
| 26 | +#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY |
| 27 | + // Enable key manager clock |
| 28 | + // Using ll APIs which do not require critical section |
| 29 | + _key_mgr_ll_enable_bus_clock(true); |
| 30 | + _key_mgr_ll_enable_peripheral_clock(true); |
| 31 | + |
| 32 | + while (key_mgr_ll_get_state() != ESP_KEY_MGR_STATE_IDLE) { |
| 33 | + }; |
| 34 | +#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY |
| 35 | + key_mgr_ll_set_key_usage(ESP_KEY_MGR_ECDSA_KEY, ESP_KEY_MGR_USE_EFUSE_KEY); |
| 36 | +#endif |
| 37 | +#if SOC_KEY_MANAGER_FE_KEY_DEPLOY |
| 38 | + key_mgr_ll_set_key_usage(ESP_KEY_MGR_XTS_AES_128_KEY, ESP_KEY_MGR_USE_EFUSE_KEY); |
| 39 | +#endif |
| 40 | +#endif /* SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY */ |
| 41 | +} |
| 42 | + |
17 | 43 | ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103) |
18 | 44 | { |
19 | 45 | esp_crypto_clk_init(); |
| 46 | + esp_key_mgr_init(); |
20 | 47 | #if CONFIG_ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP |
21 | 48 | esp_crypto_dpa_protection_startup(); |
22 | 49 | #endif |
|
0 commit comments