diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index dfd0cfde47..5f36230bfd 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -3938,6 +3938,28 @@ void aead_multipart_state_test( int key_type_arg, data_t *key_data, psa_aead_abort( &operation ); + /* ------------------------------------------------------- */ + + operation = psa_aead_operation_init( ); + + PSA_ASSERT( psa_aead_encrypt_setup( &operation, key, alg ) ); + + TEST_EQUAL( psa_aead_decrypt_setup( &operation, key, alg ), + PSA_ERROR_BAD_STATE ); + + psa_aead_abort( &operation ); + + /* ------------------------------------------------------- */ + + operation = psa_aead_operation_init( ); + + PSA_ASSERT( psa_aead_decrypt_setup( &operation, key, alg ) ); + + TEST_EQUAL( psa_aead_encrypt_setup( &operation, key, alg ), + PSA_ERROR_BAD_STATE ); + + psa_aead_abort( &operation ); + /* Test for not setting a nonce. */ operation = psa_aead_operation_init( ); @@ -3963,6 +3985,54 @@ void aead_multipart_state_test( int key_type_arg, data_t *key_data, psa_aead_abort( &operation ); + /* Test for double generating nonce. */ + + 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 ) ); + + TEST_EQUAL( psa_aead_generate_nonce( &operation, nonce_buffer, + PSA_AEAD_NONCE_MAX_SIZE, + &nonce_length ), + PSA_ERROR_BAD_STATE ); + + + psa_aead_abort( &operation ); + + /* Test for generate nonce then set and vice versa */ + + 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 ) ); + + TEST_EQUAL( psa_aead_set_nonce( &operation, nonce->x, nonce->len ), + PSA_ERROR_BAD_STATE ); + + psa_aead_abort( &operation ); + + /* ------------------------------------------------------- */ + + 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 ) ); + + TEST_EQUAL( psa_aead_generate_nonce( &operation, nonce_buffer, + PSA_AEAD_NONCE_MAX_SIZE, + &nonce_length ), + PSA_ERROR_BAD_STATE ); + + psa_aead_abort( &operation ); + /* Test for generating nonce in decrypt setup. */ operation = psa_aead_operation_init( );