Botan  2.4.0
Crypto and TLS for C++11
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 
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 */ }
55 
56  private:
57  void start_msg(const uint8_t nonce[], size_t nonce_len) override
58  {
59  if(nonce_len > 0)
60  {
61  m_cipher->set_iv(nonce, nonce_len);
62  }
63  }
64 
65  void key_schedule(const uint8_t key[], size_t length) override
66  {
67  m_cipher->set_key(key, length);
68  }
69 
70  std::unique_ptr<StreamCipher> m_cipher;
71  };
72 
73 }
74 
75 #endif
void clear() override
Definition: stream_mode.h:48
size_t default_nonce_length() const override
Definition: stream_mode.h:39
Key_Length_Specification key_spec() const override
Definition: stream_mode.h:44
std::string name() const override
Definition: stream_mode.h:46
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
size_t process(uint8_t buf[], size_t sz) override
Definition: stream_mode.h:24
size_t output_length(size_t input_length) const override
Definition: stream_mode.h:33
size_t minimum_final_size() const override
Definition: stream_mode.h:37
void finish(secure_vector< uint8_t > &buf, size_t offset) override
Definition: stream_mode.h:30
Definition: alg_id.cpp:13
void reset() override
Definition: stream_mode.h:54
Stream_Cipher_Mode(StreamCipher *cipher)
Definition: stream_mode.h:22
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
bool valid_nonce_length(size_t nonce_len) const override
Definition: stream_mode.h:41
size_t update_granularity() const override
Definition: stream_mode.h:35