olen = 0 is not allowed for SHA-3.

Sanity checks are moved to mbedtls_sha3_xxx() functions.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-05-17 11:43:15 +02:00
parent 084649d189
commit 85eeda0122
No known key found for this signature in database
GPG Key ID: C0095B7870A4CCD3

View File

@ -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;