From f5f07c847a924c96eedb7d1bb9b76f8bc4e2b789 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 4cf32db2b1..b198406688 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -545,16 +545,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;