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