소스 검색

soc/esp_ds.h: Unify esp_ds error codes for all targets

Aditya Patwardhan 3 년 전
부모
커밋
f9565fd31d

+ 4 - 4
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

+ 24 - 0
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

+ 1 - 8
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

+ 1 - 8
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

+ 1 - 7
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)

+ 1 - 8
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 */

+ 1 - 8
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 */

+ 4 - 4
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);

+ 4 - 4
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);

+ 4 - 4
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);

+ 4 - 4
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);