mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-12-24 17:41:01 +03:00
Add safety for nonce length to internal driver
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
@@ -412,6 +412,16 @@ psa_status_t mbedtls_psa_aead_set_nonce(
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
||||
if( operation->alg == PSA_ALG_CHACHA20_POLY1305 )
|
||||
{
|
||||
/* Note - ChaChaPoly allows an 8 byte nonce, but we would have to
|
||||
* allocate a buffer in the operation, copy the nonce to it and pad
|
||||
* it, so for now check the nonce is 12 bytes, as
|
||||
* mbedtls_chachapoly_starts() assumes it can read 12 bytes from the
|
||||
* passed in buffer. */
|
||||
if( nonce_length != 12 )
|
||||
{
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
}
|
||||
|
||||
status = mbedtls_to_psa_error(
|
||||
mbedtls_chachapoly_starts( &operation->ctx.chachapoly,
|
||||
nonce,
|
||||
|
||||
Reference in New Issue
Block a user