Split test hash_bad_paths into 3 different tests
1. Rename hash_bad_paths to hash_verify_bad_paths
2. Add test hash_update_bad_paths
3. Add test hash_finish_bad_paths
The different scenarios tested as part of hash_bad_paths are
moved to the relevant test.
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index 01ca74f..507ca9b 100644
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -356,9 +356,17 @@
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
hash_setup:PSA_ALG_HMAC(PSA_ALG_SHA_256):PSA_ERROR_INVALID_ARGUMENT
-PSA hash: bad paths
+PSA hash verify: bad paths
depends_on:MBEDTLS_SHA256_C
-hash_bad_paths:
+hash_verify_bad_paths:
+
+PSA hash update: bad paths
+depends_on:MBEDTLS_SHA256_C
+hash_update_bad_paths:
+
+PSA hash finish: bad paths
+depends_on:MBEDTLS_SHA256_C
+hash_finish_bad_paths:
PSA MAC setup: good, HMAC-SHA-256
depends_on:MBEDTLS_MD_C:MBEDTLS_SHA256_C
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 0d292e3..3db6df5 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -1568,14 +1568,13 @@
/* END_CASE */
/* BEGIN_CASE */
-void hash_bad_paths( )
+void hash_verify_bad_paths( )
{
psa_algorithm_t alg = PSA_ALG_SHA_256;
unsigned char hash[PSA_HASH_MAX_SIZE] = { 0 };
size_t expected_size = PSA_HASH_SIZE( alg );
unsigned char input[] = "input";
psa_hash_operation_t operation;
- size_t hash_len;
/* SHA-256 hash digest of the string 'input' with 2 extra bytes appended at
* the end */
@@ -1588,31 +1587,12 @@
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
- /* psa_hash_update without calling psa_hash_setup beforehand */
- memset( &operation, 0, sizeof( operation ) );
- TEST_ASSERT( psa_hash_update( &operation,
- input, sizeof( input ) ) ==
- PSA_ERROR_INVALID_ARGUMENT );
-
- /* psa_hash_finish without calling psa_hash_setup beforehand */
- memset( &operation, 0, sizeof( operation ) );
- TEST_ASSERT( psa_hash_finish( &operation,
- hash, expected_size,
- &hash_len ) == PSA_ERROR_INVALID_ARGUMENT );
-
/* psa_hash_verify without calling psa_hash_setup beforehand */
memset( &operation, 0, sizeof( operation ) );
TEST_ASSERT( psa_hash_verify( &operation,
hash, expected_size ) ==
PSA_ERROR_INVALID_ARGUMENT );
- /* psa_hash_finish with a smaller hash buffer than expected */
- TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
- TEST_ASSERT( psa_hash_finish( &operation,
- hash, expected_size - 1,
- &hash_len ) == PSA_ERROR_BUFFER_TOO_SMALL );
-
-
/* psa_hash_verify with a smaller hash digest than expected */
TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
TEST_ASSERT( psa_hash_verify( &operation,
@@ -1645,6 +1625,53 @@
/* END_CASE */
/* BEGIN_CASE */
+void hash_update_bad_paths( )
+{
+ unsigned char input[] = "input";
+ psa_hash_operation_t operation;
+
+ TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
+
+ /* psa_hash_update without calling psa_hash_setup beforehand */
+ memset( &operation, 0, sizeof( operation ) );
+ TEST_ASSERT( psa_hash_update( &operation,
+ input, sizeof( input ) ) ==
+ PSA_ERROR_INVALID_ARGUMENT );
+
+exit:
+ mbedtls_psa_crypto_free( );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
+void hash_finish_bad_paths( )
+{
+ psa_algorithm_t alg = PSA_ALG_SHA_256;
+ unsigned char hash[PSA_HASH_MAX_SIZE] = { 0 };
+ size_t expected_size = PSA_HASH_SIZE( alg );
+ psa_hash_operation_t operation;
+ size_t hash_len;
+
+ TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
+
+ /* psa_hash_finish without calling psa_hash_setup beforehand */
+ memset( &operation, 0, sizeof( operation ) );
+ TEST_ASSERT( psa_hash_finish( &operation,
+ hash, expected_size,
+ &hash_len ) == PSA_ERROR_INVALID_ARGUMENT );
+
+ /* psa_hash_finish with a smaller hash buffer than expected */
+ TEST_ASSERT( psa_hash_setup( &operation, alg ) == PSA_SUCCESS );
+ TEST_ASSERT( psa_hash_finish( &operation,
+ hash, expected_size - 1,
+ &hash_len ) == PSA_ERROR_BUFFER_TOO_SMALL );
+
+exit:
+ mbedtls_psa_crypto_free( );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
void mac_setup( int key_type_arg,
data_t *key,
int alg_arg,