aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/speed/speed.cpp7
-rw-r--r--src/cmd/tls_client.cpp4
-rw-r--r--src/lib/algo_base/algo_base.h41
-rw-r--r--src/lib/algo_base/sym_algo.h30
-rw-r--r--src/lib/algo_base/transform.h61
-rw-r--r--src/lib/benchmark/benchmark.cpp2
-rw-r--r--src/lib/filters/transform_filter.cpp9
-rw-r--r--src/lib/hash/hash.h8
-rw-r--r--src/lib/hash/whirlpool/whirlpool.cpp (renamed from src/lib/hash/whirlpool/whrlpool.cpp)0
-rw-r--r--src/lib/kdf/kdf.h9
-rw-r--r--src/lib/modes/aead/ccm/ccm.h2
-rw-r--r--src/lib/modes/aead/eax/eax.h6
-rw-r--r--src/lib/modes/aead/gcm/gcm.h6
-rw-r--r--src/lib/modes/aead/ocb/ocb.h6
-rw-r--r--src/lib/modes/aead/siv/siv.h6
-rw-r--r--src/lib/modes/cbc/cbc.h2
-rw-r--r--src/lib/modes/cfb/cfb.h2
-rw-r--r--src/lib/modes/cipher_mode.h2
-rw-r--r--src/lib/modes/ecb/ecb.h2
-rw-r--r--src/lib/modes/xts/xts.h2
-rw-r--r--src/lib/pbkdf/pbkdf.h12
-rw-r--r--src/lib/utils/types.h6
-rw-r--r--src/tests/test_transform.cpp2
-rw-r--r--src/tests/tests.cpp2
24 files changed, 125 insertions, 104 deletions
diff --git a/src/cmd/speed/speed.cpp b/src/cmd/speed/speed.cpp
index 2e3d2c6fa..9deb9cc63 100644
--- a/src/cmd/speed/speed.cpp
+++ b/src/cmd/speed/speed.cpp
@@ -133,9 +133,6 @@ void time_transform(std::unique_ptr<Transformation> tf,
if(!tf)
return;
- if(tf->maximum_keylength() > 0)
- tf->set_key(rng.random_vec(tf->maximum_keylength()));
-
for(size_t buf_size : { 16, 64, 256, 1024, 8192 })
{
secure_vector<byte> buffer(buf_size);
@@ -158,6 +155,10 @@ void time_transform(const std::string& algo, RandomNumberGenerator& rng)
{
std::unique_ptr<Transformation> tf;
tf.reset(get_aead(algo, ENCRYPTION));
+
+ if(Keyed_Transform* keyed = dynamic_cast<Keyed_Transform*>(tf.get()))
+ keyed->set_key(rng.random_vec(keyed->key_spec().maximum_keylength()));
+
time_transform(std::move(tf), rng);
}
diff --git a/src/cmd/tls_client.cpp b/src/cmd/tls_client.cpp
index 7f201d5a9..b7c4f619f 100644
--- a/src/cmd/tls_client.cpp
+++ b/src/cmd/tls_client.cpp
@@ -36,11 +36,11 @@ int connect_to_host(const std::string& host, u16bit port, const std::string& tra
{
hostent* host_addr = ::gethostbyname(host.c_str());
- if(host_addr == 0)
+ if(!host_addr)
throw std::runtime_error("gethostbyname failed for " + host);
if(host_addr->h_addrtype != AF_INET) // FIXME
- throw std::runtime_error(host + " has IPv6 address");
+ throw std::runtime_error(host + " has IPv6 address, not supported");
int type = (transport == "tcp") ? SOCK_STREAM : SOCK_DGRAM;
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 <botan/build.h>
-#include <string>
-
-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 <botan/algo_base.h>
#include <botan/key_spec.h>
#include <botan/exceptn.h>
#include <botan/symkey.h>
@@ -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<typename Alloc>
+ void set_key(const std::vector<byte, Alloc>& 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<typename Alloc>
- void set_key(const std::vector<byte, Alloc>& 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 <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
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<std::string, double>({
{ "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<Keyed_Transform*>(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<Keyed_Transform*>(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 <botan/buf_comp.h>
-#include <botan/algo_base.h>
#include <string>
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/whrlpool.cpp b/src/lib/hash/whirlpool/whirlpool.cpp
index 5356252b2..5356252b2 100644
--- a/src/lib/hash/whirlpool/whrlpool.cpp
+++ b/src/lib/hash/whirlpool/whirlpool.cpp
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 <botan/algo_base.h>
#include <botan/secmem.h>
#include <botan/types.h>
@@ -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<byte>
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 <botan/algo_base.h>
#include <botan/symkey.h>
#include <chrono>
@@ -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 {
diff --git a/src/tests/test_transform.cpp b/src/tests/test_transform.cpp
index 5d3c4dc3f..7e771d051 100644
--- a/src/tests/test_transform.cpp
+++ b/src/tests/test_transform.cpp
@@ -23,7 +23,7 @@ secure_vector<byte> transform_test(const std::string& algo,
{
std::unique_ptr<Transformation> transform(get_transform(algo));
- transform->set_key(key);
+ //transform->set_key(key);
transform->start_vec(nonce);
secure_vector<byte> out = in;
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index 0d21075d8..ed20aef3e 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -269,7 +269,7 @@ int main(int argc, char* argv[])
if(tests.empty())
{
- std::cout << "No tests selected by target " << target << "\n";
+ std::cout << "No tests selected by target '" << target << "'\n";
return 1;
}