From 34d79ce73d00042b3552386e40c3636039b819e3 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Fri, 27 Sep 2024 15:13:32 +0100 Subject: [PATCH] Only guard with CRYPTO_CLIENT when version >= 4 In 4.x the semantics of MBEDTLS_PSA_CRYPTO_C and MBEDTLS_PSA_CRYPTO_CLIENT are different compared with 3.6. Where this is a problem, make guards more version-specific so that we are guarding with MBEDTLS_PSA_CRYPTO_C for 3.6 and MBEDTLS_PSA_CRYPTO_CLIENT for 4.x, keeping each branch the same as it was formerly. Signed-off-by: David Horstmann --- tests/include/test/psa_crypto_helpers.h | 15 +++++++++++---- tests/src/psa_exercise_key.c | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/include/test/psa_crypto_helpers.h b/tests/include/test/psa_crypto_helpers.h index 233dbe6ad3..483c3203ce 100644 --- a/tests/include/test/psa_crypto_helpers.h +++ b/tests/include/test/psa_crypto_helpers.h @@ -11,7 +11,10 @@ #include "test/helpers.h" -#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) +#if ((MBEDTLS_VERSION_MAJOR < 4) \ + && defined(MBEDTLS_PSA_CRYPTO_C)) \ + || (MBEDTLS_VERSION_MAJOR >= 4 \ + && defined(MBEDTLS_PSA_CRYPTO_CLIENT)) #include "test/psa_helpers.h" #include #endif @@ -40,7 +43,8 @@ mbedtls_psa_crypto_free(); \ } \ while (0) -#elif defined(MBEDTLS_PSA_CRYPTO_CLIENT) /* MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C */ +#elif MBEDTLS_VERSION_MAJOR >= 4 && \ + defined(MBEDTLS_PSA_CRYPTO_CLIENT) /* MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C */ #define PSA_INIT() PSA_ASSERT(psa_crypto_init()) #define PSA_DONE() mbedtls_psa_crypto_free(); #else /* MBEDTLS_PSA_CRYPTO_CLIENT && !MBEDTLS_PSA_CRYPTO_C */ @@ -48,7 +52,10 @@ #define PSA_DONE() ((void) 0) #endif /* MBEDTLS_PSA_CRYPTO_C */ -#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) +#if ((MBEDTLS_VERSION_MAJOR < 4) \ + && defined(MBEDTLS_PSA_CRYPTO_C)) \ + || (MBEDTLS_VERSION_MAJOR >= 4 \ + && defined(MBEDTLS_PSA_CRYPTO_CLIENT)) #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) @@ -319,7 +326,7 @@ uint64_t mbedtls_test_parse_binary_string(data_t *bin_string); } \ while (0) -#endif /* MBEDTLS_PSA_CRYPTO_CLIENT */ +#endif /* MBEDTLS_PSA_CRYPTO_CLIENT || MBEDTLS_PSA_CRYPTO_C */ /** \def USE_PSA_INIT * diff --git a/tests/src/psa_exercise_key.c b/tests/src/psa_exercise_key.c index a496de0212..5c821e2f85 100644 --- a/tests/src/psa_exercise_key.c +++ b/tests/src/psa_exercise_key.c @@ -13,7 +13,8 @@ #if ((MBEDTLS_VERSION_MAJOR < 4) \ && defined(MBEDTLS_PSA_CRYPTO_C)) \ - || defined(MBEDTLS_PSA_CRYPTO_CLIENT) + || (MBEDTLS_VERSION_MAJOR >= 4 \ + && defined(MBEDTLS_PSA_CRYPTO_CLIENT)) #include #include