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