Skip to content

Commit

Permalink
Merge branch 'feature/introduce_security_component' into 'master'
Browse files Browse the repository at this point in the history
Introduce a new security component

Closes IDF-9359

See merge request espressif/esp-idf!31969
  • Loading branch information
mahavirj committed Aug 20, 2024
2 parents ff0bc81 + c338fec commit 71b56bd
Show file tree
Hide file tree
Showing 85 changed files with 2,136 additions and 2,565 deletions.
1 change: 1 addition & 0 deletions .gitlab/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
/components/esp_psram/ @esp-idf-codeowners/peripherals @esp-idf-codeowners/system
/components/esp_ringbuf/ @esp-idf-codeowners/system
/components/esp_rom/ @esp-idf-codeowners/system @esp-idf-codeowners/bluetooth @esp-idf-codeowners/wifi
/components/esp_security/ @esp-idf-codeowners/security
/components/esp_system/ @esp-idf-codeowners/system
/components/esp_timer/ @esp-idf-codeowners/system
/components/esp-tls/ @esp-idf-codeowners/app-utilities
Expand Down
22 changes: 2 additions & 20 deletions components/esp_hw_support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ endif()

set(requires soc)
# only esp_hw_support/adc_share_hw_ctrl.c requires efuse component
set(priv_requires efuse spi_flash bootloader_support)
# TODO: remove esp_security from REQUIRES in ESP-IDF v6.0 (see IDF-10733)
set(priv_requires efuse spi_flash bootloader_support esp_security)

if(${target} STREQUAL "esp32c6")
list(APPEND priv_requires hal)
Expand Down Expand Up @@ -111,26 +112,10 @@ if(NOT BOOTLOADER_BUILD)
list(APPEND srcs "port/${target}/systimer.c")
endif()

if(CONFIG_SOC_HMAC_SUPPORTED)
list(APPEND srcs "esp_hmac.c")
endif()

if(CONFIG_SOC_ETM_SUPPORTED)
list(APPEND srcs "esp_etm.c")
endif()

if(CONFIG_SOC_CRYPTO_DPA_PROTECTION_SUPPORTED)
list(APPEND srcs "esp_dpa_protection.c")
endif()

if(CONFIG_SOC_DIG_SIGN_SUPPORTED)
list(APPEND srcs "esp_ds.c")
endif()

if(CONFIG_SOC_KEY_MANAGER_SUPPORTED)
list(APPEND srcs "esp_key_mgr.c")
endif()

if(CONFIG_SOC_PAU_SUPPORTED)
list(APPEND srcs "port/pau_regdma.c"
"port/regdma_link.c")
Expand Down Expand Up @@ -203,7 +188,4 @@ if(NOT BOOTLOADER_BUILD)
if(CONFIG_SPIRAM)
idf_component_optional_requires(PRIVATE esp_psram)
endif()
if(CONFIG_SOC_CRYPTO_DPA_PROTECTION_SUPPORTED)
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u esp_crypto_dpa_prot_include_impl")
endif()
endif()
38 changes: 0 additions & 38 deletions components/esp_hw_support/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -243,44 +243,6 @@ menu "Hardware Settings"
orsource "./port/$IDF_TARGET/Kconfig.xtal"
endmenu

menu "Crypto DPA Protection"
depends on SOC_CRYPTO_DPA_PROTECTION_SUPPORTED
config ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP
bool "Enable crypto DPA protection at startup"
default y
help
This config controls the DPA (Differential Power Analysis) protection
knob for the crypto peripherals. DPA protection dynamically adjusts the
clock frequency of the crypto peripheral. DPA protection helps to make it
difficult to perform SCA attacks on the crypto peripherals. However,
there is also associated performance impact based on the security level
set. Please refer to the TRM for more details.

choice ESP_CRYPTO_DPA_PROTECTION_LEVEL
prompt "DPA protection level"
depends on ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP
default ESP_CRYPTO_DPA_PROTECTION_LEVEL_LOW
help
Configure the DPA protection security level

config ESP_CRYPTO_DPA_PROTECTION_LEVEL_LOW
bool "Security level low"

config ESP_CRYPTO_DPA_PROTECTION_LEVEL_MEDIUM
bool "Security level medium"

config ESP_CRYPTO_DPA_PROTECTION_LEVEL_HIGH
bool "Security level high"
endchoice

config ESP_CRYPTO_DPA_PROTECTION_LEVEL
int
default 1 if ESP_CRYPTO_DPA_PROTECTION_LEVEL_LOW
default 2 if ESP_CRYPTO_DPA_PROTECTION_LEVEL_MEDIUM
default 3 if ESP_CRYPTO_DPA_PROTECTION_LEVEL_HIGH

endmenu

orsource "./port/$IDF_TARGET/Kconfig.dcdc"

orsource "./port/$IDF_TARGET/Kconfig.ldo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#pragma once

#include "soc/soc_caps.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef SOC_HMAC_SUPPORTED
/**
* @brief Acquire lock for HMAC cryptography peripheral
*
Expand All @@ -23,7 +26,9 @@ void esp_crypto_hmac_lock_acquire(void);
* Internally also releases the SHA peripheral, as the HMAC depends on the SHA peripheral
*/
void esp_crypto_hmac_lock_release(void);
#endif /* SOC_HMAC_SUPPORTED */

#ifdef SOC_DIG_SIGN_SUPPORTED
/**
* @brief Acquire lock for DS cryptography peripheral
*
Expand All @@ -37,7 +42,9 @@ void esp_crypto_ds_lock_acquire(void);
* Internally also releases the HMAC (which locks SHA), AES and MPI peripheral, as the DS depends on these peripherals
*/
void esp_crypto_ds_lock_release(void);
#endif /* SOC_DIG_SIGN_SUPPORTED */

