Botan  2.1.0
Crypto and TLS for C++11
cipher_filter.h
Go to the documentation of this file.
1 /*
2 * Filter interface for ciphers
3 * (C) 2013,2016 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_TRANSFORM_FILTER_H__
9 #define BOTAN_TRANSFORM_FILTER_H__
10 
11 #include <botan/cipher_mode.h>
12 #include <botan/key_filt.h>
13 #include <botan/buf_filt.h>
14 
15 namespace Botan {
16 
17 /**
18 * Filter interface for cipher modes
19 */
20 class BOTAN_DLL Cipher_Mode_Filter : public Keyed_Filter,
21  private Buffered_Filter
22  {
23  public:
24  explicit Cipher_Mode_Filter(Cipher_Mode* t);
25 
26  void set_iv(const InitializationVector& iv) override;
27 
28  void set_key(const SymmetricKey& key) override;
29 
30  Key_Length_Specification key_spec() const override;
31 
32  bool valid_iv_length(size_t length) const override;
33 
34  std::string name() const override;
35 
36  protected:
37  const Cipher_Mode& get_mode() const { return *m_mode; }
38 
39  Cipher_Mode& get_mode() { return *m_mode; }
40 
41  private:
42  void write(const uint8_t input[], size_t input_length) override;
43  void start_msg() override;
44  void end_msg() override;
45 
46  void buffered_block(const uint8_t input[], size_t input_length) override;
47  void buffered_final(const uint8_t input[], size_t input_length) override;
48 
49  class Nonce_State
50  {
51  public:
52  explicit Nonce_State(bool allow_null_nonce) : m_fresh_nonce(allow_null_nonce) {}
53 
54  void update(const InitializationVector& iv);
55  std::vector<uint8_t> get();
56  private:
57  bool m_fresh_nonce;
58  std::vector<uint8_t> m_nonce;
59  };
60 
61  Nonce_State m_nonce;
62  std::unique_ptr<Cipher_Mode> m_mode;
63  secure_vector<uint8_t> m_buffer;
64  };
65 
66 // deprecated aliases, will be removed before 2.0
68 typedef Transform_Filter Transformation_Filter;
69 
70 }
71 
72 #endif
OctetString InitializationVector
Definition: symkey.h:141
Transform_Filter Transformation_Filter
Definition: cipher_filter.h:68
Definition: alg_id.cpp:13
Cipher_Mode_Filter Transform_Filter
Definition: cipher_filter.h:67
const Cipher_Mode & get_mode() const
Definition: cipher_filter.h:37
Cipher_Mode & get_mode()
Definition: cipher_filter.h:39