From 018765164762ecf2110a21994f87043af0081df4 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Wed, 23 Jun 2021 18:13:04 +0100 Subject: [PATCH] Test all set lengths and set/generate nonce orders Test that the two are completely interchangeable in order. Signed-off-by: Paul Elliott --- tests/suites/test_suite_psa_crypto.function | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 577b8c6e8..bb4d7e611 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -3979,6 +3979,46 @@ void aead_multipart_state_test( int key_type_arg, data_t *key_data, psa_aead_abort( &operation ); + /* Test that generate/set nonce and set lengths are interchangeable (we + * already tested set nonce followed by set lengths above). */ + + operation = psa_aead_operation_init( ); + + PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) ); + + PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len, + input_data->len ) ); + + PSA_ASSERT( psa_aead_set_nonce( &operation, nonce->x, nonce->len ) ); + + psa_aead_abort( &operation ); + + operation = psa_aead_operation_init( ); + + PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) ); + + PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len, + input_data->len ) ); + + PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer, + PSA_AEAD_NONCE_MAX_SIZE, + &nonce_length ) ); + + psa_aead_abort( &operation ); + + operation = psa_aead_operation_init( ); + + PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) ); + + PSA_ASSERT( psa_aead_generate_nonce( &operation, nonce_buffer, + PSA_AEAD_NONCE_MAX_SIZE, + &nonce_length ) ); + + PSA_ASSERT( psa_aead_set_lengths( &operation, additional_data->len, + input_data->len ) ); + + psa_aead_abort( &operation ); + /* Test for setting lengths after already starting data. */ operation = psa_aead_operation_init( );