Skip to content

Commit fcfd4f3

Browse files
Test restarting after creating a key in a specific slot
1 parent 7a054e6 commit fcfd4f3

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

tests/suites/test_suite_psa_crypto_se_driver_hal.data

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,19 @@ SE key import-export, check after restart (slot 3)
4040
key_creation_import_export:3:1
4141

4242
Key creation in a specific slot (0)
43-
key_creation_in_chosen_slot:0:PSA_SUCCESS
43+
key_creation_in_chosen_slot:0:0:PSA_SUCCESS
4444

4545
Key creation in a specific slot (max)
46-
key_creation_in_chosen_slot:ARRAY_LENGTH( ram_slots ) - 1:PSA_SUCCESS
46+
key_creation_in_chosen_slot:ARRAY_LENGTH( ram_slots ) - 1:0:PSA_SUCCESS
47+
48+
Key creation in a specific slot (0, restart)
49+
key_creation_in_chosen_slot:0:1:PSA_SUCCESS
50+
51+
Key creation in a specific slot (max, restart)
52+
key_creation_in_chosen_slot:ARRAY_LENGTH( ram_slots ) - 1:1:PSA_SUCCESS
4753

4854
Key creation in a specific slot (too large)
49-
key_creation_in_chosen_slot:ARRAY_LENGTH( ram_slots ):PSA_ERROR_INVALID_ARGUMENT
55+
key_creation_in_chosen_slot:ARRAY_LENGTH( ram_slots ):0:PSA_ERROR_INVALID_ARGUMENT
5056

5157
Key creation smoke test: AES-CTR
5258
key_creation_smoke:PSA_KEY_TYPE_AES:PSA_ALG_CTR:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

tests/suites/test_suite_psa_crypto_se_driver_hal.function

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ exit:
550550

551551
/* BEGIN_CASE */
552552
void key_creation_in_chosen_slot( int slot_arg,
553+
int restart,
553554
int expected_status_arg )
554555
{
555556
psa_key_slot_number_t wanted_slot = slot_arg;
@@ -587,17 +588,26 @@ void key_creation_in_chosen_slot( int slot_arg,
587588
&handle );
588589
TEST_EQUAL( status, expected_status );
589590

590-
if( status == PSA_SUCCESS )
591+
if( status != PSA_SUCCESS )
592+
goto exit;
593+
594+
/* Maybe restart, to check that the information is saved correctly. */
595+
if( restart )
591596
{
592-
/* Test that the key was created in the expected slot. */
593-
TEST_EQUAL( ram_slots[wanted_slot].type, PSA_KEY_TYPE_RAW_DATA );
597+
mbedtls_psa_crypto_free( );
598+
PSA_ASSERT( psa_register_se_driver( lifetime, &driver ) );
599+
PSA_ASSERT( psa_crypto_init( ) );
600+
PSA_ASSERT( psa_open_key( id, &handle ) );
601+
}
602+
603+
/* Test that the key was created in the expected slot. */
604+
TEST_EQUAL( ram_slots[wanted_slot].type, PSA_KEY_TYPE_RAW_DATA );
594605

595-
/* Test that the key is reported with the correct attributes,
596-
* including the expected slot. */
597-
PSA_ASSERT( psa_get_key_attributes( handle, &attributes ) );
606+
/* Test that the key is reported with the correct attributes,
607+
* including the expected slot. */
608+
PSA_ASSERT( psa_get_key_attributes( handle, &attributes ) );
598609

599-
PSA_ASSERT( psa_destroy_key( handle ) );
600-
}
610+
PSA_ASSERT( psa_destroy_key( handle ) );
601611

602612
exit:
603613
PSA_DONE( );

0 commit comments

Comments
 (0)