aboutsummaryrefslogtreecommitdiffstats
path: root/src/block
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-10-13 13:09:56 +0000
committerlloyd <[email protected]>2010-10-13 13:09:56 +0000
commit55550067fd69850c767cc9800433e1eabfeb5da2 (patch)
tree80ccea320ba00be2f7942d88657937462a6b1f03 /src/block
parent85a504e310666f270a3a67edf4cdac06c34c61b9 (diff)
Add a new subclass for BlockCipher BlockCipher_Fixed_Block_Size, which
sets the block size statically and also creates an enum with the size. Use the enum instead of calling block_size() where possible, since that uses two virtual function calls per block which is quite unfortunate. The real advantages here as compared to the previous version which kept the block size as a per-object u32bit: - The compiler can inline the constant as an immediate operand (previously it would load the value via an indirection on this) - Removes 32 bits per object overhead (except in cases with actually variable block sizes, which are very few and rarely used)
Diffstat (limited to 'src/block')
-rw-r--r--src/block/aes/aes.cpp10
-rw-r--r--src/block/aes/aes.h8
-rw-r--r--src/block/aes_ssse3/aes_ssse3.h15
-rw-r--r--src/block/block_cipher.h26
-rw-r--r--src/block/blowfish/blowfish.cpp8
-rw-r--r--src/block/blowfish/blowfish.h4
-rw-r--r--src/block/cascade/cascade.cpp5
-rw-r--r--src/block/cascade/cascade.h3
-rw-r--r--src/block/cast/cast128.cpp8
-rw-r--r--src/block/cast/cast128.h4
-rw-r--r--src/block/cast/cast256.cpp8
-rw-r--r--src/block/cast/cast256.h4
-rw-r--r--src/block/des/des.cpp16
-rw-r--r--src/block/des/des.h8
-rw-r--r--src/block/des/desx.cpp16
-rw-r--r--src/block/des/desx.h4
-rw-r--r--src/block/gost_28147/gost_28147.cpp10
-rw-r--r--src/block/gost_28147/gost_28147.h4
-rw-r--r--src/block/idea/idea.h4
-rw-r--r--src/block/idea_sse2/idea_sse2.cpp8
-rw-r--r--src/block/kasumi/kasumi.cpp8
-rw-r--r--src/block/kasumi/kasumi.h4
-rw-r--r--src/block/lion/lion.cpp20
-rw-r--r--src/block/lion/lion.h4
-rw-r--r--src/block/lubyrack/lubyrack.cpp11
-rw-r--r--src/block/lubyrack/lubyrack.h2
-rw-r--r--src/block/mars/mars.cpp8
-rw-r--r--src/block/mars/mars.h4
-rw-r--r--src/block/misty1/misty1.cpp12
-rw-r--r--src/block/misty1/misty1.h2
-rw-r--r--src/block/noekeon/noekeon.cpp8
-rw-r--r--src/block/noekeon/noekeon.h4
-rw-r--r--src/block/rc2/rc2.cpp8
-rw-r--r--src/block/rc2/rc2.h4
-rw-r--r--src/block/rc5/rc5.cpp12
-rw-r--r--src/block/rc5/rc5.h2
-rw-r--r--src/block/rc6/rc6.cpp8
-rw-r--r--src/block/rc6/rc6.h4
-rw-r--r--src/block/safer/safer_sk.cpp13
-rw-r--r--src/block/safer/safer_sk.h2
-rw-r--r--src/block/seed/seed.cpp8
-rw-r--r--src/block/seed/seed.h4
-rw-r--r--src/block/serpent/serpent.cpp8
-rw-r--r--src/block/serpent/serpent.h6
-rw-r--r--src/block/serpent_ia32/serp_ia32.cpp8
-rw-r--r--src/block/serpent_simd/serp_simd.cpp8
-rw-r--r--src/block/skipjack/skipjack.cpp8
-rw-r--r--src/block/skipjack/skipjack.h4
-rw-r--r--src/block/square/square.cpp8
-rw-r--r--src/block/square/square.h6
-rw-r--r--src/block/tea/tea.cpp8
-rw-r--r--src/block/tea/tea.h4
-rw-r--r--src/block/twofish/twofish.cpp8
-rw-r--r--src/block/twofish/twofish.h6
-rw-r--r--src/block/xtea/xtea.cpp16
-rw-r--r--src/block/xtea/xtea.h4
-rw-r--r--src/block/xtea_simd/xtea_simd.cpp8
57 files changed, 232 insertions, 203 deletions
diff --git a/src/block/aes/aes.cpp b/src/block/aes/aes.cpp
index 88439cf98..1530af965 100644
--- a/src/block/aes/aes.cpp
+++ b/src/block/aes/aes.cpp
@@ -521,8 +521,8 @@ void AES::encrypt_n(const byte in[], byte out[], size_t blocks) const
out[14] = SE[get_byte(2, B1)] ^ ME[14];
out[15] = SE[get_byte(3, B2)] ^ ME[15];
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -611,8 +611,8 @@ void AES::decrypt_n(const byte in[], byte out[], size_t blocks) const
out[14] = SD[get_byte(2, B1)] ^ MD[14];
out[15] = SD[get_byte(3, B0)] ^ MD[15];
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -681,7 +681,7 @@ u32bit AES::S(u32bit input)
/*
* AES Constructor
*/
-AES::AES(u32bit key_size) : BlockCipher(16, key_size),
+AES::AES(u32bit key_size) : BlockCipher_Fixed_Block_Size(key_size),
EK(56), ME(16), DK(56), MD(16)
{
if(key_size != 16 && key_size != 24 && key_size != 32)
diff --git a/src/block/aes/aes.h b/src/block/aes/aes.h
index d62413f5b..6fa0ccaff 100644
--- a/src/block/aes/aes.h
+++ b/src/block/aes/aes.h
@@ -15,17 +15,19 @@ namespace Botan {
/**
* Rijndael aka AES
*/
-class BOTAN_DLL AES : public BlockCipher
+class BOTAN_DLL AES : public BlockCipher_Fixed_Block_Size<16>
{
public:
+ std::string name() const { return "AES"; }
+
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 clear();
- 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)
+ AES() : BlockCipher_Fixed_Block_Size(16, 32, 8),
+ EK(56), ME(16), DK(56), MD(16)
{ ROUNDS = 14; }
/**
diff --git a/src/block/aes_ssse3/aes_ssse3.h b/src/block/aes_ssse3/aes_ssse3.h
index 0cdb5f4de..59bb85f12 100644
--- a/src/block/aes_ssse3/aes_ssse3.h
+++ b/src/block/aes_ssse3/aes_ssse3.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* AES-128 using SSSE3
*/
-class BOTAN_DLL AES_128_SSSE3 : public BlockCipher
+class BOTAN_DLL AES_128_SSSE3 : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,8 @@ class BOTAN_DLL AES_128_SSSE3 : public BlockCipher
std::string name() const { return "AES-128"; }
BlockCipher* clone() const { return new AES_128_SSSE3; }
- AES_128_SSSE3() : BlockCipher(16, 16), EK(44), DK(44) {}
+ AES_128_SSSE3() : BlockCipher_Fixed_Block_Size(16),
+ EK(44), DK(44) {}
private:
void key_schedule(const byte[], size_t);
@@ -35,7 +36,7 @@ class BOTAN_DLL AES_128_SSSE3 : public BlockCipher
/**
* AES-192 using SSSE3
*/
-class BOTAN_DLL AES_192_SSSE3 : public BlockCipher
+class BOTAN_DLL AES_192_SSSE3 : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -45,7 +46,8 @@ class BOTAN_DLL AES_192_SSSE3 : public BlockCipher
std::string name() const { return "AES-192"; }
BlockCipher* clone() const { return new AES_192_SSSE3; }
- AES_192_SSSE3() : BlockCipher(16, 24), EK(52), DK(52) {}
+ AES_192_SSSE3() : BlockCipher_Fixed_Block_Size(24),
+ EK(52), DK(52) {}
private:
void key_schedule(const byte[], size_t);
@@ -55,7 +57,7 @@ class BOTAN_DLL AES_192_SSSE3 : public BlockCipher
/**
* AES-256 using SSSE3
*/
-class BOTAN_DLL AES_256_SSSE3 : public BlockCipher
+class BOTAN_DLL AES_256_SSSE3 : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -65,7 +67,8 @@ class BOTAN_DLL AES_256_SSSE3 : public BlockCipher
std::string name() const { return "AES-256"; }
BlockCipher* clone() const { return new AES_256_SSSE3; }
- AES_256_SSSE3() : BlockCipher(16, 32), EK(60), DK(60) {}
+ AES_256_SSSE3() : BlockCipher_Fixed_Block_Size(32),
+ EK(60), DK(60) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/block_cipher.h b/src/block/block_cipher.h
index 5f5e5e530..e522005b9 100644
--- a/src/block/block_cipher.h
+++ b/src/block/block_cipher.h
@@ -25,24 +25,17 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
* @param key_max the maximum key size
* @param key_mod the modulo restriction on the key size
*/
- BlockCipher(u32bit block_size,
- u32bit key_min,
+ BlockCipher(u32bit key_min,
u32bit key_max = 0,
u32bit key_mod = 1) :
- SymmetricAlgorithm(key_min, key_max, key_mod),
- BLOCK_SIZE(block_size) {}
+ SymmetricAlgorithm(key_min, key_max, key_mod) {}
virtual ~BlockCipher() {}
/**
- * The block size of this algorithm.
- */
- const u32bit BLOCK_SIZE;
-
- /**
* @return block size of this algorithm
*/
- size_t block_size() const { return BLOCK_SIZE; }
+ virtual size_t block_size() const = 0;
/**
* @return native parallelism of this cipher in blocks
@@ -122,6 +115,19 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
virtual void clear() = 0;
};
+template<size_t N>
+class BlockCipher_Fixed_Block_Size : public BlockCipher
+ {
+ public:
+ BlockCipher_Fixed_Block_Size(u32bit kmin,
+ u32bit kmax = 0,
+ u32bit kmod = 1) :
+ BlockCipher(kmin, kmax, kmod) {}
+
+ enum { BLOCK_SIZE = N };
+ size_t block_size() const { return N; }
+ };
+
}
#endif
diff --git a/src/block/blowfish/blowfish.cpp b/src/block/blowfish/blowfish.cpp
index f77c65d4d..ea227e93e 100644
--- a/src/block/blowfish/blowfish.cpp
+++ b/src/block/blowfish/blowfish.cpp
@@ -40,8 +40,8 @@ void Blowfish::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, R, L);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -75,8 +75,8 @@ void Blowfish::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, R, L);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/blowfish/blowfish.h b/src/block/blowfish/blowfish.h
index 4d39e9e58..c9bf8b2e0 100644
--- a/src/block/blowfish/blowfish.h
+++ b/src/block/blowfish/blowfish.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* Blowfish
*/
-class BOTAN_DLL Blowfish : public BlockCipher
+class BOTAN_DLL Blowfish : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL Blowfish : public BlockCipher
std::string name() const { return "Blowfish"; }
BlockCipher* clone() const { return new Blowfish; }
- Blowfish() : BlockCipher(8, 1, 56), S(1024), P(18) {}
+ Blowfish() : BlockCipher_Fixed_Block_Size(1, 56), S(1024), P(18) {}
private:
void key_schedule(const byte[], size_t);
void generate_sbox(MemoryRegion<u32bit>& box,
diff --git a/src/block/cascade/cascade.cpp b/src/block/cascade/cascade.cpp
index 225b7fd6e..2701c20e7 100644
--- a/src/block/cascade/cascade.cpp
+++ b/src/block/cascade/cascade.cpp
@@ -81,10 +81,11 @@ size_t block_size_for_cascade(size_t bs, size_t bs2)
}
Cascade_Cipher::Cascade_Cipher(BlockCipher* c1, BlockCipher* c2) :
- BlockCipher(block_size_for_cascade(c1->block_size(), c2->block_size()),
- c1->MAXIMUM_KEYLENGTH + c2->MAXIMUM_KEYLENGTH),
+ BlockCipher(c1->MAXIMUM_KEYLENGTH + c2->MAXIMUM_KEYLENGTH),
cipher1(c1), cipher2(c2)
{
+ block = block_size_for_cascade(c1->block_size(), c2->block_size());
+
if(block_size() % c1->block_size() || block_size() % c2->block_size())
throw Internal_Error("Failure in " + name() + " constructor");
}
diff --git a/src/block/cascade/cascade.h b/src/block/cascade/cascade.h
index 5e1989cb6..31ee3b336 100644
--- a/src/block/cascade/cascade.h
+++ b/src/block/cascade/cascade.h
@@ -21,6 +21,8 @@ class BOTAN_DLL Cascade_Cipher : public BlockCipher
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
void decrypt_n(const byte in[], byte out[], size_t blocks) const;
+ size_t block_size() const { return block; }
+
void clear();
std::string name() const;
BlockCipher* clone() const;
@@ -36,6 +38,7 @@ class BOTAN_DLL Cascade_Cipher : public BlockCipher
private:
void key_schedule(const byte[], size_t);
+ size_t block;
BlockCipher* cipher1;
BlockCipher* cipher2;
};
diff --git a/src/block/cast/cast128.cpp b/src/block/cast/cast128.cpp
index 092fc201e..24469e025 100644
--- a/src/block/cast/cast128.cpp
+++ b/src/block/cast/cast128.cpp
@@ -74,8 +74,8 @@ void CAST_128::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, R, L);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -108,8 +108,8 @@ void CAST_128::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, R, L);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/cast/cast128.h b/src/block/cast/cast128.h
index edccf04b3..3ecbcaa5a 100644
--- a/src/block/cast/cast128.h
+++ b/src/block/cast/cast128.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* CAST-128
*/
-class BOTAN_DLL CAST_128 : public BlockCipher
+class BOTAN_DLL CAST_128 : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL CAST_128 : public BlockCipher
std::string name() const { return "CAST-128"; }
BlockCipher* clone() const { return new CAST_128; }
- CAST_128() : BlockCipher(8, 11, 16), MK(16), RK(16) {}
+ CAST_128() : BlockCipher_Fixed_Block_Size(11, 16), MK(16), RK(16) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/cast/cast256.cpp b/src/block/cast/cast256.cpp
index 1b41cd2af..8be0a8dd6 100644
--- a/src/block/cast/cast256.cpp
+++ b/src/block/cast/cast256.cpp
@@ -84,8 +84,8 @@ void CAST_256::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, A, B, C, D);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -128,8 +128,8 @@ void CAST_256::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, A, B, C, D);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/cast/cast256.h b/src/block/cast/cast256.h
index 74e38face..0dda7f0d7 100644
--- a/src/block/cast/cast256.h
+++ b/src/block/cast/cast256.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* CAST-256
*/
-class BOTAN_DLL CAST_256 : public BlockCipher
+class BOTAN_DLL CAST_256 : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL CAST_256 : public BlockCipher
std::string name() const { return "CAST-256"; }
BlockCipher* clone() const { return new CAST_256; }
- CAST_256() : BlockCipher(16, 4, 32, 4), MK(48), RK(48) {}
+ CAST_256() : BlockCipher_Fixed_Block_Size(4, 32, 4), MK(48), RK(48) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/des/des.cpp b/src/block/des/des.cpp
index 7c61df3db..15c771bda 100644
--- a/src/block/des/des.cpp
+++ b/src/block/des/des.cpp
@@ -162,8 +162,8 @@ void DES::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(T, out);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -193,8 +193,8 @@ void DES::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(T, out);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -234,8 +234,8 @@ void TripleDES::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(T, out);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -267,8 +267,8 @@ void TripleDES::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(T, out);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/des/des.h b/src/block/des/des.h
index 03641ba40..d758cc4c1 100644
--- a/src/block/des/des.h
+++ b/src/block/des/des.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* DES
*/
-class BOTAN_DLL DES : public BlockCipher
+class BOTAN_DLL DES : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL DES : public BlockCipher
std::string name() const { return "DES"; }
BlockCipher* clone() const { return new DES; }
- DES() : BlockCipher(8, 8), round_key(32) {}
+ DES() : BlockCipher_Fixed_Block_Size(8), round_key(32) {}
private:
void key_schedule(const byte[], size_t);
@@ -35,7 +35,7 @@ class BOTAN_DLL DES : public BlockCipher
/**
* Triple DES
*/
-class BOTAN_DLL TripleDES : public BlockCipher
+class BOTAN_DLL TripleDES : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -45,7 +45,7 @@ class BOTAN_DLL TripleDES : public BlockCipher
std::string name() const { return "TripleDES"; }
BlockCipher* clone() const { return new TripleDES; }
- TripleDES() : BlockCipher(8, 16, 24, 8), round_key(96) {}
+ TripleDES() : BlockCipher_Fixed_Block_Size(16, 24, 8), round_key(96) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/des/desx.cpp b/src/block/des/desx.cpp
index c4dacdfdd..b92011e56 100644
--- a/src/block/des/desx.cpp
+++ b/src/block/des/desx.cpp
@@ -17,12 +17,12 @@ void DESX::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(out, in, &K1[0], block_size());
+ xor_buf(out, in, &K1[0], BLOCK_SIZE);
des.encrypt(out);
- xor_buf(out, &K2[0], block_size());
+ xor_buf(out, &K2[0], BLOCK_SIZE);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -33,12 +33,12 @@ void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- xor_buf(out, in, &K2[0], block_size());
+ xor_buf(out, in, &K2[0], BLOCK_SIZE);
des.decrypt(out);
- xor_buf(out, &K1[0], block_size());
+ xor_buf(out, &K1[0], BLOCK_SIZE);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/des/desx.h b/src/block/des/desx.h
index b61ea3cf9..962575529 100644
--- a/src/block/des/desx.h
+++ b/src/block/des/desx.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* DESX
*/
-class BOTAN_DLL DESX : public BlockCipher
+class BOTAN_DLL DESX : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL DESX : public BlockCipher
std::string name() const { return "DESX"; }
BlockCipher* clone() const { return new DESX; }
- DESX() : BlockCipher(8, 24), K1(8), K2(8) {}
+ DESX() : BlockCipher_Fixed_Block_Size(24), K1(8), K2(8) {}
private:
void key_schedule(const byte[], size_t);
SecureVector<byte> K1, K2;
diff --git a/src/block/gost_28147/gost_28147.cpp b/src/block/gost_28147/gost_28147.cpp
index ddf26b3d0..9adc0d568 100644
--- a/src/block/gost_28147/gost_28147.cpp
+++ b/src/block/gost_28147/gost_28147.cpp
@@ -52,7 +52,7 @@ GOST_28147_89_Params::GOST_28147_89_Params(const std::string& n) : name(n)
* GOST Constructor
*/
GOST_28147_89::GOST_28147_89(const GOST_28147_89_Params& param) :
- BlockCipher(8, 32), SBOX(1024), EK(8)
+ BlockCipher_Fixed_Block_Size(32), SBOX(1024), EK(8)
{
// Convert the parallel 4x4 sboxes into larger word-based sboxes
for(size_t i = 0; i != 4; ++i)
@@ -107,8 +107,8 @@ void GOST_28147_89::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, N2, N1);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -136,8 +136,8 @@ void GOST_28147_89::decrypt_n(const byte in[], byte out[], size_t blocks) const
}
store_le(out, N2, N1);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/gost_28147/gost_28147.h b/src/block/gost_28147/gost_28147.h
index d06b63228..adf542bbe 100644
--- a/src/block/gost_28147/gost_28147.h
+++ b/src/block/gost_28147/gost_28147.h
@@ -49,7 +49,7 @@ class BOTAN_DLL GOST_28147_89_Params
/**
* GOST 28147-89
*/
-class BOTAN_DLL GOST_28147_89 : public BlockCipher
+class BOTAN_DLL GOST_28147_89 : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -66,7 +66,7 @@ class BOTAN_DLL GOST_28147_89 : public BlockCipher
GOST_28147_89(const GOST_28147_89_Params& params);
private:
GOST_28147_89(const SecureVector<u32bit>& other_SBOX) :
- BlockCipher(8, 32), SBOX(other_SBOX), EK(8) {}
+ BlockCipher_Fixed_Block_Size(32), SBOX(other_SBOX), EK(8) {}
void key_schedule(const byte[], size_t);
diff --git a/src/block/idea/idea.h b/src/block/idea/idea.h
index c0af38ad6..3552d282f 100644
--- a/src/block/idea/idea.h
+++ b/src/block/idea/idea.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* IDEA
*/
-class BOTAN_DLL IDEA : public BlockCipher
+class BOTAN_DLL IDEA : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL IDEA : public BlockCipher
std::string name() const { return "IDEA"; }
BlockCipher* clone() const { return new IDEA; }
- IDEA() : BlockCipher(8, 16), EK(52), DK(52) {}
+ IDEA() : BlockCipher_Fixed_Block_Size(16), EK(52), DK(52) {}
protected:
/**
* @return const reference to encryption subkeys
diff --git a/src/block/idea_sse2/idea_sse2.cpp b/src/block/idea_sse2/idea_sse2.cpp
index 8c7bd2a2c..469a33943 100644
--- a/src/block/idea_sse2/idea_sse2.cpp
+++ b/src/block/idea_sse2/idea_sse2.cpp
@@ -201,8 +201,8 @@ void IDEA_SSE2::encrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 8)
{
idea_op_8(in, out, KS);
- in += 8 * block_size();
- out += 8 * block_size();
+ in += 8 * BLOCK_SIZE;
+ out += 8 * BLOCK_SIZE;
blocks -= 8;
}
@@ -220,8 +220,8 @@ void IDEA_SSE2::decrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 8)
{
idea_op_8(in, out, KS);
- in += 8 * block_size();
- out += 8 * block_size();
+ in += 8 * BLOCK_SIZE;
+ out += 8 * BLOCK_SIZE;
blocks -= 8;
}
diff --git a/src/block/kasumi/kasumi.cpp b/src/block/kasumi/kasumi.cpp
index 1a217a9c7..a57c0396a 100644
--- a/src/block/kasumi/kasumi.cpp
+++ b/src/block/kasumi/kasumi.cpp
@@ -145,8 +145,8 @@ void KASUMI::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B0, B1, B2, B3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -191,8 +191,8 @@ void KASUMI::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B0, B1, B2, B3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/kasumi/kasumi.h b/src/block/kasumi/kasumi.h
index c6b3c4351..7b416f193 100644
--- a/src/block/kasumi/kasumi.h
+++ b/src/block/kasumi/kasumi.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* KASUMI, the block cipher used in 3G telephony
*/
-class BOTAN_DLL KASUMI : public BlockCipher
+class BOTAN_DLL KASUMI : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL KASUMI : public BlockCipher
std::string name() const { return "KASUMI"; }
BlockCipher* clone() const { return new KASUMI; }
- KASUMI() : BlockCipher(8, 16), EK(64) {}
+ KASUMI() : BlockCipher_Fixed_Block_Size(16), EK(64) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
index 7f6a06b79..8cede1c86 100644
--- a/src/block/lion/lion.cpp
+++ b/src/block/lion/lion.cpp
@@ -33,8 +33,8 @@ void Lion::encrypt_n(const byte in[], byte out[], size_t blocks) const
cipher->set_key(buffer, LEFT_SIZE);
cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -60,8 +60,8 @@ void Lion::decrypt_n(const byte in[], byte out[], size_t blocks) const
cipher->set_key(buffer, LEFT_SIZE);
cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -83,7 +83,7 @@ std::string Lion::name() const
{
return "Lion(" + hash->name() + "," +
cipher->name() + "," +
- to_string(block_size()) + ")";
+ to_string(BLOCK_SIZE) + ")";
}
/*
@@ -91,7 +91,7 @@ std::string Lion::name() const
*/
BlockCipher* Lion::clone() const
{
- return new Lion(hash->clone(), cipher->clone(), block_size());
+ return new Lion(hash->clone(), cipher->clone(), BLOCK_SIZE);
}
/*
@@ -109,14 +109,14 @@ void Lion::clear()
* Lion Constructor
*/
Lion::Lion(HashFunction* hash_in, StreamCipher* sc_in, size_t block_len) :
- BlockCipher(std::max<size_t>(2*hash_in->output_length() + 1, block_len),
- 2, 2*hash_in->output_length(), 2),
+ BlockCipher(2, 2*hash_in->output_length(), 2),
+ BLOCK_SIZE(std::max<size_t>(2*hash_in->output_length() + 1, block_len)),
LEFT_SIZE(hash_in->output_length()),
- RIGHT_SIZE(block_size() - LEFT_SIZE),
+ RIGHT_SIZE(BLOCK_SIZE - LEFT_SIZE),
hash(hash_in),
cipher(sc_in)
{
- if(2*LEFT_SIZE + 1 > block_size())
+ if(2*LEFT_SIZE + 1 > BLOCK_SIZE)
throw Invalid_Argument(name() + ": Chosen block size is too small");
if(!cipher->valid_keylength(LEFT_SIZE))
diff --git a/src/block/lion/lion.h b/src/block/lion/lion.h
index 9beb68ca6..d4eb9c327 100644
--- a/src/block/lion/lion.h
+++ b/src/block/lion/lion.h
@@ -28,6 +28,8 @@ class BOTAN_DLL Lion : public BlockCipher
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
void decrypt_n(const byte in[], byte out[], size_t blocks) const;
+ size_t block_size() const { return BLOCK_SIZE; }
+
void clear();
std::string name() const;
BlockCipher* clone() const;
@@ -45,7 +47,7 @@ class BOTAN_DLL Lion : public BlockCipher
private:
void key_schedule(const byte[], size_t);
- const size_t LEFT_SIZE, RIGHT_SIZE;
+ const size_t BLOCK_SIZE, LEFT_SIZE, RIGHT_SIZE;
HashFunction* hash;
StreamCipher* cipher;
diff --git a/src/block/lubyrack/lubyrack.cpp b/src/block/lubyrack/lubyrack.cpp
index aa33c6bc4..335570973 100644
--- a/src/block/lubyrack/lubyrack.cpp
+++ b/src/block/lubyrack/lubyrack.cpp
@@ -42,8 +42,8 @@ void LubyRackoff::encrypt_n(const byte in[], byte out[], size_t blocks) const
hash->final(buffer);
xor_buf(out, buffer, len);
- in += block_size();
- out += block_size();
+ in += 2 * len;
+ out += 2 * len;
}
}
@@ -79,8 +79,8 @@ void LubyRackoff::decrypt_n(const byte in[], byte out[], size_t blocks) const
hash->final(buffer);
xor_buf(out + len, buffer, len);
- in += block_size();
- out += block_size();
+ in += 2 * len;
+ out += 2 * len;
}
}
@@ -123,8 +123,7 @@ std::string LubyRackoff::name() const
* Luby-Rackoff Constructor
*/
LubyRackoff::LubyRackoff(HashFunction* h) :
- BlockCipher(2 * (h ? h->output_length(): 0),
- 2, 32, 2),
+ BlockCipher(2, 32, 2),
hash(h)
{
}
diff --git a/src/block/lubyrack/lubyrack.h b/src/block/lubyrack/lubyrack.h
index 4567215e1..0c267683a 100644
--- a/src/block/lubyrack/lubyrack.h
+++ b/src/block/lubyrack/lubyrack.h
@@ -22,6 +22,8 @@ class BOTAN_DLL LubyRackoff : public BlockCipher
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
void decrypt_n(const byte in[], byte out[], size_t blocks) const;
+ size_t block_size() const { return 2 * hash->output_length(); }
+
void clear();
std::string name() const;
BlockCipher* clone() const;
diff --git a/src/block/mars/mars.cpp b/src/block/mars/mars.cpp
index 5864ac49b..fa73e564f 100644
--- a/src/block/mars/mars.cpp
+++ b/src/block/mars/mars.cpp
@@ -267,8 +267,8 @@ void MARS::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B, C, D);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -310,8 +310,8 @@ void MARS::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, D, C, B, A);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/mars/mars.h b/src/block/mars/mars.h
index a61f475f2..7a53d116b 100644
--- a/src/block/mars/mars.h
+++ b/src/block/mars/mars.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* MARS, IBM's candidate for AES
*/
-class BOTAN_DLL MARS : public BlockCipher
+class BOTAN_DLL MARS : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL MARS : public BlockCipher
std::string name() const { return "MARS"; }
BlockCipher* clone() const { return new MARS; }
- MARS() : BlockCipher(16, 16, 32, 4), EK(40) {}
+ MARS() : BlockCipher_Fixed_Block_Size(16, 32, 4), EK(40) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/misty1/misty1.cpp b/src/block/misty1/misty1.cpp
index c904c5d78..56a995b76 100644
--- a/src/block/misty1/misty1.cpp
+++ b/src/block/misty1/misty1.cpp
@@ -144,8 +144,8 @@ void MISTY1::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B2, B3, B0, B1);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -194,8 +194,8 @@ void MISTY1::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B0, B1, B2, B3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -251,7 +251,9 @@ void MISTY1::key_schedule(const byte key[], size_t length)
/*
* MISTY1 Constructor
*/
-MISTY1::MISTY1(size_t rounds) : BlockCipher(8, 16), EK(100), DK(100)
+MISTY1::MISTY1(size_t rounds) :
+ BlockCipher_Fixed_Block_Size(16),
+ EK(100), DK(100)
{
if(rounds != 8)
throw Invalid_Argument("MISTY1: Invalid number of rounds: "
diff --git a/src/block/misty1/misty1.h b/src/block/misty1/misty1.h
index 318e63b7d..3bd05b4c6 100644
--- a/src/block/misty1/misty1.h
+++ b/src/block/misty1/misty1.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* MISTY1
*/
-class BOTAN_DLL MISTY1 : public BlockCipher
+class BOTAN_DLL MISTY1 : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
diff --git a/src/block/noekeon/noekeon.cpp b/src/block/noekeon/noekeon.cpp
index c29fed93e..06c415be9 100644
--- a/src/block/noekeon/noekeon.cpp
+++ b/src/block/noekeon/noekeon.cpp
@@ -114,8 +114,8 @@ void Noekeon::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, A0, A1, A2, A3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -152,8 +152,8 @@ void Noekeon::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, A0, A1, A2, A3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/noekeon/noekeon.h b/src/block/noekeon/noekeon.h
index 593afa634..79c627579 100644
--- a/src/block/noekeon/noekeon.h
+++ b/src/block/noekeon/noekeon.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* Noekeon
*/
-class BOTAN_DLL Noekeon : public BlockCipher
+class BOTAN_DLL Noekeon : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL Noekeon : public BlockCipher
std::string name() const { return "Noekeon"; }
BlockCipher* clone() const { return new Noekeon; }
- Noekeon() : BlockCipher(16, 16), EK(4), DK(4) {}
+ Noekeon() : BlockCipher_Fixed_Block_Size(16), EK(4), DK(4) {}
protected:
/**
* The Noekeon round constants
diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp
index 5c7cb1ead..97ca5d577 100644
--- a/src/block/rc2/rc2.cpp
+++ b/src/block/rc2/rc2.cpp
@@ -48,8 +48,8 @@ void RC2::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, R0, R1, R2, R3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -90,8 +90,8 @@ void RC2::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, R0, R1, R2, R3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/rc2/rc2.h b/src/block/rc2/rc2.h
index 4addf22ed..ad4b1a308 100644
--- a/src/block/rc2/rc2.h
+++ b/src/block/rc2/rc2.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* RC2
*/
-class BOTAN_DLL RC2 : public BlockCipher
+class BOTAN_DLL RC2 : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -32,7 +32,7 @@ class BOTAN_DLL RC2 : public BlockCipher
std::string name() const { return "RC2"; }
BlockCipher* clone() const { return new RC2; }
- RC2() : BlockCipher(8, 1, 32), K(64) {}
+ RC2() : BlockCipher_Fixed_Block_Size(1, 32), K(64) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/rc5/rc5.cpp b/src/block/rc5/rc5.cpp
index 3cd169e5d..86777f772 100644
--- a/src/block/rc5/rc5.cpp
+++ b/src/block/rc5/rc5.cpp
@@ -38,8 +38,8 @@ void RC5::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -68,8 +68,8 @@ void RC5::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -112,7 +112,9 @@ std::string RC5::name() const
/*
* RC5 Constructor
*/
-RC5::RC5(size_t r) : BlockCipher(8, 1, 32), ROUNDS(r)
+RC5::RC5(size_t r) :
+ BlockCipher_Fixed_Block_Size(1, 32),
+ ROUNDS(r)
{
if(ROUNDS < 8 || ROUNDS > 32 || (ROUNDS % 4 != 0))
throw Invalid_Argument(name() + ": Invalid number of rounds");
diff --git a/src/block/rc5/rc5.h b/src/block/rc5/rc5.h
index 11a62badb..a9f3b5b0e 100644
--- a/src/block/rc5/rc5.h
+++ b/src/block/rc5/rc5.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* RC5
*/
-class BOTAN_DLL RC5 : public BlockCipher
+class BOTAN_DLL RC5 : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
diff --git a/src/block/rc6/rc6.cpp b/src/block/rc6/rc6.cpp
index df87acbb1..53ca5a7a2 100644
--- a/src/block/rc6/rc6.cpp
+++ b/src/block/rc6/rc6.cpp
@@ -55,8 +55,8 @@ void RC6::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B, C, D);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -103,8 +103,8 @@ void RC6::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, A, B, C, D);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/rc6/rc6.h b/src/block/rc6/rc6.h
index 307834a8c..8446138e0 100644
--- a/src/block/rc6/rc6.h
+++ b/src/block/rc6/rc6.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* RC6, Ron Rivest's AES candidate
*/
-class BOTAN_DLL RC6 : public BlockCipher
+class BOTAN_DLL RC6 : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL RC6 : public BlockCipher
std::string name() const { return "RC6"; }
BlockCipher* clone() const { return new RC6; }
- RC6() : BlockCipher(16, 1, 32), S(44) {}
+ RC6() : BlockCipher_Fixed_Block_Size(1, 32), S(44) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp
index 48d96d1a2..cd9dddf34 100644
--- a/src/block/safer/safer_sk.cpp
+++ b/src/block/safer/safer_sk.cpp
@@ -43,8 +43,8 @@ void SAFER_SK::encrypt_n(const byte in[], byte out[], size_t blocks) const
out[4] = E ^ EK[16*ROUNDS+4]; out[5] = F + EK[16*ROUNDS+5];
out[6] = G + EK[16*ROUNDS+6]; out[7] = H ^ EK[16*ROUNDS+7];
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -81,8 +81,8 @@ void SAFER_SK::decrypt_n(const byte in[], byte out[], size_t blocks) const
out[0] = A; out[1] = B; out[2] = C; out[3] = D;
out[4] = E; out[5] = F; out[6] = G; out[7] = H;
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -127,8 +127,9 @@ BlockCipher* SAFER_SK::clone() const
/*
* SAFER-SK Constructor
*/
-SAFER_SK::SAFER_SK(size_t rounds) : BlockCipher(8, 16),
- EK(16 * rounds + 8), ROUNDS(rounds)
+SAFER_SK::SAFER_SK(size_t rounds) :
+ BlockCipher_Fixed_Block_Size(16),
+ EK(16 * rounds + 8), ROUNDS(rounds)
{
if(ROUNDS > 13 || ROUNDS == 0)
throw Invalid_Argument(name() + ": Invalid number of rounds");
diff --git a/src/block/safer/safer_sk.h b/src/block/safer/safer_sk.h
index a64d09fb7..5e8d32b0a 100644
--- a/src/block/safer/safer_sk.h
+++ b/src/block/safer/safer_sk.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* SAFER-SK
*/
-class BOTAN_DLL SAFER_SK : public BlockCipher
+class BOTAN_DLL SAFER_SK : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
diff --git a/src/block/seed/seed.cpp b/src/block/seed/seed.cpp
index 015d2d48d..408220013 100644
--- a/src/block/seed/seed.cpp
+++ b/src/block/seed/seed.cpp
@@ -54,8 +54,8 @@ void SEED::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B2, B3, B0, B1);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -94,8 +94,8 @@ void SEED::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, B2, B3, B0, B1);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/seed/seed.h b/src/block/seed/seed.h
index 48fefc9b0..649e28a68 100644
--- a/src/block/seed/seed.h
+++ b/src/block/seed/seed.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* SEED, a Korean block cipher
*/
-class BOTAN_DLL SEED : public BlockCipher
+class BOTAN_DLL SEED : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL SEED : public BlockCipher
std::string name() const { return "SEED"; }
BlockCipher* clone() const { return new SEED; }
- SEED() : BlockCipher(16, 16), K(32) {}
+ SEED() : BlockCipher_Fixed_Block_Size(16), K(32) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/serpent/serpent.cpp b/src/block/serpent/serpent.cpp
index ec37a9e97..1d940cf39 100644
--- a/src/block/serpent/serpent.cpp
+++ b/src/block/serpent/serpent.cpp
@@ -287,8 +287,8 @@ void Serpent::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, B0, B1, B2, B3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -339,8 +339,8 @@ void Serpent::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, B0, B1, B2, B3);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/serpent/serpent.h b/src/block/serpent/serpent.h
index 515a90407..fccdcf214 100644
--- a/src/block/serpent/serpent.h
+++ b/src/block/serpent/serpent.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* Serpent, an AES finalist
*/
-class BOTAN_DLL Serpent : public BlockCipher
+class BOTAN_DLL Serpent : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -24,7 +24,9 @@ class BOTAN_DLL Serpent : public BlockCipher
void clear() { zeroise(round_key); }
std::string name() const { return "Serpent"; }
BlockCipher* clone() const { return new Serpent; }
- Serpent() : BlockCipher(16, 16, 32, 8), round_key(132) {}
+
+ Serpent() : BlockCipher_Fixed_Block_Size(16, 32, 8),
+ round_key(132) {}
protected:
/**
* For use by subclasses using SIMD, asm, etc
diff --git a/src/block/serpent_ia32/serp_ia32.cpp b/src/block/serpent_ia32/serp_ia32.cpp
index 76814647c..d2f8adb62 100644
--- a/src/block/serpent_ia32/serp_ia32.cpp
+++ b/src/block/serpent_ia32/serp_ia32.cpp
@@ -49,8 +49,8 @@ void Serpent_IA32::encrypt_n(const byte in[], byte out[], size_t blocks) const
for(size_t i = 0; i != blocks; ++i)
{
botan_serpent_ia32_encrypt(in, out, this->get_round_keys());
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -62,8 +62,8 @@ void Serpent_IA32::decrypt_n(const byte in[], byte out[], size_t blocks) const
for(size_t i = 0; i != blocks; ++i)
{
botan_serpent_ia32_decrypt(in, out, this->get_round_keys());
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/serpent_simd/serp_simd.cpp b/src/block/serpent_simd/serp_simd.cpp
index aef37cb99..babe68d40 100644
--- a/src/block/serpent_simd/serp_simd.cpp
+++ b/src/block/serpent_simd/serp_simd.cpp
@@ -185,8 +185,8 @@ void Serpent_SIMD::encrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 4)
{
serpent_encrypt_4(in, out, KS);
- in += 4 * block_size();
- out += 4 * block_size();
+ in += 4 * BLOCK_SIZE;
+ out += 4 * BLOCK_SIZE;
blocks -= 4;
}
@@ -204,8 +204,8 @@ void Serpent_SIMD::decrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 4)
{
serpent_decrypt_4(in, out, KS);
- in += 4 * block_size();
- out += 4 * block_size();
+ in += 4 * BLOCK_SIZE;
+ out += 4 * BLOCK_SIZE;
blocks -= 4;
}
diff --git a/src/block/skipjack/skipjack.cpp b/src/block/skipjack/skipjack.cpp
index 7f25cc90a..b73972b59 100644
--- a/src/block/skipjack/skipjack.cpp
+++ b/src/block/skipjack/skipjack.cpp
@@ -108,8 +108,8 @@ void Skipjack::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, W4, W3, W2, W1);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -149,8 +149,8 @@ void Skipjack::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, W4, W3, W2, W1);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/skipjack/skipjack.h b/src/block/skipjack/skipjack.h
index dff85df6c..73ae28de2 100644
--- a/src/block/skipjack/skipjack.h
+++ b/src/block/skipjack/skipjack.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* Skipjack, a NSA designed cipher used in Fortezza
*/
-class BOTAN_DLL Skipjack : public BlockCipher
+class BOTAN_DLL Skipjack : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL Skipjack : public BlockCipher
std::string name() const { return "Skipjack"; }
BlockCipher* clone() const { return new Skipjack; }
- Skipjack() : BlockCipher(8, 10), FTAB(2560) {}
+ Skipjack() : BlockCipher_Fixed_Block_Size(10), FTAB(2560) {}
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/square/square.cpp b/src/block/square/square.cpp
index ba86dd931..b1517b990 100644
--- a/src/block/square/square.cpp
+++ b/src/block/square/square.cpp
@@ -68,8 +68,8 @@ void Square::encrypt_n(const byte in[], byte out[], size_t blocks) const
out[14] = SE[get_byte(3, B2)] ^ ME[30];
out[15] = SE[get_byte(3, B3)] ^ ME[31];
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -130,8 +130,8 @@ void Square::decrypt_n(const byte in[], byte out[], size_t blocks) const
out[14] = SD[get_byte(3, B2)] ^ MD[30];
out[15] = SD[get_byte(3, B3)] ^ MD[31];
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/square/square.h b/src/block/square/square.h
index 0a134bcb5..d6df63131 100644
--- a/src/block/square/square.h
+++ b/src/block/square/square.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* Square
*/
-class BOTAN_DLL Square : public BlockCipher
+class BOTAN_DLL Square : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,9 @@ class BOTAN_DLL Square : public BlockCipher
std::string name() const { return "Square"; }
BlockCipher* clone() const { return new Square; }
- Square() : BlockCipher(16, 16), EK(28), DK(28), ME(32), MD(32) {}
+ Square() : BlockCipher_Fixed_Block_Size(16),
+ EK(28), DK(28), ME(32), MD(32) {}
+
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/tea/tea.cpp b/src/block/tea/tea.cpp
index 328786a14..4ef995a7c 100644
--- a/src/block/tea/tea.cpp
+++ b/src/block/tea/tea.cpp
@@ -30,8 +30,8 @@ void TEA::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, L, R);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -55,8 +55,8 @@ void TEA::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, L, R);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/tea/tea.h b/src/block/tea/tea.h
index eeab13cbc..a7318ba5c 100644
--- a/src/block/tea/tea.h
+++ b/src/block/tea/tea.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* TEA
*/
-class BOTAN_DLL TEA : public BlockCipher
+class BOTAN_DLL TEA : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL TEA : public BlockCipher
std::string name() const { return "TEA"; }
BlockCipher* clone() const { return new TEA; }
- TEA() : BlockCipher(8, 16), K(4) {}
+ TEA() : BlockCipher_Fixed_Block_Size(16), K(4) {}
private:
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 a573c2ec8..41bc7ca1c 100644
--- a/src/block/twofish/twofish.cpp
+++ b/src/block/twofish/twofish.cpp
@@ -57,8 +57,8 @@ void Twofish::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, C, D, A, B);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -108,8 +108,8 @@ void Twofish::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_le(out, C, D, A, B);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/twofish/twofish.h b/src/block/twofish/twofish.h
index 38263af98..a212bd285 100644
--- a/src/block/twofish/twofish.h
+++ b/src/block/twofish/twofish.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* Twofish, an AES finalist
*/
-class BOTAN_DLL Twofish : public BlockCipher
+class BOTAN_DLL Twofish : public BlockCipher_Fixed_Block_Size<16>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,9 @@ class BOTAN_DLL Twofish : public BlockCipher
std::string name() const { return "Twofish"; }
BlockCipher* clone() const { return new Twofish; }
- Twofish() : BlockCipher(16, 16, 32, 8), SB(1024), RK(40) {}
+ Twofish() : BlockCipher_Fixed_Block_Size(16, 32, 8),
+ SB(1024), RK(40) {}
+
private:
void key_schedule(const byte[], size_t);
diff --git a/src/block/xtea/xtea.cpp b/src/block/xtea/xtea.cpp
index ba07ba57c..597eedd07 100644
--- a/src/block/xtea/xtea.cpp
+++ b/src/block/xtea/xtea.cpp
@@ -64,8 +64,8 @@ void XTEA::encrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 4)
{
xtea_encrypt_4(in, out, &(this->EK[0]));
- in += 4 * block_size();
- out += 4 * block_size();
+ in += 4 * BLOCK_SIZE;
+ out += 4 * BLOCK_SIZE;
blocks -= 4;
}
@@ -82,8 +82,8 @@ void XTEA::encrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, L, R);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
@@ -95,8 +95,8 @@ void XTEA::decrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 4)
{
xtea_decrypt_4(in, out, &(this->EK[0]));
- in += 4 * block_size();
- out += 4 * block_size();
+ in += 4 * BLOCK_SIZE;
+ out += 4 * BLOCK_SIZE;
blocks -= 4;
}
@@ -113,8 +113,8 @@ void XTEA::decrypt_n(const byte in[], byte out[], size_t blocks) const
store_be(out, L, R);
- in += block_size();
- out += block_size();
+ in += BLOCK_SIZE;
+ out += BLOCK_SIZE;
}
}
diff --git a/src/block/xtea/xtea.h b/src/block/xtea/xtea.h
index c870f588a..539725be8 100644
--- a/src/block/xtea/xtea.h
+++ b/src/block/xtea/xtea.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* XTEA
*/
-class BOTAN_DLL XTEA : public BlockCipher
+class BOTAN_DLL XTEA : public BlockCipher_Fixed_Block_Size<8>
{
public:
void encrypt_n(const byte in[], byte out[], size_t blocks) const;
@@ -25,7 +25,7 @@ class BOTAN_DLL XTEA : public BlockCipher
std::string name() const { return "XTEA"; }
BlockCipher* clone() const { return new XTEA; }
- XTEA() : BlockCipher(8, 16), EK(64) {}
+ XTEA() : BlockCipher_Fixed_Block_Size(16), EK(64) {}
protected:
/**
* @return const reference to the key schedule
diff --git a/src/block/xtea_simd/xtea_simd.cpp b/src/block/xtea_simd/xtea_simd.cpp
index 5b73c7bb9..831cc0359 100644
--- a/src/block/xtea_simd/xtea_simd.cpp
+++ b/src/block/xtea_simd/xtea_simd.cpp
@@ -99,8 +99,8 @@ void XTEA_SIMD::encrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 8)
{
xtea_encrypt_8(in, out, KS);
- in += 8 * block_size();
- out += 8 * block_size();
+ in += 8 * BLOCK_SIZE;
+ out += 8 * BLOCK_SIZE;
blocks -= 8;
}
@@ -118,8 +118,8 @@ void XTEA_SIMD::decrypt_n(const byte in[], byte out[], size_t blocks) const
while(blocks >= 8)
{
xtea_decrypt_8(in, out, KS);
- in += 8 * block_size();
- out += 8 * block_size();
+ in += 8 * BLOCK_SIZE;
+ out += 8 * BLOCK_SIZE;
blocks -= 8;
}