3
* (C) 1999-2007,2015 Jack Lloyd
5
* Botan is released under the Simplified BSD License (see license.txt)
8
#ifndef BOTAN_FILTERS_H_
9
#define BOTAN_FILTERS_H_
11
#include <botan/stream_cipher.h>
12
#include <botan/hash.h>
13
#include <botan/mac.h>
15
#include <botan/pipe.h>
16
#include <botan/basefilt.h>
17
#include <botan/key_filt.h>
18
#include <botan/data_snk.h>
20
#if defined(BOTAN_HAS_CODEC_FILTERS)
21
#include <botan/b64_filt.h>
22
#include <botan/hex_filt.h>
28
* Stream Cipher Filter
30
class BOTAN_PUBLIC_API(2,0) StreamCipher_Filter final : public Keyed_Filter
34
std::string name() const override { return m_cipher->name(); }
39
* @param input_len length of input in bytes
41
void write(const uint8_t input[], size_t input_len) override;
43
bool valid_iv_length(size_t iv_len) const override
44
{ return m_cipher->valid_iv_length(iv_len); }
47
* Set the initialization vector for this filter.
48
* @param iv the initialization vector to set
50
void set_iv(const InitializationVector& iv) override
52
m_cipher->set_iv(iv.begin(), iv.length());
56
* Set the key of this filter.
57
* @param key the key to set
59
void set_key(const SymmetricKey& key) override { m_cipher->set_key(key); }
61
Key_Length_Specification key_spec() const override { return m_cipher->key_spec(); }
64
* Construct a stream cipher filter.
65
* @param cipher a cipher object to use
67
explicit StreamCipher_Filter(StreamCipher* cipher);
70
* Construct a stream cipher filter.
71
* @param cipher a cipher object to use
72
* @param key the key to use inside this filter
74
StreamCipher_Filter(StreamCipher* cipher, const SymmetricKey& key);
77
* Construct a stream cipher filter.
78
* @param cipher the name of the desired cipher
80
explicit StreamCipher_Filter(const std::string& cipher);
83
* Construct a stream cipher filter.
84
* @param cipher the name of the desired cipher
85
* @param key the key to use inside this filter
87
StreamCipher_Filter(const std::string& cipher, const SymmetricKey& key);
89
secure_vector<uint8_t> m_buffer;
90
std::unique_ptr<StreamCipher> m_cipher;
96
class BOTAN_PUBLIC_API(2,0) Hash_Filter final : public Filter
99
void write(const uint8_t input[], size_t len) override { m_hash->update(input, len); }
100
void end_msg() override;
102
std::string name() const override { return m_hash->name(); }
105
* Construct a hash filter.
106
* @param hash the hash function to use
107
* @param len the output length of this filter. Leave the default
108
* value 0 if you want to use the full output of the hashfunction
109
* hash. Otherwise, specify a smaller value here so that the
110
* output of the hash algorithm will be cut off.
112
Hash_Filter(HashFunction* hash, size_t len = 0) :
113
m_hash(hash), m_out_len(len) {}
116
* Construct a hash filter.
117
* @param request the name of the hash algorithm to use
118
* @param len the output length of this filter. Leave the default
119
* value 0 if you want to use the full output of the hashfunction
120
* hash. Otherwise, specify a smaller value here so that the
121
* output of the hash algorithm will be cut off.
123
Hash_Filter(const std::string& request, size_t len = 0);
126
std::unique_ptr<HashFunction> m_hash;
127
const size_t m_out_len;
131
* MessageAuthenticationCode Filter.
133
class BOTAN_PUBLIC_API(2,0) MAC_Filter final : public Keyed_Filter
136
void write(const uint8_t input[], size_t len) override { m_mac->update(input, len); }
137
void end_msg() override;
139
std::string name() const override { return m_mac->name(); }
142
* Set the key of this filter.
143
* @param key the key to set
145
void set_key(const SymmetricKey& key) override { m_mac->set_key(key); }
147
Key_Length_Specification key_spec() const override { return m_mac->key_spec(); }
150
* Construct a MAC filter. The MAC key will be left empty.
151
* @param mac the MAC to use
152
* @param out_len the output length of this filter. Leave the default
153
* value 0 if you want to use the full output of the
154
* MAC. Otherwise, specify a smaller value here so that the
155
* output of the MAC will be cut off.
157
MAC_Filter(MessageAuthenticationCode* mac,
158
size_t out_len = 0) :
165
* Construct a MAC filter.
166
* @param mac the MAC to use
167
* @param key the MAC key to use
168
* @param out_len the output length of this filter. Leave the default
169
* value 0 if you want to use the full output of the
170
* MAC. Otherwise, specify a smaller value here so that the
171
* output of the MAC will be cut off.
173
MAC_Filter(MessageAuthenticationCode* mac,
174
const SymmetricKey& key,
175
size_t out_len = 0) :
183
* Construct a MAC filter. The MAC key will be left empty.
184
* @param mac the name of the MAC to use
185
* @param len the output length of this filter. Leave the default
186
* value 0 if you want to use the full output of the
187
* MAC. Otherwise, specify a smaller value here so that the
188
* output of the MAC will be cut off.
190
MAC_Filter(const std::string& mac, size_t len = 0);
193
* Construct a MAC filter.
194
* @param mac the name of the MAC to use
195
* @param key the MAC key to use
196
* @param len the output length of this filter. Leave the default
197
* value 0 if you want to use the full output of the
198
* MAC. Otherwise, specify a smaller value here so that the
199
* output of the MAC will be cut off.
201
MAC_Filter(const std::string& mac, const SymmetricKey& key,
204
std::unique_ptr<MessageAuthenticationCode> m_mac;
205
const size_t m_out_len;