8#include <botan/filters.h>
13#if defined(BOTAN_HAS_STREAM_CIPHER)
15StreamCipher_Filter::StreamCipher_Filter(StreamCipher* cipher) :
16 m_buffer(BOTAN_DEFAULT_BUFFER_SIZE),
21StreamCipher_Filter::StreamCipher_Filter(StreamCipher* cipher,
const SymmetricKey& key) :
22 StreamCipher_Filter(cipher)
24 m_cipher->set_key(key);
27StreamCipher_Filter::StreamCipher_Filter(
const std::string& sc_name) :
28 m_buffer(BOTAN_DEFAULT_BUFFER_SIZE),
29 m_cipher(StreamCipher::create_or_throw(sc_name))
33StreamCipher_Filter::StreamCipher_Filter(
const std::string& sc_name,
const SymmetricKey& key) :
34 StreamCipher_Filter(sc_name)
36 m_cipher->set_key(key);
39void StreamCipher_Filter::write(
const uint8_t input[],
size_t length)
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);
53#if defined(BOTAN_HAS_HASH)
55Hash_Filter::Hash_Filter(
const std::string& hash_name,
size_t len) :
56 m_hash(HashFunction::create_or_throw(hash_name)),
61void Hash_Filter::end_msg()
63 secure_vector<uint8_t> output = m_hash->final();
65 send(output, std::min<size_t>(m_out_len, output.size()));
71#if defined(BOTAN_HAS_MAC)
73MAC_Filter::MAC_Filter(
const std::string& mac_name,
size_t len) :
74 m_mac(MessageAuthenticationCode::create_or_throw(mac_name)),
79MAC_Filter::MAC_Filter(
const std::string& mac_name,
const SymmetricKey& key,
size_t len) :
80 MAC_Filter(mac_name, len)
85void MAC_Filter::end_msg()
87 secure_vector<uint8_t> output = m_mac->final();
89 send(output, std::min<size_t>(m_out_len, output.size()));