@@ -239,6 +239,37 @@ void test_use_other_partition_key_manage_key(void)
239
239
TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
240
240
}
241
241
242
+ void test_use_other_partition_key_mac (void )
243
+ {
244
+ static const psa_key_id_t key_id = 999 ;
245
+ static const psa_key_type_t key_type = PSA_KEY_TYPE_AES;
246
+ static const psa_algorithm_t key_alg = PSA_ALG_CBC_NO_PADDING;
247
+ static const psa_key_usage_t key_usage = PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY;
248
+ static const size_t key_bits = 128 ;
249
+ psa_key_handle_t key_handle = 0 ;
250
+ psa_mac_operation_t operation;
251
+
252
+ /* via test partition - create a key, set key policy, generate key material and close */
253
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, create_and_generate_key_via_test_partition (key_id, key_type, key_alg, key_usage,
254
+ key_bits, &key_handle, 1 ));
255
+
256
+ /* via test partition - reopen the key created by the test partition */
257
+ key_handle = 0 ;
258
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_open_persistent_key (key_id, &key_handle));
259
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
260
+
261
+ /* try to setup mac sign operation using the key that was created by the test partition */
262
+ operation = psa_mac_operation_init ();
263
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_mac_sign_setup (&operation, key_handle, key_alg));
264
+
265
+ /* try to setup mac verify operation using the key that was created by the test partition */
266
+ operation = psa_mac_operation_init ();
267
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_mac_verify_setup (&operation, key_handle, key_alg));
268
+
269
+ /* via test partition - close the key created by the test partition */
270
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
271
+ }
272
+
242
273
utest::v1::status_t case_setup_handler (const Case *const source, const size_t index_of_case)
243
274
{
244
275
psa_status_t status = mbed_psa_reboot_and_request_new_security_state (PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
@@ -278,6 +309,8 @@ Case cases[] = {
278
309
case_setup_handler, test_create_key_same_id_different_partitions, case_teardown_handler),
279
310
Case (" use other partitions' key - key manage" ,
280
311
case_setup_handler, test_use_other_partition_key_manage_key, case_teardown_handler),
312
+ Case (" use other partitions' key - mac" ,
313
+ case_setup_handler, test_use_other_partition_key_mac, case_teardown_handler),
281
314
};
282
315
283
316
Specification specification (test_setup, cases);
0 commit comments