mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 02:35:38 +01:00
Removed unneed memsets and fixed spacing
This commit is contained in:
parent
87e4040bb9
commit
4b64ab6664
@ -74,7 +74,6 @@ static int cmac_multiply_by_u( unsigned char *output,
|
|||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
size_t blocksize )
|
size_t blocksize )
|
||||||
{
|
{
|
||||||
|
|
||||||
const unsigned char R_128 = 0x87;
|
const unsigned char R_128 = 0x87;
|
||||||
const unsigned char R_64 = 0x1B;
|
const unsigned char R_64 = 0x1B;
|
||||||
unsigned char R_n, mask;
|
unsigned char R_n, mask;
|
||||||
@ -91,7 +90,6 @@ static int cmac_multiply_by_u( unsigned char *output,
|
|||||||
return( MBEDTLS_ERR_CMAC_BAD_INPUT );
|
return( MBEDTLS_ERR_CMAC_BAD_INPUT );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for( i = starting_index; i >= 0; i-- )
|
for( i = starting_index; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
output[i] = input[i] << 1 | overflow;
|
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;
|
block_size = ctx->cipher_ctx.cipher_info->block_size;
|
||||||
|
|
||||||
L = mbedtls_calloc( block_size, sizeof( unsigned char ) );
|
L = mbedtls_calloc( block_size, sizeof( unsigned char ) );
|
||||||
if( L == NULL)
|
if( L == NULL )
|
||||||
{
|
{
|
||||||
ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED;
|
ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
/* Calculate Ek(0) */
|
/* Calculate Ek(0) */
|
||||||
memset( L, 0, block_size );
|
|
||||||
if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx,
|
if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx,
|
||||||
L, block_size, L, &olen ) ) != 0 )
|
L, block_size, L, &olen ) ) != 0 )
|
||||||
{
|
{
|
||||||
@ -152,7 +149,7 @@ static int cmac_generate_subkeys( mbedtls_cmac_context *ctx )
|
|||||||
exit:
|
exit:
|
||||||
if( L != NULL )
|
if( L != NULL )
|
||||||
mbedtls_zeroize( L, sizeof( L ) );
|
mbedtls_zeroize( L, sizeof( L ) );
|
||||||
free( L );
|
mbedtls_free( L );
|
||||||
return( ret );
|
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 );
|
XOR_BLOCK( M_last, input + block_size * ( n - 1 ), ctx->K1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
memset( state, 0, block_size );
|
|
||||||
|
|
||||||
for( j = 0; j < n - 1; j++ )
|
for( j = 0; j < n - 1; j++ )
|
||||||
UPDATE_CMAC( input + block_size * j );
|
UPDATE_CMAC( input + block_size * j );
|
||||||
|
|
||||||
@ -318,8 +313,8 @@ int mbedtls_cmac_generate( mbedtls_cmac_context *ctx,
|
|||||||
memcpy( tag, state, tag_len );
|
memcpy( tag, state, tag_len );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
free( state );
|
mbedtls_free( state );
|
||||||
free( M_last );
|
mbedtls_free( M_last );
|
||||||
return( ret );
|
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,
|
check_tag = mbedtls_calloc( ctx->cipher_ctx.cipher_info->block_size,
|
||||||
sizeof( unsigned char ) );
|
sizeof( unsigned char ) );
|
||||||
if(check_tag == NULL)
|
if( check_tag == NULL )
|
||||||
{
|
{
|
||||||
ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED;
|
ret = MBEDTLS_ERR_CMAC_ALLOC_FAILED;
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -361,7 +356,7 @@ int mbedtls_cmac_verify( mbedtls_cmac_context *ctx,
|
|||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
free( check_tag );
|
mbedtls_free( check_tag );
|
||||||
return( ret );
|
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( ( ret = mbedtls_cmac_verify( &ctx, messages, message_lengths[i], &expected_result[i * block_size], block_size ) != 0 ) )
|
||||||
{
|
{
|
||||||
if( verbose != 0 )
|
if( verbose != 0 )
|
||||||
mbedtls_printf( "failed\n" );
|
mbedtls_printf( "failed\n" );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
mbedtls_printf( "passed\n" );
|
mbedtls_printf( "passed\n" );
|
||||||
}
|
}
|
||||||
exit:
|
exit:
|
||||||
free( tag );
|
mbedtls_free( tag );
|
||||||
mbedtls_cmac_free( &ctx );
|
mbedtls_cmac_free( &ctx );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user