Botan 3.14.1
Crypto and TLS for C&
eax.h
Go to the documentation of this file.
1/*
2* EAX Mode
3* (C) 1999-2007,2013 Jack Lloyd
4* (C) 2016 Daniel Neus, Rohde & Schwarz Cybersecurity
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_AEAD_EAX_H_
10#define BOTAN_AEAD_EAX_H_
11
12#include <botan/aead.h>
13
14#include <botan/block_cipher.h>
15#include <botan/mac.h>
16#include <botan/stream_cipher.h>
17
18namespace Botan {
19
20/**
21* EAX base class
22*/
23class EAX_Mode : public AEAD_Mode {
24 public:
25 void set_associated_data_n(size_t idx, std::span<const uint8_t> ad) final;
26
27 std::string name() const final;
28
29 size_t update_granularity() const final;
30
31 size_t ideal_granularity() const final;
32
34
35 // EAX supports arbitrary nonce lengths
36 bool valid_nonce_length(size_t /*length*/) const final { return true; }
37
38 size_t tag_size() const final { return m_tag_size; }
39
40 void clear() final;
41
42 void reset() final;
43
44 bool has_keying_material() const final;
45
46 protected:
47 /**
48 * @param cipher the cipher to use
49 * @param tag_size is how big the auth tag will be
50 */
51 EAX_Mode(std::unique_ptr<BlockCipher> cipher, size_t tag_size);
52
53 size_t block_size() const { return m_cipher->block_size(); }
54
55 size_t m_tag_size; // NOLINT(*non-private-member-variable*)
56
57 std::unique_ptr<BlockCipher> m_cipher; // NOLINT(*non-private-member-variable*)
58 std::unique_ptr<StreamCipher> m_ctr; // NOLINT(*non-private-member-variable*)
59 std::unique_ptr<MessageAuthenticationCode> m_cmac; // NOLINT(*non-private-member-variable*)
60
61 secure_vector<uint8_t> m_ad_mac; // NOLINT(*non-private-member-variable*)
62
63 secure_vector<uint8_t> m_nonce_mac; // NOLINT(*non-private-member-variable*)
64
65 private:
66 void start_msg(const uint8_t nonce[], size_t nonce_len) final;
67
68 void key_schedule(std::span<const uint8_t> key) final;
69};
70
71/**
72* EAX Encryption
73*/
74class EAX_Encryption final : public EAX_Mode {
75 public:
76 /**
77 * @param cipher a 128-bit block cipher
78 * @param tag_size is how big the auth tag will be
79 */
80 explicit EAX_Encryption(std::unique_ptr<BlockCipher> cipher, size_t tag_size = 0) :
81 EAX_Mode(std::move(cipher), tag_size) {}
82
83 size_t output_length(size_t input_length) const override;
84
85 size_t minimum_final_size() const override { return 0; }
86
87 private:
88 size_t process_msg(uint8_t buf[], size_t size) override;
89 void finish_msg(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
90};
91
92/**
93* EAX Decryption
94*/
95class EAX_Decryption final : public EAX_Mode {
96 public:
97 /**
98 * @param cipher a 128-bit block cipher
99 * @param tag_size is how big the auth tag will be
100 */
101 explicit EAX_Decryption(std::unique_ptr<BlockCipher> cipher, size_t tag_size = 0) :
102 EAX_Mode(std::move(cipher), tag_size) {}
103
104 size_t output_length(size_t input_length) const override;
105
106 size_t minimum_final_size() const override { return tag_size(); }
107
108 private:
109 size_t process_msg(uint8_t buf[], size_t size) override;
110 void finish_msg(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
111};
112
113} // namespace Botan
114
115#endif
size_t output_length(size_t input_length) const override
Definition eax.cpp:165
size_t minimum_final_size() const override
Definition eax.h:106
EAX_Decryption(std::unique_ptr< BlockCipher > cipher, size_t tag_size=0)
Definition eax.h:101
EAX_Encryption(std::unique_ptr< BlockCipher > cipher, size_t tag_size=0)
Definition eax.h:80
size_t output_length(size_t input_length) const override
Definition eax.cpp:135
size_t minimum_final_size() const override
Definition eax.h:85
size_t tag_size() const final
Definition eax.h:38
size_t update_granularity() const final
Definition eax.cpp:72
void set_associated_data_n(size_t idx, std::span< const uint8_t > ad) final
Definition eax.cpp:110
size_t block_size() const
Definition eax.h:53
size_t ideal_granularity() const final
Definition eax.cpp:76
void clear() final
Definition eax.cpp:51
bool valid_nonce_length(size_t) const final
Definition eax.h:36
std::unique_ptr< BlockCipher > m_cipher
Definition eax.h:57
bool has_keying_material() const final
Definition eax.cpp:84
EAX_Mode(std::unique_ptr< BlockCipher > cipher, size_t tag_size)
Definition eax.cpp:41
std::unique_ptr< StreamCipher > m_ctr
Definition eax.h:58
std::unique_ptr< MessageAuthenticationCode > m_cmac
Definition eax.h:59
Key_Length_Specification key_spec() const final
Definition eax.cpp:80
secure_vector< uint8_t > m_nonce_mac
Definition eax.h:63
size_t m_tag_size
Definition eax.h:55
void reset() final
Definition eax.cpp:59
std::string name() const final
Definition eax.cpp:68
secure_vector< uint8_t > m_ad_mac
Definition eax.h:61
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128