From 40835d4e560acfbaf9552b7b693d2b2c17e3eb9d Mon Sep 17 00:00:00 2001 From: itayzafrir Date: Thu, 2 Aug 2018 13:14:17 +0300 Subject: [PATCH] Add missing calls to psa_hash_abort in hash functions --- library/psa_crypto.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index c7d5a6780..b94e0e6a5 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1110,6 +1110,7 @@ psa_status_t psa_hash_finish( psa_hash_operation_t *operation, size_t hash_size, size_t *hash_length ) { + psa_status_t status; int ret; size_t actual_hash_length = PSA_HASH_SIZE( operation->alg ); @@ -1123,7 +1124,10 @@ psa_status_t psa_hash_finish( psa_hash_operation_t *operation, memset( hash, '!', hash_size ); if( hash_size < actual_hash_length ) - return( PSA_ERROR_BUFFER_TOO_SMALL ); + { + status = PSA_ERROR_BUFFER_TOO_SMALL; + goto exit; + } switch( operation->alg ) { @@ -1168,8 +1172,10 @@ psa_status_t psa_hash_finish( psa_hash_operation_t *operation, ret = MBEDTLS_ERR_MD_BAD_INPUT_DATA; break; } + status = mbedtls_to_psa_error( ret ); - if( ret == 0 ) +exit: + if( status == PSA_SUCCESS ) { *hash_length = actual_hash_length; return( psa_hash_abort( operation ) ); @@ -1177,7 +1183,7 @@ psa_status_t psa_hash_finish( psa_hash_operation_t *operation, else { psa_hash_abort( operation ); - return( mbedtls_to_psa_error( ret ) ); + return( status ); } }