From 85eeda01222e6632639b6ae30f65bd807c158950 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Tue, 17 May 2022 11:43:15 +0200 Subject: [PATCH] olen = 0 is not allowed for SHA-3. Sanity checks are moved to mbedtls_sha3_xxx() functions. Signed-off-by: Pol Henarejos --- library/sha3.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/library/sha3.c b/library/sha3.c index 4a08131e6..705f48c32 100644 --- a/library/sha3.c +++ b/library/sha3.c @@ -241,12 +241,9 @@ int mbedtls_sha3_update( mbedtls_sha3_context *ctx, int mbedtls_sha3_finish( mbedtls_sha3_context *ctx, uint8_t *output, size_t olen ) { - if( ctx == NULL ) + if( ctx == NULL || output == NULL ) return( MBEDTLS_ERR_SHA3_BAD_INPUT_DATA ); - if( olen == 0 ) - return( 0 ); - if( ctx->olen > 0 && ctx->olen != olen ) return( MBEDTLS_ERR_SHA3_BAD_INPUT_DATA ); @@ -275,14 +272,9 @@ int mbedtls_sha3( mbedtls_sha3_id id, const uint8_t *input, int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_sha3_context ctx; - if( ilen != 0 && input == NULL ) - return( MBEDTLS_ERR_SHA3_BAD_INPUT_DATA ); - - if( output == NULL ) - return( MBEDTLS_ERR_SHA3_BAD_INPUT_DATA ); - mbedtls_sha3_init( &ctx ); + /* Sanity checks are performed in every mbedtls_sha3_xxx() */ if( ( ret = mbedtls_sha3_starts( &ctx, id ) ) != 0 ) goto exit;