From b0450febe6fc546b9744b8637b8671a16d809bf6 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 1 Sep 2021 15:06:26 +0100 Subject: [PATCH] Tests for sending too much data after set lengths We previously had tests for not sending enough (additional) data, but were missing tests for sending too much. I have added these to the state tests, as I don't think this is complex enough to deserve a standalone test. Signed-off-by: Paul Elliott --- tests/suites/test_suite_psa_crypto.function | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 0c009811c..a88108715 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -4407,6 +4407,40 @@ void aead_multipart_state_test( int key_type_arg, data_t *key_data, psa_aead_abort( &operation ); + /* Test for sending too much additional data after setting lengths. */ + + operation = psa_aead_operation_init( ); + + PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) ); + + PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) ); + + PSA_ASSERT( psa_aead_set_lengths( &operation, 0, 0 ) ); + + + TEST_EQUAL( psa_aead_update_ad( &operation, additional_data->x, + additional_data->len ), + PSA_ERROR_INVALID_ARGUMENT ); + + psa_aead_abort( &operation ); + + /* Test for sending too much data after setting lengths. */ + + operation = psa_aead_operation_init( ); + + PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) ); + + PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) ); + + PSA_ASSERT( psa_aead_set_lengths( &operation, 0, 0 ) ); + + TEST_EQUAL( psa_aead_update( &operation, input_data->x, + input_data->len, output_data, + output_size, &output_length ), + PSA_ERROR_INVALID_ARGUMENT ); + + psa_aead_abort( &operation ); + /* Test sending additional data after data. */ operation = psa_aead_operation_init( );