chachapoly: add test for parameter validation

Also fix two bugs found by the new tests.

Also remove redundant test case dependency declarations while at it.
diff --git a/tests/suites/test_suite_chachapoly.function b/tests/suites/test_suite_chachapoly.function
index a613870..3f8145a 100644
--- a/tests/suites/test_suite_chachapoly.function
+++ b/tests/suites/test_suite_chachapoly.function
@@ -46,13 +46,13 @@
 
     mbedtls_chachapoly_init( &ctx );
 
-    mbedtls_chachapoly_setkey( &ctx, key_str );
+    TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key_str ) == 0 );
 
-    mbedtls_chachapoly_crypt_and_tag( &ctx,
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( &ctx,
                                       MBEDTLS_CHACHAPOLY_ENCRYPT,
                                       input_len, nonce_str,
                                       aad_str, aad_len,
-                                      input_str, output, mac );
+                                      input_str, output, mac ) == 0 );
 
     TEST_ASSERT( memcmp( output_str, output, output_len ) == 0 );
     TEST_ASSERT( memcmp( mac_str, mac, 16U ) == 0 );
@@ -101,7 +101,7 @@
 
     mbedtls_chachapoly_init( &ctx );
 
-    mbedtls_chachapoly_setkey( &ctx, key_str );
+    TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, key_str ) == 0 );
 
     ret = mbedtls_chachapoly_auth_decrypt( &ctx,
                                            input_len, nonce_str,
@@ -119,6 +119,155 @@
 }
 /* END_CASE */
 
+/* BEGIN_CASE */
+void chachapoly_bad_params()
+{
+    unsigned char key[32];
+    unsigned char nonce[12];
+    unsigned char aad[1];
+    unsigned char input[1];
+    unsigned char output[1];
+    unsigned char mac[16];
+    size_t input_len = sizeof( input );
+    size_t aad_len = sizeof( aad );
+    mbedtls_chachapoly_context ctx;
+
+    memset( key,    0x00, sizeof( key ) );
+    memset( nonce,  0x00, sizeof( nonce ) );
+    memset( aad,    0x00, sizeof( aad ) );
+    memset( input,  0x00, sizeof( input ) );
+    memset( output, 0x00, sizeof( output ) );
+    memset( mac,    0x00, sizeof( mac ) );
+
+    mbedtls_chachapoly_init( NULL );
+    mbedtls_chachapoly_free( NULL );
+
+    mbedtls_chachapoly_init( &ctx );
+
+    TEST_ASSERT( mbedtls_chachapoly_setkey( NULL, key )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_setkey( &ctx, NULL )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( NULL,
+                                      MBEDTLS_CHACHAPOLY_ENCRYPT,
+                                      0, nonce,
+                                      aad, 0,
+                                      input, output, mac )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( &ctx,
+                                      MBEDTLS_CHACHAPOLY_ENCRYPT,
+                                      0, NULL,
+                                      aad, 0,
+                                      input, output, mac )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( &ctx,
+                                      MBEDTLS_CHACHAPOLY_ENCRYPT,
+                                      0, nonce,
+                                      NULL, aad_len,
+                                      input, output, mac )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( &ctx,
+                                      MBEDTLS_CHACHAPOLY_ENCRYPT,
+                                      input_len, nonce,
+                                      aad, 0,
+                                      NULL, output, mac )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( &ctx,
+                                      MBEDTLS_CHACHAPOLY_ENCRYPT,
+                                      input_len, nonce,
+                                      aad, 0,
+                                      input, NULL, mac )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( &ctx,
+                                      MBEDTLS_CHACHAPOLY_ENCRYPT,
+                                      0, nonce,
+                                      aad, 0,
+                                      input, output, NULL )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+
+    TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( NULL,
+                                           0, nonce,
+                                           aad, 0,
+                                           mac, input, output )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
+                                           0, NULL,
+                                           aad, 0,
+                                           mac, input, output )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
+                                           0, nonce,
+                                           NULL, aad_len,
+                                           mac, input, output )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
+                                           0, nonce,
+                                           aad, 0,
+                                           NULL, input, output )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
+                                           input_len, nonce,
+                                           aad, 0,
+                                           mac, NULL, output )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
+                                           input_len, nonce,
+                                           aad, 0,
+                                           mac, input, NULL )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( &ctx,
+                                      MBEDTLS_CHACHAPOLY_ENCRYPT,
+                                      0, nonce,
+                                      aad, aad_len,
+                                      NULL, NULL, mac )
+                 == 0 );
+    TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
+                                           0, nonce,
+                                           aad, aad_len,
+                                           mac, NULL, NULL )
+                 == 0 );
+
+    TEST_ASSERT( mbedtls_chachapoly_crypt_and_tag( &ctx,
+                                      MBEDTLS_CHACHAPOLY_ENCRYPT,
+                                      input_len, nonce,
+                                      NULL, 0,
+                                      input, output, mac )
+                 == 0 );
+    TEST_ASSERT( mbedtls_chachapoly_auth_decrypt( &ctx,
+                                           input_len, nonce,
+                                           NULL, 0,
+                                           mac, input, output )
+                 == 0 );
+
+    TEST_ASSERT( mbedtls_chachapoly_starts( NULL, nonce, MBEDTLS_CHACHAPOLY_ENCRYPT )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_starts( &ctx, NULL, MBEDTLS_CHACHAPOLY_ENCRYPT )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+
+    TEST_ASSERT( mbedtls_chachapoly_update_aad( NULL, aad, aad_len )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_update_aad( &ctx, NULL, aad_len )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+
+    TEST_ASSERT( mbedtls_chachapoly_update( NULL, input_len, input, output )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, NULL, output )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_update( &ctx, input_len, input, NULL )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+
+    TEST_ASSERT( mbedtls_chachapoly_finish( NULL, mac )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+    TEST_ASSERT( mbedtls_chachapoly_finish( &ctx, NULL )
+                 == MBEDTLS_ERR_CHACHAPOLY_BAD_INPUT_DATA );
+
+exit:
+    mbedtls_chachapoly_free( &ctx );
+}
+/* END_CASE */
+
 /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
 void chachapoly_selftest()
 {