From 2ce0af4b3ca4badaa07dc48e2b6fbf874d2885f2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 24 Dec 2018 05:23:50 -0500 Subject: [PATCH] cmac: improve parameter validation test suite Extend the scope of NULL cipher info tests --- tests/suites/test_suite_cmac.function | 53 +++++++++++++++++++-------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/tests/suites/test_suite_cmac.function b/tests/suites/test_suite_cmac.function index a74e86a32..25c56a6e2 100644 --- a/tests/suites/test_suite_cmac.function +++ b/tests/suites/test_suite_cmac.function @@ -27,54 +27,75 @@ void mbedtls_cmac_null_args( ) mbedtls_cipher_init( &ctx ); /* Test NULL cipher info */ - TEST_INVALID_PARAM( mbedtls_cipher_cmac_update( &ctx, test_data, 16 ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_starts( &ctx, test_key, 128 ) ); + + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_update( &ctx, test_data, 16 ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_finish( &ctx, test_output ) ); + cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_ECB ); - TEST_ASSERT( mbedtls_cipher_setup( &ctx, cipher_info ) == 0 ); + TEST_ASSERT( mbedtls_cipher_setup( &ctx, cipher_info ) == 0 ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac_starts( NULL, test_key, 128 ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_starts( NULL, test_key, 128 ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac_starts( &ctx, NULL, 128 ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_starts( &ctx, NULL, 128 ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac_update( NULL, test_data, 16 ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_update( NULL, test_data, 16 ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac_update( &ctx, NULL, 16 ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_update( &ctx, NULL, 16 ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac_finish( NULL, test_output ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_finish( NULL, test_output ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac_finish( &ctx, NULL ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_finish( &ctx, NULL ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac_reset( NULL ) ); + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac_reset( NULL ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac( NULL, + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac( NULL, test_key, 128, test_data, 16, test_output ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac( cipher_info, + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac( cipher_info, NULL, 128, test_data, 16, test_output ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac( cipher_info, + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac( cipher_info, test_key, 128, NULL, 16, test_output ) ); - TEST_INVALID_PARAM( mbedtls_cipher_cmac( cipher_info, + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_cipher_cmac( cipher_info, test_key, 128, test_data, 16, NULL ) ); - TEST_INVALID_PARAM( mbedtls_aes_cmac_prf_128( NULL, 16, + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_aes_cmac_prf_128( NULL, 16, test_data, 16, test_output ) ); - TEST_INVALID_PARAM( mbedtls_aes_cmac_prf_128( test_key, 16, + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_aes_cmac_prf_128( test_key, 16, NULL, 16, test_output ) ); - TEST_INVALID_PARAM( mbedtls_aes_cmac_prf_128( test_key, 16, + TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, + mbedtls_aes_cmac_prf_128( test_key, 16, test_data, 16, NULL ) );