Botan 3.5.0
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#include <botan/block_cipher.h>
14#include <botan/mac.h>
15#include <botan/stream_cipher.h>
16
17namespace Botan {
18
19/**
20* EAX base class
21*/
22class EAX_Mode : public AEAD_Mode {
23 public:
24 void set_associated_data_n(size_t idx, std::span<const uint8_t> ad) final;
25
26 std::string name() const final;
27
28 size_t update_granularity() const final;
29
30 size_t ideal_granularity() const final;
31
33
34 // EAX supports arbitrary nonce lengths
35 bool valid_nonce_length(size_t) const final { return true; }
36
37 size_t tag_size() const final { return m_tag_size; }
38
39 void clear() final;
40
41 void reset() final;
42
43 bool has_keying_material() const final;
44
45 protected:
46 /**
47 * @param cipher the cipher to use
48 * @param tag_size is how big the auth tag will be
49 */
50 EAX_Mode(std::unique_ptr<BlockCipher> cipher, size_t tag_size);
51
52 size_t block_size() const { return m_cipher->block_size(); }
53
54 size_t m_tag_size;
55
56 std::unique_ptr<BlockCipher> m_cipher;
57 std::unique_ptr<StreamCipher> m_ctr;
58 std::unique_ptr<MessageAuthenticationCode> m_cmac;
59
61
63
64 private:
65 void start_msg(const uint8_t nonce[], size_t nonce_len) final;
66
67 void key_schedule(std::span<const uint8_t> key) final;
68};
69
70/**
71* EAX Encryption
72*/
74 public:
75 /**
76 * @param cipher a 128-bit block cipher
77 * @param tag_size is how big the auth tag will be
78 */
79 EAX_Encryption(std::unique_ptr<BlockCipher> cipher, size_t tag_size = 0) :
80 EAX_Mode(std::move(cipher), tag_size) {}
81
82 size_t output_length(size_t input_length) const override { return input_length + tag_size(); }
83
84 size_t minimum_final_size() const override { return 0; }
85
86 private:
87 size_t process_msg(uint8_t buf[], size_t size) override;
88 void finish_msg(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
89};
90
91/**
92* EAX Decryption
93*/
95 public:
96 /**
97 * @param cipher a 128-bit block cipher
98 * @param tag_size is how big the auth tag will be
99 */
100 EAX_Decryption(std::unique_ptr<BlockCipher> cipher, size_t tag_size = 0) :
101 EAX_Mode(std::move(cipher), tag_size) {}
102
103 size_t output_length(size_t input_length) const override {
104 BOTAN_ARG_CHECK(input_length >= tag_size(), "Sufficient input");
105 return input_length - tag_size();
106 }
107
108 size_t minimum_final_size() const override { return tag_size(); }
109
110 private:
111 size_t process_msg(uint8_t buf[], size_t size) override;
112 void finish_msg(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
113};
114
115} // namespace Botan
116
117#endif
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29
size_t output_length(size_t input_length) const override
Definition eax.h:103
size_t minimum_final_size() const override
Definition eax.h:108
EAX_Decryption(std::unique_ptr< BlockCipher > cipher, size_t tag_size=0)
Definition eax.h:100
EAX_Encryption(std::unique_ptr< BlockCipher > cipher, size_t tag_size=0)
Definition eax.h:79
size_t output_length(size_t input_length) const override
Definition eax.h:82
size_t minimum_final_size() const override
Definition eax.h:84
size_t tag_size() const final
Definition eax.h:37
size_t update_granularity() const final
Definition eax.cpp:69
void set_associated_data_n(size_t idx, std::span< const uint8_t > ad) final
Definition eax.cpp:100
size_t block_size() const
Definition eax.h:52
size_t ideal_granularity() const final
Definition eax.cpp:73
void clear() final
Definition eax.cpp:48
bool valid_nonce_length(size_t) const final
Definition eax.h:35
std::unique_ptr< BlockCipher > m_cipher
Definition eax.h:56
bool has_keying_material() const final
Definition eax.cpp:81
std::unique_ptr< StreamCipher > m_ctr
Definition eax.h:57
std::unique_ptr< MessageAuthenticationCode > m_cmac
Definition eax.h:58
Key_Length_Specification key_spec() const final
Definition eax.cpp:77
secure_vector< uint8_t > m_nonce_mac
Definition eax.h:62
size_t m_tag_size
Definition eax.h:54
void reset() final
Definition eax.cpp:55
std::string name() const final
Definition eax.cpp:65
secure_vector< uint8_t > m_ad_mac
Definition eax.h:60
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61