From 94e44540ff9eb42fb4e63f371335d3e7a36c32e4 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 12 Jul 2018 16:58:43 +0200 Subject: [PATCH] psa_hash_update: robustify the case length=0 Don't require hash implementations to behave correctly on a zero-length input, which may have an invalid pointer. --- library/psa_crypto.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/psa_crypto.c b/library/psa_crypto.c index eb140ea2c..47605d432 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -1018,6 +1018,12 @@ psa_status_t psa_hash_update( psa_hash_operation_t *operation, size_t input_length ) { int ret; + + /* Don't require hash implementations to behave correctly on a + * zero-length input, which may have an invalid pointer. */ + if( input_length == 0 ) + return( PSA_SUCCESS ); + switch( operation->alg ) { #if defined(MBEDTLS_MD2_C) @@ -1068,6 +1074,7 @@ psa_status_t psa_hash_update( psa_hash_operation_t *operation, ret = MBEDTLS_ERR_MD_BAD_INPUT_DATA; break; } + if( ret != 0 ) psa_hash_abort( operation ); return( mbedtls_to_psa_error( ret ) );