From 516897a44a19c862227e08b8bc5a7ef95a3d4a72 Mon Sep 17 00:00:00 2001 From: k-stachowiak Date: Wed, 19 Dec 2018 17:07:02 +0100 Subject: [PATCH] Remove unnecessary parameter validation from the Cipher module --- library/cipher.c | 6 ------ tests/suites/test_suite_cipher.function | 22 ---------------------- 2 files changed, 28 deletions(-) diff --git a/library/cipher.c b/library/cipher.c index abf268f31..273997577 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -1010,8 +1010,6 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( ilen == 0 || input != NULL ); CIPHER_VALIDATE_RET( output != NULL ); CIPHER_VALIDATE_RET( olen != NULL ); - if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); if( ( ret = mbedtls_cipher_set_iv( ctx, iv, iv_len ) ) != 0 ) return( ret ); @@ -1048,8 +1046,6 @@ int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( output != NULL ); CIPHER_VALIDATE_RET( olen != NULL ); CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL ); - if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); #if defined(MBEDTLS_GCM_C) if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode ) @@ -1105,8 +1101,6 @@ int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx, CIPHER_VALIDATE_RET( output != NULL ); CIPHER_VALIDATE_RET( olen != NULL ); CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL ); - if( ctx->cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); #if defined(MBEDTLS_GCM_C) if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode ) diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function index 16327c387..6073421a9 100644 --- a/tests/suites/test_suite_cipher.function +++ b/tests/suites/test_suite_cipher.function @@ -267,12 +267,6 @@ void cipher_invalid_param( ) valid_buffer, valid_size, valid_buffer, valid_size, valid_buffer, &size_t_var ) ); - TEST_ASSERT( - mbedtls_cipher_crypt( &invalid_ctx, - valid_buffer, valid_size, - valid_buffer, valid_size, - valid_buffer, &size_t_var ) == - MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, mbedtls_cipher_crypt( &valid_ctx, @@ -308,14 +302,6 @@ void cipher_invalid_param( ) valid_buffer, valid_size, valid_buffer, &size_t_var, valid_buffer, valid_size ) ); - TEST_ASSERT( - mbedtls_cipher_auth_encrypt( &invalid_ctx, - valid_buffer, valid_size, - valid_buffer, valid_size, - valid_buffer, valid_size, - valid_buffer, &size_t_var, - valid_buffer, valid_size ) == - MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, mbedtls_cipher_auth_encrypt( &valid_ctx, @@ -374,14 +360,6 @@ void cipher_invalid_param( ) valid_buffer, valid_size, valid_buffer, &size_t_var, valid_buffer, valid_size ) ); - TEST_ASSERT( - mbedtls_cipher_auth_decrypt( &invalid_ctx, - valid_buffer, valid_size, - valid_buffer, valid_size, - valid_buffer, valid_size, - valid_buffer, &size_t_var, - valid_buffer, valid_size ) == - MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, mbedtls_cipher_auth_decrypt( &valid_ctx,