1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-10-26 00:37:41 +03:00

Move AEAD length checks to PSA core

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
Paul Elliott
2021-05-20 17:25:06 +01:00
parent b91da71db1
commit ee4ffe0079
4 changed files with 54 additions and 37 deletions

View File

@@ -3467,7 +3467,11 @@ psa_status_t psa_aead_set_lengths( psa_aead_operation_t *operation,
exit:
if( status == PSA_SUCCESS )
{
operation->ad_remaining = ad_length;
operation->body_remaining = plaintext_length;
operation->lengths_set = 1;
}
else
psa_aead_abort( operation );
@@ -3492,6 +3496,17 @@ psa_status_t psa_aead_update_ad( psa_aead_operation_t *operation,
goto exit;
}
if( operation->lengths_set )
{
if ( operation->ad_remaining < input_length )
{
status = PSA_ERROR_INVALID_ARGUMENT;
goto exit;
}
operation->ad_remaining -= input_length;
}
status = psa_driver_wrapper_aead_update_ad( operation, input,
input_length );
@@ -3530,6 +3545,26 @@ psa_status_t psa_aead_update( psa_aead_operation_t *operation,
goto exit;
}
if( operation->lengths_set )
{
/* Additional data length was supplied, but not all the additional
data was supplied.*/
if( operation->ad_remaining != 0 )
{
status = PSA_ERROR_INVALID_ARGUMENT;
goto exit;
}
/* Too much data provided. */
if( operation->body_remaining < input_length )
{
status = PSA_ERROR_INVALID_ARGUMENT;
goto exit;
}
operation->body_remaining -= input_length;
}
status = psa_driver_wrapper_aead_update( operation, input, input_length,
output, output_size,
output_length );
@@ -3571,6 +3606,13 @@ psa_status_t psa_aead_finish( psa_aead_operation_t *operation,
goto exit;
}
if( operation->lengths_set && (operation->ad_remaining != 0 ||
operation->body_remaining != 0 ) )
{
status = PSA_ERROR_BAD_STATE;
goto exit;
}
status = psa_driver_wrapper_aead_finish( operation, ciphertext,
ciphertext_size,
ciphertext_length,
@@ -3609,6 +3651,13 @@ psa_status_t psa_aead_verify( psa_aead_operation_t *operation,
goto exit;
}
if( operation->lengths_set && (operation->ad_remaining != 0 ||
operation->body_remaining != 0 ) )
{
status = PSA_ERROR_BAD_STATE;
goto exit;
}
status = psa_driver_wrapper_aead_verify( operation, plaintext,
plaintext_size,
plaintext_length,

View File

@@ -481,10 +481,6 @@ psa_status_t mbedtls_psa_aead_set_lengths(
return ( PSA_ERROR_NOT_SUPPORTED );
}
operation->ad_remaining = ad_length;
operation->body_remaining = plaintext_length;
operation->lengths_set = 1;
return ( PSA_SUCCESS );
}
@@ -496,14 +492,6 @@ psa_status_t mbedtls_psa_aead_update_ad(
{
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
if( operation->lengths_set )
{
if ( operation->ad_remaining < input_length )
return( PSA_ERROR_INVALID_ARGUMENT );
operation->ad_remaining -= input_length;
}
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
if( operation->alg == PSA_ALG_GCM )
{
@@ -590,20 +578,6 @@ psa_status_t mbedtls_psa_aead_update(
input_length ) > output_size )
return ( PSA_ERROR_BUFFER_TOO_SMALL );
if( operation->lengths_set)
{
/* Additional data length was supplied, but not all the additional
data was supplied.*/
if( operation->ad_remaining != 0 )
return ( PSA_ERROR_INVALID_ARGUMENT );
/* Too much data provided. */
if( operation->body_remaining < input_length )
return ( PSA_ERROR_INVALID_ARGUMENT );
operation->body_remaining -= input_length;
}
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
if( operation->alg == PSA_ALG_GCM )
{
@@ -725,10 +699,6 @@ static psa_status_t mbedtls_psa_aead_finish_checks(
{
size_t finish_output_size;
if( operation->lengths_set )
if( operation->ad_remaining != 0 || operation->body_remaining != 0 )
return( PSA_ERROR_BAD_STATE );
if( tag_size < operation->tag_length )
return ( PSA_ERROR_BUFFER_TOO_SMALL );
@@ -934,7 +904,6 @@ psa_status_t mbedtls_psa_aead_abort(
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
}
operation->lengths_set = 0;
operation->is_encrypt = 0;
operation->ad_started = 0;
operation->body_started = 0;