1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

Cleanup up non-prototyped functions (static) and const-correctness

More fixes based on the compiler directives -Wcast-qual -Wwrite-strings
-Wmissing-prototypes -Wmissing-declarations. Not everything with regards
to -Wcast-qual has been fixed as some have unwanted consequences for the
rest of the code.
This commit is contained in:
Paul Bakker
2013-06-25 16:25:17 +02:00
parent 169b7f4a13
commit b6c5d2e1a6
16 changed files with 98 additions and 93 deletions

View File

@ -57,7 +57,7 @@
/*
* XTEA key schedule
*/
void xtea_setup( xtea_context *ctx, unsigned char key[16] )
void xtea_setup( xtea_context *ctx, const unsigned char key[16] )
{
int i;
@ -72,13 +72,13 @@ void xtea_setup( xtea_context *ctx, unsigned char key[16] )
/*
* XTEA encrypt function
*/
int xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
unsigned char output[8])
int xtea_crypt_ecb( xtea_context *ctx, int mode,
const unsigned char input[8], unsigned char output[8])
{
uint32_t *k, v0, v1, i;
k = ctx->k;
GET_UINT32_BE( v0, input, 0 );
GET_UINT32_BE( v1, input, 4 );
@ -114,27 +114,24 @@ int xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
/*
* XTEA-CBC buffer encryption/decryption
*/
int xtea_crypt_cbc( xtea_context *ctx,
int mode,
size_t length,
unsigned char iv[8],
unsigned char *input,
int xtea_crypt_cbc( xtea_context *ctx, int mode, size_t length,
unsigned char iv[8], const unsigned char *input,
unsigned char *output)
{
int i;
unsigned char temp[8];
if(length % 8)
if( length % 8 )
return( POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH );
if( mode == XTEA_DECRYPT )
if( mode == XTEA_DECRYPT )
{
while( length > 0 )
{
memcpy( temp, input, 8 );
xtea_crypt_ecb( ctx, mode, input, output );
for(i = 0; i < 8; i++)
for(i = 0; i < 8; i++)
output[i] = (unsigned char)( output[i] ^ iv[i] );
memcpy( iv, temp, 8 );
@ -143,8 +140,8 @@ int xtea_crypt_cbc( xtea_context *ctx,
output += 8;
length -= 8;
}
}
else
}
else
{
while( length > 0 )
{
@ -153,7 +150,7 @@ int xtea_crypt_cbc( xtea_context *ctx,
xtea_crypt_ecb( ctx, mode, output, output );
memcpy( iv, output, 8 );
input += 8;
output += 8;
length -= 8;
@ -225,7 +222,7 @@ int xtea_self_test( int verbose )
memcpy( buf, xtea_test_pt[i], 8 );
xtea_setup( &ctx, (unsigned char *) xtea_test_key[i] );
xtea_setup( &ctx, xtea_test_key[i] );
xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, buf, buf );
if( memcmp( buf, xtea_test_ct[i], 8 ) != 0 )