/* * Symmetric Algorithm Base Class * (C) 1999-2007 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #ifndef BOTAN_SYMMETRIC_ALGORITHM_H_ #define BOTAN_SYMMETRIC_ALGORITHM_H_ #include #include #include namespace Botan { /** * This class represents a symmetric algorithm object. */ class BOTAN_PUBLIC_API(2,0) SymmetricAlgorithm { public: virtual ~SymmetricAlgorithm() = default; /** * Reset the state. */ virtual void clear() = 0; /** * @return object describing limits on key size */ virtual Key_Length_Specification key_spec() const = 0; /** * @return maximum allowed key length */ size_t maximum_keylength() const { return key_spec().maximum_keylength(); } /** * @return minimum allowed key length */ 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); } /** * Set the symmetric key of this object. * @param key the SymmetricKey to be set. */ void set_key(const SymmetricKey& key) { set_key(key.begin(), key.length()); } template void set_key(const std::vector& key) { set_key(key.data(), key.size()); } /** * Set the symmetric key of this object. * @param key the to be set as a byte array. * @param length in bytes of key param */ void set_key(const uint8_t key[], size_t length); /** * @return the algorithm name */ virtual std::string name() const = 0; protected: void verify_key_set(bool cond) const { if(cond == false) throw_key_not_set_error(); } private: void throw_key_not_set_error() const; /** * Run the key schedule * @param key the key * @param length of key */ virtual void key_schedule(const uint8_t key[], size_t length) = 0; }; } #endif