diff options
author | Jack Lloyd <[email protected]> | 2019-06-08 08:43:53 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-06-08 08:43:53 -0400 |
commit | d02aa46ac0f4bf260ab343af47e2a0ae30ef4fa9 (patch) | |
tree | 07ca3c74ff9868ed9514a826351096dc3dd847d8 /src | |
parent | 097feb96b174a998fa78e2f6f040d62808f10204 (diff) | |
parent | b5513cd0d95b0ed99c581900fea226771b74339c (diff) |
Merge GH #1994 Deprecate headers
Diffstat (limited to 'src')
30 files changed, 598 insertions, 693 deletions
diff --git a/src/build-data/version.txt b/src/build-data/version.txt index 2dc302a20..ed6bafc01 100644 --- a/src/build-data/version.txt +++ b/src/build-data/version.txt @@ -2,7 +2,7 @@ release_major = 2 release_minor = 11 release_patch = 0 -release_so_abi_rev = 10 +release_so_abi_rev = 11 # These are set by the distribution script release_vc_rev = None diff --git a/src/lib/base/botan.h b/src/lib/base/botan.h index 26bfa75a7..a473e8fbf 100644 --- a/src/lib/base/botan.h +++ b/src/lib/base/botan.h @@ -16,12 +16,6 @@ * This header file will be removed in Botan 3.x */ -#if defined(__GNUC__) - #warning "botan/botan.h is deprecated" -#elif defined(_MSC_VER) - #pragma message ("botan/botan.h is deprecated") -#endif - #include <botan/lookup.h> #include <botan/version.h> #include <botan/parsing.h> @@ -42,4 +36,6 @@ #include <botan/pkcs8.h> #endif +BOTAN_DEPRECATED_HEADER(botan.h) + #endif diff --git a/src/lib/base/init.h b/src/lib/base/init.h index ba014d8e1..668650846 100644 --- a/src/lib/base/init.h +++ b/src/lib/base/init.h @@ -13,6 +13,8 @@ namespace Botan { +BOTAN_DEPRECATED_HEADER(init.h) + /* * Previously botan had state whose lifetime had to be explicitly * managed by the application. As of 1.11.14 this is no longer the diff --git a/src/lib/base/lookup.h b/src/lib/base/lookup.h index 1cfa7d3c9..4a14230db 100644 --- a/src/lib/base/lookup.h +++ b/src/lib/base/lookup.h @@ -32,6 +32,8 @@ namespace Botan { +BOTAN_DEPRECATED_HEADER(lookup.h) + /* * As of 1.11.26 this header is deprecated. Instead use the calls T::create and * T::providers (as demonstrated in the implementation below). diff --git a/src/lib/block/threefish_512/threefish.h b/src/lib/block/threefish_512/threefish.h index 6b21e9fdd..f866a717f 100644 --- a/src/lib/block/threefish_512/threefish.h +++ b/src/lib/block/threefish_512/threefish.h @@ -8,6 +8,10 @@ #ifndef BOTAN_THREEFISH_H_ #define BOTAN_THREEFISH_H_ +// This header is deprecated and will be removed in a future major release + #include <botan/threefish_512.h> +BOTAN_DEPRECATED_HEADER(threefish.h) + #endif diff --git a/src/lib/filters/aead_filt.h b/src/lib/filters/aead_filt.h deleted file mode 100644 index f569423a6..000000000 --- a/src/lib/filters/aead_filt.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -* Filter interface for AEAD Modes -* (C) 2013 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_AEAD_FILTER_H_ -#define BOTAN_AEAD_FILTER_H_ - -#include <botan/cipher_filter.h> -#include <botan/aead.h> - -namespace Botan { - -/** -* Filter interface for AEAD Modes -*/ -class AEAD_Filter final : public Cipher_Mode_Filter - { - public: - AEAD_Filter(AEAD_Mode* aead) : Cipher_Mode_Filter(aead) {} - - /** - * Set associated data that is not included in the ciphertext but - * that should be authenticated. Must be called after set_key - * and before end_msg. - * - * @param ad the associated data - * @param ad_len length of add in bytes - */ - void set_associated_data(const uint8_t ad[], size_t ad_len) - { - dynamic_cast<AEAD_Mode&>(get_transform()).set_associated_data(ad, ad_len); - } - }; - -} - -#endif diff --git a/src/lib/filters/codec_filt/b64_filt.cpp b/src/lib/filters/b64_filt.cpp index 0ce158fb4..8cbba1a6e 100644 --- a/src/lib/filters/codec_filt/b64_filt.cpp +++ b/src/lib/filters/b64_filt.cpp @@ -5,7 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/b64_filt.h> +#include <botan/filters.h> #include <botan/base64.h> #include <botan/exceptn.h> #include <algorithm> diff --git a/src/lib/filters/b64_filt.h b/src/lib/filters/b64_filt.h new file mode 100644 index 000000000..af7bb7cf2 --- /dev/null +++ b/src/lib/filters/b64_filt.h @@ -0,0 +1,14 @@ +/* +* Base64 Encoder/Decoder +* (C) 1999-2010 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_BASE64_FILTER_H_ +#define BOTAN_BASE64_FILTER_H_ + +#include <botan/filters.h> +BOTAN_DEPRECATED_HEADER(b64_filt.h) + +#endif diff --git a/src/lib/filters/basefilt.cpp b/src/lib/filters/basefilt.cpp index 89026f600..b34b70bd6 100644 --- a/src/lib/filters/basefilt.cpp +++ b/src/lib/filters/basefilt.cpp @@ -1,21 +1,13 @@ /* -* Basic Filters * (C) 1999-2007 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/basefilt.h> -#include <botan/key_filt.h> +#include <botan/filters.h> namespace Botan { -void Keyed_Filter::set_iv(const InitializationVector& iv) - { - if(iv.length() != 0) - throw Invalid_IV_Length(name(), iv.length()); - } - /* * Chain Constructor */ @@ -40,11 +32,6 @@ Chain::Chain(Filter* filters[], size_t count) } } -std::string Chain::name() const - { - return "Chain"; - } - /* * Fork Constructor */ @@ -62,9 +49,4 @@ Fork::Fork(Filter* filters[], size_t count) set_next(filters, count); } -std::string Fork::name() const - { - return "Fork"; - } - } diff --git a/src/lib/filters/basefilt.h b/src/lib/filters/basefilt.h index 922d35669..422989b75 100644 --- a/src/lib/filters/basefilt.h +++ b/src/lib/filters/basefilt.h @@ -9,116 +9,10 @@ #ifndef BOTAN_BASEFILT_H_ #define BOTAN_BASEFILT_H_ -#include <botan/filter.h> +// This header is deprecated and will be removed in a future major release -#if defined(BOTAN_TARGET_OS_HAS_THREADS) - #include <thread> -#endif - -namespace Botan { - -/** -* BitBucket is a filter which simply discards all inputs -*/ -class BOTAN_PUBLIC_API(2,0) BitBucket final : public Filter - { - public: - void write(const uint8_t[], size_t) override { /* discard */ } - - std::string name() const override { return "BitBucket"; } - }; - -/** -* This class represents Filter chains. A Filter chain is an ordered -* concatenation of Filters, the input to a Chain sequentially passes -* through all the Filters contained in the Chain. -*/ - -class BOTAN_PUBLIC_API(2,0) Chain final : public Fanout_Filter - { - public: - void write(const uint8_t input[], size_t length) override { send(input, length); } - - std::string name() const override; - - /** - * Construct a chain of up to four filters. The filters are set - * up in the same order as the arguments. - */ - Chain(Filter* = nullptr, Filter* = nullptr, - Filter* = nullptr, Filter* = nullptr); - - /** - * Construct a chain from range of filters - * @param filter_arr the list of filters - * @param length how many filters - */ - Chain(Filter* filter_arr[], size_t length); - }; - -/** -* This class represents a fork filter, whose purpose is to fork the -* flow of data. It causes an input message to result in n messages at -* the end of the filter, where n is the number of forks. -*/ -class BOTAN_PUBLIC_API(2,0) Fork : public Fanout_Filter - { - public: - void write(const uint8_t input[], size_t length) override { send(input, length); } - void set_port(size_t n) { Fanout_Filter::set_port(n); } - - std::string name() const override; - - /** - * Construct a Fork filter with up to four forks. - */ - Fork(Filter*, Filter*, Filter* = nullptr, Filter* = nullptr); - - /** - * Construct a Fork from range of filters - * @param filter_arr the list of filters - * @param length how many filters - */ - Fork(Filter* filter_arr[], size_t length); - }; - -#if defined(BOTAN_HAS_THREAD_UTILS) - -/** -* This class is a threaded version of the Fork filter. While this uses -* threads, the class itself is NOT thread-safe. This is meant as a drop- -* in replacement for Fork where performance gains are possible. -*/ -class BOTAN_PUBLIC_API(2,0) Threaded_Fork final : public Fork - { - public: - std::string name() const override; - - /** - * Construct a Threaded_Fork filter with up to four forks. - */ - Threaded_Fork(Filter*, Filter*, Filter* = nullptr, Filter* = nullptr); - - /** - * Construct a Threaded_Fork from range of filters - * @param filter_arr the list of filters - * @param length how many filters - */ - Threaded_Fork(Filter* filter_arr[], size_t length); - - ~Threaded_Fork(); - - private: - void set_next(Filter* f[], size_t n); - void send(const uint8_t in[], size_t length) override; - void thread_delegate_work(const uint8_t input[], size_t length); - void thread_entry(Filter* filter); - - std::vector<std::shared_ptr<std::thread>> m_threads; - std::unique_ptr<struct Threaded_Fork_Data> m_thread_data; - }; -#endif +#include <botan/filters.h> -} +BOTAN_DEPRECATED_HEADER(basefilt.h) #endif diff --git a/src/lib/filters/buf_filt.cpp b/src/lib/filters/buf_filt.cpp index 11ca9bbfe..0e34a56dd 100644 --- a/src/lib/filters/buf_filt.cpp +++ b/src/lib/filters/buf_filt.cpp @@ -5,7 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/buf_filt.h> +#include <botan/filters.h> #include <botan/mem_ops.h> #include <botan/internal/rounding.h> #include <botan/exceptn.h> diff --git a/src/lib/filters/buf_filt.h b/src/lib/filters/buf_filt.h index b4cd8e680..1f9ed3eff 100644 --- a/src/lib/filters/buf_filt.h +++ b/src/lib/filters/buf_filt.h @@ -8,86 +8,7 @@ #ifndef BOTAN_BUFFERED_FILTER_H_ #define BOTAN_BUFFERED_FILTER_H_ -#include <botan/secmem.h> - -namespace Botan { - -/** -* Filter mixin that breaks input into blocks, useful for -* cipher modes -*/ -class BOTAN_PUBLIC_API(2,0) Buffered_Filter - { - public: - /** - * Write bytes into the buffered filter, which will them emit them - * in calls to buffered_block in the subclass - * @param in the input bytes - * @param length of in in bytes - */ - void write(const uint8_t in[], size_t length); - - template<typename Alloc> - void write(const std::vector<uint8_t, Alloc>& in, size_t length) - { - write(in.data(), length); - } - - /** - * Finish a message, emitting to buffered_block and buffered_final - * Will throw an exception if less than final_minimum bytes were - * written into the filter. - */ - void end_msg(); - - /** - * Initialize a Buffered_Filter - * @param block_size the function buffered_block will be called - * with inputs which are a multiple of this size - * @param final_minimum the function buffered_final will be called - * with at least this many bytes. - */ - Buffered_Filter(size_t block_size, size_t final_minimum); - - virtual ~Buffered_Filter() = default; - protected: - /** - * The block processor, implemented by subclasses - * @param input some input bytes - * @param length the size of input, guaranteed to be a multiple - * of block_size - */ - virtual void buffered_block(const uint8_t input[], size_t length) = 0; - - /** - * The final block, implemented by subclasses - * @param input some input bytes - * @param length the size of input, guaranteed to be at least - * final_minimum bytes - */ - virtual void buffered_final(const uint8_t input[], size_t length) = 0; - - /** - * @return block size of inputs - */ - size_t buffered_block_size() const { return m_main_block_mod; } - - /** - * @return current position in the buffer - */ - size_t current_position() const { return m_buffer_pos; } - - /** - * Reset the buffer position - */ - void buffer_reset() { m_buffer_pos = 0; } - private: - size_t m_main_block_mod, m_final_minimum; - - secure_vector<uint8_t> m_buffer; - size_t m_buffer_pos; - }; - -} +#include <botan/filters.h> +BOTAN_DEPRECATED_HEADER(buf_filt.h) #endif diff --git a/src/lib/filters/cipher_filter.cpp b/src/lib/filters/cipher_filter.cpp index a3e7bd1c3..720aeac6f 100644 --- a/src/lib/filters/cipher_filter.cpp +++ b/src/lib/filters/cipher_filter.cpp @@ -5,7 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/cipher_filter.h> +#include <botan/filters.h> #include <botan/internal/rounding.h> namespace Botan { diff --git a/src/lib/filters/cipher_filter.h b/src/lib/filters/cipher_filter.h index 750385d15..84fc58b6e 100644 --- a/src/lib/filters/cipher_filter.h +++ b/src/lib/filters/cipher_filter.h @@ -5,54 +5,10 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#ifndef BOTAN_TRANSFORM_FILTER_H_ -#define BOTAN_TRANSFORM_FILTER_H_ +#ifndef BOTAN_CIPHER_FILTER_H_ +#define BOTAN_CIPHER_FILTER_H_ -#include <botan/cipher_mode.h> -#include <botan/key_filt.h> -#include <botan/buf_filt.h> - -namespace Botan { - -/** -* Filter interface for cipher modes -*/ -class BOTAN_PUBLIC_API(2,0) Cipher_Mode_Filter final : public Keyed_Filter, - private Buffered_Filter - { - public: - explicit Cipher_Mode_Filter(Cipher_Mode* t); - - explicit Cipher_Mode_Filter(std::unique_ptr<Cipher_Mode> t) : - Cipher_Mode_Filter(t.release()) {} - - void set_iv(const InitializationVector& iv) override; - - void set_key(const SymmetricKey& key) override; - - Key_Length_Specification key_spec() const override; - - bool valid_iv_length(size_t length) const override; - - std::string name() const override; - - private: - void write(const uint8_t input[], size_t input_length) override; - void start_msg() override; - void end_msg() override; - - void buffered_block(const uint8_t input[], size_t input_length) override; - void buffered_final(const uint8_t input[], size_t input_length) override; - - std::unique_ptr<Cipher_Mode> m_mode; - std::vector<uint8_t> m_nonce; - secure_vector<uint8_t> m_buffer; - }; - -// deprecated aliases, will be removed before 2.0 -typedef Cipher_Mode_Filter Transform_Filter; -typedef Transform_Filter Transformation_Filter; - -} +#include <botan/filters.h> +BOTAN_DEPRECATED_HEADER(cipher_filter.h) #endif diff --git a/src/lib/filters/codec_filt/b64_filt.h b/src/lib/filters/codec_filt/b64_filt.h deleted file mode 100644 index 9c9602b98..000000000 --- a/src/lib/filters/codec_filt/b64_filt.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -* Base64 Encoder/Decoder -* (C) 1999-2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_BASE64_FILTER_H_ -#define BOTAN_BASE64_FILTER_H_ - -#include <botan/filter.h> - -namespace Botan { - -/** -* This class represents a Base64 encoder. -*/ -class BOTAN_PUBLIC_API(2,0) Base64_Encoder final : public Filter - { - public: - std::string name() const override { return "Base64_Encoder"; } - - /** - * Input a part of a message to the encoder. - * @param input the message to input as a byte array - * @param length the length of the byte array input - */ - void write(const uint8_t input[], size_t length) override; - - /** - * Inform the Encoder that the current message shall be closed. - */ - void end_msg() override; - - /** - * Create a base64 encoder. - * @param breaks whether to use line breaks in the output - * @param length the length of the lines of the output - * @param t_n whether to use a trailing newline - */ - Base64_Encoder(bool breaks = false, size_t length = 72, - bool t_n = false); - private: - void encode_and_send(const uint8_t input[], size_t length, - bool final_inputs = false); - void do_output(const uint8_t output[], size_t length); - - const size_t m_line_length; - const bool m_trailing_newline; - std::vector<uint8_t> m_in, m_out; - size_t m_position, m_out_position; - }; - -/** -* This object represents a Base64 decoder. -*/ -class BOTAN_PUBLIC_API(2,0) Base64_Decoder final : public Filter - { - public: - std::string name() const override { return "Base64_Decoder"; } - - /** - * Input a part of a message to the decoder. - * @param input the message to input as a byte array - * @param length the length of the byte array input - */ - void write(const uint8_t input[], size_t length) override; - - /** - * Finish up the current message - */ - void end_msg() override; - - /** - * Create a base64 decoder. - * @param checking the type of checking that shall be performed by - * the decoder - */ - explicit Base64_Decoder(Decoder_Checking checking = NONE); - private: - const Decoder_Checking m_checking; - std::vector<uint8_t> m_in, m_out; - size_t m_position; - }; - -} - -#endif diff --git a/src/lib/filters/codec_filt/hex_filt.h b/src/lib/filters/codec_filt/hex_filt.h deleted file mode 100644 index 4128d627a..000000000 --- a/src/lib/filters/codec_filt/hex_filt.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -* Hex Encoder/Decoder -* (C) 1999-2010 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_HEX_FILTER_H_ -#define BOTAN_HEX_FILTER_H_ - -#include <botan/filter.h> - -namespace Botan { - -/** -* Converts arbitrary binary data to hex strings, optionally with -* newlines inserted -*/ -class BOTAN_PUBLIC_API(2,0) Hex_Encoder final : public Filter - { - public: - /** - * Whether to use uppercase or lowercase letters for the encoded string. - */ - enum Case { Uppercase, Lowercase }; - - std::string name() const override { return "Hex_Encoder"; } - - void write(const uint8_t in[], size_t length) override; - void end_msg() override; - - /** - * Create a hex encoder. - * @param the_case the case to use in the encoded strings. - */ - explicit Hex_Encoder(Case the_case); - - /** - * Create a hex encoder. - * @param newlines should newlines be used - * @param line_length if newlines are used, how long are lines - * @param the_case the case to use in the encoded strings - */ - Hex_Encoder(bool newlines = false, - size_t line_length = 72, - Case the_case = Uppercase); - private: - void encode_and_send(const uint8_t[], size_t); - - const Case m_casing; - const size_t m_line_length; - std::vector<uint8_t> m_in, m_out; - size_t m_position, m_counter; - }; - -/** -* Converts hex strings to bytes -*/ -class BOTAN_PUBLIC_API(2,0) Hex_Decoder final : public Filter - { - public: - std::string name() const override { return "Hex_Decoder"; } - - void write(const uint8_t[], size_t) override; - void end_msg() override; - - /** - * Construct a Hex Decoder using the specified - * character checking. - * @param checking the checking to use during decoding. - */ - explicit Hex_Decoder(Decoder_Checking checking = NONE); - private: - const Decoder_Checking m_checking; - std::vector<uint8_t> m_in, m_out; - size_t m_position; - }; - -} - -#endif diff --git a/src/lib/filters/codec_filt/info.txt b/src/lib/filters/codec_filt/info.txt index 347c876a7..fd7b3fbd3 100644 --- a/src/lib/filters/codec_filt/info.txt +++ b/src/lib/filters/codec_filt/info.txt @@ -1,8 +1,6 @@ <defines> -CODEC_FILTERS -> 20131128 </defines> <requires> -base64 filters </requires> diff --git a/src/lib/filters/comp_filter.cpp b/src/lib/filters/comp_filter.cpp index 2563a4907..c2814460a 100644 --- a/src/lib/filters/comp_filter.cpp +++ b/src/lib/filters/comp_filter.cpp @@ -6,7 +6,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/comp_filter.h> +#include <botan/filters.h> #include <botan/exceptn.h> #if defined(BOTAN_HAS_COMPRESSION) diff --git a/src/lib/filters/comp_filter.h b/src/lib/filters/comp_filter.h index d9cc00b68..86b587ac3 100644 --- a/src/lib/filters/comp_filter.h +++ b/src/lib/filters/comp_filter.h @@ -8,64 +8,8 @@ #ifndef BOTAN_COMPRESSION_FILTER_H_ #define BOTAN_COMPRESSION_FILTER_H_ -#include <botan/filter.h> +BOTAN_DEPRECATED_HEADER(comp_filter.h) -namespace Botan { - -#if defined(BOTAN_HAS_COMPRESSION) - -class Compression_Algorithm; -class Decompression_Algorithm; - -/** -* Filter interface for compression -*/ -class BOTAN_PUBLIC_API(2,0) Compression_Filter final : public Filter - { - public: - void start_msg() override; - void write(const uint8_t input[], size_t input_length) override; - void end_msg() override; - - void flush(); - - std::string name() const override; - - Compression_Filter(const std::string& type, - size_t compression_level, - size_t buffer_size = 4096); - - ~Compression_Filter(); - private: - std::unique_ptr<Compression_Algorithm> m_comp; - size_t m_buffersize, m_level; - secure_vector<uint8_t> m_buffer; - }; - -/** -* Filter interface for decompression -*/ -class BOTAN_PUBLIC_API(2,0) Decompression_Filter final : public Filter - { - public: - void start_msg() override; - void write(const uint8_t input[], size_t input_length) override; - void end_msg() override; - - std::string name() const override; - - Decompression_Filter(const std::string& type, - size_t buffer_size = 4096); - - ~Decompression_Filter(); - private: - std::unique_ptr<Decompression_Algorithm> m_comp; - std::size_t m_buffersize; - secure_vector<uint8_t> m_buffer; - }; - -#endif - -} +#include <botan/filters.h> #endif diff --git a/src/lib/filters/filters.h b/src/lib/filters/filters.h index b4aee1207..c19e1a749 100644 --- a/src/lib/filters/filters.h +++ b/src/lib/filters/filters.h @@ -1,6 +1,7 @@ /* -* Filters +* Common Filters * (C) 1999-2007,2015 Jack Lloyd +* (C) 2013 Joel Low * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -8,10 +9,15 @@ #ifndef BOTAN_FILTERS_H_ #define BOTAN_FILTERS_H_ -#include <botan/basefilt.h> -#include <botan/key_filt.h> +#include <botan/secmem.h> #include <botan/data_snk.h> #include <botan/pipe.h> +#include <botan/symkey.h> +#include <botan/cipher_mode.h> + +#if defined(BOTAN_TARGET_OS_HAS_THREADS) + #include <thread> +#endif #if defined(BOTAN_HAS_STREAM_CIPHER) #include <botan/stream_cipher.h> @@ -25,13 +31,230 @@ #include <botan/mac.h> #endif -#if defined(BOTAN_HAS_CODEC_FILTERS) - #include <botan/b64_filt.h> - #include <botan/hex_filt.h> -#endif - namespace Botan { +/** +* Filter mixin that breaks input into blocks, useful for +* cipher modes +*/ +class BOTAN_PUBLIC_API(2,0) Buffered_Filter + { + public: + /** + * Write bytes into the buffered filter, which will them emit them + * in calls to buffered_block in the subclass + * @param in the input bytes + * @param length of in in bytes + */ + void write(const uint8_t in[], size_t length); + + template<typename Alloc> + void write(const std::vector<uint8_t, Alloc>& in, size_t length) + { + write(in.data(), length); + } + + /** + * Finish a message, emitting to buffered_block and buffered_final + * Will throw an exception if less than final_minimum bytes were + * written into the filter. + */ + void end_msg(); + + /** + * Initialize a Buffered_Filter + * @param block_size the function buffered_block will be called + * with inputs which are a multiple of this size + * @param final_minimum the function buffered_final will be called + * with at least this many bytes. + */ + Buffered_Filter(size_t block_size, size_t final_minimum); + + virtual ~Buffered_Filter() = default; + protected: + /** + * The block processor, implemented by subclasses + * @param input some input bytes + * @param length the size of input, guaranteed to be a multiple + * of block_size + */ + virtual void buffered_block(const uint8_t input[], size_t length) = 0; + + /** + * The final block, implemented by subclasses + * @param input some input bytes + * @param length the size of input, guaranteed to be at least + * final_minimum bytes + */ + virtual void buffered_final(const uint8_t input[], size_t length) = 0; + + /** + * @return block size of inputs + */ + size_t buffered_block_size() const { return m_main_block_mod; } + + /** + * @return current position in the buffer + */ + size_t current_position() const { return m_buffer_pos; } + + /** + * Reset the buffer position + */ + void buffer_reset() { m_buffer_pos = 0; } + private: + size_t m_main_block_mod, m_final_minimum; + + secure_vector<uint8_t> m_buffer; + size_t m_buffer_pos; + }; + +/** +* This class represents keyed filters, i.e. filters that have to be +* fed with a key in order to function. +*/ +class BOTAN_PUBLIC_API(2,0) Keyed_Filter : public Filter + { + public: + /** + * Set the key of this filter + * @param key the key to use + */ + virtual void set_key(const SymmetricKey& key) = 0; + + /** + * Set the initialization vector of this filter. Note: you should + * call set_iv() only after you have called set_key() + * @param iv the initialization vector to use + */ + virtual void set_iv(const InitializationVector& iv) + { + if(iv.length() != 0) + throw Invalid_IV_Length(name(), iv.length()); + } + + /** + * Check whether a key length is valid for this filter + * @param length the key length to be checked for validity + * @return true if the key length is valid, false otherwise + */ + bool valid_keylength(size_t length) const + { + return key_spec().valid_keylength(length); + } + + /** + * @return object describing limits on key size + */ + virtual Key_Length_Specification key_spec() const = 0; + + /** + * Check whether an IV length is valid for this filter + * @param length the IV length to be checked for validity + * @return true if the IV length is valid, false otherwise + */ + virtual bool valid_iv_length(size_t length) const + { return (length == 0); } + }; + +/** +* Filter interface for cipher modes +*/ +class BOTAN_PUBLIC_API(2,0) Cipher_Mode_Filter final : public Keyed_Filter, + private Buffered_Filter + { + public: + explicit Cipher_Mode_Filter(Cipher_Mode* t); + + explicit Cipher_Mode_Filter(std::unique_ptr<Cipher_Mode> t) : + Cipher_Mode_Filter(t.release()) {} + + void set_iv(const InitializationVector& iv) override; + + void set_key(const SymmetricKey& key) override; + + Key_Length_Specification key_spec() const override; + + bool valid_iv_length(size_t length) const override; + + std::string name() const override; + + private: + void write(const uint8_t input[], size_t input_length) override; + void start_msg() override; + void end_msg() override; + + void buffered_block(const uint8_t input[], size_t input_length) override; + void buffered_final(const uint8_t input[], size_t input_length) override; + + std::unique_ptr<Cipher_Mode> m_mode; + std::vector<uint8_t> m_nonce; + secure_vector<uint8_t> m_buffer; + }; + +// deprecated aliases, will be removed in a future major release +typedef Cipher_Mode_Filter Transform_Filter; +typedef Transform_Filter Transformation_Filter; + +/* +* Get a cipher object +*/ + +/** +* Factory method for general symmetric cipher filters. No key will be +* set in the filter. +* +* @param algo_spec the name of the desired cipher +* @param direction determines whether the filter will be an encrypting or +* decrypting filter +* @return pointer to the encryption or decryption filter +*/ +inline Keyed_Filter* get_cipher(const std::string& algo_spec, + Cipher_Dir direction) + { + std::unique_ptr<Cipher_Mode> c(Cipher_Mode::create_or_throw(algo_spec, direction)); + return new Cipher_Mode_Filter(c.release()); + } + +/** +* Factory method for general symmetric cipher filters. +* @param algo_spec the name of the desired cipher +* @param key the key to be used for encryption/decryption performed by +* the filter +* @param direction determines whether the filter will be an encrypting +* or decrypting filter +* @return pointer to the encryption or decryption filter +*/ +inline Keyed_Filter* get_cipher(const std::string& algo_spec, + const SymmetricKey& key, + Cipher_Dir direction) + { + Keyed_Filter* cipher = get_cipher(algo_spec, direction); + cipher->set_key(key); + return cipher; + } + +/** +* Factory method for general symmetric cipher filters. +* @param algo_spec the name of the desired cipher +* @param key the key to be used for encryption/decryption performed by +* the filter +* @param iv the initialization vector to be used +* @param direction determines whether the filter will be an encrypting +* or decrypting filter +* @return pointer to newly allocated encryption or decryption filter +*/ +inline Keyed_Filter* get_cipher(const std::string& algo_spec, + const SymmetricKey& key, + const InitializationVector& iv, + Cipher_Dir direction) + { + Keyed_Filter* cipher = get_cipher(algo_spec, key, direction); + if(iv.length()) + cipher->set_iv(iv); + return cipher; + } + #if defined(BOTAN_HAS_STREAM_CIPHER) /** @@ -222,6 +445,297 @@ class BOTAN_PUBLIC_API(2,0) MAC_Filter final : public Keyed_Filter }; #endif +#if defined(BOTAN_HAS_COMPRESSION) + +class Compression_Algorithm; +class Decompression_Algorithm; + +/** +* Filter interface for compression +*/ +class BOTAN_PUBLIC_API(2,0) Compression_Filter final : public Filter + { + public: + void start_msg() override; + void write(const uint8_t input[], size_t input_length) override; + void end_msg() override; + + void flush(); + + std::string name() const override; + + Compression_Filter(const std::string& type, + size_t compression_level, + size_t buffer_size = 4096); + + ~Compression_Filter(); + private: + std::unique_ptr<Compression_Algorithm> m_comp; + size_t m_buffersize, m_level; + secure_vector<uint8_t> m_buffer; + }; + +/** +* Filter interface for decompression +*/ +class BOTAN_PUBLIC_API(2,0) Decompression_Filter final : public Filter + { + public: + void start_msg() override; + void write(const uint8_t input[], size_t input_length) override; + void end_msg() override; + + std::string name() const override; + + Decompression_Filter(const std::string& type, + size_t buffer_size = 4096); + + ~Decompression_Filter(); + private: + std::unique_ptr<Decompression_Algorithm> m_comp; + std::size_t m_buffersize; + secure_vector<uint8_t> m_buffer; + }; + +#endif + +/** +* This class represents a Base64 encoder. +*/ +class BOTAN_PUBLIC_API(2,0) Base64_Encoder final : public Filter + { + public: + std::string name() const override { return "Base64_Encoder"; } + + /** + * Input a part of a message to the encoder. + * @param input the message to input as a byte array + * @param length the length of the byte array input + */ + void write(const uint8_t input[], size_t length) override; + + /** + * Inform the Encoder that the current message shall be closed. + */ + void end_msg() override; + + /** + * Create a base64 encoder. + * @param breaks whether to use line breaks in the output + * @param length the length of the lines of the output + * @param t_n whether to use a trailing newline + */ + Base64_Encoder(bool breaks = false, size_t length = 72, + bool t_n = false); + private: + void encode_and_send(const uint8_t input[], size_t length, + bool final_inputs = false); + void do_output(const uint8_t output[], size_t length); + + const size_t m_line_length; + const bool m_trailing_newline; + std::vector<uint8_t> m_in, m_out; + size_t m_position, m_out_position; + }; + +/** +* This object represents a Base64 decoder. +*/ +class BOTAN_PUBLIC_API(2,0) Base64_Decoder final : public Filter + { + public: + std::string name() const override { return "Base64_Decoder"; } + + /** + * Input a part of a message to the decoder. + * @param input the message to input as a byte array + * @param length the length of the byte array input + */ + void write(const uint8_t input[], size_t length) override; + + /** + * Finish up the current message + */ + void end_msg() override; + + /** + * Create a base64 decoder. + * @param checking the type of checking that shall be performed by + * the decoder + */ + explicit Base64_Decoder(Decoder_Checking checking = NONE); + private: + const Decoder_Checking m_checking; + std::vector<uint8_t> m_in, m_out; + size_t m_position; + }; + +/** +* Converts arbitrary binary data to hex strings, optionally with +* newlines inserted +*/ +class BOTAN_PUBLIC_API(2,0) Hex_Encoder final : public Filter + { + public: + /** + * Whether to use uppercase or lowercase letters for the encoded string. + */ + enum Case { Uppercase, Lowercase }; + + std::string name() const override { return "Hex_Encoder"; } + + void write(const uint8_t in[], size_t length) override; + void end_msg() override; + + /** + * Create a hex encoder. + * @param the_case the case to use in the encoded strings. + */ + explicit Hex_Encoder(Case the_case); + + /** + * Create a hex encoder. + * @param newlines should newlines be used + * @param line_length if newlines are used, how long are lines + * @param the_case the case to use in the encoded strings + */ + Hex_Encoder(bool newlines = false, + size_t line_length = 72, + Case the_case = Uppercase); + private: + void encode_and_send(const uint8_t[], size_t); + + const Case m_casing; + const size_t m_line_length; + std::vector<uint8_t> m_in, m_out; + size_t m_position, m_counter; + }; + +/** +* Converts hex strings to bytes +*/ +class BOTAN_PUBLIC_API(2,0) Hex_Decoder final : public Filter + { + public: + std::string name() const override { return "Hex_Decoder"; } + + void write(const uint8_t[], size_t) override; + void end_msg() override; + + /** + * Construct a Hex Decoder using the specified + * character checking. + * @param checking the checking to use during decoding. + */ + explicit Hex_Decoder(Decoder_Checking checking = NONE); + private: + const Decoder_Checking m_checking; + std::vector<uint8_t> m_in, m_out; + size_t m_position; + }; + +/** +* BitBucket is a filter which simply discards all inputs +*/ +class BOTAN_PUBLIC_API(2,0) BitBucket final : public Filter + { + public: + void write(const uint8_t[], size_t) override { /* discard */ } + + std::string name() const override { return "BitBucket"; } + }; + +/** +* This class represents Filter chains. A Filter chain is an ordered +* concatenation of Filters, the input to a Chain sequentially passes +* through all the Filters contained in the Chain. +*/ + +class BOTAN_PUBLIC_API(2,0) Chain final : public Fanout_Filter + { + public: + void write(const uint8_t input[], size_t length) override { send(input, length); } + + std::string name() const override { return "Chain"; } + + /** + * Construct a chain of up to four filters. The filters are set + * up in the same order as the arguments. + */ + Chain(Filter* = nullptr, Filter* = nullptr, + Filter* = nullptr, Filter* = nullptr); + + /** + * Construct a chain from range of filters + * @param filter_arr the list of filters + * @param length how many filters + */ + Chain(Filter* filter_arr[], size_t length); + }; + +/** +* This class represents a fork filter, whose purpose is to fork the +* flow of data. It causes an input message to result in n messages at +* the end of the filter, where n is the number of forks. +*/ +class BOTAN_PUBLIC_API(2,0) Fork : public Fanout_Filter + { + public: + void write(const uint8_t input[], size_t length) override { send(input, length); } + void set_port(size_t n) { Fanout_Filter::set_port(n); } + + std::string name() const override { return "Fork"; } + + /** + * Construct a Fork filter with up to four forks. + */ + Fork(Filter*, Filter*, Filter* = nullptr, Filter* = nullptr); + + /** + * Construct a Fork from range of filters + * @param filter_arr the list of filters + * @param length how many filters + */ + Fork(Filter* filter_arr[], size_t length); + }; + +#if defined(BOTAN_HAS_THREAD_UTILS) + +/** +* This class is a threaded version of the Fork filter. While this uses +* threads, the class itself is NOT thread-safe. This is meant as a drop- +* in replacement for Fork where performance gains are possible. +*/ +class BOTAN_PUBLIC_API(2,0) Threaded_Fork final : public Fork + { + public: + std::string name() const override; + + /** + * Construct a Threaded_Fork filter with up to four forks. + */ + Threaded_Fork(Filter*, Filter*, Filter* = nullptr, Filter* = nullptr); + + /** + * Construct a Threaded_Fork from range of filters + * @param filter_arr the list of filters + * @param length how many filters + */ + Threaded_Fork(Filter* filter_arr[], size_t length); + + ~Threaded_Fork(); + + private: + void set_next(Filter* f[], size_t n); + void send(const uint8_t in[], size_t length) override; + void thread_delegate_work(const uint8_t input[], size_t length); + void thread_entry(Filter* filter); + + std::vector<std::shared_ptr<std::thread>> m_threads; + std::unique_ptr<struct Threaded_Fork_Data> m_thread_data; + }; +#endif + } #endif diff --git a/src/lib/filters/codec_filt/hex_filt.cpp b/src/lib/filters/hex_filt.cpp index be1dbbc5c..761c73ade 100644 --- a/src/lib/filters/codec_filt/hex_filt.cpp +++ b/src/lib/filters/hex_filt.cpp @@ -5,7 +5,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/hex_filt.h> +#include <botan/filters.h> #include <botan/hex.h> #include <botan/exceptn.h> #include <algorithm> diff --git a/src/lib/filters/hex_filt.h b/src/lib/filters/hex_filt.h new file mode 100644 index 000000000..b529b5299 --- /dev/null +++ b/src/lib/filters/hex_filt.h @@ -0,0 +1,14 @@ +/* +* Hex Encoder/Decoder +* (C) 1999-2010 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_HEX_FILTER_H_ +#define BOTAN_HEX_FILTER_H_ + +#include <botan/filters.h> +BOTAN_DEPRECATED_HEADER(hex_filt.h) + +#endif diff --git a/src/lib/filters/info.txt b/src/lib/filters/info.txt index cfc114353..9fb8ef7ce 100644 --- a/src/lib/filters/info.txt +++ b/src/lib/filters/info.txt @@ -1,18 +1,21 @@ <defines> FILTERS -> 20160415 +CODEC_FILTERS -> 20131128 </defines> <header:public> basefilt.h +comp_filter.h +cipher_filter.h buf_filt.h +key_filt.h + +secqueue.h + data_snk.h -comp_filter.h filter.h filters.h -key_filt.h pipe.h -secqueue.h -cipher_filter.h </header:public> <header:internal> @@ -21,4 +24,5 @@ out_buf.h <requires> modes +base64 </requires> diff --git a/src/lib/filters/key_filt.cpp b/src/lib/filters/key_filt.cpp deleted file mode 100644 index b87a8c87f..000000000 --- a/src/lib/filters/key_filt.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -* (C) 2015 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/key_filt.h> -#include <botan/cipher_filter.h> - -namespace Botan { - -Keyed_Filter* get_cipher(const std::string& algo_spec, - Cipher_Dir direction) - { - std::unique_ptr<Cipher_Mode> c(Cipher_Mode::create_or_throw(algo_spec, direction)); - return new Cipher_Mode_Filter(c.release()); - } - -Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - const InitializationVector& iv, - Cipher_Dir direction) - { - Keyed_Filter* cipher = get_cipher(algo_spec, key, direction); - if(iv.length()) - cipher->set_iv(iv); - return cipher; - } - -Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - Cipher_Dir direction) - { - Keyed_Filter* cipher = get_cipher(algo_spec, direction); - cipher->set_key(key); - return cipher; - } - -} diff --git a/src/lib/filters/key_filt.h b/src/lib/filters/key_filt.h index 67b689f99..3d85d886a 100644 --- a/src/lib/filters/key_filt.h +++ b/src/lib/filters/key_filt.h @@ -8,102 +8,7 @@ #ifndef BOTAN_KEYED_FILTER_H_ #define BOTAN_KEYED_FILTER_H_ -#include <botan/symkey.h> #include <botan/filter.h> -#include <botan/cipher_mode.h> - -namespace Botan { - -/** -* This class represents keyed filters, i.e. filters that have to be -* fed with a key in order to function. -*/ -class BOTAN_PUBLIC_API(2,0) Keyed_Filter : public Filter - { - public: - /** - * Set the key of this filter - * @param key the key to use - */ - virtual void set_key(const SymmetricKey& key) = 0; - - /** - * Set the initialization vector of this filter. Note: you should - * call set_iv() only after you have called set_key() - * @param iv the initialization vector to use - */ - virtual void set_iv(const InitializationVector& iv); - - /** - * Check whether a key length is valid for this filter - * @param length the key length to be checked for validity - * @return true if the key length is valid, false otherwise - */ - bool valid_keylength(size_t length) const - { - return key_spec().valid_keylength(length); - } - - /** - * @return object describing limits on key size - */ - virtual Key_Length_Specification key_spec() const = 0; - - /** - * Check whether an IV length is valid for this filter - * @param length the IV length to be checked for validity - * @return true if the IV length is valid, false otherwise - */ - virtual bool valid_iv_length(size_t length) const - { return (length == 0); } - }; - - - -/* -* Get a cipher object -*/ - -/** -* Factory method for general symmetric cipher filters. -* @param algo_spec the name of the desired cipher -* @param key the key to be used for encryption/decryption performed by -* the filter -* @param iv the initialization vector to be used -* @param direction determines whether the filter will be an encrypting -* or decrypting filter -* @return pointer to newly allocated encryption or decryption filter -*/ -BOTAN_PUBLIC_API(2,0) Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - const InitializationVector& iv, - Cipher_Dir direction); - -/** -* Factory method for general symmetric cipher filters. -* @param algo_spec the name of the desired cipher -* @param key the key to be used for encryption/decryption performed by -* the filter -* @param direction determines whether the filter will be an encrypting -* or decrypting filter -* @return pointer to the encryption or decryption filter -*/ -BOTAN_PUBLIC_API(2,0) Keyed_Filter* get_cipher(const std::string& algo_spec, - const SymmetricKey& key, - Cipher_Dir direction); - -/** -* Factory method for general symmetric cipher filters. No key will be -* set in the filter. -* -* @param algo_spec the name of the desired cipher -* @param direction determines whether the filter will be an encrypting or -* decrypting filter -* @return pointer to the encryption or decryption filter -*/ -BOTAN_PUBLIC_API(2,0) Keyed_Filter* get_cipher(const std::string& algo_spec, - Cipher_Dir direction); - -} +BOTAN_DEPRECATED_HEADER(key_filt.h) #endif diff --git a/src/lib/filters/threaded_fork.cpp b/src/lib/filters/threaded_fork.cpp index 35ea94109..2d77f9fd1 100644 --- a/src/lib/filters/threaded_fork.cpp +++ b/src/lib/filters/threaded_fork.cpp @@ -6,7 +6,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include <botan/basefilt.h> +#include <botan/filters.h> #if defined(BOTAN_HAS_THREAD_UTILS) diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h index e6b7bc4bb..80b23ca8c 100644 --- a/src/lib/math/bigint/bigint.h +++ b/src/lib/math/bigint/bigint.h @@ -905,7 +905,7 @@ class BOTAN_PUBLIC_API(2,0) BigInt final * All elements of vec must have the same size, and output must be * pre-allocated with the same size. */ - static void const_time_lookup( + static void BOTAN_DEPRECATED("No longer in use") const_time_lookup( secure_vector<word>& output, const std::vector<BigInt>& vec, size_t idx); diff --git a/src/lib/pubkey/sm2/sm2_enc.h b/src/lib/pubkey/sm2/sm2_enc.h index 1384d3726..ea8c43d9d 100644 --- a/src/lib/pubkey/sm2/sm2_enc.h +++ b/src/lib/pubkey/sm2/sm2_enc.h @@ -10,4 +10,6 @@ #include <botan/sm2.h> +BOTAN_DEPRECATED_HEADER(sm2_enc.h) + #endif diff --git a/src/lib/utils/compiler.h b/src/lib/utils/compiler.h index c515e0507..abb2a79f0 100644 --- a/src/lib/utils/compiler.h +++ b/src/lib/utils/compiler.h @@ -100,13 +100,16 @@ #if defined(__clang__) #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated)) + #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("message \"this header is deprecated\"") #elif defined(_MSC_VER) #define BOTAN_DEPRECATED(msg) __declspec(deprecated(msg)) + #define BOTAN_DEPRECATED_HEADER(hdr) __pragma("message \"this header is deprecated\"") #elif defined(__GNUG__) /* msg supported since GCC 4.5, earliest we support is 4.8 */ #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg))) + #define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("GCC warning \"this header is deprecated\"") #endif #endif @@ -115,6 +118,10 @@ #define BOTAN_DEPRECATED(msg) #endif +#if !defined(BOTAN_DEPRECATED_HEADER) + #define BOTAN_DEPRECATED_HEADER(hdr) +#endif + /* * Define BOTAN_NORETURN */ diff --git a/src/tests/test_filters.cpp b/src/tests/test_filters.cpp index 33649e56a..e99329327 100644 --- a/src/tests/test_filters.cpp +++ b/src/tests/test_filters.cpp @@ -16,15 +16,9 @@ #include <botan/pipe.h> #include <botan/filters.h> #include <botan/data_snk.h> - #include <botan/comp_filter.h> #include <botan/cipher_filter.h> #endif -#if defined(BOTAN_HAS_CODEC_FILTERS) - #include <botan/hex_filt.h> - #include <botan/b64_filt.h> -#endif - #if defined(BOTAN_HAS_PIPE_UNIXFD_IO) #include <botan/fd_unix.h> #include <unistd.h> |