1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00

Allow some parameters to be NULL if the length is 0.

This change permits users of the ChaCha20/Poly1305 algorithms
(and the AEAD construction thereof) to pass NULL pointers for
data that they do not need, and avoids the need to provide a valid
buffer for data that is not used.
This commit is contained in:
Daniel King
2016-05-17 15:56:26 -03:00
committed by Manuel Pégourié-Gonnard
parent b8025c5826
commit a310c5e42b
6 changed files with 33 additions and 4 deletions

View File

@ -293,12 +293,17 @@ int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
size_t queue_free_len;
size_t nblocks;
if ( ( ctx == NULL ) || ( input == NULL ) )
if ( ctx == NULL )
{
return( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
}
else if ( ( ilen > 0U ) && ( input == NULL ) )
{
/* input pointer is allowed to be NULL only if ilen == 0 */
return( MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA );
}
if ( ctx->queue_len > 0U )
if ( ( remaining > 0U ) && ( ctx->queue_len > 0U ) )
{
queue_free_len = ( POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len );