From 966db2677993048095d108ed508b9d5d0164f5bc Mon Sep 17 00:00:00 2001 From: Steven Cooreman Date: Tue, 13 Apr 2021 13:45:45 +0200 Subject: [PATCH] Minor code flow improvements * group setting of attributes before calling get_builtin_key * return early instead of going to exit when no resources are allocated yet Signed-off-by: Steven Cooreman --- 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 7809c0cff..0b1a3c166 100644 --- a/library/psa_crypto_slot_management.c +++ b/library/psa_crypto_slot_management.c @@ -293,13 +293,14 @@ static psa_status_t psa_load_builtin_key_into_slot( psa_key_slot_t *slot ) } /* Check the platform function to see whether this key actually exists */ - psa_set_key_id( &attributes, slot->attr.id ); status = mbedtls_psa_platform_get_builtin_key( slot->attr.id, &lifetime, &slot_number ); if( status != PSA_SUCCESS ) return( status ); - /* Set mapped lifetime on the attributes */ + /* Set required key attributes to ensure get_builtin_key can retrieve the + * full attributes. */ + psa_set_key_id( &attributes, slot->attr.id ); psa_set_key_lifetime( &attributes, lifetime ); /* Get the full key attributes from the driver in order to be able to @@ -312,7 +313,7 @@ static psa_status_t psa_load_builtin_key_into_slot( psa_key_slot_t *slot ) /* Builtin keys cannot be defined by the attributes alone */ if( status == PSA_SUCCESS ) status = PSA_ERROR_CORRUPTION_DETECTED; - goto exit; + return( status ); } /* If the key should exist according to the platform, then ask the driver