From 1cd39d52298b953d59cc791a07240d44f0522a21 Mon Sep 17 00:00:00 2001 From: Steven Cooreman Date: Thu, 23 Jul 2020 16:26:08 +0200 Subject: [PATCH] Use own define for building with test drivers Trying to compile in the PSA accelerator test driver under MBEDTLS_TEST_HOOKS turned out to be awkward regarding existing builds. We'll put it under a custom (not in config.h) define instead, since it's something that only should happen in test. Signed-off-by: Steven Cooreman --- library/psa_crypto_driver_wrappers.c | 28 +++++++++---------- tests/include/drivers/keygen.h | 4 +-- tests/include/drivers/signature.h | 4 +-- tests/scripts/all.sh | 5 ++-- tests/src/drivers/keygen.c | 4 +-- tests/src/drivers/signature.c | 4 +-- ..._suite_psa_crypto_driver_wrappers.function | 2 +- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c index 0f6cfe911..dc84f3ba8 100644 --- a/library/psa_crypto_driver_wrappers.c +++ b/library/psa_crypto_driver_wrappers.c @@ -28,13 +28,13 @@ #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) /* Include test driver definition when running tests */ -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) #undef MBEDTLS_PSA_CRYPTO_DRIVER_PRESENT #define MBEDTLS_PSA_CRYPTO_DRIVER_PRESENT #undef MBEDTLS_PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #define MBEDTLS_PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT #include "drivers/test_driver.h" -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ /* Include driver definition file for each registered driver here */ #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS */ @@ -91,7 +91,7 @@ psa_status_t psa_driver_wrapper_sign_hash( psa_key_slot_t *slot, case PSA_KEY_LOCATION_LOCAL_STORAGE: /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) status = test_transparent_signature_sign_hash( &attributes, slot->data.key.data, slot->data.key.bytes, @@ -104,11 +104,11 @@ psa_status_t psa_driver_wrapper_sign_hash( psa_key_slot_t *slot, /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return status; -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ /* Fell through, meaning no accelerator supports this operation */ return PSA_ERROR_NOT_SUPPORTED; /* Add cases for opaque driver here */ -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) case MBEDTLS_PSA_CRYPTO_TEST_DRIVER_LIFETIME: return( test_opaque_signature_sign_hash( &attributes, slot->data.key.data, @@ -119,7 +119,7 @@ psa_status_t psa_driver_wrapper_sign_hash( psa_key_slot_t *slot, signature, signature_size, signature_length ) ); -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ return status; @@ -182,7 +182,7 @@ psa_status_t psa_driver_wrapper_verify_hash( psa_key_slot_t *slot, case PSA_KEY_LOCATION_LOCAL_STORAGE: /* Key is stored in the slot in export representation, so * cycle through all known transparent accelerators */ -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) status = test_transparent_signature_verify_hash( &attributes, slot->data.key.data, slot->data.key.bytes, @@ -194,11 +194,11 @@ psa_status_t psa_driver_wrapper_verify_hash( psa_key_slot_t *slot, /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) return status; -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ /* Fell through, meaning no accelerator supports this operation */ return PSA_ERROR_NOT_SUPPORTED; /* Add cases for opaque driver here */ -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) case MBEDTLS_PSA_CRYPTO_TEST_DRIVER_LIFETIME: return( test_opaque_signature_verify_hash( &attributes, slot->data.key.data, @@ -208,7 +208,7 @@ psa_status_t psa_driver_wrapper_verify_hash( psa_key_slot_t *slot, hash_length, signature, signature_length ) ); -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ return status; @@ -330,7 +330,7 @@ psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attrib status = PSA_ERROR_NOT_SUPPORTED; break; } -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) status = test_transparent_generate_key( attributes, slot->data.key.data, slot->data.key.bytes, @@ -338,19 +338,19 @@ psa_status_t psa_driver_wrapper_generate_key( const psa_key_attributes_t *attrib /* Declared with fallback == true */ if( status != PSA_ERROR_NOT_SUPPORTED ) break; -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ /* Fell through, meaning no accelerator supports this operation */ status = PSA_ERROR_NOT_SUPPORTED; break; /* Add cases for opaque driver here */ -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) case MBEDTLS_PSA_CRYPTO_TEST_DRIVER_LIFETIME: status = test_opaque_generate_key( attributes, slot->data.key.data, slot->data.key.bytes, &slot->data.key.bytes ); break; -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ default: /* Key is declared with a lifetime not known to us */ status = PSA_ERROR_INVALID_ARGUMENT; diff --git a/tests/include/drivers/keygen.h b/tests/include/drivers/keygen.h index 436df3441..7e6ed2756 100644 --- a/tests/include/drivers/keygen.h +++ b/tests/include/drivers/keygen.h @@ -28,7 +28,7 @@ #include MBEDTLS_CONFIG_FILE #endif -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) #include extern void *test_driver_keygen_forced_output; @@ -45,5 +45,5 @@ psa_status_t test_opaque_generate_key( const psa_key_attributes_t *attributes, uint8_t *key, size_t key_size, size_t *key_length ); -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ #endif /* MBEDTLS_PSA_CRYPTO_TEST_DRIVERS_KEYGEN_H */ diff --git a/tests/include/drivers/signature.h b/tests/include/drivers/signature.h index 232ed4147..ec4f66341 100644 --- a/tests/include/drivers/signature.h +++ b/tests/include/drivers/signature.h @@ -28,7 +28,7 @@ #include MBEDTLS_CONFIG_FILE #endif -#if defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) #include extern void *test_driver_forced_output; @@ -68,5 +68,5 @@ psa_status_t test_opaque_signature_verify_hash( const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length ); -#endif /* MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ #endif /* MBEDTLS_PSA_CRYPTO_TEST_DRIVERS_SIGNATURE_H */ diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index a3f67bef8..540179b50 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -1659,9 +1659,8 @@ component_test_se_default () { component_test_psa_crypto_drivers () { msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks" scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS - scripts/config.py set MBEDTLS_TEST_HOOKS - # Need to include the test driver header path in order to build - make CC=gcc CFLAGS="$ASAN_CFLAGS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS" + # Need to define the correct symbol and include the test driver header path in order to build with the test driver + make CC=gcc CFLAGS="$ASAN_CFLAGS -DMBEDTLS_PSA_CRYPTO_DRIVER_TEST -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS" msg "test: MBEDTLS_PSA_CRYPTO_DRIVERS, signature" make test diff --git a/tests/src/drivers/keygen.c b/tests/src/drivers/keygen.c index 4c830c35e..c883e006e 100644 --- a/tests/src/drivers/keygen.c +++ b/tests/src/drivers/keygen.c @@ -25,7 +25,7 @@ #include MBEDTLS_CONFIG_FILE #endif -#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) #include "psa/crypto.h" #include "mbedtls/ecp.h" #include "mbedtls/error.h" @@ -126,4 +126,4 @@ psa_status_t test_opaque_generate_key( return( PSA_ERROR_NOT_SUPPORTED ); } -#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/src/drivers/signature.c b/tests/src/drivers/signature.c index 32ebbfdff..114007a7b 100644 --- a/tests/src/drivers/signature.c +++ b/tests/src/drivers/signature.c @@ -25,7 +25,7 @@ #include MBEDTLS_CONFIG_FILE #endif -#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(MBEDTLS_TEST_HOOKS) +#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(MBEDTLS_PSA_CRYPTO_DRIVER_TEST) #include "psa/crypto.h" #include "mbedtls/ecp.h" @@ -298,4 +298,4 @@ psa_status_t test_opaque_signature_verify_hash( return( PSA_ERROR_NOT_SUPPORTED ); } -#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && MBEDTLS_TEST_HOOKS */ +#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && MBEDTLS_PSA_CRYPTO_DRIVER_TEST */ diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index 9bb794385..f8ea80d47 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -49,7 +49,7 @@ typedef enum /* END_HEADER */ /* BEGIN_DEPENDENCIES - * depends_on:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_PSA_CRYPTO_DRIVERS:MBEDTLS_TEST_HOOKS + * depends_on:MBEDTLS_PSA_CRYPTO_C:MBEDTLS_PSA_CRYPTO_DRIVERS:MBEDTLS_PSA_CRYPTO_DRIVER_TEST * END_DEPENDENCIES */