From 4c0b60e5fa681a76194222bb9cb264edca0cbfa2 Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Mon, 14 Jun 2021 12:34:30 +0100 Subject: [PATCH] Fix exercise key test Hash and sign algorithms require the alignment of the input length with the hash length at verification as well not just when signing. Signed-off-by: Janos Follath --- tests/src/psa_exercise_key.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/src/psa_exercise_key.c b/tests/src/psa_exercise_key.c index f48a64e94..e4e55c9c2 100644 --- a/tests/src/psa_exercise_key.c +++ b/tests/src/psa_exercise_key.c @@ -316,13 +316,14 @@ static int exercise_signature_key( mbedtls_svc_key_id_t key, #endif } + /* Some algorithms require the payload to have the size of + * the hash encoded in the algorithm. Use this input size + * even for algorithms that allow other input sizes. */ + if( hash_alg != 0 ) + payload_length = PSA_HASH_LENGTH( hash_alg ); + if( usage & PSA_KEY_USAGE_SIGN_HASH ) { - /* Some algorithms require the payload to have the size of - * the hash encoded in the algorithm. Use this input size - * even for algorithms that allow other input sizes. */ - if( hash_alg != 0 ) - payload_length = PSA_HASH_LENGTH( hash_alg ); PSA_ASSERT( psa_sign_hash( key, alg, payload, payload_length, signature, sizeof( signature ),