From f9565fd31d3a28b2cf36348d4c2846cad349ae2f Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 12 Oct 2022 18:25:39 +0530 Subject: [PATCH] soc/esp_ds.h: Unify esp_ds error codes for all targets --- components/esp_common/src/esp_err_to_name.c | 8 +++---- .../esp_hw_support/include/esp_ds_err.h | 24 +++++++++++++++++++ .../include/soc/esp32c3/esp_ds.h | 9 +------ .../include/soc/esp32c6/esp_ds.h | 9 +------ .../include/soc/esp32h2/esp_ds.h | 8 +------ .../include/soc/esp32s2/esp_ds.h | 9 +------ .../include/soc/esp32s3/esp_ds.h | 9 +------ .../esp_hw_support/port/esp32c3/esp_ds.c | 8 +++---- .../esp_hw_support/port/esp32c6/esp_ds.c | 8 +++---- .../esp_hw_support/port/esp32h2/esp_ds.c | 8 +++---- .../esp_hw_support/port/esp32s3/esp_ds.c | 8 +++---- 11 files changed, 49 insertions(+), 59 deletions(-) create mode 100644 components/esp_hw_support/include/esp_ds_err.h diff --git a/components/esp_common/src/esp_err_to_name.c b/components/esp_common/src/esp_err_to_name.c index b8352c4d0e..d49aae5d31 100644 --- a/components/esp_common/src/esp_err_to_name.c +++ b/components/esp_common/src/esp_err_to_name.c @@ -18,6 +18,9 @@ #if __has_include("esp_dpp.h") #include "esp_dpp.h" #endif +#if __has_include("esp_ds_err.h") +#include "esp_ds_err.h" +#endif #if __has_include("esp_efuse.h") #include "esp_efuse.h" #endif @@ -69,9 +72,6 @@ #if __has_include("nvs.h") #include "nvs.h" #endif -#if __has_include("soc/esp32s2/esp_ds.h") -#include "soc/esp32s2/esp_ds.h" -#endif #if __has_include("spi_flash_mmap.h") #include "spi_flash_mmap.h" #endif @@ -767,7 +767,7 @@ static const esp_err_msg_t esp_err_msg_table[] = { ERR_TBL_IT(ESP_ERR_HW_CRYPTO_BASE), /* 49152 0xc000 Starting number of HW cryptography module error codes */ # endif - // components/esp_hw_support/include/soc/esp32s2/esp_ds.h + // components/esp_hw_support/include/esp_ds_err.h # ifdef ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL ERR_TBL_IT(ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL), /* 49153 0xc001 HMAC peripheral problem */ # endif diff --git a/components/esp_hw_support/include/esp_ds_err.h b/components/esp_hw_support/include/esp_ds_err.h new file mode 100644 index 0000000000..7ac11a9f2c --- /dev/null +++ b/components/esp_hw_support/include/esp_ds_err.h @@ -0,0 +1,24 @@ +/* + * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + + +#ifdef __cplusplus +extern "C" { +#endif + +#define ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL (ESP_ERR_HW_CRYPTO_BASE + 0x1) /*!< HMAC peripheral problem */ +#define ESP_ERR_HW_CRYPTO_DS_INVALID_KEY (ESP_ERR_HW_CRYPTO_BASE + 0x2) /*!< given HMAC key isn't correct, + HMAC peripheral problem */ +#define ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST (ESP_ERR_HW_CRYPTO_BASE + 0x4) /*!< message digest check failed, + result is invalid */ +#define ESP_ERR_HW_CRYPTO_DS_INVALID_PADDING (ESP_ERR_HW_CRYPTO_BASE + 0x5) /*!< padding check failed, but result + is produced anyway and can be read*/ + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_hw_support/include/soc/esp32c3/esp_ds.h b/components/esp_hw_support/include/soc/esp32c3/esp_ds.h index 3f5aaf6f0b..4859aea1f7 100644 --- a/components/esp_hw_support/include/soc/esp32c3/esp_ds.h +++ b/components/esp_hw_support/include/soc/esp32c3/esp_ds.h @@ -8,19 +8,12 @@ #include "esp_hmac.h" #include "esp_err.h" +#include "esp_ds_err.h" #ifdef __cplusplus extern "C" { #endif -#define ESP32C3_ERR_HW_CRYPTO_DS_HMAC_FAIL ESP_ERR_HW_CRYPTO_BASE + 0x1 /*!< HMAC peripheral problem */ -#define ESP32C3_ERR_HW_CRYPTO_DS_INVALID_KEY ESP_ERR_HW_CRYPTO_BASE + 0x2 /*!< given HMAC key isn't correct, - HMAC peripheral problem */ -#define ESP32C3_ERR_HW_CRYPTO_DS_INVALID_DIGEST ESP_ERR_HW_CRYPTO_BASE + 0x4 /*!< message digest check failed, - result is invalid */ -#define ESP32C3_ERR_HW_CRYPTO_DS_INVALID_PADDING ESP_ERR_HW_CRYPTO_BASE + 0x5 /*!< padding check failed, but result - is produced anyway and can be read*/ - #define ESP_DS_IV_BIT_LEN 128 #define ESP_DS_IV_LEN (ESP_DS_IV_BIT_LEN / 8) #define ESP_DS_SIGNATURE_MAX_BIT_LEN 3072 diff --git a/components/esp_hw_support/include/soc/esp32c6/esp_ds.h b/components/esp_hw_support/include/soc/esp32c6/esp_ds.h index 6393edda6b..70203f0700 100644 --- a/components/esp_hw_support/include/soc/esp32c6/esp_ds.h +++ b/components/esp_hw_support/include/soc/esp32c6/esp_ds.h @@ -8,19 +8,12 @@ #include "esp_hmac.h" #include "esp_err.h" +#include "esp_ds_err.h" #ifdef __cplusplus extern "C" { #endif -#define ESP32C6_ERR_HW_CRYPTO_DS_HMAC_FAIL ESP_ERR_HW_CRYPTO_BASE + 0x1 /*!< HMAC peripheral problem */ -#define ESP32C6_ERR_HW_CRYPTO_DS_INVALID_KEY ESP_ERR_HW_CRYPTO_BASE + 0x2 /*!< given HMAC key isn't correct, - HMAC peripheral problem */ -#define ESP32C6_ERR_HW_CRYPTO_DS_INVALID_DIGEST ESP_ERR_HW_CRYPTO_BASE + 0x4 /*!< message digest check failed, - result is invalid */ -#define ESP32C6_ERR_HW_CRYPTO_DS_INVALID_PADDING ESP_ERR_HW_CRYPTO_BASE + 0x5 /*!< padding check failed, but result - is produced anyway and can be read*/ - #define ESP_DS_IV_BIT_LEN 128 #define ESP_DS_IV_LEN (ESP_DS_IV_BIT_LEN / 8) #define ESP_DS_SIGNATURE_MAX_BIT_LEN 3072 diff --git a/components/esp_hw_support/include/soc/esp32h2/esp_ds.h b/components/esp_hw_support/include/soc/esp32h2/esp_ds.h index bf5a818027..9ebaf35922 100644 --- a/components/esp_hw_support/include/soc/esp32h2/esp_ds.h +++ b/components/esp_hw_support/include/soc/esp32h2/esp_ds.h @@ -8,18 +8,12 @@ #include "esp_hmac.h" #include "esp_err.h" +#include "esp_ds_err.h" #ifdef __cplusplus extern "C" { #endif -#define ESP32H2_ERR_HW_CRYPTO_DS_HMAC_FAIL ESP_ERR_HW_CRYPTO_BASE + 0x1 /*!< HMAC peripheral problem */ -#define ESP32H2_ERR_HW_CRYPTO_DS_INVALID_KEY ESP_ERR_HW_CRYPTO_BASE + 0x2 /*!< given HMAC key isn't correct, - HMAC peripheral problem */ -#define ESP32H2_ERR_HW_CRYPTO_DS_INVALID_DIGEST ESP_ERR_HW_CRYPTO_BASE + 0x4 /*!< message digest check failed, - result is invalid */ -#define ESP32H2_ERR_HW_CRYPTO_DS_INVALID_PADDING ESP_ERR_HW_CRYPTO_BASE + 0x5 /*!< padding check failed, but result - is produced anyway and can be read*/ #define ESP_DS_IV_BIT_LEN 128 #define ESP_DS_IV_LEN (ESP_DS_IV_BIT_LEN / 8) diff --git a/components/esp_hw_support/include/soc/esp32s2/esp_ds.h b/components/esp_hw_support/include/soc/esp32s2/esp_ds.h index 67a4a2f6ca..c4a91541f2 100644 --- a/components/esp_hw_support/include/soc/esp32s2/esp_ds.h +++ b/components/esp_hw_support/include/soc/esp32s2/esp_ds.h @@ -8,19 +8,12 @@ #include "esp_hmac.h" #include "esp_err.h" +#include "esp_ds_err.h" #ifdef __cplusplus extern "C" { #endif -#define ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL ESP_ERR_HW_CRYPTO_BASE + 0x1 /*!< HMAC peripheral problem */ -#define ESP_ERR_HW_CRYPTO_DS_INVALID_KEY ESP_ERR_HW_CRYPTO_BASE + 0x2 /*!< given HMAC key isn't correct, - HMAC peripheral problem */ -#define ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST ESP_ERR_HW_CRYPTO_BASE + 0x4 /*!< message digest check failed, - result is invalid */ -#define ESP_ERR_HW_CRYPTO_DS_INVALID_PADDING ESP_ERR_HW_CRYPTO_BASE + 0x5 /*!< padding check failed, but result - is produced anyway and can be read*/ - #define ESP_DS_IV_LEN 16 /* Length of parameter 'C' stored in flash */ diff --git a/components/esp_hw_support/include/soc/esp32s3/esp_ds.h b/components/esp_hw_support/include/soc/esp32s3/esp_ds.h index 5f4d982111..d2dc259c43 100644 --- a/components/esp_hw_support/include/soc/esp32s3/esp_ds.h +++ b/components/esp_hw_support/include/soc/esp32s3/esp_ds.h @@ -10,19 +10,12 @@ #include "esp_hmac.h" #include "esp_err.h" #include "soc/soc_caps.h" +#include "esp_ds_err.h" #ifdef __cplusplus extern "C" { #endif -#define ESP32S3_ERR_HW_CRYPTO_DS_HMAC_FAIL ESP_ERR_HW_CRYPTO_BASE + 0x1 /*!< HMAC peripheral problem */ -#define ESP32S3_ERR_HW_CRYPTO_DS_INVALID_KEY ESP_ERR_HW_CRYPTO_BASE + 0x2 /*!< given HMAC key isn't correct, - HMAC peripheral problem */ -#define ESP32S3_ERR_HW_CRYPTO_DS_INVALID_DIGEST ESP_ERR_HW_CRYPTO_BASE + 0x4 /*!< message digest check failed, - result is invalid */ -#define ESP32S3_ERR_HW_CRYPTO_DS_INVALID_PADDING ESP_ERR_HW_CRYPTO_BASE + 0x5 /*!< padding check failed, but result - is produced anyway and can be read*/ - #define ESP_DS_IV_LEN 16 /* Length of parameter 'C' stored in flash */ diff --git a/components/esp_hw_support/port/esp32c3/esp_ds.c b/components/esp_hw_support/port/esp32c3/esp_ds.c index f1d09cdf80..de1695ef2c 100644 --- a/components/esp_hw_support/port/esp32c3/esp_ds.c +++ b/components/esp_hw_support/port/esp32c3/esp_ds.c @@ -115,7 +115,7 @@ esp_err_t esp_ds_start_sign(const void *message, uint32_t conf_error = hmac_hal_configure(HMAC_OUTPUT_DS, key_id); if (conf_error) { ds_disable_release(); - return ESP32C3_ERR_HW_CRYPTO_DS_HMAC_FAIL; + return ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL; } ds_hal_start(); @@ -125,7 +125,7 @@ esp_err_t esp_ds_start_sign(const void *message, while (ds_ll_busy() != 0) { if ((esp_timer_get_time() - start_time) > SOC_DS_KEY_CHECK_MAX_WAIT_US) { ds_disable_release(); - return ESP32C3_ERR_HW_CRYPTO_DS_INVALID_KEY; + return ESP_ERR_HW_CRYPTO_DS_INVALID_KEY; } } @@ -170,11 +170,11 @@ esp_err_t esp_ds_finish_sign(void *signature, esp_ds_context_t *esp_ds_ctx) esp_err_t return_value = ESP_OK; if (sig_check_result == DS_SIGNATURE_MD_FAIL || sig_check_result == DS_SIGNATURE_PADDING_AND_MD_FAIL) { - return_value = ESP32C3_ERR_HW_CRYPTO_DS_INVALID_DIGEST; + return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST; } if (sig_check_result == DS_SIGNATURE_PADDING_FAIL) { - return_value = ESP32C3_ERR_HW_CRYPTO_DS_INVALID_PADDING; + return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_PADDING; } free(esp_ds_ctx); diff --git a/components/esp_hw_support/port/esp32c6/esp_ds.c b/components/esp_hw_support/port/esp32c6/esp_ds.c index 7d9228c0a6..95d8b3ebe4 100644 --- a/components/esp_hw_support/port/esp32c6/esp_ds.c +++ b/components/esp_hw_support/port/esp32c6/esp_ds.c @@ -115,7 +115,7 @@ esp_err_t esp_ds_start_sign(const void *message, uint32_t conf_error = hmac_hal_configure(HMAC_OUTPUT_DS, key_id); if (conf_error) { ds_disable_release(); - return ESP32C6_ERR_HW_CRYPTO_DS_HMAC_FAIL; + return ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL; } ds_hal_start(); @@ -125,7 +125,7 @@ esp_err_t esp_ds_start_sign(const void *message, while (ds_ll_busy() != 0) { if ((esp_timer_get_time() - start_time) > SOC_DS_KEY_CHECK_MAX_WAIT_US) { ds_disable_release(); - return ESP32C6_ERR_HW_CRYPTO_DS_INVALID_KEY; + return ESP_ERR_HW_CRYPTO_DS_INVALID_KEY; } } @@ -170,11 +170,11 @@ esp_err_t esp_ds_finish_sign(void *signature, esp_ds_context_t *esp_ds_ctx) esp_err_t return_value = ESP_OK; if (sig_check_result == DS_SIGNATURE_MD_FAIL || sig_check_result == DS_SIGNATURE_PADDING_AND_MD_FAIL) { - return_value = ESP32C6_ERR_HW_CRYPTO_DS_INVALID_DIGEST; + return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST; } if (sig_check_result == DS_SIGNATURE_PADDING_FAIL) { - return_value = ESP32C6_ERR_HW_CRYPTO_DS_INVALID_PADDING; + return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_PADDING; } free(esp_ds_ctx); diff --git a/components/esp_hw_support/port/esp32h2/esp_ds.c b/components/esp_hw_support/port/esp32h2/esp_ds.c index 247a59e5a1..5b5af6963b 100644 --- a/components/esp_hw_support/port/esp32h2/esp_ds.c +++ b/components/esp_hw_support/port/esp32h2/esp_ds.c @@ -115,7 +115,7 @@ esp_err_t esp_ds_start_sign(const void *message, uint32_t conf_error = hmac_hal_configure(HMAC_OUTPUT_DS, key_id); if (conf_error) { ds_disable_release(); - return ESP32H2_ERR_HW_CRYPTO_DS_HMAC_FAIL; + return ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL; } ds_hal_start(); @@ -125,7 +125,7 @@ esp_err_t esp_ds_start_sign(const void *message, while (ds_ll_busy() != 0) { if ((esp_timer_get_time() - start_time) > SOC_DS_KEY_CHECK_MAX_WAIT_US) { ds_disable_release(); - return ESP32H2_ERR_HW_CRYPTO_DS_INVALID_KEY; + return ESP_ERR_HW_CRYPTO_DS_INVALID_KEY; } } @@ -170,11 +170,11 @@ esp_err_t esp_ds_finish_sign(void *signature, esp_ds_context_t *esp_ds_ctx) esp_err_t return_value = ESP_OK; if (sig_check_result == DS_SIGNATURE_MD_FAIL || sig_check_result == DS_SIGNATURE_PADDING_AND_MD_FAIL) { - return_value = ESP32H2_ERR_HW_CRYPTO_DS_INVALID_DIGEST; + return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST; } if (sig_check_result == DS_SIGNATURE_PADDING_FAIL) { - return_value = ESP32H2_ERR_HW_CRYPTO_DS_INVALID_PADDING; + return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_PADDING; } free(esp_ds_ctx); diff --git a/components/esp_hw_support/port/esp32s3/esp_ds.c b/components/esp_hw_support/port/esp32s3/esp_ds.c index aa5969313c..af4abd7bee 100644 --- a/components/esp_hw_support/port/esp32s3/esp_ds.c +++ b/components/esp_hw_support/port/esp32s3/esp_ds.c @@ -119,7 +119,7 @@ esp_err_t esp_ds_start_sign(const void *message, uint32_t conf_error = hmac_hal_configure(HMAC_OUTPUT_DS, key_id); if (conf_error) { ds_disable_release(); - return ESP32S3_ERR_HW_CRYPTO_DS_HMAC_FAIL; + return ESP_ERR_HW_CRYPTO_DS_HMAC_FAIL; } ds_hal_start(); @@ -129,7 +129,7 @@ esp_err_t esp_ds_start_sign(const void *message, while (ds_ll_busy() != 0) { if ((esp_timer_get_time() - start_time) > SOC_DS_KEY_CHECK_MAX_WAIT_US) { ds_disable_release(); - return ESP32S3_ERR_HW_CRYPTO_DS_INVALID_KEY; + return ESP_ERR_HW_CRYPTO_DS_INVALID_KEY; } } @@ -174,11 +174,11 @@ esp_err_t esp_ds_finish_sign(void *signature, esp_ds_context_t *esp_ds_ctx) esp_err_t return_value = ESP_OK; if (sig_check_result == DS_SIGNATURE_MD_FAIL || sig_check_result == DS_SIGNATURE_PADDING_AND_MD_FAIL) { - return_value = ESP32S3_ERR_HW_CRYPTO_DS_INVALID_DIGEST; + return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST; } if (sig_check_result == DS_SIGNATURE_PADDING_FAIL) { - return_value = ESP32S3_ERR_HW_CRYPTO_DS_INVALID_PADDING; + return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_PADDING; } free(esp_ds_ctx);