From ef3020ad693703f365f7b14e81540866a25460ed Mon Sep 17 00:00:00 2001 From: Dakshit Babbar Date: Thu, 8 May 2025 14:29:24 +0530 Subject: [PATCH 1/4] Update code to work with demos using latest mbedtls version --- source/portable/mbedtls/core_pkcs11_mbedtls.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/portable/mbedtls/core_pkcs11_mbedtls.c b/source/portable/mbedtls/core_pkcs11_mbedtls.c index 53580caf..00f57f98 100644 --- a/source/portable/mbedtls/core_pkcs11_mbedtls.c +++ b/source/portable/mbedtls/core_pkcs11_mbedtls.c @@ -93,6 +93,12 @@ */ static const char * pNoLowLevelMbedTlsCodeStr = ""; +#if defined(MBEDTLS_PSA_CRYPTO_C) +extern mbedtls_threading_mutex_t mbedtls_threading_key_slot_mutex; +extern mbedtls_threading_mutex_t mbedtls_threading_psa_globaldata_mutex; +extern mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex; +#endif + /** * @brief Utility for converting the high-level code in an mbedTLS error to string, * if the code-contains a high-level code; otherwise, using a default string. @@ -475,6 +481,12 @@ static CK_RV prvMbedTLS_Initialize( void ) mbedtls_entropy_init( &xP11Context.xMbedEntropyContext ); mbedtls_ctr_drbg_init( &xP11Context.xMbedDrbgCtx ); + #if defined(MBEDTLS_PSA_CRYPTO_C) + mbedtls_mutex_init(&mbedtls_threading_key_slot_mutex); + mbedtls_mutex_init(&mbedtls_threading_psa_globaldata_mutex); + mbedtls_mutex_init(&mbedtls_threading_psa_rngdata_mutex); + #endif + lMbedTLSResult = mbedtls_ctr_drbg_seed( &xP11Context.xMbedDrbgCtx, mbedtls_entropy_func, &xP11Context.xMbedEntropyContext, From f9c7680cfb1f3f3e755b61da7b270b13c8caaca8 Mon Sep 17 00:00:00 2001 From: Dakshit Babbar Date: Thu, 8 May 2025 14:38:07 +0530 Subject: [PATCH 2/4] Add documentation for the new mutex initialisation --- source/portable/mbedtls/core_pkcs11_mbedtls.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source/portable/mbedtls/core_pkcs11_mbedtls.c b/source/portable/mbedtls/core_pkcs11_mbedtls.c index 00f57f98..fa3efec8 100644 --- a/source/portable/mbedtls/core_pkcs11_mbedtls.c +++ b/source/portable/mbedtls/core_pkcs11_mbedtls.c @@ -93,12 +93,6 @@ */ static const char * pNoLowLevelMbedTlsCodeStr = ""; -#if defined(MBEDTLS_PSA_CRYPTO_C) -extern mbedtls_threading_mutex_t mbedtls_threading_key_slot_mutex; -extern mbedtls_threading_mutex_t mbedtls_threading_psa_globaldata_mutex; -extern mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex; -#endif - /** * @brief Utility for converting the high-level code in an mbedTLS error to string, * if the code-contains a high-level code; otherwise, using a default string. @@ -117,6 +111,16 @@ extern mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex; #endif /* ifndef DISABLE_LOGGING */ +/** + * @brief Global mutexes used for threading in PSA APIs. These are defined by the + * mbedtls library, we just need to initialise them. + */ + #if defined(MBEDTLS_PSA_CRYPTO_C) + extern mbedtls_threading_mutex_t mbedtls_threading_key_slot_mutex; + extern mbedtls_threading_mutex_t mbedtls_threading_psa_globaldata_mutex; + extern mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex; + #endif + /** * @ingroup pkcs11_macros * @brief Delay to wait on acquiring a mutex, in ms. @@ -481,6 +485,7 @@ static CK_RV prvMbedTLS_Initialize( void ) mbedtls_entropy_init( &xP11Context.xMbedEntropyContext ); mbedtls_ctr_drbg_init( &xP11Context.xMbedDrbgCtx ); + /* Initialise the global mutexes for the PSA API's */ #if defined(MBEDTLS_PSA_CRYPTO_C) mbedtls_mutex_init(&mbedtls_threading_key_slot_mutex); mbedtls_mutex_init(&mbedtls_threading_psa_globaldata_mutex); From 445b68bd849634c5724c54ac9a5d1aff842f5f1e Mon Sep 17 00:00:00 2001 From: DakshitBabbar Date: Thu, 8 May 2025 14:45:17 +0530 Subject: [PATCH 3/4] Fix Formatting --- source/portable/mbedtls/core_pkcs11_mbedtls.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/portable/mbedtls/core_pkcs11_mbedtls.c b/source/portable/mbedtls/core_pkcs11_mbedtls.c index fa3efec8..bcf02a6b 100644 --- a/source/portable/mbedtls/core_pkcs11_mbedtls.c +++ b/source/portable/mbedtls/core_pkcs11_mbedtls.c @@ -112,14 +112,14 @@ #endif /* ifndef DISABLE_LOGGING */ /** - * @brief Global mutexes used for threading in PSA APIs. These are defined by the + * @brief Global mutexes used for threading in PSA APIs. These are defined by the * mbedtls library, we just need to initialise them. */ - #if defined(MBEDTLS_PSA_CRYPTO_C) +#if defined( MBEDTLS_PSA_CRYPTO_C ) extern mbedtls_threading_mutex_t mbedtls_threading_key_slot_mutex; extern mbedtls_threading_mutex_t mbedtls_threading_psa_globaldata_mutex; extern mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex; - #endif +#endif /** * @ingroup pkcs11_macros @@ -486,10 +486,10 @@ static CK_RV prvMbedTLS_Initialize( void ) mbedtls_ctr_drbg_init( &xP11Context.xMbedDrbgCtx ); /* Initialise the global mutexes for the PSA API's */ - #if defined(MBEDTLS_PSA_CRYPTO_C) - mbedtls_mutex_init(&mbedtls_threading_key_slot_mutex); - mbedtls_mutex_init(&mbedtls_threading_psa_globaldata_mutex); - mbedtls_mutex_init(&mbedtls_threading_psa_rngdata_mutex); + #if defined( MBEDTLS_PSA_CRYPTO_C ) + mbedtls_mutex_init( &mbedtls_threading_key_slot_mutex ); + mbedtls_mutex_init( &mbedtls_threading_psa_globaldata_mutex ); + mbedtls_mutex_init( &mbedtls_threading_psa_rngdata_mutex ); #endif lMbedTLSResult = mbedtls_ctr_drbg_seed( &xP11Context.xMbedDrbgCtx, From 5f2dc04cdee90e69e26e2eccb5b50502f683a544 Mon Sep 17 00:00:00 2001 From: DakshitBabbar Date: Fri, 9 May 2025 14:33:42 +0530 Subject: [PATCH 4/4] Remove unwanted extern statements --- source/portable/mbedtls/core_pkcs11_mbedtls.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/source/portable/mbedtls/core_pkcs11_mbedtls.c b/source/portable/mbedtls/core_pkcs11_mbedtls.c index bcf02a6b..f5623f6d 100644 --- a/source/portable/mbedtls/core_pkcs11_mbedtls.c +++ b/source/portable/mbedtls/core_pkcs11_mbedtls.c @@ -111,16 +111,6 @@ #endif /* ifndef DISABLE_LOGGING */ -/** - * @brief Global mutexes used for threading in PSA APIs. These are defined by the - * mbedtls library, we just need to initialise them. - */ -#if defined( MBEDTLS_PSA_CRYPTO_C ) - extern mbedtls_threading_mutex_t mbedtls_threading_key_slot_mutex; - extern mbedtls_threading_mutex_t mbedtls_threading_psa_globaldata_mutex; - extern mbedtls_threading_mutex_t mbedtls_threading_psa_rngdata_mutex; -#endif - /** * @ingroup pkcs11_macros * @brief Delay to wait on acquiring a mutex, in ms.