1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-01 10:06:53 +03:00

Move common final checks to function

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
Paul Elliott
2021-06-23 08:50:14 +01:00
parent 5b065cb8cd
commit ad53dcc975

View File

@ -3760,6 +3760,18 @@ exit:
return( status ); return( status );
} }
static psa_status_t psa_aead_final_checks( psa_aead_operation_t *operation )
{
if( operation->id == 0 || operation->nonce_set == 0 )
return( PSA_ERROR_BAD_STATE );
if( operation->lengths_set && (operation->ad_remaining != 0 ||
operation->body_remaining != 0 ) )
return( PSA_ERROR_INVALID_ARGUMENT );
return( PSA_SUCCESS );
}
/* Finish encrypting a message in a multipart AEAD operation. */ /* Finish encrypting a message in a multipart AEAD operation. */
psa_status_t psa_aead_finish( psa_aead_operation_t *operation, psa_status_t psa_aead_finish( psa_aead_operation_t *operation,
uint8_t *ciphertext, uint8_t *ciphertext,
@ -3774,25 +3786,17 @@ psa_status_t psa_aead_finish( psa_aead_operation_t *operation,
*ciphertext_length = 0; *ciphertext_length = 0;
*tag_length = tag_size; *tag_length = tag_size;
if( operation->id == 0 ) status = psa_aead_final_checks( operation );
if( status != PSA_SUCCESS )
goto exit;
if( operation->is_encrypt == 0 )
{ {
status = PSA_ERROR_BAD_STATE; status = PSA_ERROR_BAD_STATE;
goto exit; goto exit;
} }
if( !operation->nonce_set || operation->is_encrypt == 0 )
{
status = PSA_ERROR_BAD_STATE;
goto exit;
}
if( operation->lengths_set && (operation->ad_remaining != 0 ||
operation->body_remaining != 0 ) )
{
status = PSA_ERROR_INVALID_ARGUMENT;
goto exit;
}
status = psa_driver_wrapper_aead_finish( operation, ciphertext, status = psa_driver_wrapper_aead_finish( operation, ciphertext,
ciphertext_size, ciphertext_size,
ciphertext_length, ciphertext_length,
@ -3823,24 +3827,21 @@ psa_status_t psa_aead_verify( psa_aead_operation_t *operation,
*plaintext_length = 0; *plaintext_length = 0;
if( operation->id == 0 ) status = psa_aead_final_checks( operation );
if( status != PSA_SUCCESS )
goto exit;
if( operation->is_encrypt == 1 )
{ {
status = PSA_ERROR_BAD_STATE; status = PSA_ERROR_BAD_STATE;
goto exit; goto exit;
} }
if( !operation->nonce_set || operation->is_encrypt == 1 ) status = psa_aead_final_checks( operation );
{
status = PSA_ERROR_BAD_STATE;
goto exit;
}
if( operation->lengths_set && (operation->ad_remaining != 0 || if( status != PSA_SUCCESS )
operation->body_remaining != 0 ) )
{
status = PSA_ERROR_INVALID_ARGUMENT;
goto exit; goto exit;
}
status = psa_driver_wrapper_aead_verify( operation, plaintext, status = psa_driver_wrapper_aead_verify( operation, plaintext,
plaintext_size, plaintext_size,