Make empty key slots explicit

Add new status field to key slots, and use it.

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
This commit is contained in:
Ryan Everett 2023-11-08 13:28:20 +00:00
parent c27a4ce3dd
commit 5567e3a34b
3 changed files with 9 additions and 1 deletions

View File

@ -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;

View File

@ -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.

View File

@ -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) {