#if defined(SOC_SHA_SUPPORTED) && defined(SOC_AES_SUPPORTED)
/**
* @brief Acquire lock for the SHA and AES cryptography peripheral.
*
Expand All @@ -49,8 +56,29 @@ void esp_crypto_sha_aes_lock_acquire(void);
*
*/
void esp_crypto_sha_aes_lock_release(void);
#endif /* defined(SOC_SHA_SUPPORTED) && defined(SOC_AES_SUPPORTED) */

#if defined(SOC_SHA_CRYPTO_DMA) && defined(SOC_AES_CRYPTO_DMA)
/**
* This API should be used by all components which use the SHA, AES, HMAC and DS crypto hardware on the ESP32S2.
* They can not be used in parallel because they use the same DMA or are calling each other.
* E.g., HMAC uses SHA or DS uses HMAC and AES. See the ESP32S2 Technical Reference Manual for more details.
*
* Other unrelated components must not use it.
*/

/**
* Acquire lock for the AES and SHA cryptography peripherals, which both use the crypto DMA.
*/
void esp_crypto_dma_lock_acquire(void);

/**
* Release lock for the AES and SHA cryptography peripherals, which both use the crypto DMA.
*/
void esp_crypto_dma_lock_release(void);
#endif /* defined(SOC_SHA_CRYPTO_DMA) && defined(SOC_AES_CRYPTO_DMA) */

#ifdef SOC_MPI_SUPPORTED
/**
* @brief Acquire lock for the mpi cryptography peripheral.
*
Expand All @@ -62,8 +90,9 @@ void esp_crypto_mpi_lock_acquire(void);
*
*/
void esp_crypto_mpi_lock_release(void);
#endif /* SOC_MPI_SUPPORTED */


#ifdef SOC_ECC_SUPPORTED
/**
* @brief Acquire lock for the ECC cryptography peripheral.
*
Expand All @@ -75,8 +104,9 @@ void esp_crypto_ecc_lock_acquire(void);
*
*/
void esp_crypto_ecc_lock_release(void);
#endif /* SOC_ECC_SUPPORTED */


#ifdef SOC_ECDSA_SUPPORTED
/**
* @brief Acquire lock for ECDSA cryptography peripheral
*
Expand All @@ -90,7 +120,9 @@ void esp_crypto_ecdsa_lock_acquire(void);
* Internally also releases the ECC and MPI peripheral, as the ECDSA depends on these peripherals
*/
void esp_crypto_ecdsa_lock_release(void);
#endif /* SOC_ECDSA_SUPPORTED */

#ifdef SOC_KEY_MANAGER_SUPPORTED
/**
* @brief Acquire lock for Key Manager peripheral
*
Expand All @@ -102,6 +134,7 @@ void esp_crypto_key_manager_lock_acquire(void);
*
*/
void esp_crypto_key_manager_lock_release(void);
#endif /* SOC_KEY_MANAGER_SUPPORTED */

#ifdef __cplusplus
}
Expand Down
18 changes: 9 additions & 9 deletions components/esp_hw_support/include/esp_ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ typedef struct {
* since the message digest matches.
*/
esp_err_t esp_ds_sign(const void *message,
const esp_ds_data_t *data,
hmac_key_id_t key_id,
void *signature);
const esp_ds_data_t *data,
hmac_key_id_t key_id,
void *signature);

/**
* @brief Start the signing process.
Expand Down Expand Up @@ -172,9 +172,9 @@ esp_err_t esp_ds_sign(const void *message,
* - ESP_ERR_HW_CRYPTO_DS_INVALID_KEY if there's a problem with passing the HMAC key to the DS component
*/
esp_err_t esp_ds_start_sign(const void *message,
const esp_ds_data_t *data,
hmac_key_id_t key_id,
esp_ds_context_t **esp_ds_ctx);
const esp_ds_data_t *data,
hmac_key_id_t key_id,
esp_ds_context_t **esp_ds_ctx);

/**
* Return true if the DS peripheral is busy, otherwise false.
Expand Down Expand Up @@ -227,9 +227,9 @@ esp_err_t esp_ds_finish_sign(void *signature, esp_ds_context_t *esp_ds_ctx);
* - ESP_ERR_INVALID_ARG if one of the parameters is NULL or p_data->rsa_length is too long
*/
esp_err_t esp_ds_encrypt_params(esp_ds_data_t *data,
const void *iv,
const esp_ds_p_data_t *p_data,
const void *key);
const void *iv,
const esp_ds_p_data_t *p_data,
const void *key);

#ifdef __cplusplus
}
Expand Down
1 change: 0 additions & 1 deletion components/esp_hw_support/include/esp_ds_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#pragma once


#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 1 addition & 1 deletion components/esp_hw_support/include/esp_hmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef enum {
*
* @note Uses the HMAC peripheral in "upstream" mode.
*
* @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calcuation.
* @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calculation.
* The corresponding purpose field of the key block in the efuse must be set to the HMAC upstream purpose value.
* @param message the message for which to calculate the HMAC
* @param message_len message length
Expand Down
27 changes: 0 additions & 27 deletions components/esp_hw_support/include/soc/esp32/esp_crypto_lock.h

This file was deleted.

27 changes: 0 additions & 27 deletions components/esp_hw_support/include/soc/esp32c2/esp_crypto_lock.h

This file was deleted.

68 changes: 0 additions & 68 deletions components/esp_hw_support/include/soc/esp32c3/esp_crypto_lock.h

This file was deleted.

Loading

0 comments on commit 71b56bd

Please sign in to comment.