diff options
author | lloyd <[email protected]> | 2014-01-18 18:17:08 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-18 18:17:08 +0000 |
commit | b96ad4c05c0a8f835b54ef4e2cff849c749409b0 (patch) | |
tree | d8a5805e6d85cd66d2336f624f0cbeaaf1d5bed3 /src/lib/algo_base/transform.h | |
parent | 6b457468faa88180142de9bd2ba0fee90be43463 (diff) |
Split off the keyed interfaces of transform to Keyed_Transform
Remove the unhelpful 'Algorithm' base class which had previously
acted more or less as a global base.
Diffstat (limited to 'src/lib/algo_base/transform.h')
-rw-r--r-- | src/lib/algo_base/transform.h | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/src/lib/algo_base/transform.h b/src/lib/algo_base/transform.h index 5e59eb80c..229425efd 100644 --- a/src/lib/algo_base/transform.h +++ b/src/lib/algo_base/transform.h @@ -8,15 +8,19 @@ #ifndef BOTAN_TRANSFORM_H__ #define BOTAN_TRANSFORM_H__ -#include <botan/sym_algo.h> +#include <botan/secmem.h> +#include <botan/key_spec.h> +#include <botan/exceptn.h> +#include <botan/symkey.h> #include <string> +#include <vector> namespace Botan { /** * Interface for general transformations on data */ -class BOTAN_DLL Transformation : public SymmetricAlgorithm +class BOTAN_DLL Transformation { public: /** @@ -75,10 +79,6 @@ class BOTAN_DLL Transformation : public SymmetricAlgorithm */ virtual size_t default_nonce_length() const = 0; - BOTAN_DEPRECATED("Use default_nonce_length") - size_t default_nonce_size() const - { return default_nonce_length(); } - /** * Return true iff nonce_len is a valid length for the nonce */ @@ -92,9 +92,58 @@ class BOTAN_DLL Transformation : public SymmetricAlgorithm */ virtual std::string provider() const { return "core"; } + virtual std::string name() const = 0; + + virtual void clear() = 0; + virtual ~Transformation() {} }; +class BOTAN_DLL Keyed_Transform : public Transformation + { + public: + /** + * @return object describing limits on key size + */ + virtual Key_Length_Specification key_spec() const = 0; + + /** + * 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); + } + + template<typename Alloc> + void set_key(const std::vector<byte, Alloc>& key) + { + set_key(&key[0], key.size()); + } + + void set_key(const SymmetricKey& key) + { + set_key(key.begin(), key.length()); + } + + /** + * Set the symmetric key of this transform + * @param key contains the key material + * @param length in bytes of key param + */ + void set_key(const byte key[], size_t length) + { + if(!valid_keylength(length)) + throw Invalid_Key_Length(name(), length); + key_schedule(key, length); + } + + private: + virtual void key_schedule(const byte key[], size_t length) = 0; + }; + } #endif |