diff options
author | lloyd <[email protected]> | 2008-09-28 23:10:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 23:10:52 +0000 |
commit | fda3e1b51fbb539e3689e23148be08783afe0e21 (patch) | |
tree | 1419c8a7a9a1d179679185d6d09c8e427d34706b /src | |
parent | 8820c122b9cd665621729abfcf8c6751762535df (diff) |
New filters module. Add deps for it in some needed areas (codec, pbes)
Diffstat (limited to 'src')
-rw-r--r-- | src/cms/modinfo.txt | 5 | ||||
-rw-r--r-- | src/codec/openpgp/modinfo.txt | 1 | ||||
-rw-r--r-- | src/codec/pem/modinfo.txt | 1 | ||||
-rw-r--r-- | src/entropy/buf_es/modinfo.txt | 10 | ||||
-rw-r--r-- | src/filters/algo_filt.cpp (renamed from src/algo_filt.cpp) | 0 | ||||
-rw-r--r-- | src/filters/basefilt.cpp (renamed from src/basefilt.cpp) | 0 | ||||
-rw-r--r-- | src/filters/basefilt.h | 55 | ||||
-rw-r--r-- | src/filters/buf_filt.cpp (renamed from src/buf_filt.cpp) | 0 | ||||
-rw-r--r-- | src/filters/buf_filt.h | 35 | ||||
-rw-r--r-- | src/filters/data_snk.h | 48 | ||||
-rw-r--r-- | src/filters/filter.cpp (renamed from src/filter.cpp) | 0 | ||||
-rw-r--r-- | src/filters/filter.h | 70 | ||||
-rw-r--r-- | src/filters/filters.h | 78 | ||||
-rw-r--r-- | src/filters/modinfo.txt | 25 | ||||
-rw-r--r-- | src/filters/out_buf.cpp (renamed from src/out_buf.cpp) | 0 | ||||
-rw-r--r-- | src/filters/out_buf.h | 41 | ||||
-rw-r--r-- | src/filters/pipe.cpp (renamed from src/pipe.cpp) | 0 | ||||
-rw-r--r-- | src/filters/pipe.h | 100 | ||||
-rw-r--r-- | src/filters/pipe_io.cpp (renamed from src/pipe_io.cpp) | 0 | ||||
-rw-r--r-- | src/filters/pipe_rw.cpp (renamed from src/pipe_rw.cpp) | 0 | ||||
-rw-r--r-- | src/filters/secqueue.cpp (renamed from src/secqueue.cpp) | 0 | ||||
-rw-r--r-- | src/filters/secqueue.h | 41 | ||||
-rw-r--r-- | src/pbe/pbes1/modinfo.txt | 5 | ||||
-rw-r--r-- | src/pbe/pbes2/modinfo.txt | 5 |
24 files changed, 520 insertions, 0 deletions
diff --git a/src/cms/modinfo.txt b/src/cms/modinfo.txt index eb5b3e624..9dcb40043 100644 --- a/src/cms/modinfo.txt +++ b/src/cms/modinfo.txt @@ -14,3 +14,8 @@ cms_ealg.cpp cms_enc.cpp cms_enc.h </add> + +<requires> +asn1 +filters +</requires> diff --git a/src/codec/openpgp/modinfo.txt b/src/codec/openpgp/modinfo.txt index 4fd298104..0fe934ad9 100644 --- a/src/codec/openpgp/modinfo.txt +++ b/src/codec/openpgp/modinfo.txt @@ -9,4 +9,5 @@ openpgp.h <requires> base64 +filters </requires> diff --git a/src/codec/pem/modinfo.txt b/src/codec/pem/modinfo.txt index 53d3d40d5..bbe8d4c70 100644 --- a/src/codec/pem/modinfo.txt +++ b/src/codec/pem/modinfo.txt @@ -11,4 +11,5 @@ pem.h <requires> base64 +filters </requires> diff --git a/src/entropy/buf_es/modinfo.txt b/src/entropy/buf_es/modinfo.txt new file mode 100644 index 000000000..b30ece6e6 --- /dev/null +++ b/src/entropy/buf_es/modinfo.txt @@ -0,0 +1,10 @@ +realname "Buffered Entropy Source" + +define BUFFERED_ENTROPY_SOURCE + +load_on auto + +<add> +buf_es.cpp +buf_es.h +</add> diff --git a/src/algo_filt.cpp b/src/filters/algo_filt.cpp index 2c8402601..2c8402601 100644 --- a/src/algo_filt.cpp +++ b/src/filters/algo_filt.cpp diff --git a/src/basefilt.cpp b/src/filters/basefilt.cpp index f1f30c463..f1f30c463 100644 --- a/src/basefilt.cpp +++ b/src/filters/basefilt.cpp diff --git a/src/filters/basefilt.h b/src/filters/basefilt.h new file mode 100644 index 000000000..d6c5b1e0b --- /dev/null +++ b/src/filters/basefilt.h @@ -0,0 +1,55 @@ +/************************************************* +* Basic Filters Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_BASEFILT_H__ +#define BOTAN_BASEFILT_H__ + +#include <botan/filter.h> + +namespace Botan { + +/************************************************* +* Chain * +*************************************************/ +class BOTAN_DLL Chain : public Fanout_Filter + { + public: + void write(const byte input[], u32bit length) { send(input, length); } + + Chain(Filter* = 0, Filter* = 0, Filter* = 0, Filter* = 0); + Chain(Filter*[], u32bit); + }; + +/************************************************* +* Fork * +*************************************************/ +class BOTAN_DLL Fork : public Fanout_Filter + { + public: + void write(const byte input[], u32bit length) { send(input, length); } + void set_port(u32bit n) { Fanout_Filter::set_port(n); } + + Fork(Filter*, Filter*, Filter* = 0, Filter* = 0); + Fork(Filter*[], u32bit); + }; + +/************************************************* +* Keyed Filter * +*************************************************/ +class BOTAN_DLL Keyed_Filter : public Filter + { + public: + virtual void set_key(const SymmetricKey&); + virtual void set_iv(const InitializationVector&) {} + virtual bool valid_keylength(u32bit) const; + + Keyed_Filter() { base_ptr = 0; } + protected: + SymmetricAlgorithm* base_ptr; + }; + +} + +#endif diff --git a/src/buf_filt.cpp b/src/filters/buf_filt.cpp index 7acd37435..7acd37435 100644 --- a/src/buf_filt.cpp +++ b/src/filters/buf_filt.cpp diff --git a/src/filters/buf_filt.h b/src/filters/buf_filt.h new file mode 100644 index 000000000..290c7eb75 --- /dev/null +++ b/src/filters/buf_filt.h @@ -0,0 +1,35 @@ +/************************************************* +* Buffering Filter Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_BUFFERING_FILTER_H__ +#define BOTAN_BUFFERING_FILTER_H__ + +#include <botan/filter.h> + +namespace Botan { + +/************************************************* +* Buffering Filter * +*************************************************/ +class BOTAN_DLL Buffering_Filter : public Filter + { + public: + void write(const byte[], u32bit); + virtual void end_msg(); + Buffering_Filter(u32bit, u32bit = 0); + virtual ~Buffering_Filter() {} + protected: + virtual void initial_block(const byte[]) {} + virtual void main_block(const byte[]) = 0; + virtual void final_block(const byte[], u32bit) = 0; + private: + const u32bit INITIAL_BLOCK_SIZE, BLOCK_SIZE; + SecureVector<byte> initial, block; + u32bit initial_block_pos, block_pos; + }; + +} + +#endif diff --git a/src/filters/data_snk.h b/src/filters/data_snk.h new file mode 100644 index 000000000..9afe9bc4e --- /dev/null +++ b/src/filters/data_snk.h @@ -0,0 +1,48 @@ +/************************************************* +* DataSink Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_DATA_SINK_H__ +#define BOTAN_DATA_SINK_H__ + +#include <botan/filter.h> +#include <iosfwd> + +namespace Botan { + +/************************************************* +* Generic DataSink Interface * +*************************************************/ +class BOTAN_DLL DataSink : public Filter + { + public: + bool attachable() { return false; } + DataSink() {} + virtual ~DataSink() {} + private: + DataSink& operator=(const DataSink&) { return (*this); } + DataSink(const DataSink&); + }; + +/************************************************* +* Stream-Based DataSink * +*************************************************/ +class BOTAN_DLL DataSink_Stream : public DataSink + { + public: + void write(const byte[], u32bit); + + DataSink_Stream(std::ostream&, const std::string& = ""); + DataSink_Stream(const std::string&, bool = false); + ~DataSink_Stream(); + private: + const std::string identifier; + const bool owner; + + std::ostream* sink; + }; + +} + +#endif diff --git a/src/filter.cpp b/src/filters/filter.cpp index 253f20c32..253f20c32 100644 --- a/src/filter.cpp +++ b/src/filters/filter.cpp diff --git a/src/filters/filter.h b/src/filters/filter.h new file mode 100644 index 000000000..c73bda1be --- /dev/null +++ b/src/filters/filter.h @@ -0,0 +1,70 @@ +/************************************************* +* Filter Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_FILTER_H__ +#define BOTAN_FILTER_H__ + +#include <botan/base.h> +#include <vector> + +namespace Botan { + +/************************************************* +* Filter Base Class * +*************************************************/ +class BOTAN_DLL Filter + { + public: + virtual void write(const byte[], u32bit) = 0; + virtual void start_msg() {} + virtual void end_msg() {} + virtual bool attachable() { return true; } + void new_msg(); + void finish_msg(); + virtual ~Filter() {} + protected: + void send(const byte[], u32bit); + void send(byte input) { send(&input, 1); } + void send(const MemoryRegion<byte>& in) { send(in.begin(), in.size()); } + Filter(); + private: + Filter(const Filter&) {} + Filter& operator=(const Filter&) { return (*this); } + + friend class Pipe; + friend class Fanout_Filter; + + u32bit total_ports() const; + u32bit current_port() const { return port_num; } + void set_port(u32bit); + + u32bit owns() const { return filter_owns; } + + void attach(Filter*); + void set_next(Filter*[], u32bit); + Filter* get_next() const; + + SecureVector<byte> write_queue; + std::vector<Filter*> next; + u32bit port_num, filter_owns; + bool owned; + }; + +/************************************************* +* Fanout Filter Base Class * +*************************************************/ +class BOTAN_DLL Fanout_Filter : public Filter + { + protected: + void incr_owns() { ++filter_owns; } + + void set_port(u32bit n) { Filter::set_port(n); } + void set_next(Filter* f[], u32bit n) { Filter::set_next(f, n); } + void attach(Filter* f) { Filter::attach(f); } + }; + +} + +#endif diff --git a/src/filters/filters.h b/src/filters/filters.h new file mode 100644 index 000000000..926217a5d --- /dev/null +++ b/src/filters/filters.h @@ -0,0 +1,78 @@ +/************************************************* +* Filters Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_FILTERS_H__ +#define BOTAN_FILTERS_H__ + +#include <botan/pipe.h> +#include <botan/basefilt.h> +#include <botan/data_snk.h> + +#if defined(BOTAN_HAS_BASE64_CODEC) + #include <botan/base64.h> +#endif + +#if defined(BOTAN_HAS_HEX_CODEC) + #include <botan/hex.h> +#endif + +namespace Botan { + +/************************************************* +* Stream Cipher Filter * +*************************************************/ +class BOTAN_DLL StreamCipher_Filter : public Keyed_Filter + { + public: + void seek(u32bit position) { cipher->seek(position); } + bool supports_resync() const { return (cipher->IV_LENGTH != 0); } + + void set_iv(const InitializationVector&); + void write(const byte[], u32bit); + + StreamCipher_Filter(const std::string&); + StreamCipher_Filter(const std::string&, const SymmetricKey&); + ~StreamCipher_Filter() { delete cipher; } + private: + SecureVector<byte> buffer; + StreamCipher* cipher; + }; + +/************************************************* +* Hash Filter * +*************************************************/ +class BOTAN_DLL Hash_Filter : public Filter + { + public: + void write(const byte input[], u32bit len) { hash->update(input, len); } + void end_msg(); + + Hash_Filter(const std::string&, u32bit = 0); + ~Hash_Filter() { delete hash; } + private: + const u32bit OUTPUT_LENGTH; + HashFunction* hash; + }; + +/************************************************* +* MessageAuthenticationCode Filter * +*************************************************/ +class BOTAN_DLL MAC_Filter : public Keyed_Filter + { + public: + void write(const byte input[], u32bit len) { mac->update(input, len); } + void end_msg(); + + MAC_Filter(const std::string&, u32bit = 0); + MAC_Filter(const std::string&, const SymmetricKey&, u32bit = 0); + ~MAC_Filter() { delete mac; } + private: + const u32bit OUTPUT_LENGTH; + MessageAuthenticationCode* mac; + }; + +} + +#endif diff --git a/src/filters/modinfo.txt b/src/filters/modinfo.txt new file mode 100644 index 000000000..62e2d9807 --- /dev/null +++ b/src/filters/modinfo.txt @@ -0,0 +1,25 @@ +realname "Pipe/Filter" + +load_on auto + +define FILTERS + +<add> +algo_filt.cpp +basefilt.cpp +buf_filt.cpp +filter.cpp +out_buf.cpp +pipe.cpp +pipe_io.cpp +pipe_rw.cpp +secqueue.cpp +basefilt.h +buf_filt.h +data_snk.h +filter.h +filters.h +out_buf.h +pipe.h +secqueue.h +</add> diff --git a/src/out_buf.cpp b/src/filters/out_buf.cpp index 392592705..392592705 100644 --- a/src/out_buf.cpp +++ b/src/filters/out_buf.cpp diff --git a/src/filters/out_buf.h b/src/filters/out_buf.h new file mode 100644 index 000000000..103ea6cd7 --- /dev/null +++ b/src/filters/out_buf.h @@ -0,0 +1,41 @@ +/************************************************* +* Output Buffer Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_OUTPUT_BUFFER_H__ +#define BOTAN_OUTPUT_BUFFER_H__ + +#include <botan/types.h> +#include <botan/pipe.h> +#include <deque> + +namespace Botan { + +/************************************************* +* Container of output buffers for Pipe * +*************************************************/ +class BOTAN_DLL Output_Buffers + { + public: + u32bit read(byte[], u32bit, Pipe::message_id); + u32bit peek(byte[], u32bit, u32bit, Pipe::message_id) const; + u32bit remaining(Pipe::message_id) const; + + void add(class SecureQueue*); + void retire(); + + Pipe::message_id message_count() const; + + Output_Buffers(); + ~Output_Buffers(); + private: + class SecureQueue* get(Pipe::message_id) const; + + std::deque<SecureQueue*> buffers; + Pipe::message_id offset; + }; + +} + +#endif diff --git a/src/pipe.cpp b/src/filters/pipe.cpp index 228dc3a22..228dc3a22 100644 --- a/src/pipe.cpp +++ b/src/filters/pipe.cpp diff --git a/src/filters/pipe.h b/src/filters/pipe.h new file mode 100644 index 000000000..3c41f6ebe --- /dev/null +++ b/src/filters/pipe.h @@ -0,0 +1,100 @@ +/************************************************* +* Pipe Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_PIPE_H__ +#define BOTAN_PIPE_H__ + +#include <botan/data_src.h> +#include <botan/filter.h> +#include <iosfwd> + +namespace Botan { + +/************************************************* +* Pipe * +*************************************************/ +class BOTAN_DLL Pipe : public DataSource + { + public: + typedef u32bit message_id; + + class Invalid_Message_Number : public Invalid_Argument + { + public: + Invalid_Message_Number(const std::string&, message_id); + }; + + static const message_id LAST_MESSAGE; + static const message_id DEFAULT_MESSAGE; + + void write(const byte[], u32bit); + void write(const MemoryRegion<byte>&); + void write(const std::string&); + void write(DataSource&); + void write(byte); + + void process_msg(const byte[], u32bit); + void process_msg(const MemoryRegion<byte>&); + void process_msg(const std::string&); + void process_msg(DataSource&); + + u32bit remaining(message_id = DEFAULT_MESSAGE) const; + + u32bit read(byte[], u32bit); + u32bit read(byte[], u32bit, message_id); + u32bit read(byte&, message_id = DEFAULT_MESSAGE); + + SecureVector<byte> read_all(message_id = DEFAULT_MESSAGE); + std::string read_all_as_string(message_id = DEFAULT_MESSAGE); + + u32bit peek(byte[], u32bit, u32bit) const; + u32bit peek(byte[], u32bit, u32bit, message_id) const; + u32bit peek(byte&, u32bit, message_id = DEFAULT_MESSAGE) const; + + message_id default_msg() const { return default_read; } + void set_default_msg(message_id); + message_id message_count() const; + bool end_of_data() const; + + void start_msg(); + void end_msg(); + + void prepend(Filter*); + void append(Filter*); + void pop(); + void reset(); + + Pipe(Filter* = 0, Filter* = 0, Filter* = 0, Filter* = 0); + Pipe(Filter*[], u32bit); + ~Pipe(); + private: + Pipe(const Pipe&) : DataSource() {} + Pipe& operator=(const Pipe&) { return (*this); } + void init(); + void destruct(Filter*); + void find_endpoints(Filter*); + void clear_endpoints(Filter*); + + message_id get_message_no(const std::string&, message_id) const; + + Filter* pipe; + class Output_Buffers* outputs; + message_id default_read; + bool inside_msg; + }; + +/************************************************* +* I/O Operators for Pipe * +*************************************************/ +BOTAN_DLL std::ostream& operator<<(std::ostream&, Pipe&); +BOTAN_DLL std::istream& operator>>(std::istream&, Pipe&); + +} + +#endif + +#if defined(BOTAN_HAS_PIPE_UNIXFD_IO) + #include <botan/fd_unix.h> +#endif diff --git a/src/pipe_io.cpp b/src/filters/pipe_io.cpp index 85b695e32..85b695e32 100644 --- a/src/pipe_io.cpp +++ b/src/filters/pipe_io.cpp diff --git a/src/pipe_rw.cpp b/src/filters/pipe_rw.cpp index 58d7dd1ad..58d7dd1ad 100644 --- a/src/pipe_rw.cpp +++ b/src/filters/pipe_rw.cpp diff --git a/src/secqueue.cpp b/src/filters/secqueue.cpp index d5b9a5f5f..d5b9a5f5f 100644 --- a/src/secqueue.cpp +++ b/src/filters/secqueue.cpp diff --git a/src/filters/secqueue.h b/src/filters/secqueue.h new file mode 100644 index 000000000..71d902109 --- /dev/null +++ b/src/filters/secqueue.h @@ -0,0 +1,41 @@ +/************************************************* +* SecureQueue Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_SECURE_QUEUE_H__ +#define BOTAN_SECURE_QUEUE_H__ + +#include <botan/data_src.h> +#include <botan/filter.h> + +namespace Botan { + +/************************************************* +* SecureQueue * +*************************************************/ +class BOTAN_DLL SecureQueue : public Fanout_Filter, public DataSource + { + public: + void write(const byte[], u32bit); + + u32bit read(byte[], u32bit); + u32bit peek(byte[], u32bit, u32bit = 0) const; + + bool end_of_data() const; + u32bit size() const; + bool attachable() { return false; } + + SecureQueue& operator=(const SecureQueue&); + SecureQueue(); + SecureQueue(const SecureQueue&); + ~SecureQueue() { destroy(); } + private: + void destroy(); + class SecureQueueNode* head; + class SecureQueueNode* tail; + }; + +} + +#endif diff --git a/src/pbe/pbes1/modinfo.txt b/src/pbe/pbes1/modinfo.txt index 187fac802..96692a691 100644 --- a/src/pbe/pbes1/modinfo.txt +++ b/src/pbe/pbes1/modinfo.txt @@ -8,3 +8,8 @@ load_on auto pbes1.cpp pbes1.h </add> + +<requires> +asn1 +filters +</requires> diff --git a/src/pbe/pbes2/modinfo.txt b/src/pbe/pbes2/modinfo.txt index ee421363a..a32f95cf0 100644 --- a/src/pbe/pbes2/modinfo.txt +++ b/src/pbe/pbes2/modinfo.txt @@ -8,3 +8,8 @@ load_on auto pbes2.cpp pbes2.h </add> + +<requires> +asn1 +filters +</requires> |