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.
This commit is contained in:
Gilles Peskine 2018-07-12 16:58:43 +02:00 committed by itayzafrir
parent f64ee8a7f1
commit 94e44540ff

View file

@ -1018,6 +1018,12 @@ psa_status_t psa_hash_update( psa_hash_operation_t *operation,
size_t input_length ) size_t input_length )
{ {
int ret; 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 ) switch( operation->alg )
{ {
#if defined(MBEDTLS_MD2_C) #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; ret = MBEDTLS_ERR_MD_BAD_INPUT_DATA;
break; break;
} }
if( ret != 0 ) if( ret != 0 )
psa_hash_abort( operation ); psa_hash_abort( operation );
return( mbedtls_to_psa_error( ret ) ); return( mbedtls_to_psa_error( ret ) );