Add additional parameter validation tests for the AES module
This adds additional tests to validate the AES module parameter validation
checks which are enabled using the MBEDTLS_CHECK_PARAMS option.
diff --git a/tests/suites/test_suite_aes.function b/tests/suites/test_suite_aes.function
index a797e69..24b5e4d 100644
--- a/tests/suites/test_suite_aes.function
+++ b/tests/suites/test_suite_aes.function
@@ -15,8 +15,8 @@
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ TEST_FN( mbedtls_aes_init( &ctx ) );
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
if( setkey_result == 0 )
@@ -39,8 +39,8 @@
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ TEST_FN( mbedtls_aes_init( &ctx ) );
TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
if( setkey_result == 0 )
@@ -64,8 +64,8 @@
mbedtls_aes_context ctx;
memset(output, 0x00, 100);
- mbedtls_aes_init( &ctx );
+ TEST_FN( mbedtls_aes_init( &ctx ) );
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
@@ -91,7 +91,6 @@
memset(output, 0x00, 100);
mbedtls_aes_init( &ctx );
-
mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
if( cbc_result == 0)
@@ -372,6 +371,34 @@
}
/* END_CASE */
+/* BEGIN_CASE */
+void aes_invalid_param( )
+{
+ mbedtls_aes_context dummy_ctx;
+ const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+
+ TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) );
+
+ /* mbedtls_aes_setkey_enc() */
+ TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_setkey_enc( NULL, key, 128 ) );
+
+ TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_setkey_enc( &dummy_ctx, NULL, 128 ) );
+
+ /* mbedtls_aes_setkey_dec() */
+ TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_setkey_dec( NULL, key, 128 ) );
+
+ TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
+ mbedtls_aes_setkey_dec( &dummy_ctx, NULL, 128 ) );
+
+
+exit:
+ return;
+}
+/* END_CASE */
+
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
void aes_selftest( )
{