From fb9cb920558fd462dcf6cb0ff30532e46db46313 Mon Sep 17 00:00:00 2001 From: Steven Cooreman Date: Tue, 23 Feb 2021 14:37:38 +0100 Subject: [PATCH] Move wildcard-to-exercisable conversion to exercise_key in test suite Signed-off-by: Steven Cooreman --- tests/src/psa_exercise_key.c | 12 ++++++++++++ tests/suites/test_suite_psa_crypto.function | 13 ------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/src/psa_exercise_key.c b/tests/src/psa_exercise_key.c index 869da7df6..a4f87eb2c 100644 --- a/tests/src/psa_exercise_key.c +++ b/tests/src/psa_exercise_key.c @@ -122,6 +122,12 @@ static int exercise_mac_key( mbedtls_svc_key_id_t key, unsigned char mac[PSA_MAC_MAX_SIZE] = {0}; size_t mac_length = sizeof( mac ); + /* Convert wildcard algorithm to exercisable algorithm */ + if( alg & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ) + { + alg = PSA_ALG_TRUNCATED_MAC( alg, PSA_MAC_TRUNCATED_LENGTH( alg ) ); + } + if( usage & PSA_KEY_USAGE_SIGN_HASH ) { PSA_ASSERT( psa_mac_sign_setup( &operation, key, alg ) ); @@ -236,6 +242,12 @@ static int exercise_aead_key( mbedtls_svc_key_id_t key, size_t ciphertext_length = sizeof( ciphertext ); size_t plaintext_length = sizeof( ciphertext ); + /* Convert wildcard algorithm to exercisable algorithm */ + if( alg & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG ) + { + alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, PSA_ALG_AEAD_GET_TAG_LENGTH( alg ) ); + } + /* Default IV length for AES-GCM is 12 bytes */ if( PSA_ALG_AEAD_WITH_SHORTENED_TAG( alg, 0 ) == PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_GCM, 0 ) ) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index fca78cb5e..a6b0b84e8 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -1338,19 +1338,6 @@ void copy_success( int source_usage_arg, export_buffer, length ); } - /* Convert wildcard algorithm to exercisable algorithm */ - if( PSA_ALG_IS_WILDCARD( expected_alg ) ) - { - if( PSA_ALG_IS_MAC( expected_alg ) ) - expected_alg = PSA_ALG_TRUNCATED_MAC( - expected_alg, - PSA_MAC_TRUNCATED_LENGTH( expected_alg ) ); - if( PSA_ALG_IS_AEAD( expected_alg ) ) - expected_alg = PSA_ALG_AEAD_WITH_SHORTENED_TAG( - expected_alg, - PSA_ALG_AEAD_GET_TAG_LENGTH( expected_alg ) ); - } - if( ! mbedtls_test_psa_exercise_key( target_key, expected_usage, expected_alg ) ) goto exit; if( ! mbedtls_test_psa_exercise_key( target_key, expected_usage, expected_alg2 ) )