Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

algo_filt.cpp
Go to the documentation of this file.
1 /*
2 * Filters
3 * (C) 1999-2007,2015 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/filters.h>
9 #include <algorithm>
10
11 namespace Botan {
12
13 StreamCipher_Filter::StreamCipher_Filter(StreamCipher* cipher) :
14 m_buffer(DEFAULT_BUFFERSIZE),
15 m_cipher(cipher)
16 {
17 }
18
19 StreamCipher_Filter::StreamCipher_Filter(StreamCipher* cipher, const SymmetricKey& key) :
20 m_buffer(DEFAULT_BUFFERSIZE),
21 m_cipher(cipher)
22 {
23 m_cipher->set_key(key);
24 }
25
26 StreamCipher_Filter::StreamCipher_Filter(const std::string& sc_name) :
27 m_buffer(DEFAULT_BUFFERSIZE),
28 m_cipher(StreamCipher::create_or_throw(sc_name))
29 {
30 }
31
32 StreamCipher_Filter::StreamCipher_Filter(const std::string& sc_name, const SymmetricKey& key) :
33 m_buffer(DEFAULT_BUFFERSIZE),
34 m_cipher(StreamCipher::create_or_throw(sc_name))
35 {
36 m_cipher->set_key(key);
37 }
38
39 void StreamCipher_Filter::write(const uint8_t input[], size_t length)
40 {
41 while(length)
42 {
43 size_t copied = std::min<size_t>(length, m_buffer.size());
44 m_cipher->cipher(input, m_buffer.data(), copied);
45 send(m_buffer, copied);
46 input += copied;
47 length -= copied;
48 }
49 }
50
51 Hash_Filter::Hash_Filter(const std::string& hash_name, size_t len) :
52 m_hash(HashFunction::create_or_throw(hash_name)),
53 m_out_len(len)
54 {
55 }
56
57 void Hash_Filter::end_msg()
58 {
59 secure_vector<uint8_t> output = m_hash->final();
60 if(m_out_len)
61 send(output, std::min<size_t>(m_out_len, output.size()));
62 else
63 send(output);
64 }
65
66 MAC_Filter::MAC_Filter(const std::string& mac_name, size_t len) :
67 m_mac(MessageAuthenticationCode::create_or_throw(mac_name)),
68 m_out_len(len)
69 {
70 }
71
72 MAC_Filter::MAC_Filter(const std::string& mac_name, const SymmetricKey& key, size_t len) :
73 m_mac(MessageAuthenticationCode::create_or_throw(mac_name)),
74 m_out_len(len)
75 {
76 m_mac->set_key(key);
77 }
78
79 void MAC_Filter::end_msg()
80 {
81 secure_vector<uint8_t> output = m_mac->final();
82 if(m_out_len)
83 send(output, std::min<size_t>(m_out_len, output.size()));
84 else
85 send(output);
86 }
87
88 }
Botan::OctetString
Definition: symkey.h:19
m_mac
std::unique_ptr< MessageAuthenticationCode > m_mac
Definition: fpe_fe1.cpp:88
Botan::MAC_Filter::end_msg
void end_msg() override
Definition: algo_filt.cpp:79
Botan::Filter::send
virtual void send(const uint8_t in[], size_t length)
Definition: filter.cpp:27
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::StreamCipher
Definition: stream_cipher.h:19
Botan::StreamCipher_Filter::StreamCipher_Filter
StreamCipher_Filter(StreamCipher *cipher)
Definition: algo_filt.cpp:13
Botan
Definition: alg_id.cpp:13
Botan::StreamCipher_Filter::write
void write(const uint8_t input[], size_t input_len) override
Definition: algo_filt.cpp:39
Botan::HashFunction
Definition: hash.h:19
Botan::Hash_Filter::Hash_Filter
Hash_Filter(HashFunction *hash, size_t len=0)
Definition: filters.h:113
m_hash
std::unique_ptr< HashFunction > m_hash
Definition: tpm.cpp:439
Botan::MAC_Filter::MAC_Filter
MAC_Filter(MessageAuthenticationCode *mac, size_t out_len=0)
Definition: filters.h:158
Botan::Hash_Filter::end_msg
void end_msg() override
Definition: algo_filt.cpp:57