Simplify compilation guards around hash driver testing

The hash driver entry points (and consequentially the hash driver core)
are now always compiled on when PSA_CRYPTO_DRIVER_TEST is turned on.

Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
Steven Cooreman 2021-03-16 11:07:55 +01:00
parent b6bf4bbf95
commit f8e45a4e98
3 changed files with 10 additions and 37 deletions

View file

@ -43,18 +43,6 @@
#define MBEDTLS_PSA_BUILTIN_HASH #define MBEDTLS_PSA_BUILTIN_HASH
#endif #endif
#if defined(MBEDTLS_PSA_ACCEL_ALG_MD2) || \
defined(MBEDTLS_PSA_ACCEL_ALG_MD4) || \
defined(MBEDTLS_PSA_ACCEL_ALG_MD5) || \
defined(MBEDTLS_PSA_ACCEL_ALG_RIPEMD160) || \
defined(MBEDTLS_PSA_ACCEL_ALG_SHA_1) || \
defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || \
defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) || \
defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || \
defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
#define MBEDTLS_PSA_ACCEL_HASH
#endif
typedef struct typedef struct
{ {
psa_algorithm_t alg; psa_algorithm_t alg;

View file

@ -1085,7 +1085,7 @@ psa_status_t psa_driver_wrapper_hash_compute(
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
/* Try accelerators first */ /* Try accelerators first */
#if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_HASH) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = mbedtls_transparent_test_driver_hash_compute( status = mbedtls_transparent_test_driver_hash_compute(
alg, input, input_length, hash, hash_size, hash_length ); alg, input, input_length, hash, hash_size, hash_length );
if( status != PSA_ERROR_NOT_SUPPORTED ) if( status != PSA_ERROR_NOT_SUPPORTED )
@ -1117,7 +1117,7 @@ psa_status_t psa_driver_wrapper_hash_setup(
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
/* Try setup on accelerators first */ /* Try setup on accelerators first */
#if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_HASH) #if defined(PSA_CRYPTO_DRIVER_TEST)
status = mbedtls_transparent_test_driver_hash_setup( status = mbedtls_transparent_test_driver_hash_setup(
&operation->ctx.test_driver_ctx, alg ); &operation->ctx.test_driver_ctx, alg );
if( status == PSA_SUCCESS ) if( status == PSA_SUCCESS )
@ -1155,7 +1155,7 @@ psa_status_t psa_driver_wrapper_hash_clone(
return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx, return( mbedtls_psa_hash_clone( &source_operation->ctx.mbedtls_ctx,
&target_operation->ctx.mbedtls_ctx ) ); &target_operation->ctx.mbedtls_ctx ) );
#endif #endif
#if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_HASH) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID; target_operation->id = PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID;
return( mbedtls_transparent_test_driver_hash_clone( return( mbedtls_transparent_test_driver_hash_clone(
@ -1180,7 +1180,7 @@ psa_status_t psa_driver_wrapper_hash_update(
return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx, return( mbedtls_psa_hash_update( &operation->ctx.mbedtls_ctx,
input, input_length ) ); input, input_length ) );
#endif #endif
#if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_HASH) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( mbedtls_transparent_test_driver_hash_update( return( mbedtls_transparent_test_driver_hash_update(
&operation->ctx.test_driver_ctx, &operation->ctx.test_driver_ctx,
@ -1206,7 +1206,7 @@ psa_status_t psa_driver_wrapper_hash_finish(
return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx, return( mbedtls_psa_hash_finish( &operation->ctx.mbedtls_ctx,
hash, hash_size, hash_length ) ); hash, hash_size, hash_length ) );
#endif #endif
#if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_HASH) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( mbedtls_transparent_test_driver_hash_finish( return( mbedtls_transparent_test_driver_hash_finish(
&operation->ctx.test_driver_ctx, &operation->ctx.test_driver_ctx,
@ -1229,7 +1229,7 @@ psa_status_t psa_driver_wrapper_hash_abort(
case PSA_CRYPTO_MBED_TLS_DRIVER_ID: case PSA_CRYPTO_MBED_TLS_DRIVER_ID:
return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) ); return( mbedtls_psa_hash_abort( &operation->ctx.mbedtls_ctx ) );
#endif #endif
#if defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_HASH) #if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID: case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( mbedtls_transparent_test_driver_hash_abort( return( mbedtls_transparent_test_driver_hash_abort(
&operation->ctx.test_driver_ctx ) ); &operation->ctx.test_driver_ctx ) );

View file

@ -68,21 +68,6 @@
#define BUILTIN_ALG_SHA_512 1 #define BUILTIN_ALG_SHA_512 1
#endif #endif
/* If at least one of the hash algorithms is to be exercised through the
* transparent test driver, then the mbedtls_transparent_test_driver_hash_*
* entry points need to be implemented. */
#if defined(PSA_CRYPTO_DRIVER_TEST) && \
defined(MBEDTLS_PSA_ACCEL_HASH)
#define INCLUDE_HASH_TEST_DRIVER
#endif
/* If either of the built-in or test driver entry points need to be implemented, then
* the core implementation should be present. */
#if defined(MBEDTLS_PSA_BUILTIN_HASH) || \
defined(INCLUDE_HASH_TEST_DRIVER)
#define INCLUDE_HASH_CORE 1
#endif
#if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \ #if defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \ defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_OAEP) || \
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) || \ defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) || \
@ -138,7 +123,7 @@ const mbedtls_md_info_t *mbedtls_md_info_from_psa( psa_algorithm_t alg )
/* Implement the PSA driver hash interface on top of mbed TLS if either the /* Implement the PSA driver hash interface on top of mbed TLS if either the
* software driver or the test driver requires it. */ * software driver or the test driver requires it. */
#if defined(INCLUDE_HASH_CORE) #if defined(MBEDTLS_PSA_BUILTIN_HASH) || defined(PSA_CRYPTO_DRIVER_TEST)
static psa_status_t hash_abort( static psa_status_t hash_abort(
mbedtls_psa_hash_operation_t *operation ) mbedtls_psa_hash_operation_t *operation )
{ {
@ -540,7 +525,7 @@ exit:
return( status ); return( status );
} }
#endif /* INCLUDE_HASH_CORE */ #endif /* MBEDTLS_PSA_BUILTIN_HASH || PSA_CRYPTO_DRIVER_TEST */
#if defined(MBEDTLS_PSA_BUILTIN_HASH) #if defined(MBEDTLS_PSA_BUILTIN_HASH)
psa_status_t mbedtls_psa_hash_compute( psa_status_t mbedtls_psa_hash_compute(
@ -596,7 +581,7 @@ psa_status_t mbedtls_psa_hash_abort(
/* /*
* BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY. * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
*/ */
#if defined(INCLUDE_HASH_TEST_DRIVER) #if defined(PSA_CRYPTO_DRIVER_TEST)
psa_status_t is_hash_accelerated( psa_algorithm_t alg ) psa_status_t is_hash_accelerated( psa_algorithm_t alg )
{ {
@ -707,6 +692,6 @@ psa_status_t mbedtls_transparent_test_driver_hash_abort(
return( hash_abort( operation ) ); return( hash_abort( operation ) );
} }
#endif /* INCLUDE_HASH_TEST_DRIVER */ #endif /* PSA_CRYPTO_DRIVER_TEST */
#endif /* MBEDTLS_PSA_CRYPTO_C */ #endif /* MBEDTLS_PSA_CRYPTO_C */