2024-08-07 15:17:32 +05:30
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "esp_private/startup_internal.h"
|
|
|
|
|
#include "sdkconfig.h"
|
2024-09-18 17:03:59 +05:30
|
|
|
#include "soc/soc_caps.h"
|
2024-08-07 15:17:32 +05:30
|
|
|
#include "esp_crypto_clk.h"
|
2024-07-04 09:31:07 +05:30
|
|
|
#include "esp_efuse.h"
|
|
|
|
|
#include "esp_efuse_table.h"
|
2024-08-07 15:17:32 +05:30
|
|
|
#include "esp_security_priv.h"
|
2024-07-04 09:31:07 +05:30
|
|
|
#include "esp_err.h"
|
2024-09-18 17:03:59 +05:30
|
|
|
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY
|
|
|
|
|
#include "hal/key_mgr_ll.h"
|
|
|
|
|
#endif
|
2024-07-04 09:31:07 +05:30
|
|
|
|
|
|
|
|
__attribute__((unused)) static const char *TAG = "esp_security";
|
2024-08-07 15:17:32 +05:30
|
|
|
|
2024-09-18 17:03:59 +05:30
|
|
|
static void esp_key_mgr_init(void)
|
|
|
|
|
{
|
2024-10-01 22:10:57 +05:30
|
|
|
// The following code initializes the key manager.
|
2024-09-18 17:03:59 +05:30
|
|
|
#if SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY
|
|
|
|
|
// Enable key manager clock
|
|
|
|
|
// Using ll APIs which do not require critical section
|
|
|
|
|
_key_mgr_ll_enable_bus_clock(true);
|
|
|
|
|
_key_mgr_ll_enable_peripheral_clock(true);
|
2024-10-01 22:10:57 +05:30
|
|
|
_key_mgr_ll_reset_register();
|
2024-09-18 17:03:59 +05:30
|
|
|
while (key_mgr_ll_get_state() != ESP_KEY_MGR_STATE_IDLE) {
|
|
|
|
|
};
|
|
|
|
|
#endif /* SOC_KEY_MANAGER_ECDSA_KEY_DEPLOY || SOC_KEY_MANAGER_FE_KEY_DEPLOY */
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 15:17:32 +05:30
|
|
|
ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
|
|
|
|
|
{
|
|
|
|
|
esp_crypto_clk_init();
|
2024-09-18 17:03:59 +05:30
|
|
|
esp_key_mgr_init();
|
2024-08-07 15:17:32 +05:30
|
|
|
#if CONFIG_ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP
|
|
|
|
|
esp_crypto_dpa_protection_startup();
|
|
|
|
|
#endif
|
2024-07-04 09:31:07 +05:30
|
|
|
|
2024-10-22 15:17:16 +05:30
|
|
|
#if CONFIG_ESP_CRYPTO_FORCE_ECC_CONSTANT_TIME_POINT_MUL
|
2024-07-04 09:31:07 +05:30
|
|
|
if (!esp_efuse_read_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME)) {
|
|
|
|
|
ESP_EARLY_LOGD(TAG, "Forcefully enabling ECC constant time operations");
|
|
|
|
|
esp_err_t err = esp_efuse_write_field_bit(ESP_EFUSE_ECC_FORCE_CONST_TIME);
|
|
|
|
|
if (err != ESP_OK) {
|
|
|
|
|
ESP_EARLY_LOGE(TAG, "Enabling ECC constant time operations forcefully failed.");
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-08-07 15:17:32 +05:30
|
|
|
return ESP_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void esp_security_init_include_impl(void)
|
|
|
|
|
{
|
|
|
|
|
// Linker hook, exists for no other purpose
|
|
|
|
|
}
|