From: Andy Polyakov Date: Fri, 31 Oct 2008 19:30:11 +0000 (+0000) Subject: size_t-fy AES, Camellia and RC4. X-Git-Tag: OpenSSL_0_9_8k^2~198 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f768be81d804d0467be4ad7163216c8381872b94;p=oweals%2Fopenssl.git size_t-fy AES, Camellia and RC4. --- diff --git a/crypto/aes/aes.h b/crypto/aes/aes.h index 51f91e6079..35e6be0025 100644 --- a/crypto/aes/aes.h +++ b/crypto/aes/aes.h @@ -58,6 +58,8 @@ #error AES is disabled. #endif +#include + #define AES_ENCRYPT 1 #define AES_DECRYPT 0 @@ -96,35 +98,35 @@ void AES_decrypt(const unsigned char *in, unsigned char *out, void AES_ecb_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key, const int enc); void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, const int enc); void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, - unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc); void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc); void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc); void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out, const int nbits,const AES_KEY *key, unsigned char *ivec,const int enc); void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, - unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, int *num); void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE], unsigned char ecount_buf[AES_BLOCK_SIZE], unsigned int *num); /* NB: the IV is _two_ blocks long */ void AES_ige_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, const int enc); /* NB: the IV is _four_ blocks long */ void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, const AES_KEY *key2, const unsigned char *ivec, const int enc); diff --git a/crypto/aes/aes_cbc.c b/crypto/aes/aes_cbc.c index d2ba6bcdb4..5ce614570f 100644 --- a/crypto/aes/aes_cbc.c +++ b/crypto/aes/aes_cbc.c @@ -60,11 +60,10 @@ #include "aes_locl.h" void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t len, const AES_KEY *key, unsigned char *ivec, const int enc) { - unsigned long n; - unsigned long len = length; + size_t n; unsigned char tmp[AES_BLOCK_SIZE]; const unsigned char *iv = ivec; diff --git a/crypto/aes/aes_cfb.c b/crypto/aes/aes_cfb.c index 064b0d8b13..b085316941 100644 --- a/crypto/aes/aes_cfb.c +++ b/crypto/aes/aes_cfb.c @@ -73,11 +73,11 @@ */ void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, - unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc) { unsigned int n; - unsigned long l = 0; + size_t l = 0; assert(in && out && key && ivec && num); @@ -219,10 +219,10 @@ void AES_cfbr_encrypt_block(const unsigned char *in,unsigned char *out, /* N.B. This expects the input to be packed, MS bit first */ void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc) { - unsigned int n; + size_t n; unsigned char c[1],d[1]; assert(in && out && key && ivec && num); @@ -238,10 +238,10 @@ void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, } void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc) { - unsigned int n; + size_t n; assert(in && out && key && ivec && num); assert(*num == 0); diff --git a/crypto/aes/aes_ctr.c b/crypto/aes/aes_ctr.c index f36982be1e..501900a2ef 100644 --- a/crypto/aes/aes_ctr.c +++ b/crypto/aes/aes_ctr.c @@ -113,20 +113,19 @@ static void AES_ctr128_inc(unsigned char *counter) { * into the rest of the IV when incremented. */ void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE], unsigned char ecount_buf[AES_BLOCK_SIZE], unsigned int *num) { unsigned int n; - unsigned long l=length; assert(in && out && key && counter && num); assert(*num < AES_BLOCK_SIZE); n = *num; - while (l--) { + while (length--) { if (n == 0) { AES_encrypt(ivec, ecount_buf, key); AES_ctr128_inc(ivec); diff --git a/crypto/aes/aes_ige.c b/crypto/aes/aes_ige.c index 45d7096181..c161351e65 100644 --- a/crypto/aes/aes_ige.c +++ b/crypto/aes/aes_ige.c @@ -77,11 +77,11 @@ typedef struct { /* N.B. The IV for this mode is _twice_ the block size */ void AES_ige_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, const int enc) { - unsigned long n; - unsigned long len; + size_t n; + size_t len = length; OPENSSL_assert(in && out && key && ivec); OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); @@ -211,12 +211,12 @@ void AES_ige_encrypt(const unsigned char *in, unsigned char *out, /* N.B. The IV for this mode is _four times_ the block size */ void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, const AES_KEY *key2, const unsigned char *ivec, const int enc) { - unsigned long n; - unsigned long len = length; + size_t n; + size_t len = length; unsigned char tmp[AES_BLOCK_SIZE]; unsigned char tmp2[AES_BLOCK_SIZE]; unsigned char tmp3[AES_BLOCK_SIZE]; diff --git a/crypto/aes/aes_ofb.c b/crypto/aes/aes_ofb.c index eda1e55bdf..b71c6f16f8 100644 --- a/crypto/aes/aes_ofb.c +++ b/crypto/aes/aes_ofb.c @@ -71,11 +71,11 @@ * 128bit block we have used is contained in *num; */ void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, - unsigned long length, const AES_KEY *key, + size_t length, const AES_KEY *key, unsigned char *ivec, int *num) { unsigned int n; - unsigned long l=0; + size_t l=0; assert(in && out && key && ivec && num); diff --git a/crypto/camellia/camellia.h b/crypto/camellia/camellia.h index 5dd423b29b..055a25582c 100644 --- a/crypto/camellia/camellia.h +++ b/crypto/camellia/camellia.h @@ -58,6 +58,8 @@ #error CAMELLIA is disabled. #endif +#include + #define CAMELLIA_ENCRYPT 1 #define CAMELLIA_DECRYPT 0 @@ -97,25 +99,25 @@ void Camellia_decrypt(const unsigned char *in, unsigned char *out, void Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out, const CAMELLIA_KEY *key, const int enc); void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, const int enc); void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num, const int enc); void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num, const int enc); void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num, const int enc); void Camellia_cfbr_encrypt_block(const unsigned char *in,unsigned char *out, const int nbits,const CAMELLIA_KEY *key, unsigned char *ivec,const int enc); void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num); void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char ivec[CAMELLIA_BLOCK_SIZE], unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE], unsigned int *num); diff --git a/crypto/camellia/cmll_cbc.c b/crypto/camellia/cmll_cbc.c index 545e6c1f41..421c33127b 100644 --- a/crypto/camellia/cmll_cbc.c +++ b/crypto/camellia/cmll_cbc.c @@ -60,12 +60,11 @@ #include #include "cmll_locl.h" void Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t len, const CAMELLIA_KEY *key, unsigned char *ivec, const int enc) { - unsigned long n; - unsigned long len = length; + size_t n; unsigned char tmp[CAMELLIA_BLOCK_SIZE]; const unsigned char *iv = ivec; diff --git a/crypto/camellia/cmll_cfb.c b/crypto/camellia/cmll_cfb.c index af0f9f49ad..8eed2be9ea 100644 --- a/crypto/camellia/cmll_cfb.c +++ b/crypto/camellia/cmll_cfb.c @@ -124,12 +124,11 @@ */ void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num, const int enc) { unsigned int n; - unsigned long l = length; unsigned char c; assert(in && out && key && ivec && num); @@ -138,7 +137,7 @@ void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, if (enc) { - while (l--) + while (length--) { if (n == 0) { @@ -150,7 +149,7 @@ void Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, } else { - while (l--) + while (length--) { if (n == 0) { @@ -202,10 +201,10 @@ void Camellia_cfbr_encrypt_block(const unsigned char *in,unsigned char *out, /* N.B. This expects the input to be packed, MS bit first */ void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num, const int enc) { - unsigned int n; + size_t n; unsigned char c[1],d[1]; assert(in && out && key && ivec && num); @@ -221,10 +220,10 @@ void Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out, } void Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num, const int enc) { - unsigned int n; + size_t n; assert(in && out && key && ivec && num); assert(*num == 0); diff --git a/crypto/camellia/cmll_ctr.c b/crypto/camellia/cmll_ctr.c index cc21b70890..332749ef76 100644 --- a/crypto/camellia/cmll_ctr.c +++ b/crypto/camellia/cmll_ctr.c @@ -113,21 +113,20 @@ static void Camellia_ctr128_inc(unsigned char *counter) * into the rest of the IV when incremented. */ void Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char ivec[CAMELLIA_BLOCK_SIZE], unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE], unsigned int *num) { unsigned int n; - unsigned long l=length; assert(in && out && key && counter && num); assert(*num < CAMELLIA_BLOCK_SIZE); n = *num; - while (l--) + while (length--) { if (n == 0) { diff --git a/crypto/camellia/cmll_ofb.c b/crypto/camellia/cmll_ofb.c index d89cf9f3b3..1646fc0ce7 100644 --- a/crypto/camellia/cmll_ofb.c +++ b/crypto/camellia/cmll_ofb.c @@ -119,17 +119,16 @@ * 128bit block we have used is contained in *num; */ void Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out, - const unsigned long length, const CAMELLIA_KEY *key, + size_t length, const CAMELLIA_KEY *key, unsigned char *ivec, int *num) { unsigned int n; - unsigned long l=length; assert(in && out && key && ivec && num); n = *num; - while (l--) { + while (length--) { if (n == 0) { Camellia_encrypt(ivec, ivec, key); } diff --git a/crypto/rc4/rc4.h b/crypto/rc4/rc4.h index 7aec04fe93..29d1acccf5 100644 --- a/crypto/rc4/rc4.h +++ b/crypto/rc4/rc4.h @@ -64,6 +64,8 @@ #error RC4 is disabled. #endif +#include + #ifdef __cplusplus extern "C" { #endif @@ -77,7 +79,7 @@ typedef struct rc4_key_st const char *RC4_options(void); void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); -void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, +void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, unsigned char *outdata); #ifdef __cplusplus diff --git a/crypto/rc4/rc4_enc.c b/crypto/rc4/rc4_enc.c index d5f18a3a70..37ef43c16c 100644 --- a/crypto/rc4/rc4_enc.c +++ b/crypto/rc4/rc4_enc.c @@ -67,12 +67,12 @@ * Date: Wed, 14 Sep 1994 06:35:31 GMT */ -void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, +void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, unsigned char *outdata) { register RC4_INT *d; register RC4_INT x,y,tx,ty; - int i; + size_t i; x=key->x; y=key->y; @@ -120,8 +120,8 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, (RC4_CHUNK)d[(tx+ty)&0xff]\ ) - if ( ( ((unsigned long)indata & (sizeof(RC4_CHUNK)-1)) | - ((unsigned long)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 ) + if ( ( ((size_t)indata & (sizeof(RC4_CHUNK)-1)) | + ((size_t)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 ) { RC4_CHUNK ichunk,otp; const union { long one; char little; } is_endian = {1}; @@ -276,7 +276,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, #define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) #endif - i=(int)(len>>3L); + i=len>>3; if (i) { for (;;) @@ -296,7 +296,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, if (--i == 0) break; } } - i=(int)len&0x07; + i=len&0x07; if (i) { for (;;)