Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

stream_mode.h
Go to the documentation of this file.
1 /*
2 * (C) 2015 Jack Lloyd
3 * (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_STREAM_MODE_H__
9 #define BOTAN_STREAM_MODE_H__
10
11 #include <botan/cipher_mode.h>
12 #include <botan/stream_cipher.h>
13
14 namespace Botan {
15
16 class BOTAN_DLL Stream_Cipher_Mode : public Cipher_Mode
17 {
18 public:
19 /**
20 * @param cipher underyling stream cipher
21 */
22 explicit Stream_Cipher_Mode(StreamCipher* cipher) : m_cipher(cipher) {}
23
24 size_t process(uint8_t buf[], size_t sz) override
25 {
26 m_cipher->cipher1(buf, sz);
27 return sz;
28 }
29
30 void finish(secure_vector<uint8_t>& buf, size_t offset) override
31 { return update(buf, offset); }
32
33 size_t output_length(size_t input_length) const override { return input_length; }
34
35 size_t update_granularity() const override { return 1; }
36
37 size_t minimum_final_size() const override { return 0; }
38
39 size_t default_nonce_length() const override { return 0; }
40
41 bool valid_nonce_length(size_t nonce_len) const override
42 { return m_cipher->valid_iv_length(nonce_len); }
43
44 Key_Length_Specification key_spec() const override { return m_cipher->key_spec(); }
45
46 std::string name() const override { return m_cipher->name(); }
47
48 void clear() override
49 {
50 m_cipher->clear();
51 reset();
52 }
53
54 void reset() override { /* no msg state */ return; }
55
56 private:
57 void start_msg(const uint8_t nonce[], size_t nonce_len) override
58 {
59 m_cipher->set_iv(nonce, nonce_len);
60 }
61
62 void key_schedule(const uint8_t key[], size_t length) override
63 {
64 m_cipher->set_key(key, length);
65 }
66
67 std::unique_ptr<StreamCipher> m_cipher;
68 };
69
70 }
71
72 #endif
Botan::Stream_Cipher_Mode::clear
void clear() override
Definition: stream_mode.h:48
Botan::Stream_Cipher_Mode::default_nonce_length
size_t default_nonce_length() const override
Definition: stream_mode.h:39
Botan::Stream_Cipher_Mode::key_spec
Key_Length_Specification key_spec() const override
Definition: stream_mode.h:44
Botan::Key_Length_Specification
Definition: key_spec.h:18
Botan::Stream_Cipher_Mode::name
std::string name() const override
Definition: stream_mode.h:46
Botan::Stream_Cipher_Mode::process
size_t process(uint8_t buf[], size_t sz) override
Definition: stream_mode.h:24
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::StreamCipher
Definition: stream_cipher.h:19
Botan::Stream_Cipher_Mode::output_length
size_t output_length(size_t input_length) const override
Definition: stream_mode.h:33
Botan::Stream_Cipher_Mode::minimum_final_size
size_t minimum_final_size() const override
Definition: stream_mode.h:37
Botan::Stream_Cipher_Mode::finish
void finish(secure_vector< uint8_t > &buf, size_t offset) override
Definition: stream_mode.h:30
Botan
Definition: alg_id.cpp:13
Botan::Stream_Cipher_Mode::reset
void reset() override
Definition: stream_mode.h:54
Botan::Cipher_Mode
Definition: cipher_mode.h:23
Botan::Stream_Cipher_Mode
Definition: stream_mode.h:16
Botan::Stream_Cipher_Mode::Stream_Cipher_Mode
Stream_Cipher_Mode(StreamCipher *cipher)
Definition: stream_mode.h:22
Botan::Stream_Cipher_Mode::valid_nonce_length
bool valid_nonce_length(size_t nonce_len) const override
Definition: stream_mode.h:41
Botan::Stream_Cipher_Mode::update_granularity
size_t update_granularity() const override
Definition: stream_mode.h:35