aboutsummaryrefslogtreecommitdiffstats
path: root/src/sym_algo/sym_algo.h
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/sym_algo/sym_algo.h
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/sym_algo/sym_algo.h')
-rw-r--r--src/sym_algo/sym_algo.h61
1 files changed, 29 insertions, 32 deletions
diff --git a/src/sym_algo/sym_algo.h b/src/sym_algo/sym_algo.h
index 0a1423f13..aea0d06ba 100644
--- a/src/sym_algo/sym_algo.h
+++ b/src/sym_algo/sym_algo.h
@@ -9,6 +9,7 @@
#define BOTAN_SYMMETRIC_ALGORITHM_H__
#include <botan/types.h>
+#include <botan/key_spec.h>
#include <botan/exceptn.h>
#include <botan/symkey.h>
@@ -20,21 +21,43 @@ namespace Botan {
class BOTAN_DLL SymmetricAlgorithm
{
public:
+ virtual ~SymmetricAlgorithm() {}
+
+ /**
+ * Zeroize internal state
+ */
+ virtual void clear() = 0;
/**
- * The maximum allowed key length.
+ * @return object describing limits on key size
*/
- const size_t MAXIMUM_KEYLENGTH;
+ virtual Key_Length_Specification key_spec() const = 0;
/**
- * The minimal allowed key length.
+ * @return minimum allowed key length
*/
- const size_t MINIMUM_KEYLENGTH;
+ size_t maximum_keylength() const
+ {
+ return key_spec().maximum_keylength();
+ }
/**
- * A valid keylength is a multiple of this value.
+ * @return maxmium allowed key length
*/
- const size_t KEYLENGTH_MULTIPLE;
+ size_t minimum_keylength() const
+ {
+ return key_spec().minimum_keylength();
+ }
+
+ /**
+ * Check whether a given key length is valid for this algorithm.
+ * @param length the key length to be checked.
+ * @return true if the key length is valid.
+ */
+ bool valid_keylength(size_t length) const
+ {
+ return key_spec().valid_keylength(length);
+ }
/**
* The name of the algorithm.
@@ -60,32 +83,6 @@ class BOTAN_DLL SymmetricAlgorithm
throw Invalid_Key_Length(name(), length);
key_schedule(key, length);
}
-
- /**
- * Check whether a given key length is valid for this algorithm.
- * @param length the key length to be checked.
- * @return true if the key length is valid.
- */
- bool valid_keylength(size_t length) const
- {
- return ((length >= MINIMUM_KEYLENGTH) &&
- (length <= MAXIMUM_KEYLENGTH) &&
- (length % KEYLENGTH_MULTIPLE == 0));
- }
-
- /**
- * Construct a SymmetricAlgorithm.
- * @param key_min the minimum allowed key length
- * @param key_max the maximum allowed key length
- * @param key_mod any valid key length must be a multiple of this value
- */
- SymmetricAlgorithm(size_t key_min, size_t key_max, size_t key_mod) :
- MAXIMUM_KEYLENGTH(key_max ? key_max : key_min),
- MINIMUM_KEYLENGTH(key_min),
- KEYLENGTH_MULTIPLE(key_mod)
- {}
-
- virtual ~SymmetricAlgorithm() {}
private:
/**
* Run the key schedule