-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: add support for DPA protection configuration in C6/H2
- Technical details covered in section "15.3.2 Anti-DPA Attack Security Control" chapter of the ESP32-C6 TRM - Default configuration sets the security level low for the DPA protection - This change applies to all the crypto peripherals where the clock frequency is dynamically adjusted to create randomness in the power consumption trajectory - This configuration helps to make the SCA attacks difficult on the crypto peripherals
- Loading branch information
Showing
9 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <string.h> | ||
#include "sdkconfig.h" | ||
#include "soc/hp_system_reg.h" | ||
#include "esp_dpa_protection.h" | ||
|
||
static inline void esp_crypto_dpa_set_level(esp_crypto_dpa_sec_level_t level) | ||
{ | ||
assert(level >= ESP_CRYPTO_DPA_SEC_LEVEL_LOW && level <= ESP_CRYPTO_DPA_SEC_LEVEL_HIGH); | ||
REG_SET_BIT(HP_SYSTEM_SEC_DPA_CONF_REG, HP_SYSTEM_SEC_DPA_CFG_SEL); | ||
REG_SET_FIELD(HP_SYSTEM_SEC_DPA_CONF_REG, HP_SYSTEM_SEC_DPA_LEVEL, level); | ||
} | ||
|
||
#if CONFIG_ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP | ||
static void __attribute__((constructor)) esp_crypto_dpa_protection_startup(void) | ||
{ | ||
esp_crypto_dpa_set_level(CONFIG_ESP_CRYPTO_DPA_PROTECTION_LEVEL); | ||
} | ||
#endif | ||
|
||
void esp_crypto_dpa_protection_enable(esp_crypto_dpa_sec_level_t level) | ||
{ | ||
esp_crypto_dpa_set_level(level); | ||
} | ||
|
||
void esp_crypto_dpa_protection_disable(void) | ||
{ | ||
REG_CLR_BIT(HP_SYSTEM_SEC_DPA_CONF_REG, HP_SYSTEM_SEC_DPA_CFG_SEL); | ||
} | ||
|
||
void esp_crypto_dpa_prot_include_impl(void) | ||
{ | ||
// Linker hook, exists for no other purpose | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef enum { | ||
ESP_CRYPTO_DPA_SEC_LEVEL_OFF = 0, /*!< DPA protection disabled */ | ||
ESP_CRYPTO_DPA_SEC_LEVEL_LOW, /*!< DPA protection level low */ | ||
ESP_CRYPTO_DPA_SEC_LEVEL_MIDDLE, /*!< DPA protection level medium */ | ||
ESP_CRYPTO_DPA_SEC_LEVEL_HIGH, /*!< DPA protection level high */ | ||
} esp_crypto_dpa_sec_level_t; | ||
|
||
/** | ||
* @brief Enable DPA (Differential Power Analysis) related protection | ||
* | ||
* @note | ||
* Enabling the DPA protection can help to make it difficult to perform SCA | ||
* attacks on the crypto peripherals. However, based on the security level | ||
* set there will be a performance impact, higher the level higher the impact. | ||
* Please refer to the TRM for more details. | ||
* | ||
* @param level DPA Security Level of type `esp_crypto_dpa_sec_level_t` | ||
*/ | ||
void esp_crypto_dpa_protection_enable(esp_crypto_dpa_sec_level_t level); | ||
|
||
/** | ||
* @brief Disable DPA (Differential Power Analysis) related protection | ||
*/ | ||
void esp_crypto_dpa_protection_disable(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters