diff options
author | lloyd <[email protected]> | 2010-10-13 01:34:15 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-13 01:34:15 +0000 |
commit | fe4119c74b5e81a354a5313e4d2efbf9a135aa81 (patch) | |
tree | 5c5254cc3a4e5713169ef1d52a83db19c8c4ed65 | |
parent | 60fb91d8cb1710d07041f76050d24229ce91131b (diff) |
Use size_t rather than u32bit in SymmetricAlgorithm
86 files changed, 184 insertions, 182 deletions
diff --git a/src/block/aes/aes.cpp b/src/block/aes/aes.cpp index 66f9c5eb1..cfd490e1d 100644 --- a/src/block/aes/aes.cpp +++ b/src/block/aes/aes.cpp @@ -619,7 +619,7 @@ void AES::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * AES Key Schedule */ -void AES::key_schedule(const byte key[], u32bit length) +void AES::key_schedule(const byte key[], size_t length) { static const u32bit RC[10] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, @@ -629,40 +629,40 @@ void AES::key_schedule(const byte key[], u32bit length) SecureVector<u32bit> XEK(64), XDK(64); - const u32bit X = length / 4; - for(u32bit j = 0; j != X; ++j) - XEK[j] = load_be<u32bit>(key, j); + const size_t X = length / 4; + for(size_t i = 0; i != X; ++i) + XEK[i] = load_be<u32bit>(key, i); - for(u32bit j = X; j < 4*(ROUNDS+1); j += X) + for(size_t i = X; i < 4*(ROUNDS+1); i += X) { - XEK[j] = XEK[j-X] ^ S(rotate_left(XEK[j-1], 8)) ^ RC[(j-X)/X]; - for(u32bit k = 1; k != X; ++k) + XEK[i] = XEK[i-X] ^ S(rotate_left(XEK[i-1], 8)) ^ RC[(i-X)/X]; + for(size_t j = 1; j != X; ++j) { - if(X == 8 && k == 4) - XEK[j+k] = XEK[j+k-X] ^ S(XEK[j+k-1]); + if(X == 8 && j == 4) + XEK[i+j] = XEK[i+j-X] ^ S(XEK[i+j-1]); else - XEK[j+k] = XEK[j+k-X] ^ XEK[j+k-1]; + XEK[i+j] = XEK[i+j-X] ^ XEK[i+j-1]; } } - for(u32bit j = 0; j != 4*(ROUNDS+1); j += 4) + for(size_t i = 0; i != 4*(ROUNDS+1); i += 4) { - XDK[j ] = XEK[4*ROUNDS-j ]; - XDK[j+1] = XEK[4*ROUNDS-j+1]; - XDK[j+2] = XEK[4*ROUNDS-j+2]; - XDK[j+3] = XEK[4*ROUNDS-j+3]; + XDK[i ] = XEK[4*ROUNDS-i ]; + XDK[i+1] = XEK[4*ROUNDS-i+1]; + XDK[i+2] = XEK[4*ROUNDS-i+2]; + XDK[i+3] = XEK[4*ROUNDS-i+3]; } - for(u32bit j = 4; j != length + 24; ++j) - XDK[j] = TD[SE[get_byte(0, XDK[j])] + 0] ^ - TD[SE[get_byte(1, XDK[j])] + 256] ^ - TD[SE[get_byte(2, XDK[j])] + 512] ^ - TD[SE[get_byte(3, XDK[j])] + 768]; + for(size_t i = 4; i != length + 24; ++i) + XDK[i] = TD[SE[get_byte(0, XDK[i])] + 0] ^ + TD[SE[get_byte(1, XDK[i])] + 256] ^ + TD[SE[get_byte(2, XDK[i])] + 512] ^ + TD[SE[get_byte(3, XDK[i])] + 768]; - for(u32bit j = 0; j != 4; ++j) + for(size_t i = 0; i != 4; ++i) { - store_be(XEK[j+4*ROUNDS], &ME[4*j]); - store_be(XEK[j], &MD[4*j]); + store_be(XEK[i+4*ROUNDS], &ME[4*i]); + store_be(XEK[i], &MD[4*i]); } EK.copy(&XEK[0], length + 24); diff --git a/src/block/aes/aes.h b/src/block/aes/aes.h index 6bc1f44b4..d62413f5b 100644 --- a/src/block/aes/aes.h +++ b/src/block/aes/aes.h @@ -25,7 +25,8 @@ class BOTAN_DLL AES : public BlockCipher std::string name() const { return "AES"; } BlockCipher* clone() const { return new AES; } - AES() : BlockCipher(16, 16, 32, 8), EK(56), ME(16), DK(56), MD(16) { ROUNDS = 14; } + AES() : BlockCipher(16, 16, 32, 8), EK(56), ME(16), DK(56), MD(16) + { ROUNDS = 14; } /** * AES fixed to a particular key_size (16, 24, or 32 bytes) @@ -33,7 +34,7 @@ class BOTAN_DLL AES : public BlockCipher */ AES(u32bit key_size); private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); static u32bit S(u32bit); u32bit ROUNDS; @@ -41,7 +42,7 @@ class BOTAN_DLL AES : public BlockCipher SecureVector<u32bit> EK; SecureVector<byte> ME; - SecureVector<u32bit> DK; + SecureVector<u32bit > DK; SecureVector<byte> MD; }; diff --git a/src/block/aes_intel/aes_intel.cpp b/src/block/aes_intel/aes_intel.cpp index d03767e72..a2e660f2c 100644 --- a/src/block/aes_intel/aes_intel.cpp +++ b/src/block/aes_intel/aes_intel.cpp @@ -255,7 +255,7 @@ void AES_128_Intel::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * AES-128 Key Schedule */ -void AES_128_Intel::key_schedule(const byte key[], u32bit) +void AES_128_Intel::key_schedule(const byte key[], size_t) { #define AES_128_key_exp(K, RCON) \ aes_128_key_expansion(K, _mm_aeskeygenassist_si128(K, RCON)) @@ -477,7 +477,7 @@ void AES_192_Intel::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * AES-192 Key Schedule */ -void AES_192_Intel::key_schedule(const byte key[], u32bit) +void AES_192_Intel::key_schedule(const byte key[], size_t) { __m128i K0 = _mm_loadu_si128((const __m128i*)(key)); __m128i K1 = _mm_loadu_si128((const __m128i*)(key + 8)); @@ -705,7 +705,7 @@ void AES_256_Intel::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * AES-256 Key Schedule */ -void AES_256_Intel::key_schedule(const byte key[], u32bit) +void AES_256_Intel::key_schedule(const byte key[], size_t) { __m128i K0 = _mm_loadu_si128((const __m128i*)(key)); __m128i K1 = _mm_loadu_si128((const __m128i*)(key + 16)); diff --git a/src/block/aes_intel/aes_intel.h b/src/block/aes_intel/aes_intel.h index 43e8f2f0e..1d8a68389 100644 --- a/src/block/aes_intel/aes_intel.h +++ b/src/block/aes_intel/aes_intel.h @@ -29,7 +29,7 @@ class BOTAN_DLL AES_128_Intel : public BlockCipher AES_128_Intel() : BlockCipher(16, 16) { } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit, 44> EK, DK; }; @@ -51,7 +51,7 @@ class BOTAN_DLL AES_192_Intel : public BlockCipher AES_192_Intel() : BlockCipher(16, 24) { } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit, 52> EK, DK; }; @@ -73,7 +73,7 @@ class BOTAN_DLL AES_256_Intel : public BlockCipher AES_256_Intel() : BlockCipher(16, 32) { } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit, 60> EK, DK; }; diff --git a/src/block/aes_ssse3/aes_ssse3.cpp b/src/block/aes_ssse3/aes_ssse3.cpp index dda5941b7..c5869f899 100644 --- a/src/block/aes_ssse3/aes_ssse3.cpp +++ b/src/block/aes_ssse3/aes_ssse3.cpp @@ -371,7 +371,7 @@ void AES_128_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * AES-128 Key Schedule */ -void AES_128_SSSE3::key_schedule(const byte keyb[], u32bit) +void AES_128_SSSE3::key_schedule(const byte keyb[], size_t) { __m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81, 0x1F8391B9, 0xAF9DEEB6); @@ -440,7 +440,7 @@ void AES_192_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * AES-192 Key Schedule */ -void AES_192_SSSE3::key_schedule(const byte keyb[], u32bit) +void AES_192_SSSE3::key_schedule(const byte keyb[], size_t) { __m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81, 0x1F8391B9, 0xAF9DEEB6); @@ -539,7 +539,7 @@ void AES_256_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * AES-256 Key Schedule */ -void AES_256_SSSE3::key_schedule(const byte keyb[], u32bit) +void AES_256_SSSE3::key_schedule(const byte keyb[], size_t) { __m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81, 0x1F8391B9, 0xAF9DEEB6); diff --git a/src/block/aes_ssse3/aes_ssse3.h b/src/block/aes_ssse3/aes_ssse3.h index 7b2a43cb7..0cdb5f4de 100644 --- a/src/block/aes_ssse3/aes_ssse3.h +++ b/src/block/aes_ssse3/aes_ssse3.h @@ -27,7 +27,7 @@ class BOTAN_DLL AES_128_SSSE3 : public BlockCipher AES_128_SSSE3() : BlockCipher(16, 16), EK(44), DK(44) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> EK, DK; }; @@ -47,7 +47,7 @@ class BOTAN_DLL AES_192_SSSE3 : public BlockCipher AES_192_SSSE3() : BlockCipher(16, 24), EK(52), DK(52) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> EK, DK; }; @@ -67,7 +67,7 @@ class BOTAN_DLL AES_256_SSSE3 : public BlockCipher AES_256_SSSE3() : BlockCipher(16, 32), EK(60), DK(60) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> EK, DK; }; diff --git a/src/block/blowfish/blowfish.cpp b/src/block/blowfish/blowfish.cpp index e72dbb2ae..ea227e93e 100644 --- a/src/block/blowfish/blowfish.cpp +++ b/src/block/blowfish/blowfish.cpp @@ -83,13 +83,13 @@ void Blowfish::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Blowfish Key Schedule */ -void Blowfish::key_schedule(const byte key[], u32bit length) +void Blowfish::key_schedule(const byte key[], size_t length) { clear(); - for(size_t j = 0, k = 0; j != 18; ++j, k += 4) - P[j] ^= make_u32bit(key[(k ) % length], key[(k+1) % length], - key[(k+2) % length], key[(k+3) % length]); + for(size_t i = 0, j = 0; i != 18; ++i, j += 4) + P[i] ^= make_u32bit(key[(j ) % length], key[(j+1) % length], + key[(j+2) % length], key[(j+3) % length]); u32bit L = 0, R = 0; generate_sbox(P, L, R); @@ -107,22 +107,22 @@ void Blowfish::generate_sbox(MemoryRegion<u32bit>& box, const u32bit* S3 = &S[512]; const u32bit* S4 = &S[768]; - for(size_t j = 0; j != box.size(); j += 2) + for(size_t i = 0; i != box.size(); i += 2) { - for(size_t k = 0; k != 16; k += 2) + for(size_t j = 0; j != 16; j += 2) { - L ^= P[k]; + L ^= P[j]; R ^= ((S1[get_byte(0, L)] + S2[get_byte(1, L)]) ^ S3[get_byte(2, L)]) + S4[get_byte(3, L)]; - R ^= P[k+1]; + R ^= P[j+1]; L ^= ((S1[get_byte(0, R)] + S2[get_byte(1, R)]) ^ S3[get_byte(2, R)]) + S4[get_byte(3, R)]; } u32bit T = R; R = L ^ P[16]; L = T ^ P[17]; - box[j] = L; - box[j+1] = R; + box[i] = L; + box[i+1] = R; } } @@ -133,8 +133,6 @@ void Blowfish::clear() { std::copy(P_INIT, P_INIT + 18, P.begin()); std::copy(S_INIT, S_INIT + 1024, S.begin()); - //P.copy(P_INIT, 18); - //S.copy(S_INIT, 1024); } } diff --git a/src/block/blowfish/blowfish.h b/src/block/blowfish/blowfish.h index 32fb4cbd4..4d39e9e58 100644 --- a/src/block/blowfish/blowfish.h +++ b/src/block/blowfish/blowfish.h @@ -27,7 +27,7 @@ class BOTAN_DLL Blowfish : public BlockCipher Blowfish() : BlockCipher(8, 1, 56), S(1024), P(18) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); void generate_sbox(MemoryRegion<u32bit>& box, u32bit& L, u32bit& R) const; diff --git a/src/block/cascade/cascade.cpp b/src/block/cascade/cascade.cpp index e93e81d33..54c33bc68 100644 --- a/src/block/cascade/cascade.cpp +++ b/src/block/cascade/cascade.cpp @@ -29,7 +29,7 @@ void Cascade_Cipher::decrypt_n(const byte in[], byte out[], cipher1->decrypt_n(out, out, c1_blocks); } -void Cascade_Cipher::key_schedule(const byte key[], u32bit) +void Cascade_Cipher::key_schedule(const byte key[], size_t) { const byte* key2 = key + cipher1->MAXIMUM_KEYLENGTH; diff --git a/src/block/cascade/cascade.h b/src/block/cascade/cascade.h index 6e9d43cf7..5e1989cb6 100644 --- a/src/block/cascade/cascade.h +++ b/src/block/cascade/cascade.h @@ -34,7 +34,7 @@ class BOTAN_DLL Cascade_Cipher : public BlockCipher ~Cascade_Cipher(); private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); BlockCipher* cipher1; BlockCipher* cipher2; diff --git a/src/block/cast/cast128.cpp b/src/block/cast/cast128.cpp index 538c1bd5b..24469e025 100644 --- a/src/block/cast/cast128.cpp +++ b/src/block/cast/cast128.cpp @@ -116,7 +116,7 @@ void CAST_128::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * CAST-128 Key Schedule */ -void CAST_128::key_schedule(const byte key[], u32bit length) +void CAST_128::key_schedule(const byte key[], size_t length) { clear(); SecureVector<u32bit> X(4); diff --git a/src/block/cast/cast128.h b/src/block/cast/cast128.h index 18c0c1868..edccf04b3 100644 --- a/src/block/cast/cast128.h +++ b/src/block/cast/cast128.h @@ -27,7 +27,7 @@ class BOTAN_DLL CAST_128 : public BlockCipher CAST_128() : BlockCipher(8, 11, 16), MK(16), RK(16) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); static void cast_ks(MemoryRegion<u32bit>& ks, MemoryRegion<u32bit>& user_key); diff --git a/src/block/cast/cast256.cpp b/src/block/cast/cast256.cpp index 6567ffbd4..8be0a8dd6 100644 --- a/src/block/cast/cast256.cpp +++ b/src/block/cast/cast256.cpp @@ -136,7 +136,7 @@ void CAST_256::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * CAST-256 Key Schedule */ -void CAST_256::key_schedule(const byte key[], u32bit length) +void CAST_256::key_schedule(const byte key[], size_t length) { SecureVector<u32bit> K(8); for(size_t j = 0; j != length; ++j) diff --git a/src/block/cast/cast256.h b/src/block/cast/cast256.h index ef73fbf94..74e38face 100644 --- a/src/block/cast/cast256.h +++ b/src/block/cast/cast256.h @@ -27,7 +27,7 @@ class BOTAN_DLL CAST_256 : public BlockCipher CAST_256() : BlockCipher(16, 4, 32, 4), MK(48), RK(48) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); static const u32bit KEY_MASK[192]; static const byte KEY_ROT[32]; diff --git a/src/block/des/des.cpp b/src/block/des/des.cpp index 043391938..15c771bda 100644 --- a/src/block/des/des.cpp +++ b/src/block/des/des.cpp @@ -201,7 +201,7 @@ void DES::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * DES Key Schedule */ -void DES::key_schedule(const byte key[], u32bit) +void DES::key_schedule(const byte key[], size_t) { des_key_schedule(&round_key[0], key); } @@ -275,7 +275,7 @@ void TripleDES::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * TripleDES Key Schedule */ -void TripleDES::key_schedule(const byte key[], u32bit length) +void TripleDES::key_schedule(const byte key[], size_t length) { des_key_schedule(&round_key[0], key); des_key_schedule(&round_key[32], key + 8); diff --git a/src/block/des/des.h b/src/block/des/des.h index dbca8ddfd..03641ba40 100644 --- a/src/block/des/des.h +++ b/src/block/des/des.h @@ -27,7 +27,7 @@ class BOTAN_DLL DES : public BlockCipher DES() : BlockCipher(8, 8), round_key(32) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> round_key; }; @@ -47,7 +47,7 @@ class BOTAN_DLL TripleDES : public BlockCipher TripleDES() : BlockCipher(8, 16, 24, 8), round_key(96) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> round_key; }; diff --git a/src/block/des/desx.cpp b/src/block/des/desx.cpp index cb53448b4..b92011e56 100644 --- a/src/block/des/desx.cpp +++ b/src/block/des/desx.cpp @@ -45,7 +45,7 @@ void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * DESX Key Schedule */ -void DESX::key_schedule(const byte key[], u32bit) +void DESX::key_schedule(const byte key[], size_t) { K1.copy(key, 8); des.set_key(key + 8, 8); diff --git a/src/block/des/desx.h b/src/block/des/desx.h index 5b7f10281..b61ea3cf9 100644 --- a/src/block/des/desx.h +++ b/src/block/des/desx.h @@ -27,7 +27,7 @@ class BOTAN_DLL DESX : public BlockCipher DESX() : BlockCipher(8, 24), K1(8), K2(8) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<byte> K1, K2; DES des; }; diff --git a/src/block/gost_28147/gost_28147.cpp b/src/block/gost_28147/gost_28147.cpp index c23c31dfb..4b4b83dcc 100644 --- a/src/block/gost_28147/gost_28147.cpp +++ b/src/block/gost_28147/gost_28147.cpp @@ -144,7 +144,7 @@ void GOST_28147_89::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * GOST Key Schedule */ -void GOST_28147_89::key_schedule(const byte key[], u32bit) +void GOST_28147_89::key_schedule(const byte key[], size_t) { for(size_t i = 0; i != 8; ++i) EK[i] = load_le<u32bit>(key, i); diff --git a/src/block/gost_28147/gost_28147.h b/src/block/gost_28147/gost_28147.h index f70c6650f..d06b63228 100644 --- a/src/block/gost_28147/gost_28147.h +++ b/src/block/gost_28147/gost_28147.h @@ -68,7 +68,7 @@ class BOTAN_DLL GOST_28147_89 : public BlockCipher GOST_28147_89(const SecureVector<u32bit>& other_SBOX) : BlockCipher(8, 32), SBOX(other_SBOX), EK(8) {} - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> SBOX; SecureVector<u32bit> EK; diff --git a/src/block/idea/idea.cpp b/src/block/idea/idea.cpp index 8201c9193..be7680b2c 100644 --- a/src/block/idea/idea.cpp +++ b/src/block/idea/idea.cpp @@ -122,16 +122,16 @@ void IDEA::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * IDEA Key Schedule */ -void IDEA::key_schedule(const byte key[], u32bit) +void IDEA::key_schedule(const byte key[], size_t) { - for(size_t j = 0; j != 8; ++j) - EK[j] = load_be<u16bit>(key, j); + for(size_t i = 0; i != 8; ++i) + EK[i] = load_be<u16bit>(key, i); - for(size_t j = 1, k = 8, offset = 0; k != 52; j %= 8, ++j, ++k) + for(size_t i = 1, j = 8, offset = 0; j != 52; i %= 8, ++i, ++j) { - EK[j+7+offset] = static_cast<u16bit>((EK[(j % 8) + offset] << 9) | - (EK[((j+1) % 8) + offset] >> 7)); - offset += (j == 8) ? 8 : 0; + EK[i+7+offset] = static_cast<u16bit>((EK[(i % 8) + offset] << 9) | + (EK[((i+1) % 8) + offset] >> 7)); + offset += (i == 8) ? 8 : 0; } DK[51] = mul_inv(EK[3]); @@ -139,14 +139,14 @@ void IDEA::key_schedule(const byte key[], u32bit) DK[49] = -EK[1]; DK[48] = mul_inv(EK[0]); - for(size_t j = 1, k = 4, counter = 47; j != 8; ++j, k += 6) + for(size_t i = 1, j = 4, counter = 47; i != 8; ++i, j += 6) { - DK[counter--] = EK[k+1]; - DK[counter--] = EK[k]; - DK[counter--] = mul_inv(EK[k+5]); - DK[counter--] = -EK[k+3]; - DK[counter--] = -EK[k+4]; - DK[counter--] = mul_inv(EK[k+2]); + DK[counter--] = EK[j+1]; + DK[counter--] = EK[j]; + DK[counter--] = mul_inv(EK[j+5]); + DK[counter--] = -EK[j+3]; + DK[counter--] = -EK[j+4]; + DK[counter--] = mul_inv(EK[j+2]); } DK[5] = EK[47]; diff --git a/src/block/idea/idea.h b/src/block/idea/idea.h index 566d9afd4..c0af38ad6 100644 --- a/src/block/idea/idea.h +++ b/src/block/idea/idea.h @@ -38,7 +38,7 @@ class BOTAN_DLL IDEA : public BlockCipher const SecureVector<u16bit>& get_DK() const { return DK; } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u16bit> EK, DK; }; diff --git a/src/block/kasumi/kasumi.cpp b/src/block/kasumi/kasumi.cpp index 15d6a24fc..a57c0396a 100644 --- a/src/block/kasumi/kasumi.cpp +++ b/src/block/kasumi/kasumi.cpp @@ -199,7 +199,7 @@ void KASUMI::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * KASUMI Key Schedule */ -void KASUMI::key_schedule(const byte key[], u32bit) +void KASUMI::key_schedule(const byte key[], size_t) { static const u16bit RC[] = { 0x0123, 0x4567, 0x89AB, 0xCDEF, 0xFEDC, 0xBA98, 0x7654, 0x3210 }; diff --git a/src/block/kasumi/kasumi.h b/src/block/kasumi/kasumi.h index 8589af79b..c6b3c4351 100644 --- a/src/block/kasumi/kasumi.h +++ b/src/block/kasumi/kasumi.h @@ -27,7 +27,7 @@ class BOTAN_DLL KASUMI : public BlockCipher KASUMI() : BlockCipher(8, 16), EK(64) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u16bit> EK; }; diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp index b4a00ebee..daf00da81 100644 --- a/src/block/lion/lion.cpp +++ b/src/block/lion/lion.cpp @@ -68,7 +68,7 @@ void Lion::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Lion Key Schedule */ -void Lion::key_schedule(const byte key[], u32bit length) +void Lion::key_schedule(const byte key[], size_t length) { clear(); diff --git a/src/block/lion/lion.h b/src/block/lion/lion.h index 5d4d374b9..9beb68ca6 100644 --- a/src/block/lion/lion.h +++ b/src/block/lion/lion.h @@ -43,7 +43,7 @@ class BOTAN_DLL Lion : public BlockCipher ~Lion() { delete hash; delete cipher; } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); const size_t LEFT_SIZE, RIGHT_SIZE; diff --git a/src/block/lubyrack/lubyrack.cpp b/src/block/lubyrack/lubyrack.cpp index 0b7ec7bf4..383e9131b 100644 --- a/src/block/lubyrack/lubyrack.cpp +++ b/src/block/lubyrack/lubyrack.cpp @@ -87,7 +87,7 @@ void LubyRackoff::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Luby-Rackoff Key Schedule */ -void LubyRackoff::key_schedule(const byte key[], u32bit length) +void LubyRackoff::key_schedule(const byte key[], size_t length) { K1.set(key, length / 2); K2.set(key + length / 2, length / 2); diff --git a/src/block/lubyrack/lubyrack.h b/src/block/lubyrack/lubyrack.h index c20af950d..4567215e1 100644 --- a/src/block/lubyrack/lubyrack.h +++ b/src/block/lubyrack/lubyrack.h @@ -32,7 +32,7 @@ class BOTAN_DLL LubyRackoff : public BlockCipher LubyRackoff(HashFunction* hash); ~LubyRackoff() { delete hash; } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); HashFunction* hash; SecureVector<byte> K1, K2; diff --git a/src/block/mars/mars.cpp b/src/block/mars/mars.cpp index 9445ab576..fa73e564f 100644 --- a/src/block/mars/mars.cpp +++ b/src/block/mars/mars.cpp @@ -149,7 +149,7 @@ inline void decrypt_round(u32bit& A, u32bit& B, u32bit& C, u32bit& D, */ void forward_mix(u32bit& A, u32bit& B, u32bit& C, u32bit& D) { - for(u32bit j = 0; j != 2; ++j) + for(size_t j = 0; j != 2; ++j) { B ^= SBOX[get_byte(3, A)]; B += SBOX[get_byte(2, A) + 256]; C += SBOX[get_byte(1, A)]; D ^= SBOX[get_byte(0, A) + 256]; @@ -174,7 +174,7 @@ void forward_mix(u32bit& A, u32bit& B, u32bit& C, u32bit& D) */ void reverse_mix(u32bit& A, u32bit& B, u32bit& C, u32bit& D) { - for(u32bit j = 0; j != 2; ++j) + for(size_t j = 0; j != 2; ++j) { B ^= SBOX[get_byte(3, A) + 256]; C -= SBOX[get_byte(0, A)]; D -= SBOX[get_byte(1, A) + 256]; D ^= SBOX[get_byte(2, A)]; @@ -202,7 +202,7 @@ u32bit gen_mask(u32bit input) { u32bit mask = 0; - for(u32bit j = 2; j != 31; ++j) + for(size_t j = 2; j != 31; ++j) { u32bit region = (input >> (j-1)) & 0x07; @@ -318,11 +318,11 @@ void MARS::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * MARS Key Schedule */ -void MARS::key_schedule(const byte key[], u32bit length) +void MARS::key_schedule(const byte key[], size_t length) { SecureVector<u32bit> T(15); - for(size_t j = 0; j != length / 4; ++j) - T[j] = load_le<u32bit>(key, j); + for(size_t i = 0; i != length / 4; ++i) + T[i] = load_le<u32bit>(key, i); T[length / 4] = length / 4; diff --git a/src/block/mars/mars.h b/src/block/mars/mars.h index 0b98d3c25..a61f475f2 100644 --- a/src/block/mars/mars.h +++ b/src/block/mars/mars.h @@ -27,7 +27,7 @@ class BOTAN_DLL MARS : public BlockCipher MARS() : BlockCipher(16, 16, 32, 4), EK(40) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> EK; }; diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp index 891abf49f..2f82e18e8 100644 --- a/src/block/misty1/misty1.cpp +++ b/src/block/misty1/misty1.cpp @@ -202,7 +202,7 @@ void MISTY1::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * MISTY1 Key Schedule */ -void MISTY1::key_schedule(const byte key[], u32bit length) +void MISTY1::key_schedule(const byte key[], size_t length) { SecureVector<u16bit> KS(32); for(size_t i = 0; i != length / 2; ++i) diff --git a/src/block/misty1/misty1.h b/src/block/misty1/misty1.h index bb948cb07..318e63b7d 100644 --- a/src/block/misty1/misty1.h +++ b/src/block/misty1/misty1.h @@ -31,7 +31,7 @@ class BOTAN_DLL MISTY1 : public BlockCipher */ MISTY1(size_t rounds = 8); private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u16bit> EK, DK; }; diff --git a/src/block/noekeon/noekeon.cpp b/src/block/noekeon/noekeon.cpp index f9a54482b..06c415be9 100644 --- a/src/block/noekeon/noekeon.cpp +++ b/src/block/noekeon/noekeon.cpp @@ -160,16 +160,16 @@ void Noekeon::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Noekeon Key Schedule */ -void Noekeon::key_schedule(const byte key[], u32bit) +void Noekeon::key_schedule(const byte key[], size_t) { u32bit A0 = load_be<u32bit>(key, 0); u32bit A1 = load_be<u32bit>(key, 1); u32bit A2 = load_be<u32bit>(key, 2); u32bit A3 = load_be<u32bit>(key, 3); - for(size_t j = 0; j != 16; ++j) + for(size_t i = 0; i != 16; ++i) { - A0 ^= RC[j]; + A0 ^= RC[i]; theta(A0, A1, A2, A3); A1 = rotate_left(A1, 1); diff --git a/src/block/noekeon/noekeon.h b/src/block/noekeon/noekeon.h index 65d3474c7..593afa634 100644 --- a/src/block/noekeon/noekeon.h +++ b/src/block/noekeon/noekeon.h @@ -43,7 +43,7 @@ class BOTAN_DLL Noekeon : public BlockCipher const SecureVector<u32bit>& get_DK() const { return DK; } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> EK, DK; }; diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp index 6cfe8c202..97ca5d577 100644 --- a/src/block/rc2/rc2.cpp +++ b/src/block/rc2/rc2.cpp @@ -98,7 +98,7 @@ void RC2::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * RC2 Key Schedule */ -void RC2::key_schedule(const byte key[], u32bit length) +void RC2::key_schedule(const byte key[], size_t length) { static const byte TABLE[256] = { 0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED, 0x28, 0xE9, 0xFD, 0x79, diff --git a/src/block/rc2/rc2.h b/src/block/rc2/rc2.h index b8c1e069a..4addf22ed 100644 --- a/src/block/rc2/rc2.h +++ b/src/block/rc2/rc2.h @@ -34,7 +34,7 @@ class BOTAN_DLL RC2 : public BlockCipher RC2() : BlockCipher(8, 1, 32), K(64) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u16bit> K; }; diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp index 3b288d328..519735967 100644 --- a/src/block/rc5/rc5.cpp +++ b/src/block/rc5/rc5.cpp @@ -76,7 +76,7 @@ void RC5::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * RC5 Key Schedule */ -void RC5::key_schedule(const byte key[], u32bit length) +void RC5::key_schedule(const byte key[], size_t length) { const size_t WORD_KEYLENGTH = (((length - 1) / 4) + 1); const size_t MIX_ROUNDS = 3 * std::max(WORD_KEYLENGTH, S.size()); diff --git a/src/block/rc5/rc5.h b/src/block/rc5/rc5.h index f15230a00..11a62badb 100644 --- a/src/block/rc5/rc5.h +++ b/src/block/rc5/rc5.h @@ -31,7 +31,7 @@ class BOTAN_DLL RC5 : public BlockCipher */ RC5(size_t rounds); private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> S; const size_t ROUNDS; }; diff --git a/src/block/rc6/rc6.cpp b/src/block/rc6/rc6.cpp index f81f25efd..53ca5a7a2 100644 --- a/src/block/rc6/rc6.cpp +++ b/src/block/rc6/rc6.cpp @@ -111,27 +111,27 @@ void RC6::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * RC6 Key Schedule */ -void RC6::key_schedule(const byte key[], u32bit length) +void RC6::key_schedule(const byte key[], size_t length) { const size_t WORD_KEYLENGTH = (((length - 1) / 4) + 1); const size_t MIX_ROUNDS = 3 * std::max(WORD_KEYLENGTH, S.size()); S[0] = 0xB7E15163; - for(size_t j = 1; j != S.size(); ++j) - S[j] = S[j-1] + 0x9E3779B9; + for(size_t i = 1; i != S.size(); ++i) + S[i] = S[i-1] + 0x9E3779B9; SecureVector<u32bit> K(8); - for(s32bit j = length-1; j >= 0; --j) - K[j/4] = (K[j/4] << 8) + key[j]; + for(s32bit i = length-1; i >= 0; --i) + K[i/4] = (K[i/4] << 8) + key[i]; u32bit A = 0, B = 0; - for(u32bit j = 0; j != MIX_ROUNDS; ++j) + for(size_t i = 0; i != MIX_ROUNDS; ++i) { - A = rotate_left(S[j % S.size()] + A + B, 3); - B = rotate_left(K[j % WORD_KEYLENGTH] + A + B, (A + B) % 32); - S[j % S.size()] = A; - K[j % WORD_KEYLENGTH] = B; + A = rotate_left(S[i % S.size()] + A + B, 3); + B = rotate_left(K[i % WORD_KEYLENGTH] + A + B, (A + B) % 32); + S[i % S.size()] = A; + K[i % WORD_KEYLENGTH] = B; } } diff --git a/src/block/rc6/rc6.h b/src/block/rc6/rc6.h index ada7e9610..307834a8c 100644 --- a/src/block/rc6/rc6.h +++ b/src/block/rc6/rc6.h @@ -27,7 +27,7 @@ class BOTAN_DLL RC6 : public BlockCipher RC6() : BlockCipher(16, 1, 32), S(44) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> S; }; diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp index d64c37f00..f78e326e4 100644 --- a/src/block/safer/safer_sk.cpp +++ b/src/block/safer/safer_sk.cpp @@ -89,7 +89,7 @@ void SAFER_SK::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * SAFER-SK Key Schedule */ -void SAFER_SK::key_schedule(const byte key[], u32bit) +void SAFER_SK::key_schedule(const byte key[], size_t) { SecureVector<byte> KB(18); diff --git a/src/block/safer/safer_sk.h b/src/block/safer/safer_sk.h index b68cb5363..a64d09fb7 100644 --- a/src/block/safer/safer_sk.h +++ b/src/block/safer/safer_sk.h @@ -31,7 +31,7 @@ class BOTAN_DLL SAFER_SK : public BlockCipher */ SAFER_SK(size_t rounds); private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); static const byte EXP[256]; static const byte LOG[512]; diff --git a/src/block/seed/seed.cpp b/src/block/seed/seed.cpp index a253f27b8..408220013 100644 --- a/src/block/seed/seed.cpp +++ b/src/block/seed/seed.cpp @@ -102,7 +102,7 @@ void SEED::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * SEED Key Schedule */ -void SEED::key_schedule(const byte key[], u32bit) +void SEED::key_schedule(const byte key[], size_t) { const u32bit RC[16] = { 0x9E3779B9, 0x3C6EF373, 0x78DDE6E6, 0xF1BBCDCC, diff --git a/src/block/seed/seed.h b/src/block/seed/seed.h index e2b0862ae..48fefc9b0 100644 --- a/src/block/seed/seed.h +++ b/src/block/seed/seed.h @@ -27,7 +27,7 @@ class BOTAN_DLL SEED : public BlockCipher SEED() : BlockCipher(16, 16), K(32) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); class G_FUNC { diff --git a/src/block/serpent/serpent.cpp b/src/block/serpent/serpent.cpp index 8ff35b900..1d940cf39 100644 --- a/src/block/serpent/serpent.cpp +++ b/src/block/serpent/serpent.cpp @@ -351,7 +351,7 @@ void Serpent::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Serpent Key Schedule */ -void Serpent::key_schedule(const byte key[], u32bit length) +void Serpent::key_schedule(const byte key[], size_t length) { const u32bit PHI = 0x9E3779B9; diff --git a/src/block/serpent/serpent.h b/src/block/serpent/serpent.h index a436c578a..515a90407 100644 --- a/src/block/serpent/serpent.h +++ b/src/block/serpent/serpent.h @@ -41,7 +41,7 @@ class BOTAN_DLL Serpent : public BlockCipher { round_key.set(ks, 132); } private: - void key_schedule(const byte key[], u32bit length); + void key_schedule(const byte key[], size_t length); SecureVector<u32bit> round_key; }; diff --git a/src/block/serpent_ia32/serp_ia32.cpp b/src/block/serpent_ia32/serp_ia32.cpp index 6e409b580..d2f8adb62 100644 --- a/src/block/serpent_ia32/serp_ia32.cpp +++ b/src/block/serpent_ia32/serp_ia32.cpp @@ -70,7 +70,7 @@ void Serpent_IA32::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Serpent Key Schedule */ -void Serpent_IA32::key_schedule(const byte key[], u32bit length) +void Serpent_IA32::key_schedule(const byte key[], size_t length) { SecureVector<u32bit> W(140); for(size_t i = 0; i != length / 4; ++i) diff --git a/src/block/serpent_ia32/serp_ia32.h b/src/block/serpent_ia32/serp_ia32.h index cd103c130..d7b5bedc7 100644 --- a/src/block/serpent_ia32/serp_ia32.h +++ b/src/block/serpent_ia32/serp_ia32.h @@ -23,7 +23,7 @@ class BOTAN_DLL Serpent_IA32 : public Serpent BlockCipher* clone() const { return new Serpent_IA32; } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); }; } diff --git a/src/block/skipjack/skipjack.cpp b/src/block/skipjack/skipjack.cpp index e3c8598ff..b73972b59 100644 --- a/src/block/skipjack/skipjack.cpp +++ b/src/block/skipjack/skipjack.cpp @@ -157,7 +157,7 @@ void Skipjack::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Skipjack Key Schedule */ -void Skipjack::key_schedule(const byte key[], u32bit) +void Skipjack::key_schedule(const byte key[], size_t) { static const byte F[256] = { 0xA3, 0xD7, 0x09, 0x83, 0xF8, 0x48, 0xF6, 0xF4, 0xB3, 0x21, 0x15, 0x78, diff --git a/src/block/skipjack/skipjack.h b/src/block/skipjack/skipjack.h index 98cea7650..dff85df6c 100644 --- a/src/block/skipjack/skipjack.h +++ b/src/block/skipjack/skipjack.h @@ -27,7 +27,7 @@ class BOTAN_DLL Skipjack : public BlockCipher Skipjack() : BlockCipher(8, 10), FTAB(2560) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<byte> FTAB; }; diff --git a/src/block/square/square.cpp b/src/block/square/square.cpp index 601d66c15..b1517b990 100644 --- a/src/block/square/square.cpp +++ b/src/block/square/square.cpp @@ -138,7 +138,7 @@ void Square::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Square Key Schedule */ -void Square::key_schedule(const byte key[], u32bit) +void Square::key_schedule(const byte key[], size_t) { SecureVector<u32bit> XEK(36), XDK(36); diff --git a/src/block/square/square.h b/src/block/square/square.h index e3b07f24d..0a134bcb5 100644 --- a/src/block/square/square.h +++ b/src/block/square/square.h @@ -27,7 +27,7 @@ class BOTAN_DLL Square : public BlockCipher Square() : BlockCipher(16, 16), EK(28), DK(28), ME(32), MD(32) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); static void transform(u32bit[4]); diff --git a/src/block/tea/tea.cpp b/src/block/tea/tea.cpp index 434c74ba6..4ef995a7c 100644 --- a/src/block/tea/tea.cpp +++ b/src/block/tea/tea.cpp @@ -63,7 +63,7 @@ void TEA::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * TEA Key Schedule */ -void TEA::key_schedule(const byte key[], u32bit) +void TEA::key_schedule(const byte key[], size_t) { for(size_t i = 0; i != 4; ++i) K[i] = load_be<u32bit>(key, i); diff --git a/src/block/tea/tea.h b/src/block/tea/tea.h index 7cb18a4f8..eeab13cbc 100644 --- a/src/block/tea/tea.h +++ b/src/block/tea/tea.h @@ -27,7 +27,7 @@ class BOTAN_DLL TEA : public BlockCipher TEA() : BlockCipher(8, 16), K(4) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> K; }; diff --git a/src/block/twofish/twofish.cpp b/src/block/twofish/twofish.cpp index 9c3d57500..41bc7ca1c 100644 --- a/src/block/twofish/twofish.cpp +++ b/src/block/twofish/twofish.cpp @@ -116,7 +116,7 @@ void Twofish::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Twofish Key Schedule */ -void Twofish::key_schedule(const byte key[], u32bit length) +void Twofish::key_schedule(const byte key[], size_t length) { SecureVector<byte> S(16); diff --git a/src/block/twofish/twofish.h b/src/block/twofish/twofish.h index b94c3adc3..38263af98 100644 --- a/src/block/twofish/twofish.h +++ b/src/block/twofish/twofish.h @@ -27,7 +27,7 @@ class BOTAN_DLL Twofish : public BlockCipher Twofish() : BlockCipher(16, 16, 32, 8), SB(1024), RK(40) {} private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); static void rs_mul(byte[4], byte, size_t); diff --git a/src/block/xtea/xtea.cpp b/src/block/xtea/xtea.cpp index 7acad2b6b..597eedd07 100644 --- a/src/block/xtea/xtea.cpp +++ b/src/block/xtea/xtea.cpp @@ -121,7 +121,7 @@ void XTEA::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * XTEA Key Schedule */ -void XTEA::key_schedule(const byte key[], u32bit) +void XTEA::key_schedule(const byte key[], size_t) { SecureVector<u32bit> UK(4); for(size_t i = 0; i != 4; ++i) diff --git a/src/block/xtea/xtea.h b/src/block/xtea/xtea.h index 6a843e21f..c870f588a 100644 --- a/src/block/xtea/xtea.h +++ b/src/block/xtea/xtea.h @@ -33,7 +33,7 @@ class BOTAN_DLL XTEA : public BlockCipher const SecureVector<u32bit>& get_EK() const { return EK; } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); SecureVector<u32bit> EK; }; diff --git a/src/cms/cms_algo.cpp b/src/cms/cms_algo.cpp index 79faaed4f..e74c385fa 100644 --- a/src/cms/cms_algo.cpp +++ b/src/cms/cms_algo.cpp @@ -134,7 +134,7 @@ SecureVector<byte> CMS_Encoder::encode_params(const std::string& cipher, { encoder.start_cons(SEQUENCE). encode(iv.bits_of(), OCTET_STRING). - encode(8*key.length()). + encode(u32bit(8*key.length())). end_cons(); } else diff --git a/src/engine/openssl/ossl_arc4.cpp b/src/engine/openssl/ossl_arc4.cpp index 78217a760..1273d239d 100644 --- a/src/engine/openssl/ossl_arc4.cpp +++ b/src/engine/openssl/ossl_arc4.cpp @@ -23,13 +23,13 @@ class ARC4_OpenSSL : public StreamCipher std::string name() const; StreamCipher* clone() const { return new ARC4_OpenSSL(SKIP); } - ARC4_OpenSSL(u32bit s = 0) : StreamCipher(1, 32), SKIP(s) { clear(); } + ARC4_OpenSSL(size_t s = 0) : StreamCipher(1, 32), SKIP(s) { clear(); } ~ARC4_OpenSSL() { clear(); } private: - void cipher(const byte[], byte[], u32bit); - void key_schedule(const byte[], u32bit); + void cipher(const byte[], byte[], size_t); + void key_schedule(const byte[], size_t); - const u32bit SKIP; + const size_t SKIP; RC4_KEY state; }; @@ -46,18 +46,18 @@ std::string ARC4_OpenSSL::name() const /* * ARC4 Key Schedule */ -void ARC4_OpenSSL::key_schedule(const byte key[], u32bit length) +void ARC4_OpenSSL::key_schedule(const byte key[], size_t length) { RC4_set_key(&state, length, key); byte dummy = 0; - for(u32bit j = 0; j != SKIP; j++) + for(size_t i = 0; i != SKIP; ++i) RC4(&state, 1, &dummy, &dummy); } /* * ARC4 Encryption */ -void ARC4_OpenSSL::cipher(const byte in[], byte out[], u32bit length) +void ARC4_OpenSSL::cipher(const byte in[], byte out[], size_t length) { RC4(&state, length, in, out); } diff --git a/src/engine/openssl/ossl_bc.cpp b/src/engine/openssl/ossl_bc.cpp index 9dc1159a0..891927b9f 100644 --- a/src/engine/openssl/ossl_bc.cpp +++ b/src/engine/openssl/ossl_bc.cpp @@ -29,7 +29,7 @@ class EVP_BlockCipher : public BlockCipher private: void encrypt_n(const byte in[], byte out[], size_t blocks) const; void decrypt_n(const byte in[], byte out[], size_t blocks) const; - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); std::string cipher_name; mutable EVP_CIPHER_CTX encrypt, decrypt; }; @@ -110,7 +110,7 @@ void EVP_BlockCipher::decrypt_n(const byte in[], byte out[], /* * Set the key */ -void EVP_BlockCipher::key_schedule(const byte key[], u32bit length) +void EVP_BlockCipher::key_schedule(const byte key[], size_t length) { SecureVector<byte> full_key(key, length); @@ -211,14 +211,14 @@ OpenSSL_Engine::find_block_cipher(const SCAN_Name& request, HANDLE_EVP_CIPHER_KEYLEN("RC2", EVP_rc2_ecb(), 1, 32, 1); #endif -#if !defined(OPENSSL_NO_RC5) +#if !defined(OPENSSL_NO_RC5) && 0 if(request.algo_name() == "RC5") if(request.arg_as_integer(0, 12) == 12) return new EVP_BlockCipher(EVP_rc5_32_12_16_ecb(), "RC5(12)", 1, 32, 1); #endif -#if !defined(OPENSSL_NO_IDEA) +#if !defined(OPENSSL_NO_IDEA) && 0 HANDLE_EVP_CIPHER("IDEA", EVP_idea_ecb()); #endif diff --git a/src/mac/cbc_mac/cbc_mac.cpp b/src/mac/cbc_mac/cbc_mac.cpp index 1b03f0ab9..2a5a6c10f 100644 --- a/src/mac/cbc_mac/cbc_mac.cpp +++ b/src/mac/cbc_mac/cbc_mac.cpp @@ -54,7 +54,7 @@ void CBC_MAC::final_result(byte mac[]) /* * CBC-MAC Key Schedule */ -void CBC_MAC::key_schedule(const byte key[], u32bit length) +void CBC_MAC::key_schedule(const byte key[], size_t length) { e->set_key(key, length); } diff --git a/src/mac/cbc_mac/cbc_mac.h b/src/mac/cbc_mac/cbc_mac.h index 69fef9c57..6b30ef764 100644 --- a/src/mac/cbc_mac/cbc_mac.h +++ b/src/mac/cbc_mac/cbc_mac.h @@ -31,7 +31,7 @@ class BOTAN_DLL CBC_MAC : public MessageAuthenticationCode private: void add_data(const byte[], size_t); void final_result(byte[]); - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); BlockCipher* e; SecureVector<byte> state; diff --git a/src/mac/cmac/cmac.cpp b/src/mac/cmac/cmac.cpp index 05fa7d037..05f487ad1 100644 --- a/src/mac/cmac/cmac.cpp +++ b/src/mac/cmac/cmac.cpp @@ -89,7 +89,7 @@ void CMAC::final_result(byte mac[]) /* * CMAC Key Schedule */ -void CMAC::key_schedule(const byte key[], u32bit length) +void CMAC::key_schedule(const byte key[], size_t length) { clear(); e->set_key(key, length); diff --git a/src/mac/cmac/cmac.h b/src/mac/cmac/cmac.h index 5655e1eea..ac929eaf3 100644 --- a/src/mac/cmac/cmac.h +++ b/src/mac/cmac/cmac.h @@ -39,7 +39,7 @@ class BOTAN_DLL CMAC : public MessageAuthenticationCode private: void add_data(const byte[], size_t); void final_result(byte[]); - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); BlockCipher* e; SecureVector<byte> buffer, state, B, P; diff --git a/src/mac/hmac/hmac.cpp b/src/mac/hmac/hmac.cpp index c842a944d..dfd800426 100644 --- a/src/mac/hmac/hmac.cpp +++ b/src/mac/hmac/hmac.cpp @@ -34,7 +34,7 @@ void HMAC::final_result(byte mac[]) /* * HMAC Key Schedule */ -void HMAC::key_schedule(const byte key[], u32bit length) +void HMAC::key_schedule(const byte key[], size_t length) { hash->clear(); std::fill(i_key.begin(), i_key.end(), 0x36); diff --git a/src/mac/hmac/hmac.h b/src/mac/hmac/hmac.h index 3941baef9..33af62f6a 100644 --- a/src/mac/hmac/hmac.h +++ b/src/mac/hmac/hmac.h @@ -31,7 +31,8 @@ class BOTAN_DLL HMAC : public MessageAuthenticationCode private: void add_data(const byte[], size_t); void final_result(byte[]); - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); + HashFunction* hash; SecureVector<byte> i_key, o_key; }; diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp index fc8d652c6..ac71be43c 100644 --- a/src/mac/ssl3mac/ssl3_mac.cpp +++ b/src/mac/ssl3mac/ssl3_mac.cpp @@ -32,7 +32,7 @@ void SSL3_MAC::final_result(byte mac[]) /* * SSL3-MAC Key Schedule */ -void SSL3_MAC::key_schedule(const byte key[], u32bit length) +void SSL3_MAC::key_schedule(const byte key[], size_t length) { hash->clear(); std::fill(i_key.begin(), i_key.end(), 0x36); diff --git a/src/mac/ssl3mac/ssl3_mac.h b/src/mac/ssl3mac/ssl3_mac.h index 4d7b07dcc..50042f3d0 100644 --- a/src/mac/ssl3mac/ssl3_mac.h +++ b/src/mac/ssl3mac/ssl3_mac.h @@ -31,7 +31,7 @@ class BOTAN_DLL SSL3_MAC : public MessageAuthenticationCode private: void add_data(const byte[], size_t); void final_result(byte[]); - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); HashFunction* hash; SecureVector<byte> i_key, o_key; diff --git a/src/mac/x919_mac/x919_mac.cpp b/src/mac/x919_mac/x919_mac.cpp index ef812ff81..330ca0043 100644 --- a/src/mac/x919_mac/x919_mac.cpp +++ b/src/mac/x919_mac/x919_mac.cpp @@ -53,7 +53,7 @@ void ANSI_X919_MAC::final_result(byte mac[]) /* * ANSI X9.19 MAC Key Schedule */ -void ANSI_X919_MAC::key_schedule(const byte key[], u32bit length) +void ANSI_X919_MAC::key_schedule(const byte key[], size_t length) { e->set_key(key, 8); if(length == 8) d->set_key(key, 8); diff --git a/src/mac/x919_mac/x919_mac.h b/src/mac/x919_mac/x919_mac.h index a1710b654..e9fe56c8d 100644 --- a/src/mac/x919_mac/x919_mac.h +++ b/src/mac/x919_mac/x919_mac.h @@ -31,7 +31,7 @@ class BOTAN_DLL ANSI_X919_MAC : public MessageAuthenticationCode private: void add_data(const byte[], size_t); void final_result(byte[]); - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); BlockCipher* e; BlockCipher* d; diff --git a/src/stream/arc4/arc4.cpp b/src/stream/arc4/arc4.cpp index 92a9ac092..9b8404e4e 100644 --- a/src/stream/arc4/arc4.cpp +++ b/src/stream/arc4/arc4.cpp @@ -59,7 +59,7 @@ void ARC4::generate() /* * ARC4 Key Schedule */ -void ARC4::key_schedule(const byte key[], u32bit length) +void ARC4::key_schedule(const byte key[], size_t length) { clear(); diff --git a/src/stream/arc4/arc4.h b/src/stream/arc4/arc4.h index aa1c39331..85ddb69b7 100644 --- a/src/stream/arc4/arc4.h +++ b/src/stream/arc4/arc4.h @@ -33,7 +33,7 @@ class BOTAN_DLL ARC4 : public StreamCipher ~ARC4() { clear(); } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); void generate(); const size_t SKIP; diff --git a/src/stream/ctr/ctr.cpp b/src/stream/ctr/ctr.cpp index f1b73a8c3..0a962bd5a 100644 --- a/src/stream/ctr/ctr.cpp +++ b/src/stream/ctr/ctr.cpp @@ -48,7 +48,7 @@ void CTR_BE::clear() /* * Set the key */ -void CTR_BE::key_schedule(const byte key[], u32bit key_len) +void CTR_BE::key_schedule(const byte key[], size_t key_len) { permutation->set_key(key, key_len); diff --git a/src/stream/ctr/ctr.h b/src/stream/ctr/ctr.h index 45a3e29e2..8c317acb0 100644 --- a/src/stream/ctr/ctr.h +++ b/src/stream/ctr/ctr.h @@ -39,7 +39,7 @@ class BOTAN_DLL CTR_BE : public StreamCipher CTR_BE(BlockCipher* cipher); ~CTR_BE(); private: - void key_schedule(const byte key[], u32bit key_len); + void key_schedule(const byte key[], size_t key_len); void increment_counter(); BlockCipher* permutation; diff --git a/src/stream/ofb/ofb.cpp b/src/stream/ofb/ofb.cpp index 1b1a066ee..921401d32 100644 --- a/src/stream/ofb/ofb.cpp +++ b/src/stream/ofb/ofb.cpp @@ -45,7 +45,7 @@ void OFB::clear() /* * Set the key */ -void OFB::key_schedule(const byte key[], u32bit key_len) +void OFB::key_schedule(const byte key[], size_t key_len) { permutation->set_key(key, key_len); diff --git a/src/stream/ofb/ofb.h b/src/stream/ofb/ofb.h index 832b93287..af771de15 100644 --- a/src/stream/ofb/ofb.h +++ b/src/stream/ofb/ofb.h @@ -39,7 +39,7 @@ class BOTAN_DLL OFB : public StreamCipher OFB(BlockCipher* cipher); ~OFB(); private: - void key_schedule(const byte key[], u32bit key_len); + void key_schedule(const byte key[], size_t key_len); BlockCipher* permutation; SecureVector<byte> buffer; diff --git a/src/stream/salsa20/salsa20.cpp b/src/stream/salsa20/salsa20.cpp index 7f76276bb..7d062befe 100644 --- a/src/stream/salsa20/salsa20.cpp +++ b/src/stream/salsa20/salsa20.cpp @@ -126,7 +126,7 @@ void Salsa20::cipher(const byte in[], byte out[], size_t length) /* * Salsa20 Key Schedule */ -void Salsa20::key_schedule(const byte key[], u32bit length) +void Salsa20::key_schedule(const byte key[], size_t length) { static const u32bit TAU[] = { 0x61707865, 0x3120646e, 0x79622d36, 0x6b206574 }; diff --git a/src/stream/salsa20/salsa20.h b/src/stream/salsa20/salsa20.h index 2addee9a9..213cb1117 100644 --- a/src/stream/salsa20/salsa20.h +++ b/src/stream/salsa20/salsa20.h @@ -29,10 +29,12 @@ class BOTAN_DLL Salsa20 : public StreamCipher std::string name() const; StreamCipher* clone() const { return new Salsa20; } - Salsa20() : StreamCipher(16, 32, 16), state(16), buffer(64) { position = 0; } + Salsa20() : StreamCipher(16, 32, 16), state(16), buffer(64) + { position = 0; } + ~Salsa20() { clear(); } private: - void key_schedule(const byte key[], u32bit key_len); + void key_schedule(const byte key[], size_t key_len); SecureVector<u32bit> state; SecureVector<byte> buffer; diff --git a/src/stream/turing/turing.cpp b/src/stream/turing/turing.cpp index 160d07a65..82e3aa2bb 100644 --- a/src/stream/turing/turing.cpp +++ b/src/stream/turing/turing.cpp @@ -223,7 +223,7 @@ u32bit Turing::fixedS(u32bit W) /* * Turing Key Schedule */ -void Turing::key_schedule(const byte key[], u32bit length) +void Turing::key_schedule(const byte key[], size_t length) { K.resize(length / 4); for(size_t i = 0; i != length; ++i) diff --git a/src/stream/turing/turing.h b/src/stream/turing/turing.h index f270c291a..adfabc0f1 100644 --- a/src/stream/turing/turing.h +++ b/src/stream/turing/turing.h @@ -34,7 +34,7 @@ class BOTAN_DLL Turing : public StreamCipher { position = 0; } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); void generate(); static u32bit fixedS(u32bit); diff --git a/src/stream/wid_wake/wid_wake.cpp b/src/stream/wid_wake/wid_wake.cpp index 3db87214e..51159064d 100644 --- a/src/stream/wid_wake/wid_wake.cpp +++ b/src/stream/wid_wake/wid_wake.cpp @@ -72,7 +72,7 @@ void WiderWake_41_BE::generate(size_t length) /* * WiderWake Key Schedule */ -void WiderWake_41_BE::key_schedule(const byte key[], u32bit) +void WiderWake_41_BE::key_schedule(const byte key[], size_t) { for(size_t i = 0; i != 4; ++i) t_key[i] = load_be<u32bit>(key, i); diff --git a/src/stream/wid_wake/wid_wake.h b/src/stream/wid_wake/wid_wake.h index ac8d8e2d6..17e77d5b5 100644 --- a/src/stream/wid_wake/wid_wake.h +++ b/src/stream/wid_wake/wid_wake.h @@ -37,7 +37,7 @@ class BOTAN_DLL WiderWake_41_BE : public StreamCipher { } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); void generate(size_t); diff --git a/src/sym_algo/sym_algo.h b/src/sym_algo/sym_algo.h index 60180de90..0a1423f13 100644 --- a/src/sym_algo/sym_algo.h +++ b/src/sym_algo/sym_algo.h @@ -24,17 +24,17 @@ class BOTAN_DLL SymmetricAlgorithm /** * The maximum allowed key length. */ - const u32bit MAXIMUM_KEYLENGTH; + const size_t MAXIMUM_KEYLENGTH; /** * The minimal allowed key length. */ - const u32bit MINIMUM_KEYLENGTH; + const size_t MINIMUM_KEYLENGTH; /** * A valid keylength is a multiple of this value. */ - const u32bit KEYLENGTH_MULTIPLE; + const size_t KEYLENGTH_MULTIPLE; /** * The name of the algorithm. @@ -54,7 +54,7 @@ class BOTAN_DLL SymmetricAlgorithm * @param key the to be set as a byte array. * @param length in bytes of key param */ - void set_key(const byte key[], u32bit length) + void set_key(const byte key[], size_t length) { if(!valid_keylength(length)) throw Invalid_Key_Length(name(), length); @@ -66,7 +66,7 @@ class BOTAN_DLL SymmetricAlgorithm * @param length the key length to be checked. * @return true if the key length is valid. */ - bool valid_keylength(u32bit length) const + bool valid_keylength(size_t length) const { return ((length >= MINIMUM_KEYLENGTH) && (length <= MAXIMUM_KEYLENGTH) && @@ -79,7 +79,7 @@ class BOTAN_DLL SymmetricAlgorithm * @param key_max the maximum allowed key length * @param key_mod any valid key length must be a multiple of this value */ - SymmetricAlgorithm(u32bit key_min, u32bit key_max, u32bit key_mod) : + SymmetricAlgorithm(size_t key_min, size_t key_max, size_t key_mod) : MAXIMUM_KEYLENGTH(key_max ? key_max : key_min), MINIMUM_KEYLENGTH(key_min), KEYLENGTH_MULTIPLE(key_mod) @@ -92,7 +92,7 @@ class BOTAN_DLL SymmetricAlgorithm * @param key the key * @param length of key */ - virtual void key_schedule(const byte key[], u32bit length) = 0; + virtual void key_schedule(const byte key[], size_t length) = 0; }; /** diff --git a/src/sym_algo/symkey.cpp b/src/sym_algo/symkey.cpp index 4452fd8fb..e8b9ddd21 100644 --- a/src/sym_algo/symkey.cpp +++ b/src/sym_algo/symkey.cpp @@ -18,7 +18,7 @@ namespace Botan { * Create an OctetString from RNG output */ OctetString::OctetString(RandomNumberGenerator& rng, - u32bit length) + size_t length) { bits = rng.random_vec(length); } @@ -30,7 +30,7 @@ void OctetString::change(const std::string& hex_string) { SecureVector<byte> decoded(1 + hex_string.length() / 2); - u32bit written = hex_decode(&decoded[0], hex_string); + size_t written = hex_decode(&decoded[0], hex_string); bits.set(&decoded[0], written); } @@ -38,7 +38,7 @@ void OctetString::change(const std::string& hex_string) /* * Create an OctetString from a byte string */ -void OctetString::change(const byte in[], u32bit n) +void OctetString::change(const byte in[], size_t n) { bits.resize(n); bits.copy(in, n); @@ -73,7 +73,7 @@ void OctetString::set_odd_parity() 0xF1, 0xF1, 0xF2, 0xF2, 0xF4, 0xF4, 0xF7, 0xF7, 0xF8, 0xF8, 0xFB, 0xFB, 0xFD, 0xFD, 0xFE, 0xFE }; - for(u32bit j = 0; j != bits.size(); ++j) + for(size_t j = 0; j != bits.size(); ++j) bits[j] = ODD_PARITY[bits[j]]; } diff --git a/src/sym_algo/symkey.h b/src/sym_algo/symkey.h index 154ae59da..6735b2b87 100644 --- a/src/sym_algo/symkey.h +++ b/src/sym_algo/symkey.h @@ -22,7 +22,7 @@ class BOTAN_DLL OctetString /** * @return size of this octet string in bytes */ - u32bit length() const { return bits.size(); } + size_t length() const { return bits.size(); } /** * @return this object as a SecureVector<byte> @@ -67,7 +67,7 @@ class BOTAN_DLL OctetString * @param in the input * @param length of in in bytes */ - void change(const byte in[], u32bit length); + void change(const byte in[], size_t length); /** * Change the contents of this octet string @@ -80,7 +80,7 @@ class BOTAN_DLL OctetString * @param rng is a random number generator * @param len is the desired length in bytes */ - OctetString(class RandomNumberGenerator& rng, u32bit len); + OctetString(class RandomNumberGenerator& rng, size_t len); /** * Create a new OctetString @@ -93,7 +93,7 @@ class BOTAN_DLL OctetString * @param in is an array * @param len is the length of in in bytes */ - OctetString(const byte in[], u32bit len) { change(in, len); } + OctetString(const byte in[], size_t len) { change(in, len); } /** * Create a new OctetString |