Improve generate nonce test

Make sure the generated nonce works to encrypt test data if the
generated nonce is valid.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index fa5556e..577b8c6 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -3699,7 +3699,9 @@
 void aead_multipart_generate_nonce( int key_type_arg, data_t *key_data,
                                     int alg_arg,
                                     int nonce_len,
-                                    int expected_result_arg )
+                                    data_t *additional_data,
+                                    data_t *input_data,
+                                    int expected_status_arg )
 {
 
     mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
@@ -3710,6 +3712,13 @@
     psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
     psa_status_t status = PSA_ERROR_GENERIC_ERROR;
     size_t nonce_generated_len = 0;
+    unsigned char *output_data = NULL;
+    unsigned char *final_data = NULL;
+    size_t output_size = 0;
+    size_t finish_output_size = 0;
+    size_t output_length = 0;
+    size_t tag_length = 0;
+    uint8_t tag_buffer[PSA_AEAD_TAG_MAX_SIZE];
 
     PSA_ASSERT( psa_crypto_init( ) );
 
@@ -3722,6 +3731,16 @@
 
     PSA_ASSERT( psa_get_key_attributes( key, &attributes ) );
 
+    output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE( key_type, alg, input_data->len );
+
+    ASSERT_ALLOC( output_data, output_size );
+
+    finish_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE( key_type, alg );
+
+    TEST_ASSERT( finish_output_size <= PSA_AEAD_FINISH_OUTPUT_MAX_SIZE );
+
+    ASSERT_ALLOC( final_data, finish_output_size );
+
     operation = psa_aead_operation_init( );
 
     status = psa_aead_encrypt_setup( &operation, key, alg );
@@ -3743,7 +3762,23 @@
                                       nonce_len,
                                       &nonce_generated_len );
 
-    TEST_ASSERT( status == expected_result_arg );
+    TEST_ASSERT( status == expected_status_arg );
+
+    if( expected_status_arg == PSA_SUCCESS )
+    {
+
+        /* Ensure we can still complete operation. */
+
+        PSA_ASSERT( psa_aead_update_ad( &operation, additional_data->x,
+                                        additional_data->len ) );
+
+        PSA_ASSERT( psa_aead_update( &operation, input_data->x, input_data->len,
+                                     output_data, output_size, &output_length ) );
+
+        PSA_ASSERT( psa_aead_finish( &operation, final_data, finish_output_size,
+                                     &output_length, tag_buffer,
+                                     PSA_AEAD_TAG_MAX_SIZE, &tag_length ) );
+    }
 
 exit:
     psa_destroy_key( key );