Enrollment algorithm in policy: add support in psa_copy_key tests
Add parameters to psa_copy_key tests for the enrollment algorithm (alg2).
This commit only tests with alg2=0, which is equivalent to not setting
an enrollment algorithm.
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 6aed64d..b5bf7de 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -1969,30 +1969,38 @@
/* END_CASE */
/* BEGIN_CASE */
-void copy_key_policy( int source_usage_arg, int source_alg_arg,
+void copy_key_policy( int source_usage_arg,
+ int source_alg_arg, int source_alg2_arg,
int type_arg, data_t *material,
- int target_usage_arg, int target_alg_arg,
- int constraint_usage_arg, int constraint_alg_arg,
- int expected_usage_arg, int expected_alg_arg )
+ int target_usage_arg,
+ int target_alg_arg, int target_alg2_arg,
+ int constraint_usage_arg,
+ int constraint_alg_arg, int constraint_alg2_arg,
+ int expected_usage_arg,
+ int expected_alg_arg, int expected_alg2_arg )
{
psa_key_usage_t source_usage = source_usage_arg;
psa_algorithm_t source_alg = source_alg_arg;
+ psa_algorithm_t source_alg2 = source_alg2_arg;
psa_key_handle_t source_handle = 0;
psa_key_policy_t source_policy = PSA_KEY_POLICY_INIT;
psa_key_type_t source_type = type_arg;
size_t source_bits;
psa_key_usage_t target_usage = target_usage_arg;
psa_algorithm_t target_alg = target_alg_arg;
+ psa_algorithm_t target_alg2 = target_alg2_arg;
psa_key_handle_t target_handle = 0;
psa_key_policy_t target_policy = PSA_KEY_POLICY_INIT;
psa_key_type_t target_type;
size_t target_bits;
psa_key_usage_t constraint_usage = constraint_usage_arg;
psa_algorithm_t constraint_alg = constraint_alg_arg;
+ psa_algorithm_t constraint_alg2 = constraint_alg2_arg;
psa_key_policy_t constraint = PSA_KEY_POLICY_INIT;
psa_key_policy_t *p_constraint = NULL;
psa_key_usage_t expected_usage = expected_usage_arg;
psa_algorithm_t expected_alg = expected_alg_arg;
+ psa_algorithm_t expected_alg2 = expected_alg2_arg;
uint8_t *export_buffer = NULL;
if( constraint_usage_arg != -1 )
@@ -2000,6 +2008,8 @@
p_constraint = &constraint;
psa_key_policy_set_usage( p_constraint,
constraint_usage, constraint_alg );
+ psa_key_policy_set_enrollment_algorithm( p_constraint,
+ constraint_alg2 );
}
PSA_ASSERT( psa_crypto_init( ) );
@@ -2007,6 +2017,7 @@
/* Populate the source slot. */
PSA_ASSERT( psa_allocate_key( &source_handle ) );
psa_key_policy_set_usage( &source_policy, source_usage, source_alg );
+ psa_key_policy_set_enrollment_algorithm( &source_policy, source_alg2 );
PSA_ASSERT( psa_set_key_policy( source_handle, &source_policy ) );
PSA_ASSERT( psa_import_key( source_handle, source_type,
material->x, material->len ) );
@@ -2015,6 +2026,7 @@
/* Prepare the target slot. */
PSA_ASSERT( psa_allocate_key( &target_handle ) );
psa_key_policy_set_usage( &target_policy, target_usage, target_alg );
+ psa_key_policy_set_enrollment_algorithm( &target_policy, target_alg2 );
PSA_ASSERT( psa_set_key_policy( target_handle, &target_policy ) );
target_policy = psa_key_policy_init();
@@ -2032,6 +2044,8 @@
PSA_ASSERT( psa_get_key_policy( target_handle, &target_policy ) );
TEST_EQUAL( expected_usage, psa_key_policy_get_usage( &target_policy ) );
TEST_EQUAL( expected_alg, psa_key_policy_get_algorithm( &target_policy ) );
+ TEST_EQUAL( expected_alg2,
+ psa_key_policy_get_enrollment_algorithm( &target_policy ) );
if( expected_usage & PSA_KEY_USAGE_EXPORT )
{
size_t length;
@@ -2053,10 +2067,11 @@
/* END_CASE */
/* BEGIN_CASE */
-void copy_fail( int source_usage_arg, int source_alg_arg,
+void copy_fail( int source_usage_arg, int source_alg_arg, int source_alg2_arg,
int type_arg, data_t *material,
- int target_usage_arg, int target_alg_arg,
- int constraint_usage_arg, int constraint_alg_arg,
+ int target_usage_arg, int target_alg_arg, int target_alg2_arg,
+ int constraint_usage_arg,
+ int constraint_alg_arg, int constraint_alg2_arg,
int expected_status_arg )
{
/* Test copy failure into an empty slot. There is a test for copy failure
@@ -2065,18 +2080,21 @@
psa_key_usage_t source_usage = source_usage_arg;
psa_algorithm_t source_alg = source_alg_arg;
+ psa_algorithm_t source_alg2 = source_alg2_arg;
psa_key_handle_t source_handle = 0;
psa_key_policy_t source_policy = PSA_KEY_POLICY_INIT;
psa_key_type_t source_type = type_arg;
size_t source_bits;
psa_key_usage_t target_usage = target_usage_arg;
psa_algorithm_t target_alg = target_alg_arg;
+ psa_algorithm_t target_alg2 = target_alg2_arg;
psa_key_handle_t target_handle = 0;
psa_key_policy_t target_policy = PSA_KEY_POLICY_INIT;
psa_key_type_t target_type;
size_t target_bits;
psa_key_usage_t constraint_usage = constraint_usage_arg;
psa_algorithm_t constraint_alg = constraint_alg_arg;
+ psa_algorithm_t constraint_alg2 = constraint_alg2_arg;
psa_key_policy_t constraint = PSA_KEY_POLICY_INIT;
psa_key_policy_t *p_constraint = NULL;
psa_status_t expected_status = expected_status_arg;
@@ -2086,6 +2104,8 @@
p_constraint = &constraint;
psa_key_policy_set_usage( p_constraint,
constraint_usage, constraint_alg );
+ psa_key_policy_set_enrollment_algorithm( p_constraint,
+ constraint_alg2 );
}
PSA_ASSERT( psa_crypto_init( ) );
@@ -2093,6 +2113,7 @@
/* Populate the source slot. */
PSA_ASSERT( psa_allocate_key( &source_handle ) );
psa_key_policy_set_usage( &source_policy, source_usage, source_alg );
+ psa_key_policy_set_enrollment_algorithm( &source_policy, source_alg2 );
PSA_ASSERT( psa_set_key_policy( source_handle, &source_policy ) );
PSA_ASSERT( psa_import_key( source_handle, source_type,
material->x, material->len ) );
@@ -2101,6 +2122,7 @@
/* Prepare the target slot. */
PSA_ASSERT( psa_allocate_key( &target_handle ) );
psa_key_policy_set_usage( &target_policy, target_usage, target_alg );
+ psa_key_policy_set_enrollment_algorithm( &target_policy, target_alg2 );
PSA_ASSERT( psa_set_key_policy( target_handle, &target_policy ) );
target_policy = psa_key_policy_init();
@@ -2115,6 +2137,8 @@
PSA_ASSERT( psa_get_key_policy( target_handle, &target_policy ) );
TEST_EQUAL( target_usage, psa_key_policy_get_usage( &target_policy ) );
TEST_EQUAL( target_alg, psa_key_policy_get_algorithm( &target_policy ) );
+ TEST_EQUAL( target_alg2,
+ psa_key_policy_get_enrollment_algorithm( &target_policy ) );
exit:
mbedtls_psa_crypto_free( );