mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-07 15:09:28 +01: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:
parent
b8025c5826
commit
a310c5e42b
6 changed files with 33 additions and 4 deletions
|
|
@ -174,10 +174,15 @@ int mbedtls_aead_chacha20_poly1305_update_aad( mbedtls_aead_chacha20_poly1305_co
|
|||
size_t aad_len,
|
||||
const unsigned char *aad )
|
||||
{
|
||||
if ( ( ctx == NULL ) || ( aad == NULL ) )
|
||||
if ( ctx == NULL )
|
||||
{
|
||||
return( MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_INPUT_DATA );
|
||||
}
|
||||
else if ( ( aad_len > 0U ) && ( aad == NULL ) )
|
||||
{
|
||||
/* aad pointer is allowed to be NULL if aad_len == 0 */
|
||||
return( MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_INPUT_DATA );
|
||||
}
|
||||
else if ( ctx->state != AEAD_CHACHA20_POLY1305_STATE_AAD )
|
||||
{
|
||||
return (MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_STATE );
|
||||
|
|
@ -197,6 +202,11 @@ int mbedtls_aead_chacha20_poly1305_update( mbedtls_aead_chacha20_poly1305_contex
|
|||
{
|
||||
return( MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_INPUT_DATA );
|
||||
}
|
||||
else if ( ( len > 0U ) && ( ( input == NULL ) || ( output == NULL ) ) )
|
||||
{
|
||||
/* input and output pointers are allowed to be NULL if len == 0 */
|
||||
return( MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_INPUT_DATA );
|
||||
}
|
||||
else if ( ( ctx->state != AEAD_CHACHA20_POLY1305_STATE_AAD ) &&
|
||||
( ctx->state != AEAD_CHACHA20_POLY1305_STATE_CIPHERTEXT ) )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 ) )
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue