From ff2210b035a1598bf99e18a578ff075bece8fbe5 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 12 Oct 2010 19:41:37 +0000 Subject: Use size_t rather than u32bit for the blocks argument of encrypt_n --- src/block/rc2/rc2.cpp | 24 +++++++++++++----------- src/block/rc2/rc2.h | 6 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'src/block/rc2') diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp index 8a939ecae..6cfe8c202 100644 --- a/src/block/rc2/rc2.cpp +++ b/src/block/rc2/rc2.cpp @@ -14,16 +14,16 @@ namespace Botan { /* * RC2 Encryption */ -void RC2::encrypt_n(const byte in[], byte out[], u32bit blocks) const +void RC2::encrypt_n(const byte in[], byte out[], size_t blocks) const { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { u16bit R0 = load_le(in, 0); u16bit R1 = load_le(in, 1); u16bit R2 = load_le(in, 2); u16bit R3 = load_le(in, 3); - for(u32bit j = 0; j != 16; ++j) + for(size_t j = 0; j != 16; ++j) { R0 += (R1 & ~R3) + (R2 & R3) + K[4*j]; R0 = rotate_left(R0, 1); @@ -56,16 +56,16 @@ void RC2::encrypt_n(const byte in[], byte out[], u32bit blocks) const /* * RC2 Decryption */ -void RC2::decrypt_n(const byte in[], byte out[], u32bit blocks) const +void RC2::decrypt_n(const byte in[], byte out[], size_t blocks) const { - for(u32bit i = 0; i != blocks; ++i) + for(size_t i = 0; i != blocks; ++i) { u16bit R0 = load_le(in, 0); u16bit R1 = load_le(in, 1); u16bit R2 = load_le(in, 2); u16bit R3 = load_le(in, 3); - for(u32bit j = 0; j != 16; ++j) + for(size_t j = 0; j != 16; ++j) { R3 = rotate_right(R3, 5); R3 -= (R0 & ~R2) + (R1 & R2) + K[63 - (4*j + 0)]; @@ -127,11 +127,13 @@ void RC2::key_schedule(const byte key[], u32bit length) SecureVector L(128); L.copy(key, length); - for(u32bit j = length; j != 128; ++j) - L[j] = TABLE[(L[j-1] + L[j-length]) % 256]; + for(size_t i = length; i != 128; ++i) + L[i] = TABLE[(L[i-1] + L[i-length]) % 256]; + L[128-length] = TABLE[L[128-length]]; - for(s32bit j = 127-length; j >= 0; --j) - L[j] = TABLE[L[j+1] ^ L[j+length]]; + + for(s32bit i = 127-length; i >= 0; --i) + L[i] = TABLE[L[i+1] ^ L[i+length]]; load_le(&K[0], &L[0], 64); } @@ -139,7 +141,7 @@ void RC2::key_schedule(const byte key[], u32bit length) /* * Return the code of the effective key bits */ -byte RC2::EKB_code(u32bit ekb) +byte RC2::EKB_code(size_t ekb) { const byte EKB[256] = { 0xBD, 0x56, 0xEA, 0xF2, 0xA2, 0xF1, 0xAC, 0x2A, 0xB0, 0x93, 0xD1, 0x9C, diff --git a/src/block/rc2/rc2.h b/src/block/rc2/rc2.h index 7e1953441..b8c1e069a 100644 --- a/src/block/rc2/rc2.h +++ b/src/block/rc2/rc2.h @@ -18,15 +18,15 @@ namespace Botan { class BOTAN_DLL RC2 : public BlockCipher { public: - void encrypt_n(const byte in[], byte out[], u32bit blocks) const; - void decrypt_n(const byte in[], byte out[], u32bit blocks) const; + void encrypt_n(const byte in[], byte out[], size_t blocks) const; + void decrypt_n(const byte in[], byte out[], size_t blocks) const; /** * Return the code of the effective key bits * @param bits key length * @return EKB code */ - static byte EKB_code(u32bit bits); + static byte EKB_code(size_t bits); void clear() { zeroise(K); } std::string name() const { return "RC2"; } -- cgit v1.2.3