Botan: src/filters/modes/cbc/cbc.h Source File

Botan 1.10.16

cbc.h
Go to the documentation of this file.
1 /*
2 * CBC Mode
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_CBC_H__
9 #define BOTAN_CBC_H__
10
11 #include <botan/block_cipher.h>
12 #include <botan/key_filt.h>
13 #include <botan/mode_pad.h>
14 #include <botan/buf_filt.h>
15
16 namespace Botan {
17
18 /**
19 * CBC Encryption
20 */
21 class BOTAN_DLL CBC_Encryption : public Keyed_Filter,
22 private Buffered_Filter
23 {
24 public:
25 std::string name() const;
26
27 void set_iv(const InitializationVector& iv);
28
29 void set_key(const SymmetricKey& key) { cipher->set_key(key); }
30
31 bool valid_keylength(size_t key_len) const
32 { return cipher->valid_keylength(key_len); }
33
34 bool valid_iv_length(size_t iv_len) const
35 { return (iv_len == cipher->block_size()); }
36
37 CBC_Encryption(BlockCipher* cipher,
38 BlockCipherModePaddingMethod* padding);
39
40 CBC_Encryption(BlockCipher* cipher,
41 BlockCipherModePaddingMethod* padding,
42 const SymmetricKey& key,
43 const InitializationVector& iv);
44
45 ~CBC_Encryption() { delete cipher; delete padder; }
46 private:
47 void buffered_block(const byte input[], size_t input_length);
48 void buffered_final(const byte input[], size_t input_length);
49
50 void write(const byte input[], size_t input_length);
51 void end_msg();
52
53 BlockCipher* cipher;
54 const BlockCipherModePaddingMethod* padder;
55 SecureVector<byte> state;
56 };
57
58 /**
59 * CBC Decryption
60 */
61 class BOTAN_DLL CBC_Decryption : public Keyed_Filter,
62 private Buffered_Filter
63 {
64 public:
65 std::string name() const;
66
67 void set_iv(const InitializationVector& iv);
68
69 void set_key(const SymmetricKey& key) { cipher->set_key(key); }
70
71 bool valid_keylength(size_t key_len) const
72 { return cipher->valid_keylength(key_len); }
73
74 bool valid_iv_length(size_t iv_len) const
75 { return (iv_len == cipher->block_size()); }
76
77 CBC_Decryption(BlockCipher* cipher,
78 BlockCipherModePaddingMethod* padding);
79
80 CBC_Decryption(BlockCipher* cipher,
81 BlockCipherModePaddingMethod* padding,
82 const SymmetricKey& key,
83 const InitializationVector& iv);
84
85 ~CBC_Decryption() { delete cipher; delete padder; }
86 private:
87 void buffered_block(const byte input[], size_t input_length);
88 void buffered_final(const byte input[], size_t input_length);
89
90 void write(const byte[], size_t);
91 void end_msg();
92
93 BlockCipher* cipher;
94 const BlockCipherModePaddingMethod* padder;
95 SecureVector<byte> state, temp;
96 };
97
98 }
99
100 #endif
Botan::Buffered_Filter
Definition: buf_filt.h:19
Botan::CBC_Encryption::valid_keylength
bool valid_keylength(size_t key_len) const
Definition: cbc.h:31
Botan::CBC_Decryption::valid_keylength
bool valid_keylength(size_t key_len) const
Definition: cbc.h:71
Botan::OctetString
Definition: symkey.h:19
Botan::CBC_Encryption::valid_iv_length
bool valid_iv_length(size_t iv_len) const
Definition: cbc.h:34
Botan::Keyed_Filter
Definition: key_filt.h:20
Botan::CBC_Decryption::~CBC_Decryption
~CBC_Decryption()
Definition: cbc.h:85
Botan::CBC_Decryption::valid_iv_length
bool valid_iv_length(size_t iv_len) const
Definition: cbc.h:74
Botan::CBC_Decryption
Definition: cbc.h:61
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::CBC_Encryption
Definition: cbc.h:21
Botan
Definition: algo_base.h:14
Botan::BlockCipherModePaddingMethod
Definition: mode_pad.h:25
Botan::CBC_Encryption::set_key
void set_key(const SymmetricKey &key)
Definition: cbc.h:29
Botan::CBC_Encryption::~CBC_Encryption
~CBC_Encryption()
Definition: cbc.h:45
Botan::CBC_Decryption::set_key
void set_key(const SymmetricKey &key)
Definition: cbc.h:69
Botan::SecureVector< byte >
Botan::BlockCipher
Definition: block_cipher.h:18