aboutsummaryrefslogtreecommitdiffstats
path: root/src/block
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-10-28 21:15:21 +0000
committerlloyd <[email protected]>2010-10-28 21:15:21 +0000
commit22f02b418f7f53431da168abe9fb74f15bf3cb0e (patch)
treecdc81938c979403d20a438d134bbd6d64479f17d /src/block
parenta7a047e6823dcbf23e172dd5c0f9a7b4fd748f10 (diff)
Eliminate the constant size_t values in SymmetricAlgorithm that give
the parameters of the key length. Instead define a new function which returns a simple object which contains this information. This definitely breaks backwards compatability, though only with code that directly manipulates low level objects like BlockCipher*s directly, which is probably relatively rare. Also remove some deprecated accessor functions from lookup.h. It turns out block_size_of and output_size_of are being used in the TLS code; I need to remove them from there before I can delete these entirely. Really that didn't make much sense, because they assumed all implementations of a particular algorithm will have the same specifications, which is definitely not necessarily true, especially WRT key length. It is much safer (and probably simpler) to first retrieve an instance of the actual object you are going to use and then ask it directly.
Diffstat (limited to 'src/block')
-rw-r--r--src/block/block_cipher.h25
-rw-r--r--src/block/cascade/cascade.cpp7
-rw-r--r--src/block/cascade/cascade.h6
-rw-r--r--src/block/lion/lion.cpp1
-rw-r--r--src/block/lion/lion.h5
-rw-r--r--src/block/lubyrack/lubyrack.cpp4
-rw-r--r--src/block/lubyrack/lubyrack.h5
7 files changed, 25 insertions, 28 deletions
diff --git a/src/block/block_cipher.h b/src/block/block_cipher.h
index b5a3c8439..8e820fc5a 100644
--- a/src/block/block_cipher.h
+++ b/src/block/block_cipher.h
@@ -18,19 +18,6 @@ namespace Botan {
class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
{
public:
- /**
- * BlockCipher constructor
- * @param block_size the size of blocks this cipher processes
- * @param key_min the minimum key size
- * @param key_max the maximum key size
- * @param key_mod the modulo restriction on the key size
- */
- BlockCipher(size_t key_min,
- size_t key_max = 0,
- size_t key_mod = 1) :
- SymmetricAlgorithm(key_min, key_max, key_mod) {}
-
- virtual ~BlockCipher() {}
/**
* @return block size of this algorithm
@@ -108,11 +95,6 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm
* Get a new object representing the same algorithm as *this
*/
virtual BlockCipher* clone() const = 0;
-
- /**
- * Zeroize internal state
- */
- virtual void clear() = 0;
};
/**
@@ -122,10 +104,13 @@ template<size_t BS, size_t KMIN, size_t KMAX = 0, size_t KMOD = 1>
class Block_Cipher_Fixed_Params : public BlockCipher
{
public:
- Block_Cipher_Fixed_Params() : BlockCipher(KMIN, KMAX, KMOD) {}
-
enum { BLOCK_SIZE = BS };
size_t block_size() const { return BS; }
+
+ Key_Length_Specification key_spec() const
+ {
+ return Key_Length_Specification(KMIN, KMAX, KMOD);
+ }
};
}
diff --git a/src/block/cascade/cascade.cpp b/src/block/cascade/cascade.cpp
index 2701c20e7..f1b1a8f2c 100644
--- a/src/block/cascade/cascade.cpp
+++ b/src/block/cascade/cascade.cpp
@@ -31,10 +31,10 @@ void Cascade_Cipher::decrypt_n(const byte in[], byte out[],
void Cascade_Cipher::key_schedule(const byte key[], size_t)
{
- const byte* key2 = key + cipher1->MAXIMUM_KEYLENGTH;
+ const byte* key2 = key + cipher1->maximum_keylength();
- cipher1->set_key(key , cipher1->MAXIMUM_KEYLENGTH);
- cipher2->set_key(key2, cipher2->MAXIMUM_KEYLENGTH);
+ cipher1->set_key(key , cipher1->maximum_keylength());
+ cipher2->set_key(key2, cipher2->maximum_keylength());
}
void Cascade_Cipher::clear()
@@ -81,7 +81,6 @@ size_t block_size_for_cascade(size_t bs, size_t bs2)
}
Cascade_Cipher::Cascade_Cipher(BlockCipher* c1, BlockCipher* c2) :
- BlockCipher(c1->MAXIMUM_KEYLENGTH + c2->MAXIMUM_KEYLENGTH),
cipher1(c1), cipher2(c2)
{
block = block_size_for_cascade(c1->block_size(), c2->block_size());
diff --git a/src/block/cascade/cascade.h b/src/block/cascade/cascade.h
index 31ee3b336..b1376e2e0 100644
--- a/src/block/cascade/cascade.h
+++ b/src/block/cascade/cascade.h
@@ -23,6 +23,12 @@ class BOTAN_DLL Cascade_Cipher : public BlockCipher
size_t block_size() const { return block; }
+ Key_Length_Specification key_spec() const
+ {
+ return Key_Length_Specification(cipher1->maximum_keylength() +
+ cipher2->maximum_keylength());
+ }
+
void clear();
std::string name() const;
BlockCipher* clone() const;
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
index 8cede1c86..46308e428 100644
--- a/src/block/lion/lion.cpp
+++ b/src/block/lion/lion.cpp
@@ -109,7 +109,6 @@ void Lion::clear()
* Lion Constructor
*/
Lion::Lion(HashFunction* hash_in, StreamCipher* sc_in, size_t block_len) :
- 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),
diff --git a/src/block/lion/lion.h b/src/block/lion/lion.h
index d4eb9c327..5076f4461 100644
--- a/src/block/lion/lion.h
+++ b/src/block/lion/lion.h
@@ -30,6 +30,11 @@ class BOTAN_DLL Lion : public BlockCipher
size_t block_size() const { return BLOCK_SIZE; }
+ Key_Length_Specification key_spec() const
+ {
+ return Key_Length_Specification(2, 2*hash->output_length(), 2);
+ }
+
void clear();
std::string name() const;
BlockCipher* clone() const;
diff --git a/src/block/lubyrack/lubyrack.cpp b/src/block/lubyrack/lubyrack.cpp
index 335570973..731dceb0b 100644
--- a/src/block/lubyrack/lubyrack.cpp
+++ b/src/block/lubyrack/lubyrack.cpp
@@ -122,9 +122,7 @@ std::string LubyRackoff::name() const
/*
* Luby-Rackoff Constructor
*/
-LubyRackoff::LubyRackoff(HashFunction* h) :
- BlockCipher(2, 32, 2),
- hash(h)
+LubyRackoff::LubyRackoff(HashFunction* h) : hash(h)
{
}
diff --git a/src/block/lubyrack/lubyrack.h b/src/block/lubyrack/lubyrack.h
index 0c267683a..81dddf579 100644
--- a/src/block/lubyrack/lubyrack.h
+++ b/src/block/lubyrack/lubyrack.h
@@ -24,6 +24,11 @@ class BOTAN_DLL LubyRackoff : public BlockCipher
size_t block_size() const { return 2 * hash->output_length(); }
+ Key_Length_Specification key_spec() const
+ {
+ return Key_Length_Specification(2, 32, 2);
+ }
+
void clear();
std::string name() const;
BlockCipher* clone() const;