fix key lifetime set implementation , tests accordingly
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index bdb47d2..152fb17 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1297,8 +1297,8 @@
return( PSA_ERROR_INVALID_ARGUMENT );
slot = &global_data.key_slots[key];
- if( slot->type == PSA_KEY_TYPE_NONE )
- return( PSA_ERROR_EMPTY_SLOT );
+ if( slot->type != PSA_KEY_TYPE_NONE )
+ return( PSA_ERROR_OCCUPIED_SLOT );
if ( lifetime != PSA_KEY_LIFETIME_VOLATILE )
return( PSA_ERROR_NOT_SUPPORTED );
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index be31c39..6fd66ee 100644
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -90,9 +90,6 @@
PSA Key Lifetime set fail, invalid key slot
key_lifetime_set_fail:0:PSA_KEY_LIFETIME_VOLATILE:PSA_ERROR_INVALID_ARGUMENT
-PSA Key Lifetime set fail, unoccupied key slot
-key_lifetime_set_fail:2:PSA_KEY_LIFETIME_VOLATILE:PSA_ERROR_EMPTY_SLOT
-
PSA Key Lifetime set fail, can not change write_once lifetime
key_lifetime_set_fail:1:PSA_KEY_LIFETIME_WRITE_ONCE:PSA_ERROR_NOT_SUPPORTED
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 7cb38d9..c1bbe17 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -374,11 +374,11 @@
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
- TEST_ASSERT( psa_import_key( key_slot, key_type,
- key, sizeof( key ) ) == PSA_SUCCESS );
-
TEST_ASSERT( psa_set_key_lifetime( key_slot,
lifetime_set ) == PSA_SUCCESS );
+
+ TEST_ASSERT( psa_import_key( key_slot, key_type,
+ key, sizeof( key ) ) == PSA_SUCCESS );
TEST_ASSERT( psa_get_key_lifetime( key_slot,
&lifetime_get ) == PSA_SUCCESS );
@@ -396,19 +396,12 @@
void key_lifetime_set_fail( int key_slot_arg, int lifetime_arg, int expected_status_arg )
{
int key_slot = 1;
- psa_key_type_t key_type = PSA_ALG_CBC_BASE;
- unsigned char key[32] = {0};
psa_key_lifetime_t lifetime_set = (psa_key_lifetime_t) lifetime_arg;
psa_status_t actual_status;
psa_status_t expected_status = expected_status_arg;
- memset( key, 0x2a, sizeof( key ) );
-
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
- TEST_ASSERT( psa_import_key( key_slot, key_type,
- key, sizeof( key ) ) == PSA_SUCCESS );
-
actual_status = psa_set_key_lifetime( key_slot_arg, lifetime_set );
if( actual_status == PSA_SUCCESS )