Test psa_copy_key with wrong type or size in attributes
Split the test function copy_key into two: one for success and one for
failure.
Add failure tests where the attributes specify an incorrect type or size.
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index cddcb2e..c48ee64 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -1924,12 +1924,11 @@
/* END_CASE */
/* BEGIN_CASE */
-void copy_key( int source_usage_arg, int source_alg_arg,
- int type_arg, data_t *material,
- int copy_attributes,
- int target_usage_arg, int target_alg_arg,
- int expected_status_arg,
- int expected_usage_arg, int expected_alg_arg )
+void copy_success( int source_usage_arg, int source_alg_arg,
+ int type_arg, data_t *material,
+ int copy_attributes,
+ int target_usage_arg, int target_alg_arg,
+ int expected_usage_arg, int expected_alg_arg )
{
psa_key_attributes_t source_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t target_attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -1947,7 +1946,6 @@
psa_set_key_type( &source_attributes, type_arg );
PSA_ASSERT( psa_import_key( &source_attributes, &source_handle,
material->x, material->len ) );
- /* Retrieve the key size. */
PSA_ASSERT( psa_get_key_attributes( source_handle, &source_attributes ) );
/* Prepare the target attributes. */
@@ -1959,14 +1957,8 @@
psa_set_key_algorithm( &target_attributes, target_alg_arg );
/* Copy the key. */
- TEST_EQUAL( psa_copy_key( source_handle,
- &target_attributes, &target_handle ),
- expected_status_arg );
- if( expected_status_arg != PSA_SUCCESS )
- {
- TEST_EQUAL( target_handle, 0 );
- goto exit;
- }
+ PSA_ASSERT( psa_copy_key( source_handle,
+ &target_attributes, &target_handle ) );
/* Destroy the source to ensure that this doesn't affect the target. */
PSA_ASSERT( psa_destroy_key( source_handle ) );
@@ -2002,6 +1994,44 @@
/* END_CASE */
/* BEGIN_CASE */
+void copy_fail( int source_usage_arg, int source_alg_arg,
+ int type_arg, data_t *material,
+ int target_type_arg, int target_bits_arg,
+ int target_usage_arg, int target_alg_arg,
+ int expected_status_arg )
+{
+ psa_key_attributes_t source_attributes = PSA_KEY_ATTRIBUTES_INIT;
+ psa_key_attributes_t target_attributes = PSA_KEY_ATTRIBUTES_INIT;
+ psa_key_handle_t source_handle = 0;
+ psa_key_handle_t target_handle = 0;
+
+ PSA_ASSERT( psa_crypto_init( ) );
+
+ /* Prepare the source key. */
+ psa_set_key_usage_flags( &source_attributes, source_usage_arg );
+ psa_set_key_algorithm( &source_attributes, source_alg_arg );
+ psa_set_key_type( &source_attributes, type_arg );
+ PSA_ASSERT( psa_import_key( &source_attributes, &source_handle,
+ material->x, material->len ) );
+
+ /* Prepare the target attributes. */
+ psa_set_key_type( &target_attributes, target_type_arg );
+ psa_set_key_bits( &target_attributes, target_bits_arg );
+ psa_set_key_usage_flags( &target_attributes, target_usage_arg );
+ psa_set_key_algorithm( &target_attributes, target_alg_arg );
+
+ /* Try to copy the key. */
+ TEST_EQUAL( psa_copy_key( source_handle,
+ &target_attributes, &target_handle ),
+ expected_status_arg );
+exit:
+ psa_reset_key_attributes( &source_attributes );
+ psa_reset_key_attributes( &target_attributes );
+ mbedtls_psa_crypto_free( );
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
void hash_operation_init( )
{
const uint8_t input[1] = { 0 };