mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-26 03:40:26 +00:00
Add common nonce checking to oneshot encrypt
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
a561444561
commit
96b0173cec
@ -136,6 +136,22 @@ static psa_status_t psa_aead_setup(
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
/* Perform common nonce length checks */
|
||||
static psa_status_t mbedtls_aead_check_nonce_length(
|
||||
mbedtls_psa_aead_operation_t *operation,
|
||||
size_t nonce_length )
|
||||
{
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
||||
if( operation->alg == PSA_ALG_CHACHA20_POLY1305 )
|
||||
{
|
||||
if( nonce_length != 12 )
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
||||
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_psa_aead_encrypt(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||
@ -164,6 +180,13 @@ psa_status_t mbedtls_psa_aead_encrypt(
|
||||
}
|
||||
tag = ciphertext + plaintext_length;
|
||||
|
||||
if( mbedtls_aead_check_nonce_length( &operation, nonce_length )
|
||||
!= PSA_SUCCESS )
|
||||
{
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
||||
if( operation.alg == PSA_ALG_CCM )
|
||||
{
|
||||
@ -195,7 +218,7 @@ psa_status_t mbedtls_psa_aead_encrypt(
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
||||
if( operation.alg == PSA_ALG_CHACHA20_POLY1305 )
|
||||
{
|
||||
if( nonce_length != 12 || operation.tag_length != 16 )
|
||||
if( operation.tag_length != 16 )
|
||||
{
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
goto exit;
|
||||
@ -247,21 +270,6 @@ static psa_status_t psa_aead_unpadded_locate_tag( size_t tag_length,
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
|
||||
static psa_status_t mbedtls_aead_check_nonce_length(
|
||||
mbedtls_psa_aead_operation_t *operation,
|
||||
size_t nonce_length )
|
||||
{
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
||||
if( operation->alg == PSA_ALG_CHACHA20_POLY1305 )
|
||||
{
|
||||
if( nonce_length != 12 )
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
||||
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_psa_aead_decrypt(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||
|
Loading…
x
Reference in New Issue
Block a user