From b450664e2b47930a3b0061990e81d1904a95442b Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Thu, 29 Jan 2026 15:02:05 +0530 Subject: [PATCH] fix(mbedtls/include): Fix include libs in the driver's public headers --- .../include/psa_crypto_driver_esp_aes.h | 6 ++--- .../psa_crypto_driver_esp_aes_contexts.h | 7 +++-- .../include/psa_crypto_driver_esp_aes_gcm.h | 8 +++--- .../include/psa_crypto_driver_esp_cmac.h | 6 ++--- .../psa_crypto_driver_esp_cmac_contexts.h | 7 +++-- .../include/psa_crypto_driver_esp_ecdsa.h | 10 +++---- .../psa_crypto_driver_esp_ecdsa_contexts.h | 8 +++--- .../psa_crypto_driver_esp_hmac_opaque.h | 6 ++--- ...a_crypto_driver_esp_hmac_opaque_contexts.h | 6 ++--- .../psa_crypto_driver_esp_hmac_transparent.h | 6 ++--- ...pto_driver_esp_hmac_transparent_contexts.h | 2 +- .../include/psa_crypto_driver_esp_md5.h | 9 ++++--- .../include/psa_crypto_driver_esp_sha.h | 9 +++---- .../psa_crypto_driver_esp_sha_contexts.h | 27 ++++++++++--------- .../mbedtls/test_apps/main/test_psa_ecdsa.c | 12 +++++++++ 15 files changed, 71 insertions(+), 58 deletions(-) diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes.h index c7244837b2b..dcae4979c49 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes.h @@ -5,6 +5,9 @@ */ #pragma once +#include "psa/crypto.h" +#include "psa_crypto_driver_esp_aes_contexts.h" + #ifdef __cplusplus extern "C" { #endif @@ -14,9 +17,6 @@ extern "C" { #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #endif -#include "psa/crypto.h" -#include "psa_crypto_driver_esp_aes_contexts.h" - psa_status_t esp_aes_cipher_encrypt( const psa_key_attributes_t *attributes, const uint8_t *key_buffer, diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes_contexts.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes_contexts.h index 48475730ac8..e9dfd66436e 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes_contexts.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes_contexts.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,9 +23,8 @@ extern "C" { * crypto_driver_contexts_primitives.h. */ -#include -#include - +#include "esp_types.h" +#include "psa/crypto_driver_common.h" #if defined(ESP_AES_DRIVER_ENABLED) #define ESP_MBEDTLS_AES_MAX_BLOCK_LENGTH 16 diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes_gcm.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes_gcm.h index f8c18b068ec..0184bb394e1 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes_gcm.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_aes_gcm.h @@ -1,20 +1,18 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #pragma once -// #include_next "mbedtls/gcm.h" -#include "sdkconfig.h" +#include "psa/crypto.h" +#include "psa_crypto_driver_esp_aes_contexts.h" #ifdef __cplusplus extern "C" { #endif #if defined(ESP_AES_DRIVER_ENABLED) -#include "psa/crypto.h" -#include "psa_crypto_driver_esp_aes_contexts.h" psa_status_t esp_crypto_aes_gcm_encrypt_setup( esp_aes_gcm_operation_t *esp_aes_gcm_driver_ctx, diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_cmac.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_cmac.h index 4eb87dc2405..7848db62cf3 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_cmac.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_cmac.h @@ -5,15 +5,15 @@ */ #pragma once +#include "psa/crypto.h" +#include "psa_crypto_driver_esp_cmac_contexts.h" + #ifdef __cplusplus extern "C" { #endif #if defined(ESP_CMAC_DRIVER_ENABLED) -#include "psa/crypto.h" -#include "psa_crypto_driver_esp_cmac_contexts.h" - psa_status_t esp_cmac_compute(const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_cmac_contexts.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_cmac_contexts.h index 7fa24ec59de..68aa25cb4b6 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_cmac_contexts.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_cmac_contexts.h @@ -6,14 +6,17 @@ #pragma once + +#include "esp_types.h" +#include "psa/crypto_driver_common.h" +#include "psa_crypto_driver_esp_aes_contexts.h" + #ifdef __cplusplus extern "C" { #endif #if defined(ESP_CMAC_DRIVER_ENABLED) -#include "psa_crypto_driver_esp_aes_contexts.h" - #define PSA_AES_BLOCK_SIZE PSA_BLOCK_CIPHER_BLOCK_LENGTH(PSA_KEY_TYPE_AES) #define PSA_CMAC_MAX_BLOCK_SIZE PSA_AES_BLOCK_SIZE diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_ecdsa.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_ecdsa.h index 63e747e0c42..e9f0255efab 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_ecdsa.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_ecdsa.h @@ -6,17 +6,17 @@ #pragma once -#if defined(ESP_ECDSA_DRIVER_ENABLED) -#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT -#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT -#endif - #include "psa/crypto.h" #include "psa/crypto_types.h" #include "soc/soc_caps.h" #include "psa_crypto_driver_esp_ecdsa_contexts.h" +#if defined(ESP_ECDSA_DRIVER_ENABLED) +#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT +#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_ecdsa_contexts.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_ecdsa_contexts.h index a1c97438500..2a4d28b5ddb 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_ecdsa_contexts.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_ecdsa_contexts.h @@ -6,16 +6,15 @@ #pragma once -#include "stdint.h" -#include "stdbool.h" +#include "esp_types.h" #include "soc/soc_caps.h" -#include "psa/crypto.h" +#include "psa/crypto_driver_common.h" #include "sdkconfig.h" #ifdef __cplusplus extern "C" { #endif - +#if defined(ESP_ECDSA_DRIVER_ENABLED) #if SOC_ECDSA_SUPPORT_CURVE_P384 #define MAX_ECDSA_COMPONENT_LEN 48 #define MAX_ECDSA_SHA_LEN 48 @@ -75,6 +74,7 @@ typedef struct { size_t key_len; } esp_ecdsa_opaque_sign_hash_operation_t; #endif /* !(__DOXYGEN__) */ +#endif /* ESP_ECDSA_DRIVER_ENABLED */ #ifdef __cplusplus } #endif diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_opaque.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_opaque.h index 4aaadc14917..d0923d6332b 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_opaque.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_opaque.h @@ -5,6 +5,9 @@ */ #pragma once +#include "psa/crypto.h" +#include "psa_crypto_driver_esp_hmac_opaque_contexts.h" + #if defined(ESP_HMAC_OPAQUE_DRIVER_ENABLED) #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT @@ -14,9 +17,6 @@ extern "C" { #endif -#include "psa/crypto.h" -#include "psa_crypto_driver_esp_hmac_opaque_contexts.h" - /** * @brief ESP HMAC opaque PSA driver location * diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_opaque_contexts.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_opaque_contexts.h index d8cca16acf1..19ce8d705a9 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_opaque_contexts.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_opaque_contexts.h @@ -6,15 +6,14 @@ #pragma once -#include -#include +#include "esp_types.h" #include "soc/soc_caps.h" #include "psa/crypto_driver_common.h" #ifdef __cplusplus extern "C" { #endif - +#if defined(ESP_HMAC_OPAQUE_DRIVER_ENABLED) /** * @brief Size of HMAC result in bytes (the opaque driver only supports SHA-256 based HMAC) */ @@ -36,6 +35,7 @@ typedef struct { uint8_t hmac[ESP_HMAC_RESULT_SIZE]; /**< Buffer to store the HMAC result */ } esp_hmac_opaque_operation_t; +#endif /* ESP_HMAC_OPAQUE_DRIVER_ENABLED */ #ifdef __cplusplus } #endif diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_transparent.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_transparent.h index ad8b39fcd1a..b81a37d93e3 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_transparent.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_transparent.h @@ -5,14 +5,14 @@ */ #pragma once +#include "psa/crypto.h" +#include "psa_crypto_driver_esp_hmac_transparent_contexts.h" + #if defined(ESP_HMAC_TRANSPARENT_DRIVER_ENABLED) #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #endif -#include "psa/crypto.h" -#include "psa_crypto_driver_esp_hmac_transparent_contexts.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_transparent_contexts.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_transparent_contexts.h index 8d244216198..0ad70ca7b1f 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_transparent_contexts.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_hmac_transparent_contexts.h @@ -6,7 +6,7 @@ #pragma once -#include +#include "esp_types.h" #include "soc/soc_caps.h" #include "psa/crypto_driver_common.h" #include "psa_crypto_driver_esp_sha_contexts.h" diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_md5.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_md5.h index 943f4edd1dd..9705ae3319d 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_md5.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_md5.h @@ -5,14 +5,15 @@ */ #pragma once + +#include "esp_types.h" +#include "psa/crypto.h" +#include "esp_rom_md5.h" + #ifdef __cplusplus extern "C" { #endif -#include -#include "psa/crypto.h" -#include "esp_rom_md5.h" - #ifdef CONFIG_MBEDTLS_ROM_MD5 #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_sha.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_sha.h index 2c686a45548..8901ec7fd67 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_sha.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_sha.h @@ -1,18 +1,17 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #pragma once +#include "psa/crypto.h" +#include "psa_crypto_driver_esp_sha_contexts.h" + #ifdef __cplusplus extern "C" { #endif -#include "psa_crypto_driver_esp_sha_contexts.h" -#include -#include "psa/crypto.h" - #ifdef CONFIG_MBEDTLS_HARDWARE_SHA #ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT diff --git a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_sha_contexts.h b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_sha_contexts.h index 658a1279f03..19c63c20ff6 100644 --- a/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_sha_contexts.h +++ b/components/mbedtls/port/psa_driver/include/psa_crypto_driver_esp_sha_contexts.h @@ -1,11 +1,16 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #pragma once + +#include "esp_types.h" +#include +#include "soc/soc_caps.h" + #ifdef __cplusplus extern "C" { #endif @@ -23,10 +28,6 @@ extern "C" { * crypto_driver_contexts_primitives.h. */ -#include -#include -#include "sdkconfig.h" - typedef enum { ESP_SHA_OPERATION_TYPE_SHA1, ESP_SHA_OPERATION_TYPE_SHA256, @@ -53,13 +54,13 @@ typedef enum { ESP_SHA512_STATE_IN_PROCESS } esp_sha512_state; -#if CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG +#if SOC_SHA_SUPPORT_PARALLEL_ENG typedef enum { ESP_SHA_MODE_UNUSED, ESP_SHA_MODE_HARDWARE, ESP_SHA_MODE_SOFTWARE } esp_sha_mode_t; -#endif /* CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG */ +#endif /* SOC_SHA_SUPPORT_PARALLEL_ENG */ /** * \brief ESP SHA1 context structure @@ -70,9 +71,9 @@ typedef struct { unsigned char buffer[64]; /*!< The data block being processed. */ bool first_block; /*!< First block flag for hardware initialization */ int sha_state; /*!< SHA operation state */ -#if CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG +#if SOC_SHA_SUPPORT_PARALLEL_ENG esp_sha_mode_t operation_mode; /*!< Hardware or Software mode */ -#endif /* CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG */ +#endif /* SOC_SHA_SUPPORT_PARALLEL_ENG */ } esp_sha1_context; /** @@ -85,9 +86,9 @@ typedef struct { bool first_block; /*!< First block flag for hardware initialization */ int sha_state; /*!< SHA operation state */ int mode; /*!< SHA2_224 or SHA2_256 */ -#if CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG +#if SOC_SHA_SUPPORT_PARALLEL_ENG esp_sha_mode_t operation_mode; /*!< Hardware or Software mode */ -#endif /* CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG */ +#endif /* SOC_SHA_SUPPORT_PARALLEL_ENG */ } esp_sha256_context; /** @@ -102,9 +103,9 @@ typedef struct { int sha_state; int mode; uint32_t t_val; /*!< t_val for 512/t mode */ -#if CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG +#if SOC_SHA_SUPPORT_PARALLEL_ENG esp_sha_mode_t operation_mode; /*!< Hardware or Software mode */ -#endif /* CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG */ +#endif /* SOC_SHA_SUPPORT_PARALLEL_ENG */ } esp_sha512_context; typedef void *esp_sha_context_t; diff --git a/components/mbedtls/test_apps/main/test_psa_ecdsa.c b/components/mbedtls/test_apps/main/test_psa_ecdsa.c index d714df6981c..d9ceba4e370 100644 --- a/components/mbedtls/test_apps/main/test_psa_ecdsa.c +++ b/components/mbedtls/test_apps/main/test_psa_ecdsa.c @@ -76,6 +76,18 @@ const uint8_t sha[] = { 0xb2, 0x60, 0xb2, 0x38, 0x93, 0xa6, 0x27, 0x14 }; +#if !defined(ESP_ECDSA_DRIVER_ENABLED) +/** + * @brief ECDSA curve options + */ +typedef enum { + ESP_ECDSA_CURVE_SECP192R1, + ESP_ECDSA_CURVE_SECP256R1, + ESP_ECDSA_CURVE_SECP384R1, + ESP_ECDSA_CURVE_MAX, +} esp_ecdsa_curve_t; +#endif /* !defined(ESP_ECDSA_DRIVER_ENABLED) */ + #if CONFIG_MBEDTLS_HARDWARE_ECC || CONFIG_MBEDTLS_HARDWARE_ECDSA_VERIFY /* Big endian */