diff --git a/library/psa_crypto.c b/library/psa_crypto.c index bdb47d249..152fb17bf 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1297,8 +1297,8 @@ psa_status_t psa_set_key_lifetime(psa_key_slot_t key, 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 be31c39bd..6fd66ee2a 100644 --- a/tests/suites/test_suite_psa_crypto.data +++ b/tests/suites/test_suite_psa_crypto.data @@ -90,9 +90,6 @@ key_lifetime:PSA_KEY_LIFETIME_VOLATILE 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 7cb38d986..c1bbe17ee 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -374,11 +374,11 @@ void key_lifetime( int lifetime_arg ) 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 @@ exit: 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 )