diff options
64 files changed, 216 insertions, 209 deletions
diff --git a/src/checksum/adler32/adler32.cpp b/src/checksum/adler32/adler32.cpp index 09e42b8db..62589733f 100644 --- a/src/checksum/adler32/adler32.cpp +++ b/src/checksum/adler32/adler32.cpp @@ -55,9 +55,9 @@ void adler32_update(const byte input[], size_t length, /* * Update an Adler32 Checksum */ -void Adler32::add_data(const byte input[], u32bit length) +void Adler32::add_data(const byte input[], size_t length) { - const u32bit PROCESS_AMOUNT = 5552; + const size_t PROCESS_AMOUNT = 5552; while(length >= PROCESS_AMOUNT) { diff --git a/src/checksum/adler32/adler32.h b/src/checksum/adler32/adler32.h index 4993e601b..3a2441ad3 100644 --- a/src/checksum/adler32/adler32.h +++ b/src/checksum/adler32/adler32.h @@ -24,7 +24,7 @@ class BOTAN_DLL Adler32 : public HashFunction Adler32() : HashFunction(4) { clear(); } ~Adler32() { clear(); } private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); u16bit S1, S2; }; diff --git a/src/checksum/crc24/crc24.cpp b/src/checksum/crc24/crc24.cpp index 5441020f5..d641047a2 100644 --- a/src/checksum/crc24/crc24.cpp +++ b/src/checksum/crc24/crc24.cpp @@ -13,7 +13,7 @@ namespace Botan { /* * Update a CRC24 Checksum */ -void CRC24::add_data(const byte input[], u32bit length) +void CRC24::add_data(const byte input[], size_t length) { const u32bit TABLE[256] = { 0x00000000, 0x00864CFB, 0x008AD50D, 0x000C99F6, 0x0093E6E1, 0x0015AA1A, @@ -82,8 +82,10 @@ void CRC24::add_data(const byte input[], u32bit length) input += 16; length -= 16; } - for(u32bit j = 0; j != length; ++j) - tmp = TABLE[((tmp >> 16) ^ input[j]) & 0xFF] ^ (tmp << 8); + + for(size_t i = 0; i != length; ++i) + tmp = TABLE[((tmp >> 16) ^ input[i]) & 0xFF] ^ (tmp << 8); + crc = tmp; } @@ -92,8 +94,8 @@ void CRC24::add_data(const byte input[], u32bit length) */ void CRC24::final_result(byte output[]) { - for(u32bit j = 0; j != 3; ++j) - output[j] = get_byte(j+1, crc); + for(size_t i = 0; i != 3; ++i) + output[i] = get_byte(i+1, crc); clear(); } diff --git a/src/checksum/crc24/crc24.h b/src/checksum/crc24/crc24.h index 2fc5af2ff..f9786dfa4 100644 --- a/src/checksum/crc24/crc24.h +++ b/src/checksum/crc24/crc24.h @@ -24,7 +24,7 @@ class BOTAN_DLL CRC24 : public HashFunction CRC24() : HashFunction(3) { clear(); } ~CRC24() { clear(); } private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); u32bit crc; }; diff --git a/src/checksum/crc32/crc32.cpp b/src/checksum/crc32/crc32.cpp index 42462096f..574e13bae 100644 --- a/src/checksum/crc32/crc32.cpp +++ b/src/checksum/crc32/crc32.cpp @@ -13,7 +13,7 @@ namespace Botan { /* * Update a CRC32 Checksum */ -void CRC32::add_data(const byte input[], u32bit length) +void CRC32::add_data(const byte input[], size_t length) { const u32bit TABLE[256] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, @@ -83,8 +83,8 @@ void CRC32::add_data(const byte input[], u32bit length) length -= 16; } - for(u32bit j = 0; j != length; ++j) - tmp = TABLE[(tmp ^ input[j]) & 0xFF] ^ (tmp >> 8); + for(size_t i = 0; i != length; ++i) + tmp = TABLE[(tmp ^ input[i]) & 0xFF] ^ (tmp >> 8); crc = tmp; } diff --git a/src/checksum/crc32/crc32.h b/src/checksum/crc32/crc32.h index 9fd69670d..aa8c366e5 100644 --- a/src/checksum/crc32/crc32.h +++ b/src/checksum/crc32/crc32.h @@ -24,7 +24,7 @@ class BOTAN_DLL CRC32 : public HashFunction CRC32() : HashFunction(4) { clear(); } ~CRC32() { clear(); } private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); u32bit crc; }; diff --git a/src/engine/openssl/ossl_md.cpp b/src/engine/openssl/ossl_md.cpp index f41e0f950..b2707eec4 100644 --- a/src/engine/openssl/ossl_md.cpp +++ b/src/engine/openssl/ossl_md.cpp @@ -24,7 +24,7 @@ class EVP_HashFunction : public HashFunction EVP_HashFunction(const EVP_MD*, const std::string&); ~EVP_HashFunction(); private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); std::string algo_name; @@ -34,7 +34,7 @@ class EVP_HashFunction : public HashFunction /* * Update an EVP Hash Calculation */ -void EVP_HashFunction::add_data(const byte input[], u32bit length) +void EVP_HashFunction::add_data(const byte input[], size_t length) { EVP_DigestUpdate(&md, input, length); } diff --git a/src/hash/bmw/bmw_512.cpp b/src/hash/bmw/bmw_512.cpp index cfa0eee2c..a69d23bff 100644 --- a/src/hash/bmw/bmw_512.cpp +++ b/src/hash/bmw/bmw_512.cpp @@ -43,9 +43,9 @@ inline u64bit S4(u64bit X) */ void BMW_512_compress(u64bit H[16], const u64bit M[16], u64bit Q[32]) { - const u32bit EXPAND_1_ROUNDS = 2; + const size_t EXPAND_1_ROUNDS = 2; - for(u32bit i = 0; i != 16; ++i) + for(size_t i = 0; i != 16; ++i) Q[i] = H[i] ^ M[i]; Q[16] = Q[ 5] - Q[ 7] + Q[10] + Q[13] + Q[14]; @@ -82,7 +82,7 @@ void BMW_512_compress(u64bit H[16], const u64bit M[16], u64bit Q[32]) Q[14] = S4(Q[30]) + H[15]; Q[15] = S0(Q[31]) + H[ 0]; - for(u32bit i = 16; i != 16 + EXPAND_1_ROUNDS; ++i) + for(size_t i = 16; i != 16 + EXPAND_1_ROUNDS; ++i) { Q[i] = S1(Q[i-16]) + S2(Q[i-15]) + S3(Q[i-14]) + S0(Q[i-13]) + S1(Q[i-12]) + S2(Q[i-11]) + S3(Q[i-10]) + S0(Q[i- 9]) + @@ -94,7 +94,7 @@ void BMW_512_compress(u64bit H[16], const u64bit M[16], u64bit Q[32]) (0x0555555555555555 * i)) ^ H[(i-16+7)%16]); } - for(u32bit i = 16 + EXPAND_1_ROUNDS; i != 32; ++i) + for(size_t i = 16 + EXPAND_1_ROUNDS; i != 32; ++i) { Q[i] = Q[i-16] + rotate_left(Q[i-15], 5) + Q[i-14] + rotate_left(Q[i-13], 11) + @@ -139,9 +139,9 @@ void BMW_512_compress(u64bit H[16], const u64bit M[16], u64bit Q[32]) } -void BMW_512::compress_n(const byte input[], u32bit blocks) +void BMW_512::compress_n(const byte input[], size_t blocks) { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_le(&M[0], input, M.size()); @@ -168,7 +168,7 @@ void BMW_512::copy_out(byte output[]) BMW_512_compress(final, &H[0], &Q[0]); - for(u32bit i = 0; i != OUTPUT_LENGTH; i += 8) + for(size_t i = 0; i != OUTPUT_LENGTH; i += 8) store_le(final[8 + i/8], output + i); } diff --git a/src/hash/bmw/bmw_512.h b/src/hash/bmw/bmw_512.h index b1eaa6874..aa527c142 100644 --- a/src/hash/bmw/bmw_512.h +++ b/src/hash/bmw/bmw_512.h @@ -25,7 +25,7 @@ class BOTAN_DLL BMW_512 : public MDx_HashFunction BMW_512() : MDx_HashFunction(64, 128, false, true), H(16), M(16), Q(32) { clear(); } private: - void compress_n(const byte input[], u32bit blocks); + void compress_n(const byte input[], size_t blocks); void copy_out(byte output[]); SecureVector<u64bit> H, M, Q; diff --git a/src/hash/comb4p/comb4p.cpp b/src/hash/comb4p/comb4p.cpp index ecbdc4671..681e20685 100644 --- a/src/hash/comb4p/comb4p.cpp +++ b/src/hash/comb4p/comb4p.cpp @@ -13,7 +13,7 @@ namespace Botan { namespace { -u32bit comb4p_block_size(const HashFunction* h1, +size_t comb4p_block_size(const HashFunction* h1, const HashFunction* h2) { if(h1->HASH_BLOCK_SIZE == h2->HASH_BLOCK_SIZE) @@ -73,7 +73,7 @@ void Comb4P::clear() hash2->update(0); } -void Comb4P::add_data(const byte input[], u32bit length) +void Comb4P::add_data(const byte input[], size_t length) { hash1->update(input, length); hash2->update(input, length); diff --git a/src/hash/comb4p/comb4p.h b/src/hash/comb4p/comb4p.h index 550b70b14..b09f2976b 100644 --- a/src/hash/comb4p/comb4p.h +++ b/src/hash/comb4p/comb4p.h @@ -39,7 +39,7 @@ class BOTAN_DLL Comb4P : public HashFunction void clear(); private: - void add_data(const byte input[], u32bit length); + void add_data(const byte input[], size_t length); void final_result(byte out[]); HashFunction* hash1; diff --git a/src/hash/gost_3411/gost_3411.cpp b/src/hash/gost_3411/gost_3411.cpp index b460de29c..dbd6335bd 100644 --- a/src/hash/gost_3411/gost_3411.cpp +++ b/src/hash/gost_3411/gost_3411.cpp @@ -38,7 +38,7 @@ void GOST_34_11::clear() /** * Hash additional inputs */ -void GOST_34_11::add_data(const byte input[], u32bit length) +void GOST_34_11::add_data(const byte input[], size_t length) { count += length; @@ -55,8 +55,8 @@ void GOST_34_11::add_data(const byte input[], u32bit length) } } - const u32bit full_blocks = length / HASH_BLOCK_SIZE; - const u32bit remaining = length % HASH_BLOCK_SIZE; + const size_t full_blocks = length / HASH_BLOCK_SIZE; + const size_t remaining = length % HASH_BLOCK_SIZE; if(full_blocks) compress_n(input, full_blocks); @@ -68,11 +68,11 @@ void GOST_34_11::add_data(const byte input[], u32bit length) /** * The GOST 34.11 compression function */ -void GOST_34_11::compress_n(const byte input[], u32bit blocks) +void GOST_34_11::compress_n(const byte input[], size_t blocks) { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { - for(u32bit j = 0, carry = 0; j != 32; ++j) + for(size_t j = 0, carry = 0; j != 32; ++j) { u16bit s = sum[j] + input[32*i+j] + carry; carry = get_byte(0, s); @@ -85,7 +85,7 @@ void GOST_34_11::compress_n(const byte input[], u32bit blocks) load_be(U, &hash[0], 4); load_be(V, input + 32*i, 4); - for(u32bit j = 0; j != 4; ++j) + for(size_t j = 0; j != 4; ++j) { byte key[32] = { 0 }; diff --git a/src/hash/gost_3411/gost_3411.h b/src/hash/gost_3411/gost_3411.h index 5d26e8557..693b900d2 100644 --- a/src/hash/gost_3411/gost_3411.h +++ b/src/hash/gost_3411/gost_3411.h @@ -25,9 +25,9 @@ class BOTAN_DLL GOST_34_11 : public HashFunction GOST_34_11(); private: - void compress_n(const byte input[], u32bit blocks); + void compress_n(const byte input[], size_t blocks); - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); GOST_28147_89 cipher; diff --git a/src/hash/has160/has160.cpp b/src/hash/has160/has160.cpp index 5786ae0ee..4f8db53f7 100644 --- a/src/hash/has160/has160.cpp +++ b/src/hash/has160/has160.cpp @@ -58,14 +58,14 @@ inline void F4(u32bit A, u32bit& B, u32bit C, u32bit D, u32bit& E, /* * HAS-160 Compression Function */ -void HAS_160::compress_n(const byte input[], u32bit blocks) +void HAS_160::compress_n(const byte input[], size_t blocks) { using namespace HAS_160_F; u32bit A = digest[0], B = digest[1], C = digest[2], D = digest[3], E = digest[4]; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_le(&X[0], input, 16); @@ -144,8 +144,8 @@ void HAS_160::compress_n(const byte input[], u32bit blocks) */ void HAS_160::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) - store_le(digest[j/4], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 4) + store_le(digest[i/4], output + i); } /* diff --git a/src/hash/has160/has160.h b/src/hash/has160/has160.h index 7cff320b8..83ed5ab56 100644 --- a/src/hash/has160/has160.h +++ b/src/hash/has160/has160.h @@ -26,7 +26,7 @@ class BOTAN_DLL HAS_160 : public MDx_HashFunction HAS_160() : MDx_HashFunction(20, 64, false, true), X(20), digest(5) { clear(); } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u32bit> X, digest; diff --git a/src/hash/md2/md2.cpp b/src/hash/md2/md2.cpp index 462e43b25..5d8f5f15c 100644 --- a/src/hash/md2/md2.cpp +++ b/src/hash/md2/md2.cpp @@ -42,28 +42,31 @@ void MD2::hash(const byte input[]) X.copy(16, input, HASH_BLOCK_SIZE); xor_buf(&X[32], &X[0], &X[16], HASH_BLOCK_SIZE); byte T = 0; - for(u32bit j = 0; j != 18; ++j) + + for(size_t i = 0; i != 18; ++i) { - for(u32bit k = 0; k != 48; k += 8) + for(size_t k = 0; k != 48; k += 8) { T = X[k ] ^= SBOX[T]; T = X[k+1] ^= SBOX[T]; T = X[k+2] ^= SBOX[T]; T = X[k+3] ^= SBOX[T]; T = X[k+4] ^= SBOX[T]; T = X[k+5] ^= SBOX[T]; T = X[k+6] ^= SBOX[T]; T = X[k+7] ^= SBOX[T]; } - T += j; + T += i; } + T = checksum[15]; - for(u32bit j = 0; j != HASH_BLOCK_SIZE; ++j) - T = checksum[j] ^= SBOX[input[j] ^ T]; + for(size_t i = 0; i != HASH_BLOCK_SIZE; ++i) + T = checksum[i] ^= SBOX[input[i] ^ T]; } /** * Update the hash */ -void MD2::add_data(const byte input[], u32bit length) +void MD2::add_data(const byte input[], size_t length) { buffer.copy(position, input, length); + if(position + length >= HASH_BLOCK_SIZE) { hash(&buffer[0]); @@ -86,8 +89,9 @@ void MD2::add_data(const byte input[], u32bit length) */ void MD2::final_result(byte output[]) { - for(u32bit j = position; j != HASH_BLOCK_SIZE; ++j) - buffer[j] = static_cast<byte>(HASH_BLOCK_SIZE - position); + for(size_t i = position; i != HASH_BLOCK_SIZE; ++i) + buffer[i] = static_cast<byte>(HASH_BLOCK_SIZE - position); + hash(&buffer[0]); hash(&checksum[0]); copy_mem(output, &X[0], OUTPUT_LENGTH); diff --git a/src/hash/md2/md2.h b/src/hash/md2/md2.h index b25d5f410..86e0d3c80 100644 --- a/src/hash/md2/md2.h +++ b/src/hash/md2/md2.h @@ -25,12 +25,12 @@ class BOTAN_DLL MD2 : public HashFunction MD2() : HashFunction(16, 16), X(48), checksum(16), buffer(16) { clear(); } private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void hash(const byte[]); void final_result(byte[]); SecureVector<byte> X, checksum, buffer; - u32bit position; + size_t position; }; } diff --git a/src/hash/md4/md4.cpp b/src/hash/md4/md4.cpp index 326ca8eba..3f9259deb 100644 --- a/src/hash/md4/md4.cpp +++ b/src/hash/md4/md4.cpp @@ -45,11 +45,11 @@ inline void HH(u32bit& A, u32bit B, u32bit C, u32bit D, u32bit M, byte S) /* * MD4 Compression Function */ -void MD4::compress_n(const byte input[], u32bit blocks) +void MD4::compress_n(const byte input[], size_t blocks) { u32bit A = digest[0], B = digest[1], C = digest[2], D = digest[3]; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_le(&M[0], input, M.size()); @@ -94,8 +94,8 @@ void MD4::compress_n(const byte input[], u32bit blocks) */ void MD4::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) - store_le(digest[j/4], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 4) + store_le(digest[i/4], output + i); } /* diff --git a/src/hash/md4/md4.h b/src/hash/md4/md4.h index 44081e635..07467fdfc 100644 --- a/src/hash/md4/md4.h +++ b/src/hash/md4/md4.h @@ -25,7 +25,7 @@ class BOTAN_DLL MD4 : public MDx_HashFunction MD4() : MDx_HashFunction(16, 64, false, true), M(16), digest(4) { clear(); } protected: - void compress_n(const byte input[], u32bit blocks); + void compress_n(const byte input[], size_t blocks); void copy_out(byte[]); SecureVector<u32bit> M, digest; diff --git a/src/hash/md4_ia32/md4_ia32.cpp b/src/hash/md4_ia32/md4_ia32.cpp index 8a60d8f0e..8983995fc 100644 --- a/src/hash/md4_ia32/md4_ia32.cpp +++ b/src/hash/md4_ia32/md4_ia32.cpp @@ -14,9 +14,9 @@ extern "C" void botan_md4_ia32_compress(u32bit[4], const byte[64], u32bit[16]); /* * MD4 Compression Function */ -void MD4_IA32::compress_n(const byte input[], u32bit blocks) +void MD4_IA32::compress_n(const byte input[], size_t blocks) { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { botan_md4_ia32_compress(digest, input, M); input += HASH_BLOCK_SIZE; diff --git a/src/hash/md4_ia32/md4_ia32.h b/src/hash/md4_ia32/md4_ia32.h index ef8060d3f..4bb8f1add 100644 --- a/src/hash/md4_ia32/md4_ia32.h +++ b/src/hash/md4_ia32/md4_ia32.h @@ -20,7 +20,7 @@ class BOTAN_DLL MD4_IA32 : public MD4 public: HashFunction* clone() const { return new MD4_IA32; } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); }; } diff --git a/src/hash/md5/md5.cpp b/src/hash/md5/md5.cpp index b1745b944..69ab89e63 100644 --- a/src/hash/md5/md5.cpp +++ b/src/hash/md5/md5.cpp @@ -58,11 +58,11 @@ inline void II(u32bit& A, u32bit B, u32bit C, u32bit D, u32bit msg, /* * MD5 Compression Function */ -void MD5::compress_n(const byte input[], u32bit blocks) +void MD5::compress_n(const byte input[], size_t blocks) { u32bit A = digest[0], B = digest[1], C = digest[2], D = digest[3]; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_le(&M[0], input, M.size()); @@ -116,8 +116,8 @@ void MD5::compress_n(const byte input[], u32bit blocks) */ void MD5::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) - store_le(digest[j/4], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 4) + store_le(digest[i/4], output + i); } /* diff --git a/src/hash/md5/md5.h b/src/hash/md5/md5.h index 732ec026d..f79a3ec65 100644 --- a/src/hash/md5/md5.h +++ b/src/hash/md5/md5.h @@ -25,7 +25,7 @@ class BOTAN_DLL MD5 : public MDx_HashFunction MD5() : MDx_HashFunction(16, 64, false, true), M(16), digest(4) { clear(); } protected: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u32bit> M, digest; diff --git a/src/hash/md5_ia32/md5_ia32.cpp b/src/hash/md5_ia32/md5_ia32.cpp index affd0b8f7..66a18e6f5 100644 --- a/src/hash/md5_ia32/md5_ia32.cpp +++ b/src/hash/md5_ia32/md5_ia32.cpp @@ -19,9 +19,9 @@ void botan_md5_ia32_compress(u32bit[4], const byte[64], u32bit[16]); /* * MD5 Compression Function */ -void MD5_IA32::compress_n(const byte input[], u32bit blocks) +void MD5_IA32::compress_n(const byte input[], size_t blocks) { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { botan_md5_ia32_compress(digest, input, M); input += HASH_BLOCK_SIZE; diff --git a/src/hash/md5_ia32/md5_ia32.h b/src/hash/md5_ia32/md5_ia32.h index b65490760..bf4b4c505 100644 --- a/src/hash/md5_ia32/md5_ia32.h +++ b/src/hash/md5_ia32/md5_ia32.h @@ -20,7 +20,7 @@ class BOTAN_DLL MD5_IA32 : public MD5 public: HashFunction* clone() const { return new MD5_IA32; } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); }; } diff --git a/src/hash/mdx_hash/mdx_hash.cpp b/src/hash/mdx_hash/mdx_hash.cpp index 560832542..cea66044b 100644 --- a/src/hash/mdx_hash/mdx_hash.cpp +++ b/src/hash/mdx_hash/mdx_hash.cpp @@ -14,9 +14,9 @@ namespace Botan { /* * MDx_HashFunction Constructor */ -MDx_HashFunction::MDx_HashFunction(u32bit hash_len, u32bit block_len, +MDx_HashFunction::MDx_HashFunction(size_t hash_len, size_t block_len, bool byte_end, bool bit_end, - u32bit cnt_size) : + size_t cnt_size) : HashFunction(hash_len, block_len), buffer(block_len), BIG_BYTE_ENDIAN(byte_end), BIG_BIT_ENDIAN(bit_end), COUNT_SIZE(cnt_size) { @@ -37,7 +37,7 @@ void MDx_HashFunction::clear() /* * Update the hash */ -void MDx_HashFunction::add_data(const byte input[], u32bit length) +void MDx_HashFunction::add_data(const byte input[], size_t length) { count += length; @@ -54,8 +54,8 @@ void MDx_HashFunction::add_data(const byte input[], u32bit length) } } - const u32bit full_blocks = length / HASH_BLOCK_SIZE; - const u32bit remaining = length % HASH_BLOCK_SIZE; + const size_t full_blocks = length / HASH_BLOCK_SIZE; + const size_t remaining = length % HASH_BLOCK_SIZE; if(full_blocks) compress_n(input, full_blocks); @@ -70,8 +70,8 @@ void MDx_HashFunction::add_data(const byte input[], u32bit length) void MDx_HashFunction::final_result(byte output[]) { buffer[position] = (BIG_BIT_ENDIAN ? 0x80 : 0x01); - for(u32bit j = position+1; j != HASH_BLOCK_SIZE; ++j) - buffer[j] = 0; + for(size_t i = position+1; i != HASH_BLOCK_SIZE; ++i) + buffer[i] = 0; if(position >= HASH_BLOCK_SIZE - COUNT_SIZE) { diff --git a/src/hash/mdx_hash/mdx_hash.h b/src/hash/mdx_hash/mdx_hash.h index 087c7fc46..6603f54bc 100644 --- a/src/hash/mdx_hash/mdx_hash.h +++ b/src/hash/mdx_hash/mdx_hash.h @@ -25,15 +25,15 @@ class BOTAN_DLL MDx_HashFunction : public HashFunction * @param big_bit_endian specifies if the hash uses big-endian bits * @param counter_size specifies the size of the counter var in bytes */ - MDx_HashFunction(u32bit hash_length, - u32bit block_length, + MDx_HashFunction(size_t hash_length, + size_t block_length, bool big_byte_endian, bool big_bit_endian, - u32bit counter_size = 8); + size_t counter_size = 8); virtual ~MDx_HashFunction() {} protected: - void add_data(const byte input[], u32bit length); + void add_data(const byte input[], size_t length); void final_result(byte output[]); /** @@ -41,7 +41,7 @@ class BOTAN_DLL MDx_HashFunction : public HashFunction * @param blocks the input * @param block_n the number of blocks */ - virtual void compress_n(const byte blocks[], u32bit block_n) = 0; + virtual void compress_n(const byte blocks[], size_t block_n) = 0; void clear(); @@ -59,7 +59,7 @@ class BOTAN_DLL MDx_HashFunction : public HashFunction private: SecureVector<byte> buffer; u64bit count; - u32bit position; + size_t position; const bool BIG_BYTE_ENDIAN, BIG_BIT_ENDIAN; const u32bit COUNT_SIZE; diff --git a/src/hash/par_hash/par_hash.cpp b/src/hash/par_hash/par_hash.cpp index 0ba3f5a4f..794166327 100644 --- a/src/hash/par_hash/par_hash.cpp +++ b/src/hash/par_hash/par_hash.cpp @@ -14,12 +14,12 @@ namespace { /* * Return the sum of the hash sizes */ -u32bit sum_of_hash_lengths(const std::vector<HashFunction*>& hashes) +size_t sum_of_hash_lengths(const std::vector<HashFunction*>& hashes) { - u32bit sum = 0; + size_t sum = 0; - for(u32bit j = 0; j != hashes.size(); ++j) - sum += hashes[j]->OUTPUT_LENGTH; + for(size_t i = 0; i != hashes.size(); ++i) + sum += hashes[i]->OUTPUT_LENGTH; return sum; } @@ -29,10 +29,10 @@ u32bit sum_of_hash_lengths(const std::vector<HashFunction*>& hashes) /* * Update the hash */ -void Parallel::add_data(const byte input[], u32bit length) +void Parallel::add_data(const byte input[], size_t length) { - for(u32bit j = 0; j != hashes.size(); ++j) - hashes[j]->update(input, length); + for(size_t i = 0; i != hashes.size(); ++i) + hashes[i]->update(input, length); } /* @@ -40,11 +40,11 @@ void Parallel::add_data(const byte input[], u32bit length) */ void Parallel::final_result(byte hash[]) { - u32bit offset = 0; - for(u32bit j = 0; j != hashes.size(); ++j) + size_t offset = 0; + for(size_t i = 0; i != hashes.size(); ++i) { - hashes[j]->final(hash + offset); - offset += hashes[j]->OUTPUT_LENGTH; + hashes[i]->final(hash + offset); + offset += hashes[i]->OUTPUT_LENGTH; } } @@ -54,11 +54,11 @@ void Parallel::final_result(byte hash[]) std::string Parallel::name() const { std::string hash_names; - for(u32bit j = 0; j != hashes.size(); ++j) + for(size_t i = 0; i != hashes.size(); ++i) { - if(j) + if(i) hash_names += ','; - hash_names += hashes[j]->name(); + hash_names += hashes[i]->name(); } return "Parallel(" + hash_names + ")"; } @@ -69,8 +69,8 @@ std::string Parallel::name() const HashFunction* Parallel::clone() const { std::vector<HashFunction*> hash_copies; - for(u32bit j = 0; j != hashes.size(); ++j) - hash_copies.push_back(hashes[j]->clone()); + for(size_t i = 0; i != hashes.size(); ++i) + hash_copies.push_back(hashes[i]->clone()); return new Parallel(hash_copies); } @@ -79,8 +79,8 @@ HashFunction* Parallel::clone() const */ void Parallel::clear() { - for(u32bit j = 0; j != hashes.size(); ++j) - hashes[j]->clear(); + for(size_t i = 0; i != hashes.size(); ++i) + hashes[i]->clear(); } /* @@ -96,8 +96,8 @@ Parallel::Parallel(const std::vector<HashFunction*>& hash_in) : */ Parallel::~Parallel() { - for(u32bit j = 0; j != hashes.size(); ++j) - delete hashes[j]; + for(size_t i = 0; i != hashes.size(); ++i) + delete hashes[i]; } } diff --git a/src/hash/par_hash/par_hash.h b/src/hash/par_hash/par_hash.h index d82a74a19..35154dde4 100644 --- a/src/hash/par_hash/par_hash.h +++ b/src/hash/par_hash/par_hash.h @@ -29,7 +29,7 @@ class BOTAN_DLL Parallel : public HashFunction Parallel(const std::vector<HashFunction*>& hashes); ~Parallel(); private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); std::vector<HashFunction*> hashes; }; diff --git a/src/hash/rmd128/rmd128.cpp b/src/hash/rmd128/rmd128.cpp index 3e7eb9143..61737a4a0 100644 --- a/src/hash/rmd128/rmd128.cpp +++ b/src/hash/rmd128/rmd128.cpp @@ -58,7 +58,7 @@ inline void F4(u32bit& A, u32bit B, u32bit C, u32bit D, /* * RIPEMD-128 Compression Function */ -void RIPEMD_128::compress_n(const byte input[], u32bit blocks) +void RIPEMD_128::compress_n(const byte input[], size_t blocks) { using namespace RIPEMD_128_F; @@ -66,7 +66,7 @@ void RIPEMD_128::compress_n(const byte input[], u32bit blocks) MAGIC4 = 0x8F1BBCDC, MAGIC5 = 0x50A28BE6, MAGIC6 = 0x5C4DD124, MAGIC7 = 0x6D703EF3; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_le(&M[0], input, M.size()); @@ -156,8 +156,8 @@ void RIPEMD_128::compress_n(const byte input[], u32bit blocks) */ void RIPEMD_128::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) - store_le(digest[j/4], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 4) + store_le(digest[i/4], output + i); } /* diff --git a/src/hash/rmd128/rmd128.h b/src/hash/rmd128/rmd128.h index 23272c622..faead3245 100644 --- a/src/hash/rmd128/rmd128.h +++ b/src/hash/rmd128/rmd128.h @@ -25,7 +25,7 @@ class BOTAN_DLL RIPEMD_128 : public MDx_HashFunction RIPEMD_128() : MDx_HashFunction(16, 64, false, true), M(16), digest(4) { clear(); } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u32bit> M, digest; diff --git a/src/hash/rmd160/rmd160.cpp b/src/hash/rmd160/rmd160.cpp index f832d4ec1..255f3f95a 100644 --- a/src/hash/rmd160/rmd160.cpp +++ b/src/hash/rmd160/rmd160.cpp @@ -73,14 +73,14 @@ inline void F5(u32bit& A, u32bit B, u32bit& C, u32bit D, u32bit E, /* * RIPEMD-160 Compression Function */ -void RIPEMD_160::compress_n(const byte input[], u32bit blocks) +void RIPEMD_160::compress_n(const byte input[], size_t blocks) { const u32bit MAGIC2 = 0x5A827999, MAGIC3 = 0x6ED9EBA1, MAGIC4 = 0x8F1BBCDC, MAGIC5 = 0xA953FD4E, MAGIC6 = 0x50A28BE6, MAGIC7 = 0x5C4DD124, MAGIC8 = 0x6D703EF3, MAGIC9 = 0x7A6D76E9; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_le(&M[0], input, M.size()); @@ -189,8 +189,8 @@ void RIPEMD_160::compress_n(const byte input[], u32bit blocks) */ void RIPEMD_160::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) - store_le(digest[j/4], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 4) + store_le(digest[i/4], output + i); } /* diff --git a/src/hash/rmd160/rmd160.h b/src/hash/rmd160/rmd160.h index 09c995628..69c6b4a40 100644 --- a/src/hash/rmd160/rmd160.h +++ b/src/hash/rmd160/rmd160.h @@ -25,7 +25,7 @@ class BOTAN_DLL RIPEMD_160 : public MDx_HashFunction RIPEMD_160() : MDx_HashFunction(20, 64, false, true), M(16), digest(5) { clear(); } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u32bit> M, digest; diff --git a/src/hash/sha1/sha160.cpp b/src/hash/sha1/sha160.cpp index 79348a371..6c98b21d2 100644 --- a/src/hash/sha1/sha160.cpp +++ b/src/hash/sha1/sha160.cpp @@ -54,16 +54,16 @@ inline void F4(u32bit A, u32bit& B, u32bit C, u32bit D, u32bit& E, u32bit msg) /* * SHA-160 Compression Function */ -void SHA_160::compress_n(const byte input[], u32bit blocks) +void SHA_160::compress_n(const byte input[], size_t blocks) { u32bit A = digest[0], B = digest[1], C = digest[2], D = digest[3], E = digest[4]; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_be(&W[0], input, 16); - for(u32bit j = 16; j != 80; j += 8) + for(size_t j = 16; j != 80; j += 8) { W[j ] = rotate_left((W[j-3] ^ W[j-8] ^ W[j-14] ^ W[j-16]), 1); W[j+1] = rotate_left((W[j-2] ^ W[j-7] ^ W[j-13] ^ W[j-15]), 1); @@ -134,7 +134,7 @@ void SHA_160::compress_n(const byte input[], u32bit blocks) */ void SHA_160::copy_out(byte output[]) { - for(u32bit i = 0; i != OUTPUT_LENGTH; i += 4) + for(size_t i = 0; i != OUTPUT_LENGTH; i += 4) store_be(digest[i/4], output + i); } @@ -164,7 +164,7 @@ SHA_160::SHA_160() : /* * SHA_160 Constructor */ -SHA_160::SHA_160(u32bit W_size) : +SHA_160::SHA_160(size_t W_size) : MDx_HashFunction(20, 64, true, true), digest(5), W(W_size) { clear(); diff --git a/src/hash/sha1/sha160.h b/src/hash/sha1/sha160.h index 690aea1d5..d420f8f94 100644 --- a/src/hash/sha1/sha160.h +++ b/src/hash/sha1/sha160.h @@ -30,9 +30,9 @@ class BOTAN_DLL SHA_160 : public MDx_HashFunction * constraints * @param W_size how big to make W */ - SHA_160(u32bit W_size); + SHA_160(size_t W_size); - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u32bit> digest; diff --git a/src/hash/sha1_amd64/sha1_amd64.cpp b/src/hash/sha1_amd64/sha1_amd64.cpp index 885853182..00b1788cb 100644 --- a/src/hash/sha1_amd64/sha1_amd64.cpp +++ b/src/hash/sha1_amd64/sha1_amd64.cpp @@ -19,9 +19,9 @@ void botan_sha160_amd64_compress(u32bit[5], const byte[64], u32bit[80]); /* * SHA-160 Compression Function */ -void SHA_160_AMD64::compress_n(const byte input[], u32bit blocks) +void SHA_160_AMD64::compress_n(const byte input[], size_t blocks) { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { botan_sha160_amd64_compress(&digest[0], input, &W[0]); input += HASH_BLOCK_SIZE; diff --git a/src/hash/sha1_amd64/sha1_amd64.h b/src/hash/sha1_amd64/sha1_amd64.h index 6cf3b0fb7..6b741184d 100644 --- a/src/hash/sha1_amd64/sha1_amd64.h +++ b/src/hash/sha1_amd64/sha1_amd64.h @@ -20,7 +20,7 @@ class BOTAN_DLL SHA_160_AMD64 : public SHA_160 public: HashFunction* clone() const { return new SHA_160_AMD64; } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); }; } diff --git a/src/hash/sha1_ia32/sha1_ia32.cpp b/src/hash/sha1_ia32/sha1_ia32.cpp index 611cc1961..6bc9f31ec 100644 --- a/src/hash/sha1_ia32/sha1_ia32.cpp +++ b/src/hash/sha1_ia32/sha1_ia32.cpp @@ -19,9 +19,9 @@ void botan_sha160_ia32_compress(u32bit[5], const byte[64], u32bit[81]); /* * SHA-160 Compression Function */ -void SHA_160_IA32::compress_n(const byte input[], u32bit blocks) +void SHA_160_IA32::compress_n(const byte input[], size_t blocks) { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { botan_sha160_ia32_compress(&digest[0], input, &W[0]); input += HASH_BLOCK_SIZE; diff --git a/src/hash/sha1_ia32/sha1_ia32.h b/src/hash/sha1_ia32/sha1_ia32.h index f579fbc90..5cff03016 100644 --- a/src/hash/sha1_ia32/sha1_ia32.h +++ b/src/hash/sha1_ia32/sha1_ia32.h @@ -23,7 +23,7 @@ class BOTAN_DLL SHA_160_IA32 : public SHA_160 // Note 81 instead of normal 80: IA-32 asm needs an extra temp SHA_160_IA32() : SHA_160(81) {} private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); }; } diff --git a/src/hash/sha1_sse2/sha1_sse2.cpp b/src/hash/sha1_sse2/sha1_sse2.cpp index f1102afc5..8270f9ac4 100644 --- a/src/hash/sha1_sse2/sha1_sse2.cpp +++ b/src/hash/sha1_sse2/sha1_sse2.cpp @@ -149,7 +149,7 @@ inline void F4(u32bit A, u32bit& B, u32bit C, u32bit D, u32bit& E, u32bit msg) /* * SHA-160 Compression Function using SSE for message expansion */ -void SHA_160_SSE2::compress_n(const byte input_bytes[], u32bit blocks) +void SHA_160_SSE2::compress_n(const byte input_bytes[], size_t blocks) { const __m128i K00_19 = _mm_set1_epi32(0x5A827999); const __m128i K20_39 = _mm_set1_epi32(0x6ED9EBA1); @@ -164,7 +164,7 @@ void SHA_160_SSE2::compress_n(const byte input_bytes[], u32bit blocks) const __m128i* input = reinterpret_cast<const __m128i*>(input_bytes); - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { union v4si { u32bit u32[4]; diff --git a/src/hash/sha1_sse2/sha1_sse2.h b/src/hash/sha1_sse2/sha1_sse2.h index 90935c737..9b7b327f0 100644 --- a/src/hash/sha1_sse2/sha1_sse2.h +++ b/src/hash/sha1_sse2/sha1_sse2.h @@ -21,7 +21,7 @@ class BOTAN_DLL SHA_160_SSE2 : public SHA_160 HashFunction* clone() const { return new SHA_160_SSE2; } SHA_160_SSE2() : SHA_160(0) {} // no W needed private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); }; } diff --git a/src/hash/sha2_32/sha2_32.cpp b/src/hash/sha2_32/sha2_32.cpp index acd06061e..6bbf6dec9 100644 --- a/src/hash/sha2_32/sha2_32.cpp +++ b/src/hash/sha2_32/sha2_32.cpp @@ -48,17 +48,17 @@ inline void F1(u32bit A, u32bit B, u32bit C, u32bit& D, */ void sha2_32_compress(MemoryRegion<u32bit>& W, MemoryRegion<u32bit>& digest, - const byte input[], u32bit blocks) + const byte input[], size_t blocks) { u32bit A = digest[0], B = digest[1], C = digest[2], D = digest[3], E = digest[4], F = digest[5], G = digest[6], H = digest[7]; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_be(&W[0], input, 16); - for(u32bit j = 16; j != 64; j += 8) + for(size_t j = 16; j != 64; j += 8) { W[j ] = sigma(W[j- 2], 17, 19, 10) + W[j-7] + sigma(W[j-15], 7, 18, 3) + W[j-16]; @@ -161,7 +161,7 @@ void sha2_32_compress(MemoryRegion<u32bit>& W, /* * SHA-224 compression function */ -void SHA_224::compress_n(const byte input[], u32bit blocks) +void SHA_224::compress_n(const byte input[], size_t blocks) { sha2_32_compress(W, digest, input, blocks); } @@ -171,8 +171,8 @@ void SHA_224::compress_n(const byte input[], u32bit blocks) */ void SHA_224::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) - store_be(digest[j/4], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 4) + store_be(digest[i/4], output + i); } /* @@ -195,7 +195,7 @@ void SHA_224::clear() /* * SHA-256 compression function */ -void SHA_256::compress_n(const byte input[], u32bit blocks) +void SHA_256::compress_n(const byte input[], size_t blocks) { sha2_32_compress(W, digest, input, blocks); } @@ -205,8 +205,8 @@ void SHA_256::compress_n(const byte input[], u32bit blocks) */ void SHA_256::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 4) - store_be(digest[j/4], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 4) + store_be(digest[i/4], output + i); } /* diff --git a/src/hash/sha2_32/sha2_32.h b/src/hash/sha2_32/sha2_32.h index a3e3a6f19..3b95812b8 100644 --- a/src/hash/sha2_32/sha2_32.h +++ b/src/hash/sha2_32/sha2_32.h @@ -26,7 +26,7 @@ class BOTAN_DLL SHA_224 : public MDx_HashFunction SHA_224() : MDx_HashFunction(28, 64, true, true), W(64), digest(8) { clear(); } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u32bit> W, digest; @@ -45,7 +45,7 @@ class BOTAN_DLL SHA_256 : public MDx_HashFunction SHA_256() : MDx_HashFunction(32, 64, true, true), W(64), digest(8) { clear(); } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u32bit> W, digest; diff --git a/src/hash/sha2_64/sha2_64.cpp b/src/hash/sha2_64/sha2_64.cpp index 5ca78173c..96e672819 100644 --- a/src/hash/sha2_64/sha2_64.cpp +++ b/src/hash/sha2_64/sha2_64.cpp @@ -47,17 +47,17 @@ inline u64bit sigma(u64bit X, u32bit rot1, u32bit rot2, u32bit shift) */ void sha2_64_compress(MemoryRegion<u64bit>& W, MemoryRegion<u64bit>& digest, - const byte input[], u32bit blocks) + const byte input[], size_t blocks) { u64bit A = digest[0], B = digest[1], C = digest[2], D = digest[3], E = digest[4], F = digest[5], G = digest[6], H = digest[7]; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_be(&W[0], input, 16); - for(u32bit j = 16; j != 80; j += 8) + for(size_t j = 16; j != 80; j += 8) { W[j ] = sigma(W[j-2], 19, 61, 6) + W[j-7] + sigma(W[j-15], 1, 8, 7) + W[j-16]; W[j+1] = sigma(W[j-1], 19, 61, 6) + W[j-6] + sigma(W[j-14], 1, 8, 7) + W[j-15]; @@ -168,7 +168,7 @@ void sha2_64_compress(MemoryRegion<u64bit>& W, /* * SHA-384 compression function */ -void SHA_384::compress_n(const byte input[], u32bit blocks) +void SHA_384::compress_n(const byte input[], size_t blocks) { sha2_64_compress(W, digest, input, blocks); } @@ -178,8 +178,8 @@ void SHA_384::compress_n(const byte input[], u32bit blocks) */ void SHA_384::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 8) - store_be(digest[j/8], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 8) + store_be(digest[i/8], output + i); } /* @@ -202,7 +202,7 @@ void SHA_384::clear() /* * SHA-512 compression function */ -void SHA_512::compress_n(const byte input[], u32bit blocks) +void SHA_512::compress_n(const byte input[], size_t blocks) { sha2_64_compress(W, digest, input, blocks); } @@ -212,8 +212,8 @@ void SHA_512::compress_n(const byte input[], u32bit blocks) */ void SHA_512::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 8) - store_be(digest[j/8], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 8) + store_be(digest[i/8], output + i); } /* diff --git a/src/hash/sha2_64/sha2_64.h b/src/hash/sha2_64/sha2_64.h index 726712221..59e2c4c83 100644 --- a/src/hash/sha2_64/sha2_64.h +++ b/src/hash/sha2_64/sha2_64.h @@ -25,7 +25,7 @@ class BOTAN_DLL SHA_384 : public MDx_HashFunction SHA_384() : MDx_HashFunction(48, 128, true, true, 16), W(80), digest(8) { clear(); } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u64bit> W, digest; @@ -43,7 +43,7 @@ class BOTAN_DLL SHA_512 : public MDx_HashFunction SHA_512() : MDx_HashFunction(64, 128, true, true, 16), W(80), digest(8) { clear(); } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); SecureVector<u64bit> W, digest; diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp index a3aff52ab..665dd7248 100644 --- a/src/hash/skein/skein_512.cpp +++ b/src/hash/skein/skein_512.cpp @@ -29,11 +29,11 @@ enum type_code { void ubi_512(MemoryRegion<u64bit>& H, MemoryRegion<u64bit>& T, - const byte msg[], u32bit msg_len) + const byte msg[], size_t msg_len) { do { - const u32bit to_proc = std::min<u32bit>(msg_len, 64); + const size_t to_proc = std::min<size_t>(msg_len, 64); T[0] += to_proc; u64bit M[8] = { 0 }; @@ -42,7 +42,7 @@ void ubi_512(MemoryRegion<u64bit>& H, if(to_proc % 8) { - for(u32bit j = 0; j != to_proc % 8; ++j) + for(size_t j = 0; j != to_proc % 8; ++j) M[to_proc/8] |= ((u64bit)msg[8*(to_proc/8)+j] << (8*j)); } @@ -197,7 +197,7 @@ void Skein_512::clear() buf_pos = 0; } -void Skein_512::add_data(const byte input[], u32bit length) +void Skein_512::add_data(const byte input[], size_t length) { if(length == 0) return; @@ -215,7 +215,7 @@ void Skein_512::add_data(const byte input[], u32bit length) } } - const u32bit full_blocks = (length - 1) / 64; + const size_t full_blocks = (length - 1) / 64; if(full_blocks) ubi_512(H, T, input, 64*full_blocks); @@ -230,33 +230,33 @@ void Skein_512::final_result(byte out[]) { T[1] |= ((u64bit)1 << 63); // final block flag - for(u32bit i = buf_pos; i != buffer.size(); ++i) + for(size_t i = buf_pos; i != buffer.size(); ++i) buffer[i] = 0; ubi_512(H, T, &buffer[0], buf_pos); byte counter[8] = { 0 }; - u32bit out_bytes = output_bits / 8; + size_t out_bytes = output_bits / 8; SecureVector<u64bit> H_out(9); while(out_bytes) { - const u32bit to_proc = std::min<u32bit>(out_bytes, 64); + const size_t to_proc = std::min<size_t>(out_bytes, 64); H_out.copy(&H[0], 8); reset_tweak(T, SKEIN_OUTPUT, true); ubi_512(H_out, T, counter, sizeof(counter)); - for(u32bit i = 0; i != to_proc; ++i) + for(size_t i = 0; i != to_proc; ++i) out[i] = get_byte(7-i%8, H_out[i/8]); out_bytes -= to_proc; out += to_proc; - for(u32bit i = 0; i != sizeof(counter); ++i) + for(size_t i = 0; i != sizeof(counter); ++i) if(++counter[i]) break; } diff --git a/src/hash/skein/skein_512.h b/src/hash/skein/skein_512.h index 811b633eb..803f1c916 100644 --- a/src/hash/skein/skein_512.h +++ b/src/hash/skein/skein_512.h @@ -32,16 +32,16 @@ class BOTAN_DLL Skein_512 : public HashFunction std::string name() const; void clear(); private: - void add_data(const byte input[], u32bit length); + void add_data(const byte input[], size_t length); void final_result(byte out[]); std::string personalization; - u32bit output_bits; + size_t output_bits; SecureVector<u64bit> H; SecureVector<u64bit> T; SecureVector<byte> buffer; - u32bit buf_pos; + size_t buf_pos; }; } diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp index 9d3e2cbe4..fa5effd80 100644 --- a/src/hash/tiger/tiger.cpp +++ b/src/hash/tiger/tiger.cpp @@ -43,11 +43,11 @@ inline void mix(MemoryRegion<u64bit>& X) /* * Tiger Compression Function */ -void Tiger::compress_n(const byte input[], u32bit blocks) +void Tiger::compress_n(const byte input[], size_t blocks) { u64bit A = digest[0], B = digest[1], C = digest[2]; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_le(&X[0], input, X.size()); @@ -55,7 +55,7 @@ void Tiger::compress_n(const byte input[], u32bit blocks) pass(C, A, B, X, 7); mix(X); pass(B, C, A, X, 9); - for(u32bit j = 3; j != PASS; ++j) + for(size_t j = 3; j != PASS; ++j) { mix(X); pass(A, B, C, X, 9); @@ -75,8 +75,8 @@ void Tiger::compress_n(const byte input[], u32bit blocks) */ void Tiger::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; ++j) - output[j] = get_byte(7 - (j % 8), digest[j/8]); + for(size_t i = 0; i != OUTPUT_LENGTH; ++i) + output[i] = get_byte(7 - (i % 8), digest[i/8]); } /* @@ -166,7 +166,7 @@ std::string Tiger::name() const /* * Tiger Constructor */ -Tiger::Tiger(u32bit hashlen, u32bit pass) : +Tiger::Tiger(size_t hashlen, size_t pass) : MDx_HashFunction(hashlen, 64, false, false), X(8), digest(3), diff --git a/src/hash/tiger/tiger.h b/src/hash/tiger/tiger.h index 4b8a99344..7305ddb46 100644 --- a/src/hash/tiger/tiger.h +++ b/src/hash/tiger/tiger.h @@ -30,9 +30,9 @@ class BOTAN_DLL Tiger : public MDx_HashFunction * @param out_size specifies the output length; can be 16, 20, or 24 * @param passes to make in the algorithm */ - Tiger(u32bit out_size = 24, u32bit passes = 3); + Tiger(size_t out_size = 24, size_t passes = 3); private: - void compress_n(const byte[], u32bit block); + void compress_n(const byte[], size_t block); void copy_out(byte[]); static void pass(u64bit& A, u64bit& B, u64bit& C, @@ -45,7 +45,7 @@ class BOTAN_DLL Tiger : public MDx_HashFunction static const u64bit SBOX4[256]; SecureVector<u64bit> X, digest; - const u32bit PASS; + const size_t PASS; }; } diff --git a/src/hash/whirlpool/whrlpool.cpp b/src/hash/whirlpool/whrlpool.cpp index fcd244ce2..fdbdf5d0f 100644 --- a/src/hash/whirlpool/whrlpool.cpp +++ b/src/hash/whirlpool/whrlpool.cpp @@ -13,7 +13,7 @@ namespace Botan { /* * Whirlpool Compression Function */ -void Whirlpool::compress_n(const byte in[], u32bit blocks) +void Whirlpool::compress_n(const byte in[], size_t blocks) { static const u64bit RC[10] = { 0x1823C6E887B8014F, 0x36A6D2F5796F9152, @@ -23,7 +23,7 @@ void Whirlpool::compress_n(const byte in[], u32bit blocks) 0xFBEE7C66DD17479E, 0xCA2DBF07AD5A8333 }; - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { load_be(&M[0], in, M.size()); @@ -35,7 +35,7 @@ void Whirlpool::compress_n(const byte in[], u32bit blocks) B0 = K0 ^ M[0]; B1 = K1 ^ M[1]; B2 = K2 ^ M[2]; B3 = K3 ^ M[3]; B4 = K4 ^ M[4]; B5 = K5 ^ M[5]; B6 = K6 ^ M[6]; B7 = K7 ^ M[7]; - for(u32bit j = 0; j != 10; ++j) + for(size_t j = 0; j != 10; ++j) { u64bit T0, T1, T2, T3, T4, T5, T6, T7; T0 = C0[get_byte(0, K0)] ^ C1[get_byte(1, K7)] ^ @@ -129,8 +129,8 @@ void Whirlpool::compress_n(const byte in[], u32bit blocks) */ void Whirlpool::copy_out(byte output[]) { - for(u32bit j = 0; j != OUTPUT_LENGTH; j += 8) - store_be(digest[j/8], output + j); + for(size_t i = 0; i != OUTPUT_LENGTH; i += 8) + store_be(digest[i/8], output + i); } /* diff --git a/src/hash/whirlpool/whrlpool.h b/src/hash/whirlpool/whrlpool.h index 98be0b480..30bf91a34 100644 --- a/src/hash/whirlpool/whrlpool.h +++ b/src/hash/whirlpool/whrlpool.h @@ -25,7 +25,7 @@ class BOTAN_DLL Whirlpool : public MDx_HashFunction Whirlpool() : MDx_HashFunction(64, 64, true, true, 32), M(8), digest(8) { clear(); } private: - void compress_n(const byte[], u32bit blocks); + void compress_n(const byte[], size_t blocks); void copy_out(byte[]); static const u64bit C0[256]; diff --git a/src/mac/cbc_mac/cbc_mac.cpp b/src/mac/cbc_mac/cbc_mac.cpp index 5b9708d41..1b03f0ab9 100644 --- a/src/mac/cbc_mac/cbc_mac.cpp +++ b/src/mac/cbc_mac/cbc_mac.cpp @@ -14,9 +14,9 @@ namespace Botan { /* * Update an CBC-MAC Calculation */ -void CBC_MAC::add_data(const byte input[], u32bit length) +void CBC_MAC::add_data(const byte input[], size_t length) { - u32bit xored = std::min(OUTPUT_LENGTH - position, length); + size_t xored = std::min(OUTPUT_LENGTH - position, length); xor_buf(&state[position], input, xored); position += xored; diff --git a/src/mac/cbc_mac/cbc_mac.h b/src/mac/cbc_mac/cbc_mac.h index 772abd38f..69fef9c57 100644 --- a/src/mac/cbc_mac/cbc_mac.h +++ b/src/mac/cbc_mac/cbc_mac.h @@ -29,13 +29,13 @@ class BOTAN_DLL CBC_MAC : public MessageAuthenticationCode CBC_MAC(BlockCipher* cipher); ~CBC_MAC(); private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); void key_schedule(const byte[], u32bit); BlockCipher* e; SecureVector<byte> state; - u32bit position; + size_t position; }; } diff --git a/src/mac/cmac/cmac.cpp b/src/mac/cmac/cmac.cpp index 38b62c6cb..05fa7d037 100644 --- a/src/mac/cmac/cmac.cpp +++ b/src/mac/cmac/cmac.cpp @@ -21,10 +21,10 @@ SecureVector<byte> CMAC::poly_double(const MemoryRegion<byte>& in, SecureVector<byte> out = in; byte carry = 0; - for(u32bit j = out.size(); j != 0; --j) + for(size_t i = out.size(); i != 0; --i) { - byte temp = out[j-1]; - out[j-1] = (temp << 1) | carry; + byte temp = out[i-1]; + out[i-1] = (temp << 1) | carry; carry = (temp >> 7); } @@ -37,7 +37,7 @@ SecureVector<byte> CMAC::poly_double(const MemoryRegion<byte>& in, /* * Update an CMAC Calculation */ -void CMAC::add_data(const byte input[], u32bit length) +void CMAC::add_data(const byte input[], size_t length) { buffer.copy(position, input, length); if(position + length > OUTPUT_LENGTH) @@ -78,8 +78,8 @@ void CMAC::final_result(byte mac[]) e->encrypt(state); - for(u32bit j = 0; j != OUTPUT_LENGTH; ++j) - mac[j] = state[j]; + for(size_t i = 0; i != OUTPUT_LENGTH; ++i) + mac[i] = state[i]; zeroise(state); zeroise(buffer); diff --git a/src/mac/cmac/cmac.h b/src/mac/cmac/cmac.h index b5f3eec1a..5655e1eea 100644 --- a/src/mac/cmac/cmac.h +++ b/src/mac/cmac/cmac.h @@ -37,13 +37,13 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode CMAC(BlockCipher* cipher); ~CMAC(); private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); void key_schedule(const byte[], u32bit); BlockCipher* e; SecureVector<byte> buffer, state, B, P; - u32bit position; + size_t position; byte polynomial; }; diff --git a/src/mac/hmac/hmac.cpp b/src/mac/hmac/hmac.cpp index 1ad9487b4..c842a944d 100644 --- a/src/mac/hmac/hmac.cpp +++ b/src/mac/hmac/hmac.cpp @@ -14,7 +14,7 @@ namespace Botan { /* * Update a HMAC Calculation */ -void HMAC::add_data(const byte input[], u32bit length) +void HMAC::add_data(const byte input[], size_t length) { hash->update(input, length); } diff --git a/src/mac/hmac/hmac.h b/src/mac/hmac/hmac.h index 43a5d22a4..3941baef9 100644 --- a/src/mac/hmac/hmac.h +++ b/src/mac/hmac/hmac.h @@ -29,7 +29,7 @@ class BOTAN_DLL HMAC : public MessageAuthenticationCode HMAC(HashFunction* hash); ~HMAC() { delete hash; } private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); void key_schedule(const byte[], u32bit); HashFunction* hash; diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp index 781cb7f27..fc8d652c6 100644 --- a/src/mac/ssl3mac/ssl3_mac.cpp +++ b/src/mac/ssl3mac/ssl3_mac.cpp @@ -12,7 +12,7 @@ namespace Botan { /* * Update a SSL3-MAC Calculation */ -void SSL3_MAC::add_data(const byte input[], u32bit length) +void SSL3_MAC::add_data(const byte input[], size_t length) { hash->update(input, length); } @@ -80,7 +80,7 @@ SSL3_MAC::SSL3_MAC(HashFunction* hash_in) : if(hash->HASH_BLOCK_SIZE == 0) throw Invalid_Argument("SSL3-MAC cannot be used with " + hash->name()); - u32bit INNER_HASH_LENGTH = + size_t INNER_HASH_LENGTH = (hash->name() == "SHA-160") ? 60 : hash->HASH_BLOCK_SIZE; i_key.resize(INNER_HASH_LENGTH); diff --git a/src/mac/ssl3mac/ssl3_mac.h b/src/mac/ssl3mac/ssl3_mac.h index 019163ec8..4d7b07dcc 100644 --- a/src/mac/ssl3mac/ssl3_mac.h +++ b/src/mac/ssl3mac/ssl3_mac.h @@ -29,7 +29,7 @@ class BOTAN_DLL SSL3_MAC : public MessageAuthenticationCode SSL3_MAC(HashFunction* hash); ~SSL3_MAC() { delete hash; } private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); void key_schedule(const byte[], u32bit); diff --git a/src/mac/x919_mac/x919_mac.cpp b/src/mac/x919_mac/x919_mac.cpp index 0515dbee9..ef812ff81 100644 --- a/src/mac/x919_mac/x919_mac.cpp +++ b/src/mac/x919_mac/x919_mac.cpp @@ -14,9 +14,9 @@ namespace Botan { /* * Update an ANSI X9.19 MAC Calculation */ -void ANSI_X919_MAC::add_data(const byte input[], u32bit length) +void ANSI_X919_MAC::add_data(const byte input[], size_t length) { - u32bit xored = std::min(8 - position, length); + size_t xored = std::min(8 - position, length); xor_buf(&state[position], input, xored); position += xored; diff --git a/src/mac/x919_mac/x919_mac.h b/src/mac/x919_mac/x919_mac.h index 275d39367..a1710b654 100644 --- a/src/mac/x919_mac/x919_mac.h +++ b/src/mac/x919_mac/x919_mac.h @@ -29,14 +29,14 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode ANSI_X919_MAC(BlockCipher* cipher); ~ANSI_X919_MAC(); private: - void add_data(const byte[], u32bit); + void add_data(const byte[], size_t); void final_result(byte[]); void key_schedule(const byte[], u32bit); BlockCipher* e; BlockCipher* d; SecureVector<byte> state; - u32bit position; + size_t position; }; } diff --git a/src/pbkdf/pbkdf2/pbkdf2.cpp b/src/pbkdf/pbkdf2/pbkdf2.cpp index b1c7b2e07..88131da01 100644 --- a/src/pbkdf/pbkdf2/pbkdf2.cpp +++ b/src/pbkdf/pbkdf2/pbkdf2.cpp @@ -42,7 +42,7 @@ OctetString PKCS5_PBKDF2::derive_key(u32bit key_len, u32bit counter = 1; while(key_len) { - u32bit T_size = std::min(mac->OUTPUT_LENGTH, key_len); + u32bit T_size = std::min<u32bit>(mac->OUTPUT_LENGTH, key_len); mac->update(salt, salt_size); for(u32bit j = 0; j != 4; ++j) diff --git a/src/utils/buf_comp/buf_comp.h b/src/utils/buf_comp/buf_comp.h index 784a3285d..0904941d6 100644 --- a/src/utils/buf_comp/buf_comp.h +++ b/src/utils/buf_comp/buf_comp.h @@ -25,14 +25,14 @@ class BOTAN_DLL BufferedComputation /** * The length of the output of this function in bytes. */ - const u32bit OUTPUT_LENGTH; + const size_t OUTPUT_LENGTH; /** * Add new input to process. * @param in the input to process as a byte array * @param length of param in in bytes */ - void update(const byte in[], u32bit length) { add_data(in, length); } + void update(const byte in[], size_t length) { add_data(in, length); } /** * Add new input to process. @@ -96,7 +96,7 @@ class BOTAN_DLL BufferedComputation * @param length the length of the byte array * @result the result of the call to final() */ - SecureVector<byte> process(const byte in[], u32bit length) + SecureVector<byte> process(const byte in[], size_t length) { add_data(in, length); return final(); @@ -129,7 +129,7 @@ class BOTAN_DLL BufferedComputation /** * @param out_len the output length of this computation */ - BufferedComputation(u32bit out_len) : OUTPUT_LENGTH(out_len) {} + BufferedComputation(size_t out_len) : OUTPUT_LENGTH(out_len) {} virtual ~BufferedComputation() {} private: @@ -140,7 +140,7 @@ class BOTAN_DLL BufferedComputation * @param input is an input buffer * @param length is the length of input in bytes */ - virtual void add_data(const byte input[], u32bit length) = 0; + virtual void add_data(const byte input[], size_t length) = 0; /** * Write the final output to out diff --git a/src/utils/xor_buf.h b/src/utils/xor_buf.h index 34abb48d3..3c96dea70 100644 --- a/src/utils/xor_buf.h +++ b/src/utils/xor_buf.h @@ -18,7 +18,7 @@ namespace Botan { * @param in the read-only input buffer * @param length the length of the buffers */ -inline void xor_buf(byte out[], const byte in[], u32bit length) +inline void xor_buf(byte out[], const byte in[], size_t length) { while(length >= 8) { @@ -33,8 +33,9 @@ inline void xor_buf(byte out[], const byte in[], u32bit length) out += 8; in += 8; length -= 8; } - for(u32bit j = 0; j != length; ++j) - out[j] ^= in[j]; + + for(size_t i = 0; i != length; ++i) + out[i] ^= in[i]; } /** @@ -47,7 +48,7 @@ inline void xor_buf(byte out[], const byte in[], u32bit length) inline void xor_buf(byte out[], const byte in[], const byte in2[], - u32bit length) + size_t length) { while(length >= 8) { @@ -65,8 +66,8 @@ inline void xor_buf(byte out[], in += 8; in2 += 8; out += 8; length -= 8; } - for(u32bit j = 0; j != length; ++j) - out[j] = in[j] ^ in2[j]; + for(size_t i = 0; i != length; ++i) + out[i] = in[i] ^ in2[i]; } } |