Fix parantheses on return and sizeof statements.
Used script:
```
import re
import sys
for arg in sys.argv[1:]:
print(arg)
with open(arg, 'r') as file:
content = file.read()
content = re.sub(r"return\s?\((?!.*\).*\()\s*\n?(.*)\n?\);", r"return \1;", \
content, flags = re.M)
content = re.sub(r"sizeof ([^\(][a-zA-Z0-9_\[\]]*)", r"sizeof(\1)",\
content, flags = re.M)
with open(arg, 'w') as file:
file.write(content)
```
Executed with:
` find . -regextype posix-egrep -regex ".*\.([hc]|fmt|function)" | xargs -L1 python script.py`
Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
diff --git a/library/chachapoly.c b/library/chachapoly.c
index 77d5477..ffa074b 100644
--- a/library/chachapoly.c
+++ b/library/chachapoly.c
@@ -61,7 +61,7 @@
unsigned char zeroes[15];
if( partial_block_len == 0U )
- return( 0 );
+ return 0 ;
memset( zeroes, 0, sizeof( zeroes ) );
@@ -81,7 +81,7 @@
unsigned char zeroes[15];
if( partial_block_len == 0U )
- return( 0 );
+ return 0 ;
memset( zeroes, 0, sizeof( zeroes ) );
return( mbedtls_poly1305_update( &ctx->poly1305_ctx,
@@ -123,7 +123,7 @@
ret = mbedtls_chacha20_setkey( &ctx->chacha20_ctx, key );
- return( ret );
+ return ret ;
}
int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx,
@@ -163,7 +163,7 @@
cleanup:
mbedtls_platform_zeroize( poly1305_key, 64U );
- return( ret );
+ return ret ;
}
int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
@@ -174,11 +174,11 @@
CHACHAPOLY_VALIDATE_RET( aad_len == 0 || aad != NULL );
if( ctx->state != CHACHAPOLY_STATE_AAD )
- return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
+ return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ;
ctx->aad_len += aad_len;
- return( mbedtls_poly1305_update( &ctx->poly1305_ctx, aad, aad_len ) );
+ return mbedtls_poly1305_update( &ctx->poly1305_ctx, aad, aad_len ) ;
}
int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
@@ -194,7 +194,7 @@
if( ( ctx->state != CHACHAPOLY_STATE_AAD ) &&
( ctx->state != CHACHAPOLY_STATE_CIPHERTEXT ) )
{
- return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
+ return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ;
}
if( ctx->state == CHACHAPOLY_STATE_AAD )
@@ -203,7 +203,7 @@
ret = chachapoly_pad_aad( ctx );
if( ret != 0 )
- return( ret );
+ return ret ;
}
ctx->ciphertext_len += len;
@@ -212,24 +212,24 @@
{
ret = mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output );
if( ret != 0 )
- return( ret );
+ return ret ;
ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, output, len );
if( ret != 0 )
- return( ret );
+ return ret ;
}
else /* DECRYPT */
{
ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, input, len );
if( ret != 0 )
- return( ret );
+ return ret ;
ret = mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output );
if( ret != 0 )
- return( ret );
+ return ret ;
}
- return( 0 );
+ return 0 ;
}
int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
@@ -242,20 +242,20 @@
if( ctx->state == CHACHAPOLY_STATE_INIT )
{
- return( MBEDTLS_ERR_CHACHAPOLY_BAD_STATE );
+ return MBEDTLS_ERR_CHACHAPOLY_BAD_STATE ;
}
if( ctx->state == CHACHAPOLY_STATE_AAD )
{
ret = chachapoly_pad_aad( ctx );
if( ret != 0 )
- return( ret );
+ return ret ;
}
else if( ctx->state == CHACHAPOLY_STATE_CIPHERTEXT )
{
ret = chachapoly_pad_ciphertext( ctx );
if( ret != 0 )
- return( ret );
+ return ret ;
}
ctx->state = CHACHAPOLY_STATE_FINISHED;
@@ -282,11 +282,11 @@
ret = mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U );
if( ret != 0 )
- return( ret );
+ return ret ;
ret = mbedtls_poly1305_finish( &ctx->poly1305_ctx, mac );
- return( ret );
+ return ret ;
}
static int chachapoly_crypt_and_tag( mbedtls_chachapoly_context *ctx,
@@ -316,7 +316,7 @@
ret = mbedtls_chachapoly_finish( ctx, tag );
cleanup:
- return( ret );
+ return ret ;
}
int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx,
@@ -364,7 +364,7 @@
MBEDTLS_CHACHAPOLY_DECRYPT, length, nonce,
aad, aad_len, input, output, check_tag ) ) != 0 )
{
- return( ret );
+ return ret ;
}
/* Check tag in "constant-time" */
@@ -374,10 +374,10 @@
if( diff != 0 )
{
mbedtls_platform_zeroize( output, length );
- return( MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED );
+ return MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED ;
}
- return( 0 );
+ return 0 ;
}
#endif /* MBEDTLS_CHACHAPOLY_ALT */
@@ -481,7 +481,7 @@
if( verbose != 0 ) \
mbedtls_printf args; \
\
- return( -1 ); \
+ return -1 ; \
} \
} \
while( 0 )
@@ -530,7 +530,7 @@
if( verbose != 0 )
mbedtls_printf( "\n" );
- return( 0 );
+ return 0 ;
}
#endif /* MBEDTLS_SELF_TEST */