From 1459b7af04ac0bfe4ade114826f666e9f4f3f07b Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Sat, 1 May 2021 15:02:51 +0200 Subject: [PATCH] tests: driver wrappers: Add hash finish tests Signed-off-by: Ronald Cron --- ...test_suite_psa_crypto_driver_wrappers.data | 8 +++ ..._suite_psa_crypto_driver_wrappers.function | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.data b/tests/suites/test_suite_psa_crypto_driver_wrappers.data index 17e7b03c1..5fbfac66a 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.data +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.data @@ -306,6 +306,14 @@ Hash multi-part update: SHA-256, update failure depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED +Hash multi-part finish: SHA-256, finish successful +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS + +Hash multi-part finish: SHA-256, finish failure +depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 +hash_multipart_update:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_ERROR_NOT_SUPPORTED + Hash clone: SHA-256, clone successful depends_on:MBEDTLS_PSA_ACCEL_ALG_SHA_256 hash_clone:PSA_ALG_SHA_256:"b0bd69":"4096804221093ddccfbf46831490ea63e9e99414858f8d75ff7f642c7ca61803":PSA_SUCCESS diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index a1dd2bc11..8969e22b6 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -1207,6 +1207,58 @@ exit: } /* END_CASE */ +/* BEGIN_CASE */ +void hash_multipart_finish( int alg_arg, + data_t *input, data_t *hash, + int forced_status_arg ) +{ + psa_algorithm_t alg = alg_arg; + psa_status_t forced_status = forced_status_arg; + unsigned char *output = NULL; + psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; + size_t output_length; + + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); + ASSERT_ALLOC( output, PSA_HASH_LENGTH( alg ) ); + + PSA_ASSERT( psa_crypto_init( ) ); + + /* + * Finish none active operation, the driver shouldn't be called. + */ + TEST_EQUAL( psa_hash_finish( &operation, output, PSA_HASH_LENGTH( alg ), + &output_length ), + PSA_ERROR_BAD_STATE ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 0 ); + + PSA_ASSERT( psa_hash_setup( &operation, alg ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 1 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + PSA_ASSERT( psa_hash_update( &operation, input->x, input->len ) ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 2 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS ); + + mbedtls_test_driver_hash_hooks.forced_status = forced_status; + TEST_EQUAL( psa_hash_finish( &operation, + output, PSA_HASH_LENGTH( alg ), + &output_length ), + forced_status ); + /* Two more calls to the driver interface: finish + abort */ + TEST_EQUAL( mbedtls_test_driver_hash_hooks.hits, 4 ); + TEST_EQUAL( mbedtls_test_driver_hash_hooks.driver_status, forced_status ); + + if( forced_status == PSA_SUCCESS ) + ASSERT_COMPARE( output, output_length, hash->x, hash->len ); + +exit: + psa_hash_abort( &operation ); + mbedtls_free( output ); + PSA_DONE( ); + mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init(); +} +/* END_CASE */ + /* BEGIN_CASE */ void hash_clone( int alg_arg, data_t *input, data_t *hash,