cmac: improve parameter validation test suite

Extend the scope of NULL cipher info tests
This commit is contained in:
Unknown 2018-12-24 05:23:50 -05:00
parent f8d0e1d456
commit 2ce0af4b3c

View File

@ -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 ) );