diff options
Diffstat (limited to 'src/lib/stream')
-rw-r--r-- | src/lib/stream/chacha/chacha.cpp | 6 | ||||
-rw-r--r-- | src/lib/stream/ctr/ctr.cpp | 14 | ||||
-rw-r--r-- | src/lib/stream/ctr/ctr.h | 2 | ||||
-rw-r--r-- | src/lib/stream/info.txt | 8 | ||||
-rw-r--r-- | src/lib/stream/ofb/ofb.cpp | 14 | ||||
-rw-r--r-- | src/lib/stream/ofb/ofb.h | 2 | ||||
-rw-r--r-- | src/lib/stream/rc4/rc4.cpp | 13 | ||||
-rw-r--r-- | src/lib/stream/rc4/rc4.h | 2 | ||||
-rw-r--r-- | src/lib/stream/salsa20/salsa20.cpp | 6 | ||||
-rw-r--r-- | src/lib/stream/stream_cipher.h | 3 |
10 files changed, 61 insertions, 9 deletions
diff --git a/src/lib/stream/chacha/chacha.cpp b/src/lib/stream/chacha/chacha.cpp index 7aac66b3d..d0c534083 100644 --- a/src/lib/stream/chacha/chacha.cpp +++ b/src/lib/stream/chacha/chacha.cpp @@ -5,13 +5,13 @@ * 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> -#include <botan/rotate.h> -#include <botan/internal/xor_buf.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 27118ee64..b6057a2a8 100644 --- a/src/lib/stream/ctr/ctr.cpp +++ b/src/lib/stream/ctr/ctr.cpp @@ -5,11 +5,23 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/stream_utils.h> #include <botan/ctr.h> -#include <botan/internal/xor_buf.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 = Algo_Registry<BlockCipher>::global_registry().make(spec.arg(0))) + return new CTR_BE(c); + } + return nullptr; + } + CTR_BE::CTR_BE(BlockCipher* ciph) : m_cipher(ciph), m_counter(256 * m_cipher->block_size()), diff --git a/src/lib/stream/ctr/ctr.h b/src/lib/stream/ctr/ctr.h index 52b6b66fa..1515b0e82 100644 --- a/src/lib/stream/ctr/ctr.h +++ b/src/lib/stream/ctr/ctr.h @@ -38,6 +38,8 @@ class BOTAN_DLL CTR_BE : public StreamCipher void clear(); + static CTR_BE* make(const Spec& spec); + /** * @param cipher the underlying block cipher to use */ diff --git a/src/lib/stream/info.txt b/src/lib/stream/info.txt index faa2db215..15f0e91e5 100644 --- a/src/lib/stream/info.txt +++ b/src/lib/stream/info.txt @@ -3,3 +3,11 @@ define STREAM_CIPHER 20131128 <requires> algo_base </requires> + +<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 986e6bf71..37429cd38 100644 --- a/src/lib/stream/ofb/ofb.cpp +++ b/src/lib/stream/ofb/ofb.cpp @@ -5,11 +5,23 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/stream_utils.h> #include <botan/ofb.h> -#include <botan/internal/xor_buf.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 = Algo_Registry<BlockCipher>::global_registry().make(spec.arg(0))) + return new OFB(c); + } + return nullptr; + } + OFB::OFB(BlockCipher* cipher) : m_cipher(cipher), m_buffer(m_cipher->block_size()), diff --git a/src/lib/stream/ofb/ofb.h b/src/lib/stream/ofb/ofb.h index 925e7a773..09e11644a 100644 --- a/src/lib/stream/ofb/ofb.h +++ b/src/lib/stream/ofb/ofb.h @@ -38,6 +38,8 @@ class BOTAN_DLL OFB : public StreamCipher void clear(); + static OFB* make(const Spec& spec); + /** * @param cipher the underlying block cipher to use */ diff --git a/src/lib/stream/rc4/rc4.cpp b/src/lib/stream/rc4/rc4.cpp index 1a5ad80e9..dcf4af241 100644 --- a/src/lib/stream/rc4/rc4.cpp +++ b/src/lib/stream/rc4/rc4.cpp @@ -5,12 +5,23 @@ * Botan is released under the Simplified BSD License (see license.txt) */ +#include <botan/internal/stream_utils.h> #include <botan/rc4.h> -#include <botan/internal/xor_buf.h> #include <botan/internal/rounding.h> namespace Botan { +BOTAN_REGISTER_NAMED_T(StreamCipher, "RC4", RC4, RC4::make); + +RC4* RC4::make(const Spec& spec) + { + if(spec.algo_name() == "RC4") + return new RC4(spec.arg_as_integer(0, 0)); + if(spec.algo_name() == "RC4_drop") + return new RC4(768); + return nullptr; + } + /* * Combine cipher stream with message */ diff --git a/src/lib/stream/rc4/rc4.h b/src/lib/stream/rc4/rc4.h index f72e2e75d..b2006fec5 100644 --- a/src/lib/stream/rc4/rc4.h +++ b/src/lib/stream/rc4/rc4.h @@ -31,6 +31,8 @@ class BOTAN_DLL RC4 : public StreamCipher return Key_Length_Specification(1, 256); } + static RC4* make(const Spec& spec); + /** * @param skip skip this many initial bytes in the keystream */ diff --git a/src/lib/stream/salsa20/salsa20.cpp b/src/lib/stream/salsa20/salsa20.cpp index a307110b3..7ab7b4f76 100644 --- a/src/lib/stream/salsa20/salsa20.cpp +++ b/src/lib/stream/salsa20/salsa20.cpp @@ -5,13 +5,13 @@ * 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> -#include <botan/rotate.h> -#include <botan/internal/xor_buf.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.h b/src/lib/stream/stream_cipher.h index 5708c2ab6..2ca92e467 100644 --- a/src/lib/stream/stream_cipher.h +++ b/src/lib/stream/stream_cipher.h @@ -9,6 +9,7 @@ #define BOTAN_STREAM_CIPHER_H__ #include <botan/sym_algo.h> +#include <botan/scan_name.h> namespace Botan { @@ -63,6 +64,8 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm * Get a new object representing the same algorithm as *this */ virtual StreamCipher* clone() const = 0; + + typedef SCAN_Name Spec; }; } |