@@ -51,6 +51,21 @@ void inject_entropy()
51
51
}
52
52
#endif // defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
53
53
54
+ static psa_status_t create_and_generate_key_via_test_partition (psa_key_id_t key_id, psa_key_type_t key_type,
55
+ psa_algorithm_t key_alg, psa_key_usage_t key_usage,
56
+ size_t key_bits, psa_key_handle_t *key_handle,
57
+ unsigned char close_key)
58
+ {
59
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_create_persistent_key (key_id, key_handle));
60
+ TEST_ASSERT_NOT_EQUAL (0 , *key_handle);
61
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_set_key_policy (*key_handle, key_usage, key_alg));
62
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_generate_key (*key_handle, key_type, key_bits));
63
+ if (close_key) {
64
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (*key_handle));
65
+ }
66
+ return (PSA_SUCCESS);
67
+ }
68
+
54
69
void test_open_other_partition_key (void )
55
70
{
56
71
static const psa_key_id_t key_id = 999 ;
@@ -61,11 +76,8 @@ void test_open_other_partition_key(void)
61
76
psa_key_handle_t key_handle = 0 ;
62
77
63
78
/* via test partition - create a key, set key policy, generate key material and close */
64
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_create_persistent_key (key_id, &key_handle));
65
- TEST_ASSERT_NOT_EQUAL (0 , key_handle);
66
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_set_key_policy (key_handle, key_usage, key_alg));
67
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_generate_key (key_handle, key_type, key_bits));
68
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
79
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, create_and_generate_key_via_test_partition (key_id, key_type, key_alg, key_usage,
80
+ key_bits, &key_handle, 1 ));
69
81
70
82
/* via test partition - reopen the key created by the test partition */
71
83
key_handle = 0 ;
@@ -99,11 +111,9 @@ void test_create_key_same_id_different_partitions(void)
99
111
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
100
112
101
113
/* via test partition - create a key, set key policy, generate key material and close */
102
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_create_persistent_key (key_id, &key_handle_remote));
103
- TEST_ASSERT_NOT_EQUAL (0 , key_handle_remote);
104
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_set_key_policy (key_handle_remote, key_usage_remote, key_alg));
105
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_generate_key (key_handle_remote, key_type, key_bits_remote));
106
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle_remote));
114
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, create_and_generate_key_via_test_partition (key_id, key_type, key_alg,
115
+ key_usage_remote, key_bits_remote,
116
+ &key_handle_remote, 1 ));
107
117
108
118
/* create a key, set key policy, generate key material and close from current partition (i.e. NSPE) */
109
119
TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_create_key (PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle_local));
0 commit comments