From 7a32072038b851afca44e4b2afe42985feae1e0b Mon Sep 17 00:00:00 2001 From: Andrzej Kurek Date: Thu, 1 Sep 2022 09:23:09 -0400 Subject: [PATCH] Setup / deinitialize PSA in pk tests only if no MD is used Signed-off-by: Andrzej Kurek --- tests/include/test/psa_crypto_helpers.h | 14 ++++++++------ tests/suites/test_suite_pkcs5.function | 8 ++++---- tests/suites/test_suite_pkparse.function | 8 ++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/include/test/psa_crypto_helpers.h b/tests/include/test/psa_crypto_helpers.h index 43023452f..bc2b016db 100644 --- a/tests/include/test/psa_crypto_helpers.h +++ b/tests/include/test/psa_crypto_helpers.h @@ -276,15 +276,17 @@ psa_key_usage_t mbedtls_test_update_key_usage_flags( psa_key_usage_t usage_flags } \ } \ while( 0 ) -#else -/* Define empty macros so that we can use them in the preamble and teardown - * of every test function that uses PSA conditionally based on - * MBEDTLS_PSA_CRYPTO_C. */ -#define PSA_INIT( ) ( (void) 0 ) -#define PSA_DONE( ) ( (void) 0 ) +#if !defined(MBEDTLS_MD_C) +#define PSA_INIT_IF_NO_MD( ) PSA_INIT( ) +#define PSA_DONE_IF_NO_MD( ) PSA_DONE( ) +#endif #endif /* MBEDTLS_PSA_CRYPTO_C */ +#if defined(MBEDTLS_MD_C) +#define PSA_INIT_IF_NO_MD( ) ( (void) 0 ) +#define PSA_DONE_IF_NO_MD( ) ( (void) 0 ) +#endif /** \def USE_PSA_INIT * * Call this macro to initialize the PSA subsystem if #MBEDTLS_USE_PSA_CRYPTO diff --git a/tests/suites/test_suite_pkcs5.function b/tests/suites/test_suite_pkcs5.function index e2347ccd5..fcbf9b195 100644 --- a/tests/suites/test_suite_pkcs5.function +++ b/tests/suites/test_suite_pkcs5.function @@ -14,14 +14,14 @@ void pbkdf2_hmac( int hash, data_t * pw_str, data_t * salt_str, { unsigned char key[100]; - PSA_INIT(); + PSA_INIT_IF_NO_MD(); TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac_ext( hash, pw_str->x, pw_str->len, salt_str->x, salt_str->len, it_cnt, key_len, key ) == 0 ); TEST_ASSERT( mbedtls_test_hexcmp( key, result_key_string->x, key_len, result_key_string->len ) == 0 ); - PSA_DONE(); + PSA_DONE_IF_NO_MD(); } /* END_CASE */ @@ -33,7 +33,7 @@ void mbedtls_pkcs5_pbes2( int params_tag, data_t *params_hex, data_t *pw, mbedtls_asn1_buf params; unsigned char *my_out = NULL; - PSA_INIT(); + PSA_INIT_IF_NO_MD(); params.tag = params_tag; params.p = params_hex->x; @@ -50,7 +50,7 @@ void mbedtls_pkcs5_pbes2( int params_tag, data_t *params_hex, data_t *pw, exit: mbedtls_free( my_out ); - PSA_DONE(); + PSA_DONE_IF_NO_MD(); } /* END_CASE */ diff --git a/tests/suites/test_suite_pkparse.function b/tests/suites/test_suite_pkparse.function index 1e003b9b5..8ca3aca79 100644 --- a/tests/suites/test_suite_pkparse.function +++ b/tests/suites/test_suite_pkparse.function @@ -17,7 +17,7 @@ void pk_parse_keyfile_rsa( char * key_file, char * password, int result ) int res; char *pwd = password; - PSA_INIT(); + PSA_INIT_IF_NO_MD(); mbedtls_pk_init( &ctx ); if( strcmp( pwd, "NULL" ) == 0 ) @@ -38,7 +38,7 @@ void pk_parse_keyfile_rsa( char * key_file, char * password, int result ) exit: mbedtls_pk_free( &ctx ); - PSA_DONE(); + PSA_DONE_IF_NO_MD(); } /* END_CASE */ @@ -48,7 +48,7 @@ void pk_parse_public_keyfile_rsa( char * key_file, int result ) mbedtls_pk_context ctx; int res; - PSA_INIT(); + PSA_INIT_IF_NO_MD(); mbedtls_pk_init( &ctx ); res = mbedtls_pk_parse_public_keyfile( &ctx, key_file ); @@ -65,7 +65,7 @@ void pk_parse_public_keyfile_rsa( char * key_file, int result ) exit: mbedtls_pk_free( &ctx ); - PSA_DONE(); + PSA_DONE_IF_NO_MD(); } /* END_CASE */