Only set slot to OCCUPIED on successful key loading

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
This commit is contained in:
Ryan Everett 2023-11-16 13:37:51 +00:00
parent 34d6a5c3df
commit 975d411d92
2 changed files with 7 additions and 2 deletions

View file

@ -1786,7 +1786,6 @@ static psa_status_t psa_start_key_creation(
* definition. */ * definition. */
slot->attr = attributes->core; slot->attr = attributes->core;
slot->status = PSA_SLOT_OCCUPIED;
if (PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)) { if (PSA_KEY_LIFETIME_IS_VOLATILE(slot->attr.lifetime)) {
#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) #if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
slot->attr.id = volatile_key_id; slot->attr.id = volatile_key_id;
@ -1850,6 +1849,8 @@ static psa_status_t psa_start_key_creation(
} }
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
slot->status = PSA_SLOT_OCCUPIED;
return PSA_SUCCESS; return PSA_SUCCESS;
} }

View file

@ -221,7 +221,6 @@ static psa_status_t psa_load_persistent_key_into_slot(psa_key_slot_t *slot)
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
goto exit; goto exit;
} }
slot->status = PSA_SLOT_OCCUPIED;
#if defined(MBEDTLS_PSA_CRYPTO_SE_C) #if defined(MBEDTLS_PSA_CRYPTO_SE_C)
/* Special handling is required for loading keys associated with a /* 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 */ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
status = psa_copy_key_material_into_slot(slot, key_data, key_data_length); 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: exit:
psa_free_persistent_key_data(key_data, key_data_length); psa_free_persistent_key_data(key_data, key_data_length);