diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 0660ee411b..49dd915463 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1786,7 +1786,6 @@ static psa_status_t psa_start_key_creation( * definition. */ slot->attr = attributes->core; - slot->status = PSA_SLOT_OCCUPIED; if (PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)) { #if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) slot->attr.id = volatile_key_id; @@ -1850,6 +1849,8 @@ static psa_status_t psa_start_key_creation( } #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ + slot->status = PSA_SLOT_OCCUPIED; + return PSA_SUCCESS; } diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index 36d541044a..38e3273851 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -221,7 +221,6 @@ static psa_status_t psa_load_persistent_key_into_slot(psa_key_slot_t *slot) if (status != PSA_SUCCESS) { goto exit; } - slot->status = PSA_SLOT_OCCUPIED; #if defined(MBEDTLS_PSA_CRYPTO_SE_C) /* Special handling is required for loading keys associated with a @@ -243,6 +242,11 @@ static psa_status_t psa_load_persistent_key_into_slot(psa_key_slot_t *slot) #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ status = psa_copy_key_material_into_slot(slot, key_data, key_data_length); + if (status != PSA_SUCCESS){ + goto exit; + } + + slot->status = PSA_SLOT_OCCUPIED; exit: psa_free_persistent_key_data(key_data, key_data_length);