From 27fdf46d16a32c9f3e95458bd57a06ba365c8fe9 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Thu, 9 Jun 2011 13:55:13 +0000
Subject: [PATCH] - Removed deprecated casts to int for now unsigned values
---
library/aes.c | 14 ++++++++------
library/md2.c | 2 +-
library/md4.c | 2 +-
library/md5.c | 2 +-
library/rsa.c | 10 +++++-----
library/sha1.c | 2 +-
library/sha2.c | 2 +-
library/sha4.c | 8 ++++----
library/x509parse.c | 24 ++++++++++++------------
9 files changed, 34 insertions(+), 32 deletions(-)
diff --git a/library/aes.c b/library/aes.c
index ce418d679b..7bccdf93a1 100644
--- a/library/aes.c
+++ b/library/aes.c
@@ -822,12 +822,13 @@ int aes_crypt_cbc( aes_context *ctx,
int aes_crypt_cfb128( aes_context *ctx,
int mode,
size_t length,
- int *iv_off,
+ size_t *iv_off,
unsigned char iv[16],
const unsigned char *input,
unsigned char *output )
{
- int c, n = *iv_off;
+ int c;
+ size_t n = *iv_off;
if( mode == AES_DECRYPT )
{
@@ -867,14 +868,15 @@ int aes_crypt_cfb128( aes_context *ctx,
* AES-CTR buffer encryption/decryption
*/
int aes_crypt_ctr( aes_context *ctx,
- int length,
- int *nc_off,
+ size_t length,
+ size_t *nc_off,
unsigned char nonce_counter[16],
unsigned char stream_block[16],
const unsigned char *input,
unsigned char *output )
{
- int c, n = *nc_off, i, cb;
+ int c, i, cb;
+ size_t n = *nc_off;
while( length-- )
{
@@ -1089,7 +1091,7 @@ int aes_self_test( int verbose )
unsigned char prv[16];
unsigned char iv[16];
#if defined(POLARSSL_CIPHER_MODE_CTR) || defined(POLARSSL_CIPHER_MODE_CFB)
- int offset;
+ size_t offset;
#endif
#if defined(POLARSSL_CIPHER_MODE_CTR)
int len;
diff --git a/library/md2.c b/library/md2.c
index de64d70a9c..4616b83f7d 100644
--- a/library/md2.c
+++ b/library/md2.c
@@ -194,7 +194,7 @@ int md2_file( const char *path, unsigned char output[16] )
md2_starts( &ctx );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
- md2_update( &ctx, buf, (int) n );
+ md2_update( &ctx, buf, n );
md2_finish( &ctx, output );
diff --git a/library/md4.c b/library/md4.c
index 2b5fcff8ed..a1c82447b2 100644
--- a/library/md4.c
+++ b/library/md4.c
@@ -290,7 +290,7 @@ int md4_file( const char *path, unsigned char output[16] )
md4_starts( &ctx );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
- md4_update( &ctx, buf, (int) n );
+ md4_update( &ctx, buf, n );
md4_finish( &ctx, output );
diff --git a/library/md5.c b/library/md5.c
index a7faa8db1e..1c5b397b6a 100644
--- a/library/md5.c
+++ b/library/md5.c
@@ -309,7 +309,7 @@ int md5_file( const char *path, unsigned char output[16] )
md5_starts( &ctx );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
- md5_update( &ctx, buf, (int) n );
+ md5_update( &ctx, buf, n );
md5_finish( &ctx, output );
diff --git a/library/rsa.c b/library/rsa.c
index 90ea54bd54..1a6a1621bb 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -482,7 +482,7 @@ int rsa_pkcs1_decrypt( rsa_context *ctx,
ilen = ctx->len;
- if( ilen < 16 || ilen > (int) sizeof( buf ) )
+ if( ilen < 16 || ilen > sizeof( buf ) )
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
ret = ( mode == RSA_PUBLIC )
@@ -565,10 +565,10 @@ int rsa_pkcs1_decrypt( rsa_context *ctx,
return( POLARSSL_ERR_RSA_INVALID_PADDING );
}
- if (ilen - (int)(p - buf) > output_max_len)
+ if (ilen - (p - buf) > output_max_len)
return( POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE );
- *olen = ilen - (int)(p - buf);
+ *olen = ilen - (p - buf);
memcpy( output, p, *olen );
return( 0 );
@@ -826,7 +826,7 @@ int rsa_pkcs1_verify( rsa_context *ctx,
#endif
siglen = ctx->len;
- if( siglen < 16 || siglen > (int) sizeof( buf ) )
+ if( siglen < 16 || siglen > sizeof( buf ) )
return( POLARSSL_ERR_RSA_BAD_INPUT_DATA );
ret = ( mode == RSA_PUBLIC )
@@ -853,7 +853,7 @@ int rsa_pkcs1_verify( rsa_context *ctx,
}
p++;
- len = siglen - (int)( p - buf );
+ len = siglen - ( p - buf );
if( len == 34 )
{
diff --git a/library/sha1.c b/library/sha1.c
index b65ab24aa1..56028fe4c5 100644
--- a/library/sha1.c
+++ b/library/sha1.c
@@ -344,7 +344,7 @@ int sha1_file( const char *path, unsigned char output[20] )
sha1_starts( &ctx );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
- sha1_update( &ctx, buf, (int) n );
+ sha1_update( &ctx, buf, n );
sha1_finish( &ctx, output );
diff --git a/library/sha2.c b/library/sha2.c
index 385c048188..9cc88e8203 100644
--- a/library/sha2.c
+++ b/library/sha2.c
@@ -346,7 +346,7 @@ int sha2_file( const char *path, unsigned char output[32], int is224 )
sha2_starts( &ctx, is224 );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
- sha2_update( &ctx, buf, (int) n );
+ sha2_update( &ctx, buf, n );
sha2_finish( &ctx, output );
diff --git a/library/sha4.c b/library/sha4.c
index e0232376a3..54d94fd28f 100644
--- a/library/sha4.c
+++ b/library/sha4.c
@@ -233,7 +233,7 @@ void sha4_update( sha4_context *ctx, const unsigned char *input, size_t ilen )
return;
left = ctx->total[0] & 0x7F;
- fill = (int)( 128 - left );
+ fill = 128 - left;
ctx->total[0] += (unsigned int64) ilen;
@@ -281,7 +281,7 @@ static const unsigned char sha4_padding[128] =
*/
void sha4_finish( sha4_context *ctx, unsigned char output[64] )
{
- int last, padn;
+ size_t last, padn;
unsigned int64 high, low;
unsigned char msglen[16];
@@ -292,7 +292,7 @@ void sha4_finish( sha4_context *ctx, unsigned char output[64] )
PUT_UINT64_BE( high, msglen, 0 );
PUT_UINT64_BE( low, msglen, 8 );
- last = (int)( ctx->total[0] & 0x7F );
+ last = (size_t)( ctx->total[0] & 0x7F );
padn = ( last < 112 ) ? ( 112 - last ) : ( 240 - last );
sha4_update( ctx, (unsigned char *) sha4_padding, padn );
@@ -344,7 +344,7 @@ int sha4_file( const char *path, unsigned char output[64], int is384 )
sha4_starts( &ctx, is384 );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
- sha4_update( &ctx, buf, (int) n );
+ sha4_update( &ctx, buf, n );
sha4_finish( &ctx, output );
diff --git a/library/x509parse.c b/library/x509parse.c
index 16b2034b38..74c4fd5e65 100644
--- a/library/x509parse.c
+++ b/library/x509parse.c
@@ -145,7 +145,7 @@ static int asn1_get_int( unsigned char **p,
if( ( ret = asn1_get_tag( p, end, &len, ASN1_INTEGER ) ) != 0 )
return( ret );
- if( len > (int) sizeof( int ) || ( **p & 0x80 ) != 0 )
+ if( len > sizeof( int ) || ( **p & 0x80 ) != 0 )
return( POLARSSL_ERR_ASN1_INVALID_LENGTH );
*val = 0;
@@ -509,8 +509,8 @@ static int x509_get_time( unsigned char **p,
return( POLARSSL_ERR_X509_CERT_INVALID_DATE + ret );
memset( date, 0, sizeof( date ) );
- memcpy( date, *p, ( len < (int) sizeof( date ) - 1 ) ?
- len : (int) sizeof( date ) - 1 );
+ memcpy( date, *p, ( len < sizeof( date ) - 1 ) ?
+ len : sizeof( date ) - 1 );
if( sscanf( date, "%2d%2d%2d%2d%2d%2d",
&time->year, &time->mon, &time->day,
@@ -533,8 +533,8 @@ static int x509_get_time( unsigned char **p,
return( POLARSSL_ERR_X509_CERT_INVALID_DATE + ret );
memset( date, 0, sizeof( date ) );
- memcpy( date, *p, ( len < (int) sizeof( date ) - 1 ) ?
- len : (int) sizeof( date ) - 1 );
+ memcpy( date, *p, ( len < sizeof( date ) - 1 ) ?
+ len : sizeof( date ) - 1 );
if( sscanf( date, "%4d%2d%2d%2d%2d%2d",
&time->year, &time->mon, &time->day,
@@ -1789,7 +1789,7 @@ int x509parse_crtfile( x509_cert *chain, const char *path )
if ( load_file( path, &buf, &n ) )
return( 1 );
- ret = x509parse_crt( chain, buf, (int) n );
+ ret = x509parse_crt( chain, buf, n );
memset( buf, 0, n + 1 );
free( buf );
@@ -1809,7 +1809,7 @@ int x509parse_crlfile( x509_crl *chain, const char *path )
if ( load_file( path, &buf, &n ) )
return( 1 );
- ret = x509parse_crl( chain, buf, (int) n );
+ ret = x509parse_crl( chain, buf, n );
memset( buf, 0, n + 1 );
free( buf );
@@ -1830,9 +1830,9 @@ int x509parse_keyfile( rsa_context *rsa, const char *path, const char *pwd )
return( 1 );
if( pwd == NULL )
- ret = x509parse_key( rsa, buf, (int) n, NULL, 0 );
+ ret = x509parse_key( rsa, buf, n, NULL, 0 );
else
- ret = x509parse_key( rsa, buf, (int) n,
+ ret = x509parse_key( rsa, buf, n,
(unsigned char *) pwd, strlen( pwd ) );
memset( buf, 0, n + 1 );
@@ -1853,7 +1853,7 @@ int x509parse_public_keyfile( rsa_context *rsa, const char *path )
if ( load_file( path, &buf, &n ) )
return( 1 );
- ret = x509parse_public_key( rsa, buf, (int) n );
+ ret = x509parse_public_key( rsa, buf, n );
memset( buf, 0, n + 1 );
free( buf );
@@ -2177,7 +2177,7 @@ int x509parse_dhmfile( dhm_context *dhm, const char *path )
if ( load_file( path, &buf, &n ) )
return( 1 );
- ret = x509parse_dhm( dhm, buf, (int) n);
+ ret = x509parse_dhm( dhm, buf, n );
memset( buf, 0, n + 1 );
free( buf );
@@ -2315,7 +2315,7 @@ int x509parse_dn_gets( char *buf, size_t size, const x509_name *dn )
for( i = 0; i < name->val.len; i++ )
{
- if( i >= (int) sizeof( s ) - 1 )
+ if( i >= sizeof( s ) - 1 )
break;
c = name->val.p[i];