diff options
-rw-r--r-- | src/lib/filters/key_filt.cpp | 1 | ||||
-rw-r--r-- | src/lib/filters/key_filt.h | 1 | ||||
-rw-r--r-- | src/lib/modes/cipher_mode.cpp | 1 | ||||
-rw-r--r-- | src/lib/modes/cipher_mode.h | 50 | ||||
-rw-r--r-- | src/lib/modes/info.txt | 2 | ||||
-rw-r--r-- | src/lib/modes/stream_mode.h | 63 | ||||
-rw-r--r-- | src/lib/stream/rc4/rc4.cpp | 3 | ||||
-rw-r--r-- | src/lib/utils/types.h | 6 |
8 files changed, 72 insertions, 55 deletions
diff --git a/src/lib/filters/key_filt.cpp b/src/lib/filters/key_filt.cpp index ca554ae2c..2cc350268 100644 --- a/src/lib/filters/key_filt.cpp +++ b/src/lib/filters/key_filt.cpp @@ -5,7 +5,6 @@ */ #include <botan/key_filt.h> -#include <botan/cipher_mode.h> #include <botan/transform_filter.h> namespace Botan { diff --git a/src/lib/filters/key_filt.h b/src/lib/filters/key_filt.h index 96b472b7e..ae1d4c5f0 100644 --- a/src/lib/filters/key_filt.h +++ b/src/lib/filters/key_filt.h @@ -9,6 +9,7 @@ #define BOTAN_KEYED_FILTER_H__ #include <botan/filter.h> +#include <botan/cipher_mode.h> #include <botan/sym_algo.h> namespace Botan { diff --git a/src/lib/modes/cipher_mode.cpp b/src/lib/modes/cipher_mode.cpp index f568415f4..095ef9008 100644 --- a/src/lib/modes/cipher_mode.cpp +++ b/src/lib/modes/cipher_mode.cpp @@ -6,6 +6,7 @@ */ #include <botan/cipher_mode.h> +#include <botan/stream_mode.h> #include <botan/lookup.h> #include <sstream> diff --git a/src/lib/modes/cipher_mode.h b/src/lib/modes/cipher_mode.h index 19c0af150..110053489 100644 --- a/src/lib/modes/cipher_mode.h +++ b/src/lib/modes/cipher_mode.h @@ -26,51 +26,11 @@ class BOTAN_DLL Cipher_Mode : public Keyed_Transform virtual bool authenticated() const { return false; } }; -class BOTAN_DLL Stream_Cipher_Mode : public Cipher_Mode - { - public: - Stream_Cipher_Mode(StreamCipher* cipher) : m_cipher(cipher) {} - - void update(secure_vector<byte>& buf, size_t offset) override - { - if(offset < buf.size()) - m_cipher->cipher1(&buf[offset], buf.size() - offset); - } - - void finish(secure_vector<byte>& buf, size_t offset) override - { return update(buf, offset); } - - size_t output_length(size_t input_length) const override { return input_length; } - - size_t update_granularity() const override { return 64; /* arbitrary */ } - - size_t minimum_final_size() const override { return 0; } - - size_t default_nonce_length() const override { return 0; } - - bool valid_nonce_length(size_t nonce_len) const override - { return m_cipher->valid_iv_length(nonce_len); } - - Key_Length_Specification key_spec() const override { return m_cipher->key_spec(); } - - std::string name() const override { return m_cipher->name(); } - - void clear() override { return m_cipher->clear(); } - - private: - secure_vector<byte> start_raw(const byte nonce[], size_t nonce_len) override - { - m_cipher->set_iv(nonce, nonce_len); - return secure_vector<byte>(); - } - - void key_schedule(const byte key[], size_t length) - { - m_cipher->set_key(key, length); - } - - std::unique_ptr<StreamCipher> m_cipher; - }; +/** +* The two possible directions for cipher filters, determining whether they +* actually perform encryption or decryption. +*/ +enum Cipher_Dir { ENCRYPTION, DECRYPTION }; BOTAN_DLL Cipher_Mode* get_cipher_mode(const std::string& algo_spec, Cipher_Dir direction); diff --git a/src/lib/modes/info.txt b/src/lib/modes/info.txt index bda618e66..95104e903 100644 --- a/src/lib/modes/info.txt +++ b/src/lib/modes/info.txt @@ -1,6 +1,6 @@ - <header:public> cipher_mode.h +stream_mode.h </header:public> <header:internal> diff --git a/src/lib/modes/stream_mode.h b/src/lib/modes/stream_mode.h new file mode 100644 index 000000000..80fec96f9 --- /dev/null +++ b/src/lib/modes/stream_mode.h @@ -0,0 +1,63 @@ +/* +* (C) 2015 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_STREAM_MODE_H__ +#define BOTAN_STREAM_MODE_H__ + +#include <botan/cipher_mode.h> +#include <botan/stream_cipher.h> + +namespace Botan { + +class BOTAN_DLL Stream_Cipher_Mode : public Cipher_Mode + { + public: + Stream_Cipher_Mode(StreamCipher* cipher) : m_cipher(cipher) {} + + void update(secure_vector<byte>& buf, size_t offset) override + { + if(offset < buf.size()) + m_cipher->cipher1(&buf[offset], buf.size() - offset); + } + + void finish(secure_vector<byte>& buf, size_t offset) override + { return update(buf, offset); } + + size_t output_length(size_t input_length) const override { return input_length; } + + size_t update_granularity() const override { return 64; /* arbitrary */ } + + size_t minimum_final_size() const override { return 0; } + + size_t default_nonce_length() const override { return 0; } + + bool valid_nonce_length(size_t nonce_len) const override + { return m_cipher->valid_iv_length(nonce_len); } + + Key_Length_Specification key_spec() const override { return m_cipher->key_spec(); } + + std::string name() const override { return m_cipher->name(); } + + void clear() override { return m_cipher->clear(); } + + private: + secure_vector<byte> start_raw(const byte nonce[], size_t nonce_len) override + { + m_cipher->set_iv(nonce, nonce_len); + return secure_vector<byte>(); + } + + void key_schedule(const byte key[], size_t length) + { + m_cipher->set_key(key, length); + } + + std::unique_ptr<StreamCipher> m_cipher; + }; + +} + +#endif diff --git a/src/lib/stream/rc4/rc4.cpp b/src/lib/stream/rc4/rc4.cpp index dcf4af241..096772314 100644 --- a/src/lib/stream/rc4/rc4.cpp +++ b/src/lib/stream/rc4/rc4.cpp @@ -7,7 +7,6 @@ #include <botan/internal/stream_utils.h> #include <botan/rc4.h> -#include <botan/internal/rounding.h> namespace Botan { @@ -73,7 +72,7 @@ void RC4::generate() void RC4::key_schedule(const byte key[], size_t length) { state.resize(256); - buffer.resize(round_up<size_t>(DEFAULT_BUFFERSIZE, 4)); + buffer.resize(256); position = X = Y = 0; diff --git a/src/lib/utils/types.h b/src/lib/utils/types.h index c12cc72dc..4427038a6 100644 --- a/src/lib/utils/types.h +++ b/src/lib/utils/types.h @@ -39,12 +39,6 @@ typedef 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 { |