aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/rc2
diff options
context:
space:
mode:
Diffstat (limited to 'src/block/rc2')
-rw-r--r--src/block/rc2/rc2.cpp39
-rw-r--r--src/block/rc2/rc2.h14
2 files changed, 27 insertions, 26 deletions
diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp
index 3114c6055..5c7cb1ead 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<u16bit>(in, 0);
u16bit R1 = load_le<u16bit>(in, 1);
u16bit R2 = load_le<u16bit>(in, 2);
u16bit R3 = load_le<u16bit>(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);
@@ -48,24 +48,24 @@ void RC2::encrypt_n(const byte in[], byte out[], u32bit blocks) const
store_le(out, R0, R1, R2, R3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
/*
* 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<u16bit>(in, 0);
u16bit R1 = load_le<u16bit>(in, 1);
u16bit R2 = load_le<u16bit>(in, 2);
u16bit R3 = load_le<u16bit>(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)];
@@ -90,15 +90,15 @@ void RC2::decrypt_n(const byte in[], byte out[], u32bit blocks) const
store_le(out, R0, R1, R2, R3);
- in += BLOCK_SIZE;
- out += BLOCK_SIZE;
+ in += block_size();
+ out += block_size();
}
}
/*
* 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,
@@ -124,23 +124,24 @@ void RC2::key_schedule(const byte key[], u32bit length)
0xC5, 0xF3, 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77, 0x0A, 0xA6, 0x20, 0x68,
0xFE, 0x7F, 0xC1, 0xAD };
- SecureVector<byte, 128> L;
+ SecureVector<byte> 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(u32bit j = 0; j != 64; ++j)
- K[j] = load_le<u16bit>(L, j);
+ for(s32bit i = 127-length; i >= 0; --i)
+ L[i] = TABLE[L[i+1] ^ L[i+length]];
+
+ load_le<u16bit>(&K[0], &L[0], 64);
}
/*
* 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 c16680347..4addf22ed 100644
--- a/src/block/rc2/rc2.h
+++ b/src/block/rc2/rc2.h
@@ -18,25 +18,25 @@ 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() { K.clear(); }
+ void clear() { zeroise(K); }
std::string name() const { return "RC2"; }
BlockCipher* clone() const { return new RC2; }
- RC2() : BlockCipher(8, 1, 32) {}
+ RC2() : BlockCipher(8, 1, 32), K(64) {}
private:
- void key_schedule(const byte[], u32bit);
+ void key_schedule(const byte[], size_t);
- SecureVector<u16bit, 64> K;
+ SecureVector<u16bit> K;
};
}