From 7934b3f9f92f578e46ef7287f17ebb8a65823a8d Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 21 Apr 2021 20:06:51 +0200 Subject: [PATCH] Fix mbedtls_psa_get_stats for keys with fancy lifetimes mbedtls_psa_get_stats() was written back before lifetimes were structured as persistence and location. Fix its classification of volatile external keys and internal keys with a non-default persistence. Signed-off-by: Gilles Peskine --- library/psa_crypto_slot_management.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/psa_crypto_slot_management.c b/library/psa_crypto_slot_management.c index 0b1a3c166..9bab7e415 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -556,16 +556,17 @@ void mbedtls_psa_get_stats( mbedtls_psa_stats_t *stats ) ++stats->empty_slots; continue; } - if( slot->attr.lifetime == PSA_KEY_LIFETIME_VOLATILE ) + if( PSA_KEY_LIFETIME_IS_VOLATILE( slot->attr.lifetime ) ) ++stats->volatile_slots; - else if( slot->attr.lifetime == PSA_KEY_LIFETIME_PERSISTENT ) + else { psa_key_id_t id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ); ++stats->persistent_slots; if( id > stats->max_open_internal_key_id ) stats->max_open_internal_key_id = id; } - else + if( PSA_KEY_LIFETIME_GET_LOCATION( slot->attr.lifetime ) != + PSA_KEY_LOCATION_LOCAL_STORAGE ) { psa_key_id_t id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( slot->attr.id ); ++stats->external_slots;