@@ -301,6 +301,42 @@ void test_use_other_partition_key_cipher(void)
301
301
TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
302
302
}
303
303
304
+ void test_use_other_partition_key_aead (void )
305
+ {
306
+ static const psa_key_id_t key_id = 999 ;
307
+ static const psa_key_type_t key_type = PSA_KEY_TYPE_AES;
308
+ static const psa_algorithm_t key_alg = PSA_ALG_GCM;
309
+ static const psa_key_usage_t key_usage = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT;
310
+ static const size_t key_bits = 128 ;
311
+ static const unsigned char nonce[16 ] = { 0 };
312
+ unsigned char plain_text[] = " encrypt me!" ;
313
+ unsigned char cipher_text[PSA_AEAD_ENCRYPT_OUTPUT_SIZE (key_alg, sizeof (plain_text))] = { 0 };
314
+ psa_key_handle_t key_handle = 0 ;
315
+ size_t len;
316
+
317
+ /* via test partition - create a key, set key policy, generate key material and close */
318
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, create_and_generate_key_via_test_partition (key_id, key_type, key_alg, key_usage,
319
+ key_bits, &key_handle, 1 ));
320
+
321
+ /* via test partition - reopen the key created by the test partition */
322
+ key_handle = 0 ;
323
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_open_persistent_key (key_id, &key_handle));
324
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
325
+
326
+ /* try to aead encrypt using the key that was created by the test partition */
327
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_aead_encrypt (key_handle, key_alg, nonce, sizeof (nonce), NULL , 0 ,
328
+ plain_text, sizeof (plain_text),
329
+ cipher_text, sizeof (cipher_text), &len));
330
+
331
+ /* try to aead decrypt using the key that was created by the test partition */
332
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_aead_decrypt (key_handle, key_alg, nonce, sizeof (nonce), NULL , 0 ,
333
+ cipher_text, sizeof (cipher_text),
334
+ plain_text, sizeof (plain_text), &len));
335
+
336
+ /* via test partition - close the key created by the test partition */
337
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
338
+ }
339
+
304
340
utest::v1::status_t case_setup_handler (const Case *const source, const size_t index_of_case)
305
341
{
306
342
psa_status_t status = mbed_psa_reboot_and_request_new_security_state (PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
@@ -344,6 +380,8 @@ Case cases[] = {
344
380
case_setup_handler, test_use_other_partition_key_mac, case_teardown_handler),
345
381
Case (" use other partitions' key - cipher" ,
346
382
case_setup_handler, test_use_other_partition_key_cipher, case_teardown_handler),
383
+ Case (" use other partitions' key - aead" ,
384
+ case_setup_handler, test_use_other_partition_key_aead, case_teardown_handler),
347
385
};
348
386
349
387
Specification specification (test_setup, cases);
0 commit comments