@@ -79,6 +79,82 @@ void test_open_other_partition_key(void)
79
79
TEST_ASSERT_EQUAL (PSA_ERROR_DOES_NOT_EXIST, psa_open_key (PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle));
80
80
}
81
81
82
+ void test_create_key_same_id_different_partitions (void )
83
+ {
84
+ static const psa_key_id_t key_id = 999 ;
85
+ static const psa_key_type_t key_type = PSA_KEY_TYPE_AES;
86
+ static const psa_key_usage_t key_usage_remote = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT,
87
+ key_usage_local = PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY;
88
+ static const psa_algorithm_t key_alg = PSA_ALG_CBC_NO_PADDING;
89
+ static const size_t key_bits_remote = 128 ,
90
+ key_bits_local = 256 ;
91
+ psa_key_handle_t key_handle_remote = 0 ,
92
+ key_handle_local = 0 ;
93
+ psa_key_type_t got_key_type_remote = 0 ,
94
+ got_key_type_local = 0 ;
95
+ size_t got_key_bits_remote = 0 ,
96
+ got_key_bits_local = 0 ;
97
+ psa_key_usage_t got_key_usage_remote = 0 ;
98
+ psa_algorithm_t got_key_alg_remote = 0 ;
99
+ psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
100
+
101
+ /* 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));
107
+
108
+ /* create a key, set key policy, generate key material and close from current partition (i.e. NSPE) */
109
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_create_key (PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle_local));
110
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle_local);
111
+ psa_key_policy_set_usage (&policy, key_usage_local, key_alg);
112
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_set_key_policy (key_handle_local, &policy));
113
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_generate_key (key_handle_local, key_type, key_bits_local, NULL , 0 ));
114
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_close_key (key_handle_local));
115
+
116
+ /* via test partition - reopen the key created by the test partition */
117
+ key_handle_remote = 0 ;
118
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_open_persistent_key (key_id, &key_handle_remote));
119
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle_remote);
120
+
121
+ /* reopen the key created from the current partition (NSPE) */
122
+ key_handle_local = 0 ;
123
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_open_key (PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle_local));
124
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle_local);
125
+
126
+ /* via test partition - get key info for the key created by the test partition */
127
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_get_key_information (key_handle_remote,
128
+ &got_key_type_remote,
129
+ &got_key_bits_remote));
130
+ TEST_ASSERT_EQUAL (key_type, got_key_type_remote);
131
+ TEST_ASSERT_EQUAL (key_bits_remote, got_key_bits_remote);
132
+
133
+ /* via test partition - get key policy for key created by the test partition */
134
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_get_key_policy (key_handle_remote,
135
+ &got_key_usage_remote,
136
+ &got_key_alg_remote));
137
+ TEST_ASSERT_EQUAL (key_usage_remote, got_key_usage_remote);
138
+ TEST_ASSERT_EQUAL (key_alg, got_key_alg_remote);
139
+
140
+ /* get key info for key created by the current partition (NSPE) */
141
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_get_key_information (key_handle_local, &got_key_type_local, &got_key_bits_local));
142
+ TEST_ASSERT_EQUAL (key_type, got_key_type_local);
143
+ TEST_ASSERT_EQUAL (key_bits_local, got_key_bits_local);
144
+
145
+ /* get key policy for key created by the current partition (NSPE) */
146
+ policy = psa_key_policy_init ();
147
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_get_key_policy (key_handle_local, &policy));
148
+ TEST_ASSERT_EQUAL (key_usage_local, policy.usage );
149
+ TEST_ASSERT_EQUAL (key_alg, policy.alg );
150
+
151
+ /* via test partition - close the key created by the test partition */
152
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle_remote));
153
+
154
+ /* close the key created by the current partition (NSPE) */
155
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_close_key (key_handle_local));
156
+ }
157
+
82
158
utest::v1::status_t case_setup_handler (const Case *const source, const size_t index_of_case)
83
159
{
84
160
psa_status_t status = mbed_psa_reboot_and_request_new_security_state (PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
@@ -114,6 +190,8 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
114
190
Case cases[] = {
115
191
Case (" open other partitions' key" ,
116
192
case_setup_handler, test_open_other_partition_key, case_teardown_handler),
193
+ Case (" create key with same id different partitions" ,
194
+ case_setup_handler, test_create_key_same_id_different_partitions, case_teardown_handler),
117
195
};
118
196
119
197
Specification specification (test_setup, cases);
0 commit comments