From 2bfbb17f3055cf2b4829864bd17a9f6c2dada48b Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 7 Jun 2021 23:27:54 +0200 Subject: [PATCH] Remove duplicate wipe call in psa_destroy_key Signed-off-by: Gilles Peskine --- library/psa_crypto.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index f4860e631..33b44334e 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1138,11 +1138,10 @@ psa_status_t psa_destroy_key( mbedtls_svc_key_id_t key ) /* Refuse the destruction of a read-only key (which may or may not work * if we attempt it, depending on whether the key is merely read-only * by policy or actually physically read-only). - * Just do the best we can, which is to wipe the copy in memory. */ - status = psa_wipe_key_slot( slot ); - if( status != PSA_SUCCESS ) - return( status ); - return( PSA_ERROR_NOT_PERMITTED ); + * Just do the best we can, which is to wipe the copy in memory + * (done in this function's cleanup code). */ + overall_status = PSA_ERROR_NOT_PERMITTED; + goto exit; } #if defined(MBEDTLS_PSA_CRYPTO_SE_C) @@ -1206,12 +1205,10 @@ psa_status_t psa_destroy_key( mbedtls_svc_key_id_t key ) } #endif /* MBEDTLS_PSA_CRYPTO_SE_C */ -#if defined(MBEDTLS_PSA_CRYPTO_SE_C) exit: -#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ status = psa_wipe_key_slot( slot ); /* Prioritize CORRUPTION_DETECTED from wiping over a storage error */ - if( overall_status == PSA_SUCCESS ) + if( status != PSA_SUCCESS ) overall_status = status; return( overall_status ); }