mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +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:
committed by
Manuel Pégourié-Gonnard
parent
b8025c5826
commit
a310c5e42b
@ -291,10 +291,15 @@ int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
|
||||
size_t offset = 0U;
|
||||
size_t i;
|
||||
|
||||
if ( ( ctx == NULL ) || ( input == NULL ) || ( output == NULL ) )
|
||||
if ( ctx == NULL )
|
||||
{
|
||||
return( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA );
|
||||
}
|
||||
else if ( ( size > 0U ) && ( ( input == NULL ) || ( output == NULL ) ) )
|
||||
{
|
||||
/* input and output pointers are allowed to be NULL only if size == 0 */
|
||||
return( MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
/* Use leftover keystream bytes, if available */
|
||||
while ( ( size > 0U ) && ( ctx->keystream_bytes_used < CHACHA20_BLOCK_SIZE_BYTES ) )
|
||||
|
Reference in New Issue
Block a user