From b96ad4c05c0a8f835b54ef4e2cff849c749409b0 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 18 Jan 2014 18:17:08 +0000 Subject: 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. --- src/lib/algo_base/algo_base.h | 41 ---------- src/lib/algo_base/sym_algo.h | 30 +++---- src/lib/algo_base/transform.h | 61 +++++++++++++-- src/lib/benchmark/benchmark.cpp | 2 +- src/lib/filters/transform_filter.cpp | 9 ++- src/lib/hash/hash.h | 8 +- src/lib/hash/whirlpool/whirlpool.cpp | 146 +++++++++++++++++++++++++++++++++++ src/lib/hash/whirlpool/whrlpool.cpp | 146 ----------------------------------- src/lib/kdf/kdf.h | 9 ++- src/lib/modes/aead/ccm/ccm.h | 2 +- src/lib/modes/aead/eax/eax.h | 6 +- src/lib/modes/aead/gcm/gcm.h | 6 +- src/lib/modes/aead/ocb/ocb.h | 6 +- src/lib/modes/aead/siv/siv.h | 6 +- src/lib/modes/cbc/cbc.h | 2 +- src/lib/modes/cfb/cfb.h | 2 +- src/lib/modes/cipher_mode.h | 2 +- src/lib/modes/ecb/ecb.h | 2 +- src/lib/modes/xts/xts.h | 2 +- src/lib/pbkdf/pbkdf.h | 12 +-- src/lib/utils/types.h | 6 ++ 21 files changed, 263 insertions(+), 243 deletions(-) delete mode 100644 src/lib/algo_base/algo_base.h create mode 100644 src/lib/hash/whirlpool/whirlpool.cpp delete mode 100644 src/lib/hash/whirlpool/whrlpool.cpp (limited to 'src/lib') diff --git a/src/lib/algo_base/algo_base.h b/src/lib/algo_base/algo_base.h deleted file mode 100644 index f757a9a83..000000000 --- a/src/lib/algo_base/algo_base.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Algorithm Base Class -* (C) 2010 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_ALGO_BASE_CLASS_H__ -#define BOTAN_ALGO_BASE_CLASS_H__ - -#include -#include - -namespace Botan { - -/** -* This class represents an algorithm of some kind -*/ -class BOTAN_DLL Algorithm - { - public: - /** - * Zeroize internal state - */ - virtual void clear() = 0; - - /** - * @return name of this algorithm - */ - virtual std::string name() const = 0; - - Algorithm() {} - Algorithm(const Algorithm&) = delete; - Algorithm& operator=(const Algorithm&) = delete; - - virtual ~Algorithm() {} - }; - -} - -#endif diff --git a/src/lib/algo_base/sym_algo.h b/src/lib/algo_base/sym_algo.h index c937d08ff..0b3b21f5e 100644 --- a/src/lib/algo_base/sym_algo.h +++ b/src/lib/algo_base/sym_algo.h @@ -8,7 +8,6 @@ #ifndef BOTAN_SYMMETRIC_ALGORITHM_H__ #define BOTAN_SYMMETRIC_ALGORITHM_H__ -#include #include #include #include @@ -19,9 +18,13 @@ namespace Botan { /** * This class represents a symmetric algorithm object. */ -class BOTAN_DLL SymmetricAlgorithm : public Algorithm +class BOTAN_DLL SymmetricAlgorithm { public: + virtual ~SymmetricAlgorithm() {} + + virtual void clear() = 0; + /** * @return object describing limits on key size */ @@ -58,7 +61,15 @@ class BOTAN_DLL SymmetricAlgorithm : public Algorithm * @param key the SymmetricKey to be set. */ void set_key(const SymmetricKey& key) - { set_key(key.begin(), key.length()); } + { + set_key(key.begin(), key.length()); + } + + template + void set_key(const std::vector& key) + { + set_key(&key[0], key.size()); + } /** * Set the symmetric key of this object. @@ -72,11 +83,8 @@ class BOTAN_DLL SymmetricAlgorithm : public Algorithm key_schedule(key, length); } - template - void set_key(const std::vector& v) - { - set_key(&v[0], v.size()); - } + virtual std::string name() const = 0; + private: /** * Run the key schedule @@ -86,12 +94,6 @@ class BOTAN_DLL SymmetricAlgorithm : public Algorithm virtual void key_schedule(const byte key[], size_t length) = 0; }; -/** -* The two possible directions for cipher filters, determining whether they -* actually perform encryption or decryption. -*/ -enum Cipher_Dir { ENCRYPTION, DECRYPTION }; - } #endif 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 +#include +#include +#include +#include #include +#include 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 + void set_key(const std::vector& 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 diff --git a/src/lib/benchmark/benchmark.cpp b/src/lib/benchmark/benchmark.cpp index 396670168..df15ffa6f 100644 --- a/src/lib/benchmark/benchmark.cpp +++ b/src/lib/benchmark/benchmark.cpp @@ -103,7 +103,7 @@ time_algorithm_ops(const std::string& name, if(enc && dec) { - const SymmetricKey key(rng, enc->maximum_keylength()); + const SymmetricKey key(rng, enc->key_spec().maximum_keylength()); return std::map({ { "key schedule", time_op(runtime / 4, [&]() { enc->set_key(key); dec->set_key(key); }) / 2 }, diff --git a/src/lib/filters/transform_filter.cpp b/src/lib/filters/transform_filter.cpp index 2f25aa2c5..5465b9d9b 100644 --- a/src/lib/filters/transform_filter.cpp +++ b/src/lib/filters/transform_filter.cpp @@ -46,12 +46,17 @@ void Transformation_Filter::set_iv(const InitializationVector& iv) void Transformation_Filter::set_key(const SymmetricKey& key) { - m_transform->set_key(key); + if(Keyed_Transform* keyed = dynamic_cast(m_transform.get())) + keyed->set_key(key); + else if(key.length() != 0) + throw std::runtime_error("Transformation " + name() + " does not accept keys"); } Key_Length_Specification Transformation_Filter::key_spec() const { - return m_transform->key_spec(); + if(Keyed_Transform* keyed = dynamic_cast(m_transform.get())) + return keyed->key_spec(); + return Key_Length_Specification(0); } bool Transformation_Filter::valid_iv_length(size_t length) const diff --git a/src/lib/hash/hash.h b/src/lib/hash/hash.h index 1e4b045e2..58a810c4b 100644 --- a/src/lib/hash/hash.h +++ b/src/lib/hash/hash.h @@ -9,7 +9,6 @@ #define BOTAN_HASH_FUNCTION_BASE_CLASS_H__ #include -#include #include namespace Botan { @@ -17,8 +16,7 @@ namespace Botan { /** * This class represents hash function (message digest) objects */ -class BOTAN_DLL HashFunction : public Buffered_Computation, - public Algorithm +class BOTAN_DLL HashFunction : public Buffered_Computation { public: /** @@ -26,6 +24,10 @@ class BOTAN_DLL HashFunction : public Buffered_Computation, */ virtual HashFunction* clone() const = 0; + virtual void clear() = 0; + + virtual std::string name() const = 0; + /** * @return hash block size as defined for this algorithm */ diff --git a/src/lib/hash/whirlpool/whirlpool.cpp b/src/lib/hash/whirlpool/whirlpool.cpp new file mode 100644 index 000000000..5356252b2 --- /dev/null +++ b/src/lib/hash/whirlpool/whirlpool.cpp @@ -0,0 +1,146 @@ +/* +* Whirlpool +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include +#include + +namespace Botan { + +/* +* Whirlpool Compression Function +*/ +void Whirlpool::compress_n(const byte in[], size_t blocks) + { + static const u64bit RC[10] = { + 0x1823C6E887B8014F, 0x36A6D2F5796F9152, + 0x60BC9B8EA30C7B35, 0x1DE0D7C22E4BFE57, + 0x157737E59FF04ADA, 0x58C9290AB1A06B85, + 0xBD5D10F4CB3E0567, 0xE427418BA77D95D8, + 0xFBEE7C66DD17479E, 0xCA2DBF07AD5A8333 + }; + + for(size_t i = 0; i != blocks; ++i) + { + load_be(&M[0], in, M.size()); + + u64bit K0, K1, K2, K3, K4, K5, K6, K7; + K0 = digest[0]; K1 = digest[1]; K2 = digest[2]; K3 = digest[3]; + K4 = digest[4]; K5 = digest[5]; K6 = digest[6]; K7 = digest[7]; + + u64bit B0, B1, B2, B3, B4, B5, B6, B7; + B0 = K0 ^ M[0]; B1 = K1 ^ M[1]; B2 = K2 ^ M[2]; B3 = K3 ^ M[3]; + B4 = K4 ^ M[4]; B5 = K5 ^ M[5]; B6 = K6 ^ M[6]; B7 = K7 ^ M[7]; + + for(size_t j = 0; j != 10; ++j) + { + u64bit T0, T1, T2, T3, T4, T5, T6, T7; + T0 = C0[get_byte(0, K0)] ^ C1[get_byte(1, K7)] ^ + C2[get_byte(2, K6)] ^ C3[get_byte(3, K5)] ^ + C4[get_byte(4, K4)] ^ C5[get_byte(5, K3)] ^ + C6[get_byte(6, K2)] ^ C7[get_byte(7, K1)] ^ RC[j]; + T1 = C0[get_byte(0, K1)] ^ C1[get_byte(1, K0)] ^ + C2[get_byte(2, K7)] ^ C3[get_byte(3, K6)] ^ + C4[get_byte(4, K5)] ^ C5[get_byte(5, K4)] ^ + C6[get_byte(6, K3)] ^ C7[get_byte(7, K2)]; + T2 = C0[get_byte(0, K2)] ^ C1[get_byte(1, K1)] ^ + C2[get_byte(2, K0)] ^ C3[get_byte(3, K7)] ^ + C4[get_byte(4, K6)] ^ C5[get_byte(5, K5)] ^ + C6[get_byte(6, K4)] ^ C7[get_byte(7, K3)]; + T3 = C0[get_byte(0, K3)] ^ C1[get_byte(1, K2)] ^ + C2[get_byte(2, K1)] ^ C3[get_byte(3, K0)] ^ + C4[get_byte(4, K7)] ^ C5[get_byte(5, K6)] ^ + C6[get_byte(6, K5)] ^ C7[get_byte(7, K4)]; + T4 = C0[get_byte(0, K4)] ^ C1[get_byte(1, K3)] ^ + C2[get_byte(2, K2)] ^ C3[get_byte(3, K1)] ^ + C4[get_byte(4, K0)] ^ C5[get_byte(5, K7)] ^ + C6[get_byte(6, K6)] ^ C7[get_byte(7, K5)]; + T5 = C0[get_byte(0, K5)] ^ C1[get_byte(1, K4)] ^ + C2[get_byte(2, K3)] ^ C3[get_byte(3, K2)] ^ + C4[get_byte(4, K1)] ^ C5[get_byte(5, K0)] ^ + C6[get_byte(6, K7)] ^ C7[get_byte(7, K6)]; + T6 = C0[get_byte(0, K6)] ^ C1[get_byte(1, K5)] ^ + C2[get_byte(2, K4)] ^ C3[get_byte(3, K3)] ^ + C4[get_byte(4, K2)] ^ C5[get_byte(5, K1)] ^ + C6[get_byte(6, K0)] ^ C7[get_byte(7, K7)]; + T7 = C0[get_byte(0, K7)] ^ C1[get_byte(1, K6)] ^ + C2[get_byte(2, K5)] ^ C3[get_byte(3, K4)] ^ + C4[get_byte(4, K3)] ^ C5[get_byte(5, K2)] ^ + C6[get_byte(6, K1)] ^ C7[get_byte(7, K0)]; + + K0 = T0; K1 = T1; K2 = T2; K3 = T3; + K4 = T4; K5 = T5; K6 = T6; K7 = T7; + + T0 = C0[get_byte(0, B0)] ^ C1[get_byte(1, B7)] ^ + C2[get_byte(2, B6)] ^ C3[get_byte(3, B5)] ^ + C4[get_byte(4, B4)] ^ C5[get_byte(5, B3)] ^ + C6[get_byte(6, B2)] ^ C7[get_byte(7, B1)] ^ K0; + T1 = C0[get_byte(0, B1)] ^ C1[get_byte(1, B0)] ^ + C2[get_byte(2, B7)] ^ C3[get_byte(3, B6)] ^ + C4[get_byte(4, B5)] ^ C5[get_byte(5, B4)] ^ + C6[get_byte(6, B3)] ^ C7[get_byte(7, B2)] ^ K1; + T2 = C0[get_byte(0, B2)] ^ C1[get_byte(1, B1)] ^ + C2[get_byte(2, B0)] ^ C3[get_byte(3, B7)] ^ + C4[get_byte(4, B6)] ^ C5[get_byte(5, B5)] ^ + C6[get_byte(6, B4)] ^ C7[get_byte(7, B3)] ^ K2; + T3 = C0[get_byte(0, B3)] ^ C1[get_byte(1, B2)] ^ + C2[get_byte(2, B1)] ^ C3[get_byte(3, B0)] ^ + C4[get_byte(4, B7)] ^ C5[get_byte(5, B6)] ^ + C6[get_byte(6, B5)] ^ C7[get_byte(7, B4)] ^ K3; + T4 = C0[get_byte(0, B4)] ^ C1[get_byte(1, B3)] ^ + C2[get_byte(2, B2)] ^ C3[get_byte(3, B1)] ^ + C4[get_byte(4, B0)] ^ C5[get_byte(5, B7)] ^ + C6[get_byte(6, B6)] ^ C7[get_byte(7, B5)] ^ K4; + T5 = C0[get_byte(0, B5)] ^ C1[get_byte(1, B4)] ^ + C2[get_byte(2, B3)] ^ C3[get_byte(3, B2)] ^ + C4[get_byte(4, B1)] ^ C5[get_byte(5, B0)] ^ + C6[get_byte(6, B7)] ^ C7[get_byte(7, B6)] ^ K5; + T6 = C0[get_byte(0, B6)] ^ C1[get_byte(1, B5)] ^ + C2[get_byte(2, B4)] ^ C3[get_byte(3, B3)] ^ + C4[get_byte(4, B2)] ^ C5[get_byte(5, B1)] ^ + C6[get_byte(6, B0)] ^ C7[get_byte(7, B7)] ^ K6; + T7 = C0[get_byte(0, B7)] ^ C1[get_byte(1, B6)] ^ + C2[get_byte(2, B5)] ^ C3[get_byte(3, B4)] ^ + C4[get_byte(4, B3)] ^ C5[get_byte(5, B2)] ^ + C6[get_byte(6, B1)] ^ C7[get_byte(7, B0)] ^ K7; + + B0 = T0; B1 = T1; B2 = T2; B3 = T3; + B4 = T4; B5 = T5; B6 = T6; B7 = T7; + } + + digest[0] ^= B0 ^ M[0]; + digest[1] ^= B1 ^ M[1]; + digest[2] ^= B2 ^ M[2]; + digest[3] ^= B3 ^ M[3]; + digest[4] ^= B4 ^ M[4]; + digest[5] ^= B5 ^ M[5]; + digest[6] ^= B6 ^ M[6]; + digest[7] ^= B7 ^ M[7]; + + in += hash_block_size(); + } + } + +/* +* Copy out the digest +*/ +void Whirlpool::copy_out(byte output[]) + { + for(size_t i = 0; i != output_length(); i += 8) + store_be(digest[i/8], output + i); + } + +/* +* Clear memory of sensitive data +*/ +void Whirlpool::clear() + { + MDx_HashFunction::clear(); + zeroise(M); + zeroise(digest); + } + +} diff --git a/src/lib/hash/whirlpool/whrlpool.cpp b/src/lib/hash/whirlpool/whrlpool.cpp deleted file mode 100644 index 5356252b2..000000000 --- a/src/lib/hash/whirlpool/whrlpool.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* -* Whirlpool -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -namespace Botan { - -/* -* Whirlpool Compression Function -*/ -void Whirlpool::compress_n(const byte in[], size_t blocks) - { - static const u64bit RC[10] = { - 0x1823C6E887B8014F, 0x36A6D2F5796F9152, - 0x60BC9B8EA30C7B35, 0x1DE0D7C22E4BFE57, - 0x157737E59FF04ADA, 0x58C9290AB1A06B85, - 0xBD5D10F4CB3E0567, 0xE427418BA77D95D8, - 0xFBEE7C66DD17479E, 0xCA2DBF07AD5A8333 - }; - - for(size_t i = 0; i != blocks; ++i) - { - load_be(&M[0], in, M.size()); - - u64bit K0, K1, K2, K3, K4, K5, K6, K7; - K0 = digest[0]; K1 = digest[1]; K2 = digest[2]; K3 = digest[3]; - K4 = digest[4]; K5 = digest[5]; K6 = digest[6]; K7 = digest[7]; - - u64bit B0, B1, B2, B3, B4, B5, B6, B7; - B0 = K0 ^ M[0]; B1 = K1 ^ M[1]; B2 = K2 ^ M[2]; B3 = K3 ^ M[3]; - B4 = K4 ^ M[4]; B5 = K5 ^ M[5]; B6 = K6 ^ M[6]; B7 = K7 ^ M[7]; - - for(size_t j = 0; j != 10; ++j) - { - u64bit T0, T1, T2, T3, T4, T5, T6, T7; - T0 = C0[get_byte(0, K0)] ^ C1[get_byte(1, K7)] ^ - C2[get_byte(2, K6)] ^ C3[get_byte(3, K5)] ^ - C4[get_byte(4, K4)] ^ C5[get_byte(5, K3)] ^ - C6[get_byte(6, K2)] ^ C7[get_byte(7, K1)] ^ RC[j]; - T1 = C0[get_byte(0, K1)] ^ C1[get_byte(1, K0)] ^ - C2[get_byte(2, K7)] ^ C3[get_byte(3, K6)] ^ - C4[get_byte(4, K5)] ^ C5[get_byte(5, K4)] ^ - C6[get_byte(6, K3)] ^ C7[get_byte(7, K2)]; - T2 = C0[get_byte(0, K2)] ^ C1[get_byte(1, K1)] ^ - C2[get_byte(2, K0)] ^ C3[get_byte(3, K7)] ^ - C4[get_byte(4, K6)] ^ C5[get_byte(5, K5)] ^ - C6[get_byte(6, K4)] ^ C7[get_byte(7, K3)]; - T3 = C0[get_byte(0, K3)] ^ C1[get_byte(1, K2)] ^ - C2[get_byte(2, K1)] ^ C3[get_byte(3, K0)] ^ - C4[get_byte(4, K7)] ^ C5[get_byte(5, K6)] ^ - C6[get_byte(6, K5)] ^ C7[get_byte(7, K4)]; - T4 = C0[get_byte(0, K4)] ^ C1[get_byte(1, K3)] ^ - C2[get_byte(2, K2)] ^ C3[get_byte(3, K1)] ^ - C4[get_byte(4, K0)] ^ C5[get_byte(5, K7)] ^ - C6[get_byte(6, K6)] ^ C7[get_byte(7, K5)]; - T5 = C0[get_byte(0, K5)] ^ C1[get_byte(1, K4)] ^ - C2[get_byte(2, K3)] ^ C3[get_byte(3, K2)] ^ - C4[get_byte(4, K1)] ^ C5[get_byte(5, K0)] ^ - C6[get_byte(6, K7)] ^ C7[get_byte(7, K6)]; - T6 = C0[get_byte(0, K6)] ^ C1[get_byte(1, K5)] ^ - C2[get_byte(2, K4)] ^ C3[get_byte(3, K3)] ^ - C4[get_byte(4, K2)] ^ C5[get_byte(5, K1)] ^ - C6[get_byte(6, K0)] ^ C7[get_byte(7, K7)]; - T7 = C0[get_byte(0, K7)] ^ C1[get_byte(1, K6)] ^ - C2[get_byte(2, K5)] ^ C3[get_byte(3, K4)] ^ - C4[get_byte(4, K3)] ^ C5[get_byte(5, K2)] ^ - C6[get_byte(6, K1)] ^ C7[get_byte(7, K0)]; - - K0 = T0; K1 = T1; K2 = T2; K3 = T3; - K4 = T4; K5 = T5; K6 = T6; K7 = T7; - - T0 = C0[get_byte(0, B0)] ^ C1[get_byte(1, B7)] ^ - C2[get_byte(2, B6)] ^ C3[get_byte(3, B5)] ^ - C4[get_byte(4, B4)] ^ C5[get_byte(5, B3)] ^ - C6[get_byte(6, B2)] ^ C7[get_byte(7, B1)] ^ K0; - T1 = C0[get_byte(0, B1)] ^ C1[get_byte(1, B0)] ^ - C2[get_byte(2, B7)] ^ C3[get_byte(3, B6)] ^ - C4[get_byte(4, B5)] ^ C5[get_byte(5, B4)] ^ - C6[get_byte(6, B3)] ^ C7[get_byte(7, B2)] ^ K1; - T2 = C0[get_byte(0, B2)] ^ C1[get_byte(1, B1)] ^ - C2[get_byte(2, B0)] ^ C3[get_byte(3, B7)] ^ - C4[get_byte(4, B6)] ^ C5[get_byte(5, B5)] ^ - C6[get_byte(6, B4)] ^ C7[get_byte(7, B3)] ^ K2; - T3 = C0[get_byte(0, B3)] ^ C1[get_byte(1, B2)] ^ - C2[get_byte(2, B1)] ^ C3[get_byte(3, B0)] ^ - C4[get_byte(4, B7)] ^ C5[get_byte(5, B6)] ^ - C6[get_byte(6, B5)] ^ C7[get_byte(7, B4)] ^ K3; - T4 = C0[get_byte(0, B4)] ^ C1[get_byte(1, B3)] ^ - C2[get_byte(2, B2)] ^ C3[get_byte(3, B1)] ^ - C4[get_byte(4, B0)] ^ C5[get_byte(5, B7)] ^ - C6[get_byte(6, B6)] ^ C7[get_byte(7, B5)] ^ K4; - T5 = C0[get_byte(0, B5)] ^ C1[get_byte(1, B4)] ^ - C2[get_byte(2, B3)] ^ C3[get_byte(3, B2)] ^ - C4[get_byte(4, B1)] ^ C5[get_byte(5, B0)] ^ - C6[get_byte(6, B7)] ^ C7[get_byte(7, B6)] ^ K5; - T6 = C0[get_byte(0, B6)] ^ C1[get_byte(1, B5)] ^ - C2[get_byte(2, B4)] ^ C3[get_byte(3, B3)] ^ - C4[get_byte(4, B2)] ^ C5[get_byte(5, B1)] ^ - C6[get_byte(6, B0)] ^ C7[get_byte(7, B7)] ^ K6; - T7 = C0[get_byte(0, B7)] ^ C1[get_byte(1, B6)] ^ - C2[get_byte(2, B5)] ^ C3[get_byte(3, B4)] ^ - C4[get_byte(4, B3)] ^ C5[get_byte(5, B2)] ^ - C6[get_byte(6, B1)] ^ C7[get_byte(7, B0)] ^ K7; - - B0 = T0; B1 = T1; B2 = T2; B3 = T3; - B4 = T4; B5 = T5; B6 = T6; B7 = T7; - } - - digest[0] ^= B0 ^ M[0]; - digest[1] ^= B1 ^ M[1]; - digest[2] ^= B2 ^ M[2]; - digest[3] ^= B3 ^ M[3]; - digest[4] ^= B4 ^ M[4]; - digest[5] ^= B5 ^ M[5]; - digest[6] ^= B6 ^ M[6]; - digest[7] ^= B7 ^ M[7]; - - in += hash_block_size(); - } - } - -/* -* Copy out the digest -*/ -void Whirlpool::copy_out(byte output[]) - { - for(size_t i = 0; i != output_length(); i += 8) - store_be(digest[i/8], output + i); - } - -/* -* Clear memory of sensitive data -*/ -void Whirlpool::clear() - { - MDx_HashFunction::clear(); - zeroise(M); - zeroise(digest); - } - -} diff --git a/src/lib/kdf/kdf.h b/src/lib/kdf/kdf.h index b0f6e1dc3..39e7253f9 100644 --- a/src/lib/kdf/kdf.h +++ b/src/lib/kdf/kdf.h @@ -8,7 +8,6 @@ #ifndef BOTAN_KDF_BASE_H__ #define BOTAN_KDF_BASE_H__ -#include #include #include @@ -17,9 +16,13 @@ namespace Botan { /** * Key Derivation Function */ -class BOTAN_DLL KDF : public Algorithm +class BOTAN_DLL KDF { public: + virtual ~KDF() {} + + virtual std::string name() const = 0; + /** * Derive a key * @param key_len the desired output length in bytes @@ -102,8 +105,6 @@ class BOTAN_DLL KDF : public Algorithm return derive(key_len, secret, secret_len, salt, salt_len); } - void clear() {} - virtual KDF* clone() const = 0; private: virtual secure_vector diff --git a/src/lib/modes/aead/ccm/ccm.h b/src/lib/modes/aead/ccm/ccm.h index 87dd5805c..a57ef34c1 100644 --- a/src/lib/modes/aead/ccm/ccm.h +++ b/src/lib/modes/aead/ccm/ccm.h @@ -39,7 +39,7 @@ class BOTAN_DLL CCM_Mode : public AEAD_Mode size_t default_nonce_length() const override; - void clear(); + void clear() override; size_t tag_size() const { return m_tag_size; } diff --git a/src/lib/modes/aead/eax/eax.h b/src/lib/modes/aead/eax/eax.h index 224fb5298..89dfff86f 100644 --- a/src/lib/modes/aead/eax/eax.h +++ b/src/lib/modes/aead/eax/eax.h @@ -28,16 +28,16 @@ class BOTAN_DLL EAX_Mode : public AEAD_Mode std::string name() const override; - size_t update_granularity() const; + size_t update_granularity() const override; Key_Length_Specification key_spec() const override; // EAX supports arbitrary nonce lengths bool valid_nonce_length(size_t) const override { return true; } - size_t tag_size() const { return m_tag_size; } + size_t tag_size() const override { return m_tag_size; } - void clear(); + void clear() override; protected: void key_schedule(const byte key[], size_t length) override; diff --git a/src/lib/modes/aead/gcm/gcm.h b/src/lib/modes/aead/gcm/gcm.h index 12d66a3d1..3feaece02 100644 --- a/src/lib/modes/aead/gcm/gcm.h +++ b/src/lib/modes/aead/gcm/gcm.h @@ -36,9 +36,9 @@ class BOTAN_DLL GCM_Mode : public AEAD_Mode // GCM supports arbitrary nonce lengths bool valid_nonce_length(size_t) const override { return true; } - size_t tag_size() const { return m_tag_size; } + size_t tag_size() const override { return m_tag_size; } - void clear(); + void clear() override; protected: void key_schedule(const byte key[], size_t length) override; @@ -124,7 +124,7 @@ class BOTAN_DLL GHASH : public SymmetricAlgorithm Key_Length_Specification key_spec() const { return Key_Length_Specification(16); } - void clear(); + void clear() override; std::string name() const { return "GHASH"; } private: diff --git a/src/lib/modes/aead/ocb/ocb.h b/src/lib/modes/aead/ocb/ocb.h index e7d042de3..05bc859e0 100644 --- a/src/lib/modes/aead/ocb/ocb.h +++ b/src/lib/modes/aead/ocb/ocb.h @@ -35,15 +35,15 @@ class BOTAN_DLL OCB_Mode : public AEAD_Mode std::string name() const override; - size_t update_granularity() const; + size_t update_granularity() const override; Key_Length_Specification key_spec() const override; bool valid_nonce_length(size_t) const override; - size_t tag_size() const { return m_tag_size; } + size_t tag_size() const override { return m_tag_size; } - void clear(); + void clear() override; ~OCB_Mode(); protected: diff --git a/src/lib/modes/aead/siv/siv.h b/src/lib/modes/aead/siv/siv.h index 31df4d049..5ab85e133 100644 --- a/src/lib/modes/aead/siv/siv.h +++ b/src/lib/modes/aead/siv/siv.h @@ -35,15 +35,15 @@ class BOTAN_DLL SIV_Mode : public AEAD_Mode std::string name() const override; - size_t update_granularity() const; + size_t update_granularity() const override; Key_Length_Specification key_spec() const override; bool valid_nonce_length(size_t) const override; - void clear(); + void clear() override; - size_t tag_size() const { return 16; } + size_t tag_size() const override { return 16; } protected: SIV_Mode(BlockCipher* cipher); diff --git a/src/lib/modes/cbc/cbc.h b/src/lib/modes/cbc/cbc.h index 0a10f3661..707b4a446 100644 --- a/src/lib/modes/cbc/cbc.h +++ b/src/lib/modes/cbc/cbc.h @@ -33,7 +33,7 @@ class BOTAN_DLL CBC_Mode : public Cipher_Mode bool valid_nonce_length(size_t n) const override; - void clear(); + void clear() override; protected: CBC_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding); diff --git a/src/lib/modes/cfb/cfb.h b/src/lib/modes/cfb/cfb.h index 48be0a2d9..9145e5667 100644 --- a/src/lib/modes/cfb/cfb.h +++ b/src/lib/modes/cfb/cfb.h @@ -37,7 +37,7 @@ class BOTAN_DLL CFB_Mode : public Cipher_Mode bool valid_nonce_length(size_t n) const override; - void clear(); + void clear() override; protected: CFB_Mode(BlockCipher* cipher, size_t feedback_bits); diff --git a/src/lib/modes/cipher_mode.h b/src/lib/modes/cipher_mode.h index 91e2af5a9..ce5427ad9 100644 --- a/src/lib/modes/cipher_mode.h +++ b/src/lib/modes/cipher_mode.h @@ -15,7 +15,7 @@ namespace Botan { /** * Interface for cipher modes */ -class BOTAN_DLL Cipher_Mode : public Transformation +class BOTAN_DLL Cipher_Mode : public Keyed_Transform { public: /** diff --git a/src/lib/modes/ecb/ecb.h b/src/lib/modes/ecb/ecb.h index 441eafbc1..b1561bf4f 100644 --- a/src/lib/modes/ecb/ecb.h +++ b/src/lib/modes/ecb/ecb.h @@ -33,7 +33,7 @@ class BOTAN_DLL ECB_Mode : public Cipher_Mode bool valid_nonce_length(size_t n) const override; - void clear(); + void clear() override; protected: ECB_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding); diff --git a/src/lib/modes/xts/xts.h b/src/lib/modes/xts/xts.h index 21bc495e1..3a83b3864 100644 --- a/src/lib/modes/xts/xts.h +++ b/src/lib/modes/xts/xts.h @@ -34,7 +34,7 @@ class BOTAN_DLL XTS_Mode : public Cipher_Mode bool valid_nonce_length(size_t n) const override; - void clear(); + void clear() override; protected: XTS_Mode(BlockCipher* cipher); diff --git a/src/lib/pbkdf/pbkdf.h b/src/lib/pbkdf/pbkdf.h index 65ad8e83a..2e27a1da8 100644 --- a/src/lib/pbkdf/pbkdf.h +++ b/src/lib/pbkdf/pbkdf.h @@ -8,7 +8,6 @@ #ifndef BOTAN_PBKDF_H__ #define BOTAN_PBKDF_H__ -#include #include #include @@ -19,16 +18,18 @@ namespace Botan { * implementations. Converts a password into a key using a salt * and iterated hashing to make brute force attacks harder. */ -class BOTAN_DLL PBKDF : public Algorithm +class BOTAN_DLL PBKDF { public: + virtual ~PBKDF() {} + /** * @return new instance of this same algorithm */ virtual PBKDF* clone() const = 0; - void clear() {} + virtual std::string name() const = 0; /** * Derive a key from a passphrase @@ -114,11 +115,6 @@ class BOTAN_DLL PBKDF : public Algorithm std::chrono::milliseconds msec) const = 0; }; -/** -* For compatability with 1.8 -*/ -typedef PBKDF S2K; - } #endif diff --git a/src/lib/utils/types.h b/src/lib/utils/types.h index f4a2eeacd..1fd54e060 100644 --- a/src/lib/utils/types.h +++ b/src/lib/utils/types.h @@ -36,6 +36,12 @@ typedef std::int32_t s32bit; */ static const size_t DEFAULT_BUFFERSIZE = BOTAN_DEFAULT_BUFFER_SIZE; +/** +* The two possible directions for cipher filters, determining whether they +* actually perform encryption or decryption. +*/ +enum Cipher_Dir { ENCRYPTION, DECRYPTION }; + } namespace Botan_types { -- cgit v1.2.3