Make empty key slots explicit
Add new status field to key slots, and use it.
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index bbd6b24..0660ee4 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1786,6 +1786,7 @@
* 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 d406ce4..700e0fe 100644
--- a/library/psa_crypto_core.h
+++ b/library/psa_crypto_core.h
@@ -39,6 +39,11 @@
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 @@
*/
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 3b8a319..36d5410 100644
--- a/library/psa_crypto_slot_management.c
+++ b/library/psa_crypto_slot_management.c
@@ -221,6 +221,7 @@
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 @@
/* 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) {