aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/block_cipher.h
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/block_cipher.h
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/block_cipher.h')
-rw-r--r--src/block/block_cipher.h26
1 files changed, 16 insertions, 10 deletions
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