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

Botan 1.10.17

eax.h
Go to the documentation of this file.
1 /*
2 * EAX Mode
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_EAX_H__
9 #define BOTAN_EAX_H__
10
11 #include <botan/key_filt.h>
12 #include <botan/block_cipher.h>
13 #include <botan/stream_cipher.h>
14 #include <botan/mac.h>
15
16 namespace Botan {
17
18 /**
19 * EAX Base Class
20 */
21 class BOTAN_DLL EAX_Base : public Keyed_Filter
22 {
23 public:
24 void set_key(const SymmetricKey& key);
25 void set_iv(const InitializationVector& iv);
26
27 /**
28 * Set some additional data that is not included in the
29 * ciphertext but that will be authenticated.
30 * @param header the header contents
31 * @param header_len length of header in bytes
32 */
33 void set_header(const byte header[], size_t header_len);
34
35 /**
36 * @return name of this mode
37 */
38 std::string name() const;
39
40 bool valid_keylength(size_t key_len) const;
41
42 /**
43 * EAX supports arbitrary IV lengths
44 */
45 bool valid_iv_length(size_t) const { return true; }
46
47 ~EAX_Base() { delete ctr; delete cmac; }
48 protected:
49 /**
50 * @param cipher the cipher to use
51 * @param tag_size is how big the auth tag will be
52 */
53 EAX_Base(BlockCipher* cipher, size_t tag_size);
54 void start_msg();
55
56 /**
57 * The block size of the underlying cipher
58 */
59 const size_t BLOCK_SIZE;
60
61 /**
62 * The requested tag name
63 */
64 const size_t TAG_SIZE;
65
66 /**
67 * The name of the cipher
68 */
69 std::string cipher_name;
70
71 /**
72 * The stream cipher (CTR mode)
73 */
74 StreamCipher* ctr;
75
76 /**
77 * The MAC (CMAC)
78 */
79 MessageAuthenticationCode* cmac;
80
81 /**
82 * The MAC of the nonce
83 */
84 SecureVector<byte> nonce_mac;
85
86 /**
87 * The MAC of the header
88 */
89 SecureVector<byte> header_mac;
90
91 /**
92 * A buffer for CTR mode encryption
93 */
94 SecureVector<byte> ctr_buf;
95 };
96
97 /**
98 * EAX Encryption
99 */
100 class BOTAN_DLL EAX_Encryption : public EAX_Base
101 {
102 public:
103 /**
104 * @param ciph the cipher to use
105 * @param tag_size is how big the auth tag will be
106 */
107 EAX_Encryption(BlockCipher* ciph, size_t tag_size = 0) :
108 EAX_Base(ciph, tag_size) {}
109
110 /**
111 * @param ciph the cipher to use
112 * @param key the key to use
113 * @param iv the initially set IV
114 * @param tag_size is how big the auth tag will be
115 */
116 EAX_Encryption(BlockCipher* ciph, const SymmetricKey& key,
117 const InitializationVector& iv,
118 size_t tag_size) : EAX_Base(ciph, tag_size)
119 {
120 set_key(key);
121 set_iv(iv);
122 }
123 private:
124 void write(const byte[], size_t);
125 void end_msg();
126 };
127
128 /**
129 * EAX Decryption
130 */
131 class BOTAN_DLL EAX_Decryption : public EAX_Base
132 {
133 public:
134 /**
135 * @param ciph the cipher to use
136 * @param tag_size is how big the auth tag will be
137 */
138 EAX_Decryption(BlockCipher* ciph, size_t tag_size = 0);
139
140 /**
141 * @param ciph the cipher to use
142 * @param key the key to use
143 * @param iv the initially set IV
144 * @param tag_size is how big the auth tag will be
145 */
146 EAX_Decryption(BlockCipher* ciph, const SymmetricKey& key,
147 const InitializationVector& iv,
148 size_t tag_size = 0);
149 private:
150 void write(const byte[], size_t);
151 void do_write(const byte[], size_t);
152 void end_msg();
153
154 SecureVector<byte> queue;
155 size_t queue_start, queue_end;
156 };
157
158 }
159
160 #endif
Botan::EAX_Base::valid_iv_length
bool valid_iv_length(size_t) const
Definition: eax.h:45
Botan::EAX_Base::ctr
StreamCipher * ctr
Definition: eax.h:74
Botan::OctetString
Definition: symkey.h:19
Botan::EAX_Base::ctr_buf
SecureVector< byte > ctr_buf
Definition: eax.h:94
Botan::EAX_Base::header_mac
SecureVector< byte > header_mac
Definition: eax.h:89
Botan::Keyed_Filter
Definition: key_filt.h:20
Botan::EAX_Base::TAG_SIZE
const size_t TAG_SIZE
Definition: eax.h:64
Botan::EAX_Base::cmac
MessageAuthenticationCode * cmac
Definition: eax.h:79
Botan::EAX_Base::cipher_name
std::string cipher_name
Definition: eax.h:69
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::EAX_Decryption
Definition: eax.h:131
Botan::EAX_Encryption
Definition: eax.h:100
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::StreamCipher
Definition: stream_cipher.h:18
Botan::EAX_Encryption::EAX_Encryption
EAX_Encryption(BlockCipher *ciph, const SymmetricKey &key, const InitializationVector &iv, size_t tag_size)
Definition: eax.h:116
Botan::EAX_Base
Definition: eax.h:21
Botan
Definition: algo_base.h:14
Botan::EAX_Base::BLOCK_SIZE
const size_t BLOCK_SIZE
Definition: eax.h:59
Botan::SecureVector< byte >
Botan::EAX_Encryption::EAX_Encryption
EAX_Encryption(BlockCipher *ciph, size_t tag_size=0)
Definition: eax.h:107
Botan::EAX_Base::nonce_mac
SecureVector< byte > nonce_mac
Definition: eax.h:84
Botan::EAX_Base::~EAX_Base
~EAX_Base()
Definition: eax.h:47
Botan::BlockCipher
Definition: block_cipher.h:18