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.
diff --git a/library/poly1305.c b/library/poly1305.c
index 9a61a85..f9bdf2c 100644
--- a/library/poly1305.c
+++ b/library/poly1305.c
@@ -293,12 +293,17 @@
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 );