Fix some whitespace and other style issues

In addition to whitespace:
- wrapped a few long lines
- added parenthesis to return statements
This commit is contained in:
Manuel Pégourié-Gonnard 2018-02-28 10:54:31 +01:00
parent fdd4354329
commit 4231e7f46f
4 changed files with 120 additions and 109 deletions

View file

@ -81,7 +81,8 @@ void mbedtls_aria_free( mbedtls_aria_context *ctx );
*
* \return 0 if successful, or MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH
*/
int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx, const unsigned char *key,
int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx,
const unsigned char *key,
unsigned int keybits );
/**
@ -93,7 +94,8 @@ int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx, const unsigned char *key
*
* \return 0 if successful, or MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH
*/
int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx, const unsigned char *key,
int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx,
const unsigned char *key,
unsigned int keybits );
/**

View file

@ -56,7 +56,6 @@ static void mbedtls_zeroize( void *v, size_t n ) {
/*
* 32-bit integer manipulation macros (little endian)
*/
#ifndef GET_UINT32_LE
#define GET_UINT32_LE( n, b, i ) \
{ \
@ -446,7 +445,7 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
uint32_t w[4][4], *w2;
if (keybits != 128 && keybits != 192 && keybits != 256)
return MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH;
return( MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH );
/* Copy key to W0 (and potential remainder to W1) */
GET_UINT32_LE( w[0][0], key, 0 );
@ -485,7 +484,7 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
}
aria_rot128( ctx->rk[16], w[0], w[1], 19 );
return 0;
return( 0 );
}
/*
@ -498,7 +497,7 @@ int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
ret = mbedtls_aria_setkey_enc( ctx, key, keybits );
if( ret != 0 )
return ret;
return( ret );
/* flip the order of round keys */
for( i = 0, j = ctx->nr; i < j; i++, j-- )
@ -513,9 +512,12 @@ int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
/* apply affine transform to middle keys */
for (i = 1; i < ctx->nr; i++ )
aria_a( &ctx->rk[i][0], &ctx->rk[i][1], &ctx->rk[i][2], &ctx->rk[i][3] );
{
aria_a( &ctx->rk[i][0], &ctx->rk[i][1],
&ctx->rk[i][2], &ctx->rk[i][3] );
}
return 0;
return( 0 );
}
/*
@ -572,7 +574,7 @@ int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx,
PUT_UINT32_LE( c, output, 8 );
PUT_UINT32_LE( d, output, 12 );
return 0;
return( 0 );
}
/* Initialize context */

View file

@ -27,12 +27,14 @@ void aria_encrypt_ecb( char *hex_key_string, char *hex_src_string,
key_len = unhexify( key_str, hex_key_string );
data_len = unhexify( src_str, hex_src_string );
TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ) == setkey_result );
TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 )
== setkey_result );
if( setkey_result == 0 )
{
for( i = 0; i < data_len; i += 16 )
{
TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, MBEDTLS_ARIA_ENCRYPT, src_str + i, output + i ) == 0 );
TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, MBEDTLS_ARIA_ENCRYPT,
src_str + i, output + i ) == 0 );
}
hexify( dst_str, output, data_len );
@ -64,7 +66,8 @@ void aria_decrypt_ecb( char *hex_key_string, char *hex_src_string,
key_len = unhexify( key_str, hex_key_string );
data_len = unhexify( src_str, hex_src_string );
TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 ) == setkey_result );
TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 )
== setkey_result );
if( setkey_result == 0 )
{
for( i = 0; i < data_len; i += 16 )
@ -107,8 +110,9 @@ void aria_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
data_len = unhexify( src_str, hex_src_string );
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT,
data_len, iv_str, src_str, output) == cbc_result );
TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, data_len,
iv_str, src_str, output )
== cbc_result );
if( cbc_result == 0 )
{
hexify( dst_str, output, data_len );
@ -146,8 +150,9 @@ void aria_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
data_len = unhexify( src_str, hex_src_string );
mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 );
TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT,
data_len, iv_str, src_str, output ) == cbc_result );
TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, data_len,
iv_str, src_str, output )
== cbc_result );
if( cbc_result == 0 )
{
hexify( dst_str, output, data_len );
@ -187,7 +192,8 @@ void aria_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT,
data_len, &iv_offset, iv_str, src_str, output ) == result );
data_len, &iv_offset, iv_str,
src_str, output ) == result );
hexify( dst_str, output, data_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
@ -224,7 +230,8 @@ void aria_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT,
data_len, &iv_offset, iv_str, src_str, output ) == result );
data_len, &iv_offset, iv_str,
src_str, output ) == result );
hexify( dst_str, output, data_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
@ -261,8 +268,8 @@ void aria_encrypt_ctr( char *hex_key_string, char *hex_iv_string,
data_len = unhexify( src_str, hex_src_string );
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len,
&iv_offset, iv_str, blk, src_str, output ) == result );
TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
blk, src_str, output ) == result );
hexify( dst_str, output, data_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
@ -299,8 +306,8 @@ void aria_decrypt_ctr( char *hex_key_string, char *hex_iv_string,
data_len = unhexify( src_str, hex_src_string );
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len,
&iv_offset, iv_str, blk, src_str, output ) == result );
TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
blk, src_str, output ) == result );
hexify( dst_str, output, data_len );
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );