aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/stream
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/stream')
-rw-r--r--src/lib/stream/chacha/chacha.cpp4
-rw-r--r--src/lib/stream/ctr/ctr.cpp7
-rw-r--r--src/lib/stream/info.txt4
-rw-r--r--src/lib/stream/ofb/ofb.cpp7
-rw-r--r--src/lib/stream/rc4/rc4.cpp3
-rw-r--r--src/lib/stream/salsa20/salsa20.cpp4
-rw-r--r--src/lib/stream/stream_cipher.cpp73
-rw-r--r--src/lib/stream/stream_cipher.h24
-rw-r--r--src/lib/stream/stream_utils.h31
9 files changed, 97 insertions, 60 deletions
diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp
index 9841f99a2..0a32c720b 100644
--- a/src/lib/stream/chacha/chacha.cpp
+++ b/src/lib/stream/chacha/chacha.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/chacha.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_STREAM_CIPHER_NOARGS(ChaCha);
-
void ChaCha::chacha(byte output[64], const u32bit input[16])
{
u32bit x00 = input[ 0], x01 = input[ 1], x02 = input[ 2], x03 = input[ 3],
diff --git a/src/lib/stream/ctr/ctr.cpp b/src/lib/stream/ctr/ctr.cpp
index f1cdc7c42..e90bb43a4 100644
--- a/src/lib/stream/ctr/ctr.cpp
+++ b/src/lib/stream/ctr/ctr.cpp
@@ -5,19 +5,16 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/ctr.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(StreamCipher, "CTR-BE", CTR_BE, CTR_BE::make);
-
CTR_BE* CTR_BE::make(const Spec& spec)
{
if(spec.algo_name() == "CTR-BE" && spec.arg_count() == 1)
{
- if(BlockCipher* c = get_block_cipher(spec.arg(0)))
- return new CTR_BE(c);
+ if(auto c = BlockCipher::create(spec.arg(0)))
+ return new CTR_BE(c.release());
}
return nullptr;
}
diff --git a/src/lib/stream/info.txt b/src/lib/stream/info.txt
index 8dc30936d..59b5d577a 100644
--- a/src/lib/stream/info.txt
+++ b/src/lib/stream/info.txt
@@ -3,7 +3,3 @@ define STREAM_CIPHER 20131128
<header:public>
stream_cipher.h
</header:public>
-
-<header:internal>
-stream_utils.h
-</header:internal>
diff --git a/src/lib/stream/ofb/ofb.cpp b/src/lib/stream/ofb/ofb.cpp
index b98f81be3..e8cb463db 100644
--- a/src/lib/stream/ofb/ofb.cpp
+++ b/src/lib/stream/ofb/ofb.cpp
@@ -5,19 +5,16 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/ofb.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(StreamCipher, "OFB", OFB, OFB::make);
-
OFB* OFB::make(const Spec& spec)
{
if(spec.algo_name() == "OFB" && spec.arg_count() == 1)
{
- if(BlockCipher* c = get_block_cipher(spec.arg(0)))
- return new OFB(c);
+ if(auto c = BlockCipher::create(spec.arg(0)))
+ return new OFB(c.release());
}
return nullptr;
}
diff --git a/src/lib/stream/rc4/rc4.cpp b/src/lib/stream/rc4/rc4.cpp
index 3fd0d2276..6146e2818 100644
--- a/src/lib/stream/rc4/rc4.cpp
+++ b/src/lib/stream/rc4/rc4.cpp
@@ -5,13 +5,10 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/rc4.h>
namespace Botan {
-BOTAN_REGISTER_NAMED_T(StreamCipher, "RC4", RC4, RC4::make);
-
RC4* RC4::make(const Spec& spec)
{
if(spec.algo_name() == "RC4")
diff --git a/src/lib/stream/salsa20/salsa20.cpp b/src/lib/stream/salsa20/salsa20.cpp
index daf01dd0a..1d3fe3d28 100644
--- a/src/lib/stream/salsa20/salsa20.cpp
+++ b/src/lib/stream/salsa20/salsa20.cpp
@@ -5,13 +5,11 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/
-#include <botan/internal/stream_utils.h>
#include <botan/salsa20.h>
+#include <botan/loadstor.h>
namespace Botan {
-BOTAN_REGISTER_STREAM_CIPHER_NOARGS(Salsa20);
-
namespace {
#define SALSA20_QUARTER_ROUND(x1, x2, x3, x4) \
diff --git a/src/lib/stream/stream_cipher.cpp b/src/lib/stream/stream_cipher.cpp
new file mode 100644
index 000000000..060e65d86
--- /dev/null
+++ b/src/lib/stream/stream_cipher.cpp
@@ -0,0 +1,73 @@
+/*
+* Stream Ciphers
+* (C) 2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/stream_cipher.h>
+#include <botan/internal/algo_registry.h>
+
+#if defined(BOTAN_HAS_CHACHA)
+ #include <botan/chacha.h>
+#endif
+
+#if defined(BOTAN_HAS_SALSA20)
+ #include <botan/salsa20.h>
+#endif
+
+#if defined(BOTAN_HAS_CTR_BE)
+ #include <botan/ctr.h>
+#endif
+
+#if defined(BOTAN_HAS_OFB)
+ #include <botan/ofb.h>
+#endif
+
+#if defined(BOTAN_HAS_RC4)
+ #include <botan/rc4.h>
+#endif
+
+namespace Botan {
+
+std::unique_ptr<StreamCipher> StreamCipher::create(const std::string& algo_spec,
+ const std::string& provider)
+ {
+ return std::unique_ptr<StreamCipher>(make_a<StreamCipher>(algo_spec, provider));
+ }
+
+std::vector<std::string> StreamCipher::providers(const std::string& algo_spec)
+ {
+ return providers_of<StreamCipher>(StreamCipher::Spec(algo_spec));
+ }
+
+StreamCipher::StreamCipher() {}
+StreamCipher::~StreamCipher() {}
+
+void StreamCipher::set_iv(const byte[], size_t iv_len)
+ {
+ if(!valid_iv_length(iv_len))
+ throw Invalid_IV_Length(name(), iv_len);
+ }
+
+#if defined(BOTAN_HAS_CHACHA)
+BOTAN_REGISTER_T_NOARGS(StreamCipher, ChaCha);
+#endif
+
+#if defined(BOTAN_HAS_SALSA20)
+BOTAN_REGISTER_T_NOARGS(StreamCipher, Salsa20);
+#endif
+
+#if defined(BOTAN_HAS_CTR_BE)
+BOTAN_REGISTER_NAMED_T(StreamCipher, "CTR-BE", CTR_BE, CTR_BE::make);
+#endif
+
+#if defined(BOTAN_HAS_OFB)
+BOTAN_REGISTER_NAMED_T(StreamCipher, "OFB", OFB, OFB::make);
+#endif
+
+#if defined(BOTAN_HAS_RC4)
+BOTAN_REGISTER_NAMED_T(StreamCipher, "RC4", RC4, RC4::make);
+#endif
+
+}
diff --git a/src/lib/stream/stream_cipher.h b/src/lib/stream/stream_cipher.h
index bfdd152a7..8c9b28147 100644
--- a/src/lib/stream/stream_cipher.h
+++ b/src/lib/stream/stream_cipher.h
@@ -20,6 +20,21 @@ namespace Botan {
class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
{
public:
+ typedef SCAN_Name Spec;
+
+ /**
+ * Create an instance based on a name
+ * Will return a null pointer if the algo/provider combination cannot
+ * be found. If provider is empty then best available is chosen.
+ */
+ static std::unique_ptr<StreamCipher> create(const std::string& algo_spec,
+ const std::string& provider = "");
+
+ /**
+ * Returns the list of available providers for this algorithm, empty if not available
+ */
+ static std::vector<std::string> providers(const std::string& algo_spec);
+
/**
* Encrypt or decrypt a message
* @param in the plaintext
@@ -53,11 +68,7 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
* @param iv the initialization vector
* @param iv_len the length of the IV in bytes
*/
- virtual void set_iv(const byte[], size_t iv_len)
- {
- if(iv_len)
- throw Invalid_IV_Length(name(), iv_len);
- }
+ virtual void set_iv(const byte[], size_t iv_len);
/**
* @param iv_len the length of the IV in bytes
@@ -70,7 +81,8 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
*/
virtual StreamCipher* clone() const = 0;
- typedef SCAN_Name Spec;
+ StreamCipher();
+ virtual ~StreamCipher();
};
}
diff --git a/src/lib/stream/stream_utils.h b/src/lib/stream/stream_utils.h
deleted file mode 100644
index 8ba8d4b01..000000000
--- a/src/lib/stream/stream_utils.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-* Stream Cipher Utility Header
-* (C) 2015 Jack Lloyd
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_STREAM_CIPHER_UTILS_H__
-#define BOTAN_STREAM_CIPHER_UTILS_H__
-
-#include <botan/stream_cipher.h>
-#include <botan/internal/algo_registry.h>
-#include <botan/loadstor.h>
-#include <botan/rotate.h>
-#include <botan/internal/xor_buf.h>
-#include <algorithm>
-
-namespace Botan {
-
-#define BOTAN_REGISTER_STREAM_CIPHER(name, maker) BOTAN_REGISTER_T(StreamCipher, name, maker)
-#define BOTAN_REGISTER_STREAM_CIPHER_NOARGS(name) BOTAN_REGISTER_T_NOARGS(StreamCipher, name)
-
-#define BOTAN_REGISTER_STREAM_CIPHER_1LEN(name, def) BOTAN_REGISTER_T_1LEN(StreamCipher, name, def)
-
-#define BOTAN_REGISTER_STREAM_CIPHER_NAMED_NOARGS(type, name) BOTAN_REGISTER_NAMED_T(StreamCipher, name, type, make_new_T<type>)
-#define BOTAN_REGISTER_STREAM_CIPHER_NAMED_1LEN(type, name, def) \
- BOTAN_REGISTER_NAMED_T(StreamCipher, name, type, (make_new_T_1len<type,def>))
-
-}
-
-#endif