From a2b7519d63871270f2fb656b34be298fe3335164 Mon Sep 17 00:00:00 2001 From: Thomas Daubney Date: Fri, 28 Jul 2023 15:21:46 +0100 Subject: [PATCH] Use memcmp instead of reinventing it Signed-off-by: Thomas Daubney --- programs/psa/psa_hash.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/programs/psa/psa_hash.c b/programs/psa/psa_hash.c index f09b48c064..a2e2731a98 100644 --- a/programs/psa/psa_hash.c +++ b/programs/psa/psa_hash.c @@ -134,13 +134,12 @@ int main(void) return EXIT_FAILURE; } - for (size_t j = 0; j < test_sha256_hash_len; j++) { - if (hash[j] != test_sha256_hash[j]) { - mbedtls_printf("One-shot hash operation gave the wrong result!\n\n"); - psa_hash_abort(&hash_operation); - psa_hash_abort(&cloned_hash_operation); - return EXIT_FAILURE; - } + if (memcmp(hash, test_sha256_hash, test_sha256_hash_len) != 0) + { + mbedtls_printf("One-shot hash operation gave the wrong result!\n\n"); + psa_hash_abort(&hash_operation); + psa_hash_abort(&cloned_hash_operation); + return EXIT_FAILURE; } mbedtls_printf("One-shot hash operation successful!\n\n");