From ce14124f7c47b3955e43a34408cc7826763e5b4e Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 28 Jul 2023 16:14:20 +0100 Subject: [PATCH] Check result of multipart operation Check that the multi-part operation has produced the correct result. Signed-off-by: Thomas Daubney --- programs/psa/psa_hash.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/programs/psa/psa_hash.c b/programs/psa/psa_hash.c index 2afe34de6b..ae4e9a5d2b 100644 --- a/programs/psa/psa_hash.c +++ b/programs/psa/psa_hash.c @@ -111,6 +111,15 @@ int main(void) return EXIT_FAILURE; } + /* Check the result of the operation against the sample */ + if ((memcmp(hash, sample_hash, sample_hash_len) != 0) || hash_length != sample_hash_len) + { + mbedtls_printf("Multi-part hash operation gave the wrong result!\n\n"); + psa_hash_abort(&hash_operation); + psa_hash_abort(&cloned_hash_operation); + return EXIT_FAILURE; + } + status = psa_hash_verify(&cloned_hash_operation, sample_hash, sample_hash_len);