diff --git a/library/psa_crypto.c b/library/psa_crypto.c index bbd6b24ed4..0660ee411b 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1786,6 +1786,7 @@ 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; diff --git a/library/psa_crypto_core.h b/library/psa_crypto_core.h index d406ce459d..700e0fef66 100644 --- a/library/psa_crypto_core.h +++ b/library/psa_crypto_core.h @@ -39,6 +39,11 @@ int psa_can_do_hash(psa_algorithm_t hash_alg); typedef struct { psa_core_key_attributes_t attr; + enum { + PSA_SLOT_EMPTY = 0, + PSA_SLOT_OCCUPIED, + } status; + /* * Number of locks on the key slot held by the library. * @@ -88,7 +93,7 @@ typedef struct { */ static inline int psa_is_key_slot_occupied(const psa_key_slot_t *slot) { - return slot->attr.type != 0; + return slot->status == PSA_SLOT_OCCUPIED; } /** Test whether a key slot is locked. diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index 3b8a319cbb..36d541044a 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -221,6 +221,7 @@ 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 @@ -315,6 +316,7 @@ static psa_status_t psa_load_builtin_key_into_slot(psa_key_slot_t *slot) /* Copy actual key length and core attributes into the slot on success */ slot->key.bytes = key_buffer_length; slot->attr = attributes.core; + slot->status = PSA_SLOT_OCCUPIED; exit: if (status != PSA_SUCCESS) {