mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-05 19:35:48 +03:00
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:
@@ -1786,6 +1786,7 @@ 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;
|
||||||
|
@@ -39,6 +39,11 @@ int psa_can_do_hash(psa_algorithm_t hash_alg);
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
psa_core_key_attributes_t attr;
|
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.
|
* 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)
|
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.
|
/** Test whether a key slot is locked.
|
||||||
|
@@ -221,6 +221,7 @@ 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
|
||||||
@@ -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 */
|
/* Copy actual key length and core attributes into the slot on success */
|
||||||
slot->key.bytes = key_buffer_length;
|
slot->key.bytes = key_buffer_length;
|
||||||
slot->attr = attributes.core;
|
slot->attr = attributes.core;
|
||||||
|
slot->status = PSA_SLOT_OCCUPIED;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
|
Reference in New Issue
Block a user