1 /* 2 * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <string.h> 8 #include "sdkconfig.h" 9 #include "soc/hp_system_reg.h" 10 #include "esp_dpa_protection.h" 11 esp_crypto_dpa_set_level(esp_crypto_dpa_sec_level_t level)12static inline void esp_crypto_dpa_set_level(esp_crypto_dpa_sec_level_t level) 13 { 14 assert(level >= ESP_CRYPTO_DPA_SEC_LEVEL_LOW && level <= ESP_CRYPTO_DPA_SEC_LEVEL_HIGH); 15 REG_SET_BIT(HP_SYSTEM_SEC_DPA_CONF_REG, HP_SYSTEM_SEC_DPA_CFG_SEL); 16 REG_SET_FIELD(HP_SYSTEM_SEC_DPA_CONF_REG, HP_SYSTEM_SEC_DPA_LEVEL, level); 17 } 18 19 #if CONFIG_ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP esp_crypto_dpa_protection_startup(void)20static void __attribute__((constructor)) esp_crypto_dpa_protection_startup(void) 21 { 22 esp_crypto_dpa_set_level(CONFIG_ESP_CRYPTO_DPA_PROTECTION_LEVEL); 23 } 24 #endif 25 esp_crypto_dpa_protection_enable(esp_crypto_dpa_sec_level_t level)26void esp_crypto_dpa_protection_enable(esp_crypto_dpa_sec_level_t level) 27 { 28 esp_crypto_dpa_set_level(level); 29 } 30 esp_crypto_dpa_protection_disable(void)31void esp_crypto_dpa_protection_disable(void) 32 { 33 REG_CLR_BIT(HP_SYSTEM_SEC_DPA_CONF_REG, HP_SYSTEM_SEC_DPA_CFG_SEL); 34 } 35 esp_crypto_dpa_prot_include_impl(void)36void esp_crypto_dpa_prot_include_impl(void) 37 { 38 // Linker hook, exists for no other purpose 39 } 40