Commit 4b64ab66 authored by Brian Murray's avatar Brian Murray Committed by Simon Butcher

Removed unneed memsets and fixed spacing

parent 87e4040b
......@@ -74,7 +74,6 @@ static int cmac_multiply_by_u( unsigned char *output,
const unsigned char *input,
size_t blocksize )
{
const unsigned char R_128 = 0x87;
const unsigned char R_64 = 0x1B;
unsigned char R_n, mask;
......@@ -91,7 +90,6 @@ static int cmac_multiply_by_u( unsigned char *output,
return( MBEDTLS_ERR_CMAC_BAD_INPUT );
}
for( i = starting_index; i >= 0; i-- )
{
output[i] = input[i] << 1 | overflow;
......@@ -128,13 +126,12 @@ static int cmac_generate_subkeys( mbedtls_cmac_context *ctx )
block_size = ctx->cipher_ctx.cipher_info->block_size;
L = mbedtls_calloc( block_size, sizeof( unsigned char ) );
if( L == NULL)
if( L == NULL )
{
ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED;
goto exit;
}
/* Calculate Ek(0) */
memset( L, 0, block_size );
if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx,
L, block_size, L, &olen ) ) != 0 )
{
......@@ -152,7 +149,7 @@ static int cmac_generate_subkeys( mbedtls_cmac_context *ctx )
exit:
if( L != NULL )
mbedtls_zeroize( L, sizeof( L ) );
free( L );
mbedtls_free( L );
return( ret );
}
......@@ -308,8 +305,6 @@ int mbedtls_cmac_generate( mbedtls_cmac_context *ctx,
XOR_BLOCK( M_last, input + block_size * ( n - 1 ), ctx->K1 );
}
memset( state, 0, block_size );
for( j = 0; j < n - 1; j++ )
UPDATE_CMAC( input + block_size * j );
......@@ -318,8 +313,8 @@ int mbedtls_cmac_generate( mbedtls_cmac_context *ctx,
memcpy( tag, state, tag_len );
exit:
free( state );
free( M_last );
mbedtls_free( state );
mbedtls_free( M_last );
return( ret );
}
......@@ -340,7 +335,7 @@ int mbedtls_cmac_verify( mbedtls_cmac_context *ctx,
check_tag = mbedtls_calloc( ctx->cipher_ctx.cipher_info->block_size,
sizeof( unsigned char ) );
if(check_tag == NULL)
if( check_tag == NULL )
{
ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED;
goto exit;
......@@ -361,7 +356,7 @@ int mbedtls_cmac_verify( mbedtls_cmac_context *ctx,
goto exit;
exit:
free( check_tag );
mbedtls_free( check_tag );
return( ret );
}
......@@ -727,14 +722,14 @@ int test_cmac_with_cipher( int verbose,
if( ( ret = mbedtls_cmac_verify( &ctx, messages, message_lengths[i], &expected_result[i * block_size], block_size ) != 0 ) )
{
if( verbose != 0 )
mbedtls_printf( "failed\n" );
goto exit;
if( verbose != 0 )
mbedtls_printf( "failed\n" );
goto exit;
}
mbedtls_printf( "passed\n" );
}
exit:
free( tag );
mbedtls_free( tag );
mbedtls_cmac_free( &ctx );
return( ret );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment