diff options
-rw-r--r-- | src/core/base.cpp | 69 | ||||
-rw-r--r-- | src/core/base.h | 77 | ||||
-rw-r--r-- | src/core/botan.h | 4 | ||||
-rw-r--r-- | src/core/info.txt | 2 | ||||
-rw-r--r-- | src/hash/hash.h (renamed from src/core/hash.h) | 0 |
5 files changed, 20 insertions, 132 deletions
diff --git a/src/core/base.cpp b/src/core/base.cpp index ede199685..846217d66 100644 --- a/src/core/base.cpp +++ b/src/core/base.cpp @@ -1,74 +1,13 @@ -/************************************************* -* Base Classes Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ +/** +* Stream Cipher Default Implementation for IV and Seek +* (C) 1999-2007 Jack Lloyd +*/ #include <botan/base.h> -#include <botan/version.h> namespace Botan { /************************************************* -* SymmetricAlgorithm Constructor * -*************************************************/ -SymmetricAlgorithm::SymmetricAlgorithm(u32bit key_min, u32bit key_max, - u32bit key_mod) : - MAXIMUM_KEYLENGTH(key_max ? key_max : key_min), - MINIMUM_KEYLENGTH(key_min), - KEYLENGTH_MULTIPLE(key_mod) - { - } - -/************************************************* -* Query if the keylength is valid * -*************************************************/ -bool SymmetricAlgorithm::valid_keylength(u32bit length) const - { - return ((length >= MINIMUM_KEYLENGTH) && - (length <= MAXIMUM_KEYLENGTH) && - (length % KEYLENGTH_MULTIPLE == 0)); - } - -/************************************************* -* Set the key * -*************************************************/ -void SymmetricAlgorithm::set_key(const SymmetricKey& algo_key) - throw(Invalid_Key_Length) - { - set_key(algo_key.begin(), algo_key.length()); - } - -/************************************************* -* Set the key * -*************************************************/ -void SymmetricAlgorithm::set_key(const byte algo_key[], u32bit length) - throw(Invalid_Key_Length) - { - if(!valid_keylength(length)) - throw Invalid_Key_Length(name(), length); - key(algo_key, length); - } - -/************************************************* -* BlockCipher Constructor * -*************************************************/ -BlockCipher::BlockCipher(u32bit block, u32bit key_min, u32bit key_max, - u32bit key_mod) : - SymmetricAlgorithm(key_min, key_max, key_mod), - BLOCK_SIZE(block) - { - } - -/************************************************* -* StreamCipher Constructor * -*************************************************/ -StreamCipher::StreamCipher(u32bit key_min, u32bit key_max, u32bit key_mod, - u32bit iv_len) : - SymmetricAlgorithm(key_min, key_max, key_mod), IV_LENGTH(iv_len) - { - } - -/************************************************* * Default StreamCipher Resync Operation * *************************************************/ void StreamCipher::resync(const byte[], u32bit length) diff --git a/src/core/base.h b/src/core/base.h index b9be665b1..d23a71471 100644 --- a/src/core/base.h +++ b/src/core/base.h @@ -8,6 +8,7 @@ #include <botan/exceptn.h> #include <botan/symkey.h> +#include <botan/sym_algo.h> namespace Botan { @@ -17,67 +18,6 @@ namespace Botan { static const u32bit DEFAULT_BUFFERSIZE = BOTAN_DEFAULT_BUFFER_SIZE; /** -* This class represents a symmetric algorithm object. -*/ -class BOTAN_DLL SymmetricAlgorithm - { - public: - - /** - * The maximum allowed key length. - */ - const u32bit MAXIMUM_KEYLENGTH; - - /** - * The minimal allowed key length. - */ - const u32bit MINIMUM_KEYLENGTH; - - /** - * A valid keylength is a multiple of this value. - */ - const u32bit KEYLENGTH_MULTIPLE; - - /** - * The name of the algorithm. - * @return the name of the algorithm - */ - virtual std::string name() const = 0; - - /** - * Set the symmetric key of this object. - * @param key the SymmetricKey to be set. - */ - void set_key(const SymmetricKey& key) throw(Invalid_Key_Length); - - /** - * Set the symmetric key of this object. - * @param key the to be set as a byte array. - * @param the length of the byte array. - */ - void set_key(const byte key[], u32bit length) throw(Invalid_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(u32bit length) const; - - /** - * 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(u32bit key_min, u32bit key_max, u32bit key_mod); - - virtual ~SymmetricAlgorithm() {} - private: - virtual void key(const byte[], u32bit) = 0; - }; - -/** * This class represents a block cipher object. */ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm @@ -132,7 +72,13 @@ class BOTAN_DLL BlockCipher : public SymmetricAlgorithm */ virtual void clear() throw() = 0; - BlockCipher(u32bit, u32bit, u32bit = 0, u32bit = 1); + BlockCipher(u32bit block_size, + u32bit key_min, + u32bit key_max = 0, + u32bit key_mod = 1) : + SymmetricAlgorithm(key_min, key_max, key_mod), + BLOCK_SIZE(block_size) {} + virtual ~BlockCipher() {} private: virtual void enc(const byte[], byte[]) const = 0; @@ -203,7 +149,12 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm */ virtual void clear() throw() = 0; - StreamCipher(u32bit, u32bit = 0, u32bit = 1, u32bit = 0); + StreamCipher(u32bit key_min, u32bit key_max = 0, + u32bit key_mod = 1, + u32bit iv_len = 0) : + SymmetricAlgorithm(key_min, key_max, key_mod), + IV_LENGTH(iv_len) {} + virtual ~StreamCipher() {} private: virtual void cipher(const byte[], byte[], u32bit) = 0; diff --git a/src/core/botan.h b/src/core/botan.h index 8f18f93be..c7109aaa5 100644 --- a/src/core/botan.h +++ b/src/core/botan.h @@ -3,11 +3,9 @@ * (C) 1999-2007 Jack Lloyd * *************************************************/ -#include <botan/base.h> -#include <botan/hash.h> -#include <botan/rng.h> #include <botan/init.h> #include <botan/lookup.h> +#include <botan/rng.h> #include <botan/version.h> #include <botan/parsing.h> diff --git a/src/core/info.txt b/src/core/info.txt index 40e897689..d95e3e486 100644 --- a/src/core/info.txt +++ b/src/core/info.txt @@ -26,11 +26,11 @@ defalloc.h enums.h exceptn.cpp exceptn.h -hash.h mem_pool.cpp mem_pool.h mutex.h secmem.h +sym_algo.h symkey.cpp symkey.h </add> diff --git a/src/core/hash.h b/src/hash/hash.h index d42ee0d82..d42ee0d82 100644 --- a/src/core/hash.h +++ b/src/hash/hash.h |