mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-28 08:37:25 +00:00
Remove NULL pointer validation in gcm.c
Signed-off-by: Tuvshinzaya Erdenekhuu <tuvshinzaya.erdenekhuu@arm.com>
This commit is contained in:
parent
6c68927948
commit
505ce0b37e
@ -63,7 +63,6 @@
|
|||||||
*/
|
*/
|
||||||
void mbedtls_gcm_init( mbedtls_gcm_context *ctx )
|
void mbedtls_gcm_init( mbedtls_gcm_context *ctx )
|
||||||
{
|
{
|
||||||
GCM_VALIDATE( ctx != NULL );
|
|
||||||
memset( ctx, 0, sizeof( mbedtls_gcm_context ) );
|
memset( ctx, 0, sizeof( mbedtls_gcm_context ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +142,6 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
|
|||||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
const mbedtls_cipher_info_t *cipher_info;
|
const mbedtls_cipher_info_t *cipher_info;
|
||||||
|
|
||||||
GCM_VALIDATE_RET( ctx != NULL );
|
|
||||||
GCM_VALIDATE_RET( key != NULL );
|
|
||||||
GCM_VALIDATE_RET( keybits == 128 || keybits == 192 || keybits == 256 );
|
GCM_VALIDATE_RET( keybits == 128 || keybits == 192 || keybits == 256 );
|
||||||
|
|
||||||
cipher_info = mbedtls_cipher_info_from_values( cipher, keybits,
|
cipher_info = mbedtls_cipher_info_from_values( cipher, keybits,
|
||||||
@ -256,9 +253,6 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
|
|||||||
size_t use_len, olen = 0;
|
size_t use_len, olen = 0;
|
||||||
uint64_t iv_bits;
|
uint64_t iv_bits;
|
||||||
|
|
||||||
GCM_VALIDATE_RET( ctx != NULL );
|
|
||||||
GCM_VALIDATE_RET( iv != NULL );
|
|
||||||
|
|
||||||
/* IV is limited to 2^64 bits, so 2^61 bytes */
|
/* IV is limited to 2^64 bits, so 2^61 bytes */
|
||||||
/* IV is not allowed to be zero length */
|
/* IV is not allowed to be zero length */
|
||||||
if( iv_len == 0 || (uint64_t) iv_len >> 61 != 0 )
|
if( iv_len == 0 || (uint64_t) iv_len >> 61 != 0 )
|
||||||
@ -334,8 +328,6 @@ int mbedtls_gcm_update_ad( mbedtls_gcm_context *ctx,
|
|||||||
const unsigned char *p;
|
const unsigned char *p;
|
||||||
size_t use_len, i, offset;
|
size_t use_len, i, offset;
|
||||||
|
|
||||||
GCM_VALIDATE_RET( add_len == 0 || add != NULL );
|
|
||||||
|
|
||||||
/* IV is limited to 2^64 bits, so 2^61 bytes */
|
/* IV is limited to 2^64 bits, so 2^61 bytes */
|
||||||
if( (uint64_t) add_len >> 61 != 0 )
|
if( (uint64_t) add_len >> 61 != 0 )
|
||||||
return( MBEDTLS_ERR_GCM_BAD_INPUT );
|
return( MBEDTLS_ERR_GCM_BAD_INPUT );
|
||||||
@ -434,7 +426,6 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
|
|||||||
|
|
||||||
if( output_size < input_length )
|
if( output_size < input_length )
|
||||||
return( MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL );
|
return( MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL );
|
||||||
GCM_VALIDATE_RET( output_length != NULL );
|
|
||||||
*output_length = input_length;
|
*output_length = input_length;
|
||||||
|
|
||||||
/* Exit early if input_length==0 so that we don't do any pointer arithmetic
|
/* Exit early if input_length==0 so that we don't do any pointer arithmetic
|
||||||
@ -444,10 +435,6 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
|
|||||||
if( input_length == 0 )
|
if( input_length == 0 )
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
|
||||||
GCM_VALIDATE_RET( ctx != NULL );
|
|
||||||
GCM_VALIDATE_RET( input != NULL );
|
|
||||||
GCM_VALIDATE_RET( output != NULL );
|
|
||||||
|
|
||||||
if( output > input && (size_t) ( output - input ) < input_length )
|
if( output > input && (size_t) ( output - input ) < input_length )
|
||||||
return( MBEDTLS_ERR_GCM_BAD_INPUT );
|
return( MBEDTLS_ERR_GCM_BAD_INPUT );
|
||||||
|
|
||||||
@ -519,9 +506,6 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
|
|||||||
uint64_t orig_len;
|
uint64_t orig_len;
|
||||||
uint64_t orig_add_len;
|
uint64_t orig_add_len;
|
||||||
|
|
||||||
GCM_VALIDATE_RET( ctx != NULL );
|
|
||||||
GCM_VALIDATE_RET( tag != NULL );
|
|
||||||
|
|
||||||
/* We never pass any output in finish(). The output parameter exists only
|
/* We never pass any output in finish(). The output parameter exists only
|
||||||
* for the sake of alternative implementations. */
|
* for the sake of alternative implementations. */
|
||||||
(void) output;
|
(void) output;
|
||||||
@ -580,13 +564,6 @@ int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
|
|||||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
size_t olen;
|
size_t olen;
|
||||||
|
|
||||||
GCM_VALIDATE_RET( ctx != NULL );
|
|
||||||
GCM_VALIDATE_RET( iv != NULL );
|
|
||||||
GCM_VALIDATE_RET( add_len == 0 || add != NULL );
|
|
||||||
GCM_VALIDATE_RET( length == 0 || input != NULL );
|
|
||||||
GCM_VALIDATE_RET( length == 0 || output != NULL );
|
|
||||||
GCM_VALIDATE_RET( tag != NULL );
|
|
||||||
|
|
||||||
if( ( ret = mbedtls_gcm_starts( ctx, mode, iv, iv_len ) ) != 0 )
|
if( ( ret = mbedtls_gcm_starts( ctx, mode, iv, iv_len ) ) != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
||||||
@ -619,13 +596,6 @@ int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
|
|||||||
size_t i;
|
size_t i;
|
||||||
int diff;
|
int diff;
|
||||||
|
|
||||||
GCM_VALIDATE_RET( ctx != NULL );
|
|
||||||
GCM_VALIDATE_RET( iv != NULL );
|
|
||||||
GCM_VALIDATE_RET( add_len == 0 || add != NULL );
|
|
||||||
GCM_VALIDATE_RET( tag != NULL );
|
|
||||||
GCM_VALIDATE_RET( length == 0 || input != NULL );
|
|
||||||
GCM_VALIDATE_RET( length == 0 || output != NULL );
|
|
||||||
|
|
||||||
if( ( ret = mbedtls_gcm_crypt_and_tag( ctx, MBEDTLS_GCM_DECRYPT, length,
|
if( ( ret = mbedtls_gcm_crypt_and_tag( ctx, MBEDTLS_GCM_DECRYPT, length,
|
||||||
iv, iv_len, add, add_len,
|
iv, iv_len, add, add_len,
|
||||||
input, output, tag_len, check_tag ) ) != 0 )
|
input, output, tag_len, check_tag ) ) != 0 )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user