From e1f932ba4d1a6f54870d7151a6b1ec829d073b08 Mon Sep 17 00:00:00 2001 From: itayzafrir Date: Mon, 29 Oct 2018 13:34:37 +0200 Subject: [PATCH] Refactor hash multi part test Refactor test hash_multi_part to test various sizes when calling psa_hash_update. --- .../test_suite_psa_crypto_hash.function | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto_hash.function b/tests/suites/test_suite_psa_crypto_hash.function index 75878ef3c..14e6a9769 100644 --- a/tests/suites/test_suite_psa_crypto_hash.function +++ b/tests/suites/test_suite_psa_crypto_hash.function @@ -64,29 +64,32 @@ exit: void hash_multi_part( int alg_arg, data_t *input, data_t *expected_hash ) { psa_algorithm_t alg = alg_arg; - unsigned char actual_hash[PSA_HASH_MAX_SIZE] = { 0 }; + unsigned char actual_hash[PSA_HASH_MAX_SIZE]; size_t actual_hash_length; psa_hash_operation_t operation; - uint32_t halfway; + uint32_t len = 0; TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); - TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS ); + do + { + memset( actual_hash, 0, sizeof( actual_hash ) ); + TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS ); - halfway = input->len / 2; - TEST_ASSERT( psa_hash_update( &operation, - input->x, - halfway ) == PSA_SUCCESS ); - TEST_ASSERT( psa_hash_update( &operation, - input->x + halfway, - input->len - halfway ) == PSA_SUCCESS ); + TEST_ASSERT( psa_hash_update( &operation, + input->x, len ) == PSA_SUCCESS ); + TEST_ASSERT( psa_hash_update( &operation, + input->x + len, input->len - len ) == + PSA_SUCCESS ); - TEST_ASSERT( psa_hash_finish( &operation, - actual_hash, sizeof( actual_hash ), - &actual_hash_length ) == PSA_SUCCESS ); + TEST_ASSERT( psa_hash_finish( &operation, + actual_hash, sizeof( actual_hash ), + &actual_hash_length ) == PSA_SUCCESS ); - ASSERT_COMPARE( expected_hash->x, expected_hash->len, - actual_hash, actual_hash_length ); + ASSERT_COMPARE( expected_hash->x, expected_hash->len, + actual_hash, actual_hash_length ); + + } while( len++ != input->len ); exit: mbedtls_psa_crypto_free( );