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
16namespace Botan {
17
18/**
19* EAX Base Class
20*/
21class 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 */
75
76 /**
77 * The MAC (CMAC)
78 */
80
81 /**
82 * The MAC of the nonce
83 */
85
86 /**
87 * The MAC of the header
88 */
90
91 /**
92 * A buffer for CTR mode encryption
93 */
95 };
96
97/**
98* EAX Encryption
99*/
100class 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 */
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*/
131class 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
const size_t TAG_SIZE
Definition eax.h:64
SecureVector< byte > ctr_buf
Definition eax.h:94
const size_t BLOCK_SIZE
Definition eax.h:59
std::string cipher_name
Definition eax.h:69
SecureVector< byte > header_mac
Definition eax.h:89
MessageAuthenticationCode * cmac
Definition eax.h:79
EAX_Base(BlockCipher *cipher, size_t tag_size)
Definition eax.cpp:38
void set_header(const byte header[], size_t header_len)
Definition eax.cpp:98
SecureVector< byte > nonce_mac
Definition eax.h:84
bool valid_iv_length(size_t) const
Definition eax.h:45
void set_iv(const InitializationVector &iv)
Definition eax.cpp:89
StreamCipher * ctr
Definition eax.h:74
std::string name() const
Definition eax.cpp:106
void set_key(const SymmetricKey &key)
Definition eax.cpp:64
bool valid_keylength(size_t key_len) const
Definition eax.cpp:54
EAX_Decryption(BlockCipher *ciph, size_t tag_size=0)
Definition eax_dec.cpp:18
EAX_Encryption(BlockCipher *ciph, size_t tag_size=0)
Definition eax.h:107
EAX_Encryption(BlockCipher *ciph, const SymmetricKey &key, const InitializationVector &iv, size_t tag_size)
Definition eax.h:116
OctetString SymmetricKey
Definition symkey.h:147
OctetString InitializationVector
Definition symkey.h:152