@@ -89,6 +89,14 @@ void test_open_other_partition_key(void)
89
89
90
90
/* try to open the key created by the test partition */
91
91
TEST_ASSERT_EQUAL (PSA_ERROR_DOES_NOT_EXIST, psa_open_key (PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle));
92
+
93
+ /* via test partition - reopen the key created by the test partition and keep it open */
94
+ key_handle = 0 ;
95
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_open_persistent_key (key_id, &key_handle));
96
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
97
+
98
+ /* via test partition - destroy the key created by the test partition */
99
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
92
100
}
93
101
94
102
void test_create_key_same_id_different_partitions (void )
@@ -158,11 +166,11 @@ void test_create_key_same_id_different_partitions(void)
158
166
TEST_ASSERT_EQUAL (key_usage_local, policy.usage );
159
167
TEST_ASSERT_EQUAL (key_alg, policy.alg );
160
168
161
- /* via test partition - close the key created by the test partition */
162
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle_remote));
169
+ /* via test partition - destroy the key created by the test partition */
170
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle_remote));
163
171
164
- /* close the key created by the current partition (NSPE) */
165
- TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_close_key (key_handle_local));
172
+ /* destroy the key created by the current partition (NSPE) */
173
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, psa_destroy_key (key_handle_local));
166
174
}
167
175
168
176
void test_use_other_partition_key_manage_key (void )
@@ -235,8 +243,8 @@ void test_use_other_partition_key_manage_key(void)
235
243
/* via test partition - import key data for the key created by the test partition */
236
244
TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_import_key (key_handle, key_type, key_data, sizeof (key_data)));
237
245
238
- /* via test partition - close the key created by the test partition */
239
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
246
+ /* via test partition - destroy the key created by the test partition */
247
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
240
248
}
241
249
242
250
void test_use_other_partition_key_mac (void )
@@ -266,8 +274,8 @@ void test_use_other_partition_key_mac(void)
266
274
operation = psa_mac_operation_init ();
267
275
TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_mac_verify_setup (&operation, key_handle, key_alg));
268
276
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));
277
+ /* via test partition - destroy the key created by the test partition */
278
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
271
279
}
272
280
273
281
void test_use_other_partition_key_cipher (void )
@@ -297,8 +305,8 @@ void test_use_other_partition_key_cipher(void)
297
305
operation = psa_cipher_operation_init ();
298
306
TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_cipher_decrypt_setup (&operation, key_handle, key_alg));
299
307
300
- /* via test partition - close the key created by the test partition */
301
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
308
+ /* via test partition - destroy the key created by the test partition */
309
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
302
310
}
303
311
304
312
void test_use_other_partition_key_aead (void )
@@ -333,8 +341,8 @@ void test_use_other_partition_key_aead(void)
333
341
cipher_text, sizeof (cipher_text),
334
342
plain_text, sizeof (plain_text), &len));
335
343
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));
344
+ /* via test partition - destroy the key created by the test partition */
345
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
338
346
}
339
347
340
348
void test_use_other_partition_key_asymmetric_sign_verify (void )
@@ -366,8 +374,8 @@ void test_use_other_partition_key_asymmetric_sign_verify(void)
366
374
TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_asymmetric_verify (key_handle, key_alg, input, sizeof (input),
367
375
signature, sizeof (signature)));
368
376
369
- /* via test partition - close the key created by the test partition */
370
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
377
+ /* via test partition - destroy the key created by the test partition */
378
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
371
379
}
372
380
373
381
void test_use_other_partition_key_asymmetric_encrypt_decrypt (void )
@@ -438,8 +446,92 @@ void test_use_other_partition_key_asymmetric_encrypt_decrypt(void)
438
446
encrypted, sizeof (encrypted), NULL , 0 ,
439
447
decrypted, sizeof (decrypted), &len));
440
448
441
- /* via test partition - close the key created by the test partition */
442
- TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_close_key (key_handle));
449
+ /* via test partition - destroy the key created by the test partition */
450
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
451
+ }
452
+
453
+ void test_use_other_partition_key_derivation_setup (void )
454
+ {
455
+ static const psa_key_id_t key_id = 999 ;
456
+ static const psa_algorithm_t key_alg = PSA_ALG_HKDF (PSA_ALG_SHA_256);
457
+ static const psa_key_usage_t key_usage = PSA_KEY_USAGE_DERIVE;
458
+ static const psa_key_type_t key_type = PSA_KEY_TYPE_DERIVE;
459
+ static const unsigned char key_data[] = {
460
+ 0x30 , 0x82 , 0x01 , 0x3b , 0x02 , 0x01 , 0x00 , 0x02 , 0x41 , 0x00 , 0xee , 0x2b ,
461
+ 0x13 , 0x1d , 0x6b , 0x18 , 0x18 , 0xa9 , 0x4c , 0xa8 , 0xe9 , 0x1c , 0x42 , 0x38
462
+ };
463
+ static const unsigned char salt[] = {
464
+ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a , 0x0b ,
465
+ 0x0c
466
+ };
467
+ static const unsigned char label[] = {
468
+ 0xf0 , 0xf1 , 0xf2 , 0xf3 , 0xf4 , 0xf5 , 0xf6 , 0xf7 , 0xf8 , 0xf9
469
+ };
470
+
471
+ psa_key_handle_t key_handle = 0 ;
472
+ psa_crypto_generator_t generator = psa_crypto_generator_init ();
473
+ size_t bits = 128 ;
474
+
475
+ /* via test partition - create a key without generating any key material */
476
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_create_persistent_key (key_id, &key_handle));
477
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
478
+
479
+ /* via test partition - set key policy */
480
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_set_key_policy (key_handle, key_usage, key_alg));
481
+
482
+ /* via test partition - import key data for the key created by the test partition */
483
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_import_key (key_handle, key_type, key_data, sizeof (key_data)));
484
+
485
+ /* try to setup key derivation using the key that was created by the test partition */
486
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_key_derivation (&generator, key_handle, key_alg,
487
+ (unsigned char *)salt, sizeof (salt),
488
+ (unsigned char *)label, sizeof (label),
489
+ PSA_BITS_TO_BYTES (bits)));
490
+
491
+ /* via test partition - destroy the key created by the test partition */
492
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
493
+ }
494
+
495
+ void test_use_other_partition_key_agreement_setup (void )
496
+ {
497
+ static const psa_key_id_t key_id = 999 ;
498
+ static const psa_algorithm_t key_alg = PSA_ALG_ECDH (PSA_ALG_SELECT_RAW);
499
+ static const psa_key_usage_t key_usage = PSA_KEY_USAGE_DERIVE;
500
+ static const psa_key_type_t key_type = PSA_KEY_TYPE_ECC_KEYPAIR (PSA_ECC_CURVE_SECP256R1);
501
+ static const unsigned char key_data[] = {
502
+ 0xc8 , 0x8f , 0x01 , 0xf5 , 0x10 , 0xd9 , 0xac , 0x3f , 0x70 , 0xa2 , 0x92 , 0xda ,
503
+ 0xa2 , 0x31 , 0x6d , 0xe5 , 0x44 , 0xe9 , 0xaa , 0xb8 , 0xaf , 0xe8 , 0x40 , 0x49 ,
504
+ 0xc6 , 0x2a , 0x9c , 0x57 , 0x86 , 0x2d , 0x14 , 0x33
505
+ };
506
+ static const unsigned char peer_key_data[] = {
507
+ 0x04 , 0xd1 , 0x2d , 0xfb , 0x52 , 0x89 , 0xc8 , 0xd4 , 0xf8 , 0x12 , 0x08 , 0xb7 ,
508
+ 0x02 , 0x70 , 0x39 , 0x8c , 0x34 , 0x22 , 0x96 , 0x97 , 0x0a , 0x0b , 0xcc , 0xb7 ,
509
+ 0x4c , 0x73 , 0x6f , 0xc7 , 0x55 , 0x44 , 0x94 , 0xbf , 0x63 , 0x56 , 0xfb , 0xf3 ,
510
+ 0xca , 0x36 , 0x6c , 0xc2 , 0x3e , 0x81 , 0x57 , 0x85 , 0x4c , 0x13 , 0xc5 , 0x8d ,
511
+ 0x6a , 0xac , 0x23 , 0xf0 , 0x46 , 0xad , 0xa3 , 0x0f , 0x83 , 0x53 , 0xe7 , 0x4f ,
512
+ 0x33 , 0x03 , 0x98 , 0x72 , 0xab
513
+ };
514
+
515
+ psa_key_handle_t key_handle = 0 ;
516
+ psa_crypto_generator_t generator = psa_crypto_generator_init ();
517
+
518
+ /* via test partition - create a key without generating any key material */
519
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_create_persistent_key (key_id, &key_handle));
520
+ TEST_ASSERT_NOT_EQUAL (0 , key_handle);
521
+
522
+ /* via test partition - set key policy */
523
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_set_key_policy (key_handle, key_usage, key_alg));
524
+
525
+ /* via test partition - import key data for the key created by the test partition */
526
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_import_key (key_handle, key_type, key_data, sizeof (key_data)));
527
+
528
+ /* try to setup key agreement using the key that was created by the test partition */
529
+ TEST_ASSERT_EQUAL (PSA_ERROR_INVALID_HANDLE, psa_key_agreement (&generator, key_handle,
530
+ (unsigned char *)peer_key_data, sizeof (peer_key_data),
531
+ key_alg));
532
+
533
+ /* via test partition - destroy the key created by the test partition */
534
+ TEST_ASSERT_EQUAL (PSA_SUCCESS, test_partition_crypto_destroy_key (key_handle));
443
535
}
444
536
445
537
utest::v1::status_t case_setup_handler (const Case *const source, const size_t index_of_case)
@@ -473,22 +565,26 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
473
565
}
474
566
475
567
Case cases[] = {
476
- Case (" open other partitions' key" ,
568
+ Case (" open other partition's key" ,
477
569
case_setup_handler, test_open_other_partition_key, case_teardown_handler),
478
570
Case (" create key with same id different partitions" ,
479
571
case_setup_handler, test_create_key_same_id_different_partitions, case_teardown_handler),
480
- Case (" use other partitions' key - key manage" ,
572
+ Case (" use other partition's key - key manage" ,
481
573
case_setup_handler, test_use_other_partition_key_manage_key, case_teardown_handler),
482
- Case (" use other partitions' key - mac" ,
574
+ Case (" use other partition's key - mac" ,
483
575
case_setup_handler, test_use_other_partition_key_mac, case_teardown_handler),
484
- Case (" use other partitions' key - cipher" ,
576
+ Case (" use other partition's key - cipher" ,
485
577
case_setup_handler, test_use_other_partition_key_cipher, case_teardown_handler),
486
- Case (" use other partitions' key - aead" ,
578
+ Case (" use other partition's key - aead" ,
487
579
case_setup_handler, test_use_other_partition_key_aead, case_teardown_handler),
488
- Case (" use other partitions' key - asymmetric sign verify" ,
580
+ Case (" use other partition's key - asymmetric sign verify" ,
489
581
case_setup_handler, test_use_other_partition_key_asymmetric_sign_verify, case_teardown_handler),
490
- Case (" use other partitions' key - asymmetric encrypt decrypt" ,
582
+ Case (" use other partition's key - asymmetric encrypt decrypt" ,
491
583
case_setup_handler, test_use_other_partition_key_asymmetric_encrypt_decrypt, case_teardown_handler),
584
+ Case (" use other partition's key - key derivation setup" ,
585
+ case_setup_handler, test_use_other_partition_key_derivation_setup, case_teardown_handler),
586
+ Case (" use other partition's key - key agreement setup" ,
587
+ case_setup_handler, test_use_other_partition_key_agreement_setup, case_teardown_handler),
492
588
};
493
589
494
590
Specification specification (test_setup, cases);
0 commit comments