From 39b328e60bdf4b6bb1ccec5b5d5a2a6bc5dbf7dc Mon Sep 17 00:00:00 2001 From: Anton Matkin Date: Fri, 20 Jun 2025 13:44:05 +0200 Subject: [PATCH] Add preprocessor code, for compatibility with older mbedtls version, namely, now the inclusioin of header files in the private/ folder is conditional Signed-off-by: Anton Matkin --- tests/include/test/bignum_helpers.h | 4 ++++ tests/include/test/drivers/cipher.h | 4 ++++ tests/include/test/helpers.h | 6 ++++++ tests/include/test/psa_crypto_helpers.h | 5 +++++ tests/src/bignum_helpers.c | 5 +++++ tests/src/drivers/test_driver_asymmetric_encryption.c | 6 ++++++ tests/src/drivers/test_driver_cipher.c | 5 +++++ tests/src/drivers/test_driver_key_management.c | 6 ++++++ tests/src/drivers/test_driver_signature.c | 9 +++++++++ tests/src/fake_external_rng_for_test.c | 5 +++++ tests/src/psa_crypto_helpers.c | 9 +++++++++ tests/src/psa_exercise_key.c | 6 ++++++ tests/src/random.c | 4 ++++ 13 files changed, 74 insertions(+) diff --git a/tests/include/test/bignum_helpers.h b/tests/include/test/bignum_helpers.h index bc94a2a88..0787c5180 100644 --- a/tests/include/test/bignum_helpers.h +++ b/tests/include/test/bignum_helpers.h @@ -17,7 +17,11 @@ #if defined(MBEDTLS_BIGNUM_C) +#if MBEDTLS_VERSION_MAJOR >= 4 #include +#else +#include +#endif #include /** Allocate and populate a core MPI from a test case argument. diff --git a/tests/include/test/drivers/cipher.h b/tests/include/test/drivers/cipher.h index 2df1dc777..3749d81f3 100644 --- a/tests/include/test/drivers/cipher.h +++ b/tests/include/test/drivers/cipher.h @@ -16,7 +16,11 @@ #include #include +#if MBEDTLS_MAJOR_VERSION >= 4 #include "mbedtls/private/cipher.h" +#else +#include "mbedtls/cipher.h" +#endif typedef struct { /* If non-null, on success, copy this to the output. */ diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h index 6776d4f18..221579f64 100644 --- a/tests/include/test/helpers.h +++ b/tests/include/test/helpers.h @@ -51,7 +51,13 @@ #include #if defined(MBEDTLS_BIGNUM_C) + +#if MBEDTLS_VERSION_MAJOR >= 4 #include "mbedtls/private/bignum.h" +#else +#include "mbedtls/bignum.h" +#endif + #endif /** The type of test case arguments that contain binary data. */ diff --git a/tests/include/test/psa_crypto_helpers.h b/tests/include/test/psa_crypto_helpers.h index 70f3d356b..a0d5647ed 100644 --- a/tests/include/test/psa_crypto_helpers.h +++ b/tests/include/test/psa_crypto_helpers.h @@ -17,7 +17,12 @@ #endif #include + +#if MBEDTLS_VERSION_MAJOR >= 4 #include +#else +#include +#endif #if defined(MBEDTLS_PSA_CRYPTO_C) /** Initialize the PSA Crypto subsystem. */ diff --git a/tests/src/bignum_helpers.c b/tests/src/bignum_helpers.c index db725326a..8f8ec9e6f 100644 --- a/tests/src/bignum_helpers.c +++ b/tests/src/bignum_helpers.c @@ -18,7 +18,12 @@ #include #include +#if MBEDTLS_VERSION_MAJOR >= 4 #include +#else +#include +#endif + #include #include #include diff --git a/tests/src/drivers/test_driver_asymmetric_encryption.c b/tests/src/drivers/test_driver_asymmetric_encryption.c index 6689036a7..38621fca7 100644 --- a/tests/src/drivers/test_driver_asymmetric_encryption.c +++ b/tests/src/drivers/test_driver_asymmetric_encryption.c @@ -9,7 +9,13 @@ #if defined(PSA_CRYPTO_DRIVER_TEST) #include "psa/crypto.h" + +#if MBEDTLS_VERSION_MAJOR >= 4 #include "mbedtls/private/rsa.h" +#else +#include "mbedtls/rsa.h" +#endif + #include "psa_crypto_rsa.h" #include "string.h" #include "test/drivers/asymmetric_encryption.h" diff --git a/tests/src/drivers/test_driver_cipher.c b/tests/src/drivers/test_driver_cipher.c index 31fbe33bf..89e1cc36d 100644 --- a/tests/src/drivers/test_driver_cipher.c +++ b/tests/src/drivers/test_driver_cipher.c @@ -12,7 +12,12 @@ #include "psa/crypto.h" #include "psa_crypto_cipher.h" #include "psa_crypto_core.h" + +#if MBEDTLS_VERSION_MAJOR >= 4 #include "mbedtls/private/cipher.h" +#else +#include "mbedtls/cipher.h" +#endif #include "test/drivers/cipher.h" diff --git a/tests/src/drivers/test_driver_key_management.c b/tests/src/drivers/test_driver_key_management.c index e0434f690..2d34f957a 100644 --- a/tests/src/drivers/test_driver_key_management.c +++ b/tests/src/drivers/test_driver_key_management.c @@ -14,7 +14,13 @@ #include "psa_crypto_ecp.h" #include "psa_crypto_rsa.h" #include "psa_crypto_ffdh.h" + +#if MBEDTLS_VERSION_MAJOR >= 4 #include "mbedtls/private/ecp.h" +#else +#include "mbedtls/ecp.h" +#endif + #include "mbedtls/error.h" #include "test/drivers/key_management.h" diff --git a/tests/src/drivers/test_driver_signature.c b/tests/src/drivers/test_driver_signature.c index af20a21fe..cc0db54c3 100644 --- a/tests/src/drivers/test_driver_signature.c +++ b/tests/src/drivers/test_driver_signature.c @@ -15,13 +15,22 @@ #include "psa_crypto_ecp.h" #include "psa_crypto_hash.h" #include "psa_crypto_rsa.h" + +#if MBEDTLS_VERSION_MAJOR >= 4 #include "mbedtls/private/ecp.h" +#else +#include "mbedtls/ecp.h" +#endif #include "test/drivers/hash.h" #include "test/drivers/signature.h" #include "test/drivers/hash.h" +#if MBEDTLS_VERSION_MAJOR >= 4 #include "mbedtls/private/ecdsa.h" +#else +#include "mbedtls/ecdsa.h" +#endif #include "test/random.h" diff --git a/tests/src/fake_external_rng_for_test.c b/tests/src/fake_external_rng_for_test.c index 83976137e..d1ab67543 100644 --- a/tests/src/fake_external_rng_for_test.c +++ b/tests/src/fake_external_rng_for_test.c @@ -58,7 +58,12 @@ psa_status_t mbedtls_psa_external_get_random( #if defined(MBEDTLS_PLATFORM_GET_ENTROPY_ALT) || defined(MBEDTLS_PSA_DRIVER_GET_ENTROPY) #include + +#if MBEDTLS_VERSION_MAJOR >= 4 #include +#else +#include +#endif static int platform_get_entropy_force_failure; static size_t platform_get_entropy_forced_entropy_content = SIZE_MAX; diff --git a/tests/src/psa_crypto_helpers.c b/tests/src/psa_crypto_helpers.c index c253cef26..662204398 100644 --- a/tests/src/psa_crypto_helpers.c +++ b/tests/src/psa_crypto_helpers.c @@ -14,7 +14,11 @@ #include #if defined(MBEDTLS_CTR_DRBG_C) +#if MBEDTLS_VERSION_MAJOR >= 4 #include +#else +#include +#endif #endif #if defined(MBEDTLS_PSA_CRYPTO_C) @@ -249,7 +253,12 @@ exit: #if defined(MBEDTLS_PSA_INJECT_ENTROPY) +#if MBEDTLS_VERSION_MAJOR >= 4 #include +#else +#include +#endif + #include int mbedtls_test_inject_entropy_seed_read(unsigned char *buf, size_t len) diff --git a/tests/src/psa_exercise_key.c b/tests/src/psa_exercise_key.c index 42e29f40b..a5108b4ec 100644 --- a/tests/src/psa_exercise_key.c +++ b/tests/src/psa_exercise_key.c @@ -25,7 +25,13 @@ #include #endif #if defined(MBEDTLS_ECP_C) + +#if MBEDTLS_VERSION_MAJOR >= 4 #include +#else +#include +#endif + #endif #if defined(MBEDTLS_RSA_C) #include diff --git a/tests/src/random.c b/tests/src/random.c index 1bcee2fd1..d02df7c5d 100644 --- a/tests/src/random.c +++ b/tests/src/random.c @@ -23,7 +23,11 @@ #include #include +#if MBEDTLS_VERSION_MAJOR >= 4 #include +#else +#include +#endif #include int mbedtls_test_rnd_std_rand(void *rng_state,