Re-add option of NULL buffer for nonce tests

NULL/zero length or valid buffer/zero length both now tested

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index 371fee0..ff3718b 100644
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -2598,10 +2598,14 @@
 depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
 aead_multipart_generate_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:16:12:"":"":PSA_SUCCESS
 
-PSA Multipart Set Nonce, AES - GCM, IV = 0
+PSA Multipart Set Nonce, AES - GCM, IV = 0 (NULL)
 depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
 aead_multipart_set_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):0:"":"":PSA_ERROR_INVALID_ARGUMENT
 
+PSA Multipart Set Nonce, AES - GCM, IV = 0 (Non-NULL)
+depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
+aead_multipart_set_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):-1:"":"":PSA_ERROR_INVALID_ARGUMENT
+
 PSA Multipart Set Nonce, AES - GCM, IV = 16
 depends_on:PSA_WANT_ALG_GCM:PSA_WANT_KEY_TYPE_AES
 aead_multipart_set_nonce:PSA_KEY_TYPE_AES:"aa740abfadcda779220d3b406c5d7ec09a77fe9d94104539":PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM,16):16:"290322092d57479e20f6281e331d95a9":"e7fb0631eebf9bdba87045b33650c4ce":PSA_SUCCESS
@@ -2618,10 +2622,14 @@
 depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
 aead_multipart_set_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:8:"":"":PSA_ERROR_INVALID_ARGUMENT
 
-PSA Multipart Set Nonce: ChaCha20 - Poly1305, IV = 0
+PSA Multipart Set Nonce: ChaCha20 - Poly1305, IV = 0 (NULL)
 depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
 aead_multipart_set_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:0:"":"":PSA_ERROR_INVALID_ARGUMENT
 
+PSA Multipart Set Nonce: ChaCha20 - Poly1305, IV = 0 (Non-NULL)
+depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
+aead_multipart_set_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:-1:"":"":PSA_ERROR_INVALID_ARGUMENT
+
 PSA Multipart Set Nonce: ChaCha20 - Poly1305, IV = 16
 depends_on:PSA_WANT_ALG_CHACHA20_POLY1305:PSA_WANT_KEY_TYPE_CHACHA20
 aead_multipart_set_nonce:PSA_KEY_TYPE_CHACHA20:"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f":PSA_ALG_CHACHA20_POLY1305:16:"":"":PSA_ERROR_INVALID_ARGUMENT
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index 19b687e..4dfaccb 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -3777,7 +3777,7 @@
 /* BEGIN_CASE */
 void aead_multipart_set_nonce( int key_type_arg, data_t *key_data,
                                int alg_arg,
-                               int nonce_length,
+                               int nonce_length_arg,
                                data_t *additional_data,
                                data_t *input_data,
                                int expected_status_arg )
@@ -3793,12 +3793,13 @@
     psa_status_t expected_status = expected_status_arg;
     unsigned char *output = NULL;
     unsigned char *ciphertext = NULL;
+    size_t nonce_length;
     size_t output_size = 0;
     size_t ciphertext_size = 0;
     size_t ciphertext_length = 0;
     size_t tag_length = 0;
     uint8_t tag_buffer[PSA_AEAD_TAG_MAX_SIZE];
-    int index = 0;
+    size_t index = 0;
 
     PSA_ASSERT( psa_crypto_init( ) );
 
@@ -3831,23 +3832,30 @@
     if( status == PSA_ERROR_NOT_SUPPORTED )
     {
         MBEDTLS_TEST_PSA_SKIP_IF_ALT_AES_192( key_type, key_data->len * 8 );
-        MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce_length );
+        MBEDTLS_TEST_PSA_SKIP_IF_ALT_GCM_NOT_12BYTES_NONCE( alg, nonce_length_arg );
     }
 
     PSA_ASSERT( status );
 
-    if( nonce_length == 0 )
+    /* -1 == zero length and valid buffer, 0 = zero length and NULL buffer. */
+    if( nonce_length_arg == -1 )
     {
          /* Arbitrary size buffer, to test zero length valid buffer. */
          ASSERT_ALLOC( nonce_buffer, 4 );
+         nonce_length = 0;
     }
     else
     {
+        /* If length is zero, then this will return NULL. */
+        nonce_length = ( size_t ) nonce_length_arg;
         ASSERT_ALLOC( nonce_buffer, nonce_length );
 
-        for( index = 0; index < nonce_length - 1; ++index)
+        if( nonce_buffer )
         {
-            nonce_buffer[index] = 'a' + index;
+            for( index = 0; index < nonce_length - 1; ++index )
+            {
+                nonce_buffer[index] = 'a' + index;
+            }
         }
     }