/src/botan/build/include/internal/botan/internal/aes.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * AES |
3 | | * (C) 1999-2010 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_AES_H_ |
9 | | #define BOTAN_AES_H_ |
10 | | |
11 | | #include <botan/block_cipher.h> |
12 | | |
13 | | namespace Botan { |
14 | | |
15 | | /** |
16 | | * AES-128 |
17 | | */ |
18 | | class AES_128 final : public Block_Cipher_Fixed_Params<16, 16> { |
19 | | public: |
20 | | void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
21 | | void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
22 | | |
23 | | void clear() override; |
24 | | |
25 | | std::string provider() const override; |
26 | | |
27 | 101 | std::string name() const override { return "AES-128"; } |
28 | | |
29 | 87 | std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<AES_128>(); } |
30 | | |
31 | | size_t parallelism() const override; |
32 | | |
33 | | bool has_keying_material() const override; |
34 | | |
35 | | private: |
36 | | void key_schedule(std::span<const uint8_t> key) override; |
37 | | |
38 | | #if defined(BOTAN_HAS_AES_VPERM) |
39 | | void vperm_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
40 | | void vperm_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
41 | | void vperm_key_schedule(const uint8_t key[], size_t length); |
42 | | #endif |
43 | | |
44 | | #if defined(BOTAN_HAS_AES_NI) |
45 | | void aesni_key_schedule(const uint8_t key[], size_t length); |
46 | | #endif |
47 | | |
48 | | #if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) |
49 | | void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
50 | | void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
51 | | #endif |
52 | | |
53 | | #if defined(BOTAN_HAS_AES_VAES) |
54 | | void x86_vaes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
55 | | void x86_vaes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
56 | | #endif |
57 | | |
58 | | secure_vector<uint32_t> m_EK, m_DK; |
59 | | }; |
60 | | |
61 | | /** |
62 | | * AES-192 |
63 | | */ |
64 | | class AES_192 final : public Block_Cipher_Fixed_Params<16, 24> { |
65 | | public: |
66 | | void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
67 | | void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
68 | | |
69 | | void clear() override; |
70 | | |
71 | | std::string provider() const override; |
72 | | |
73 | 55 | std::string name() const override { return "AES-192"; } |
74 | | |
75 | 0 | std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<AES_192>(); } |
76 | | |
77 | | size_t parallelism() const override; |
78 | | bool has_keying_material() const override; |
79 | | |
80 | | private: |
81 | | #if defined(BOTAN_HAS_AES_VPERM) |
82 | | void vperm_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
83 | | void vperm_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
84 | | void vperm_key_schedule(const uint8_t key[], size_t length); |
85 | | #endif |
86 | | |
87 | | #if defined(BOTAN_HAS_AES_NI) |
88 | | void aesni_key_schedule(const uint8_t key[], size_t length); |
89 | | #endif |
90 | | |
91 | | #if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) |
92 | | void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
93 | | void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
94 | | #endif |
95 | | |
96 | | #if defined(BOTAN_HAS_AES_VAES) |
97 | | void x86_vaes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
98 | | void x86_vaes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
99 | | #endif |
100 | | |
101 | | void key_schedule(std::span<const uint8_t> key) override; |
102 | | |
103 | | secure_vector<uint32_t> m_EK, m_DK; |
104 | | }; |
105 | | |
106 | | /** |
107 | | * AES-256 |
108 | | */ |
109 | | class AES_256 final : public Block_Cipher_Fixed_Params<16, 32> { |
110 | | public: |
111 | | void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
112 | | void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
113 | | |
114 | | void clear() override; |
115 | | |
116 | | std::string provider() const override; |
117 | | |
118 | 57 | std::string name() const override { return "AES-256"; } |
119 | | |
120 | 8 | std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<AES_256>(); } |
121 | | |
122 | | size_t parallelism() const override; |
123 | | bool has_keying_material() const override; |
124 | | |
125 | | private: |
126 | | #if defined(BOTAN_HAS_AES_VPERM) |
127 | | void vperm_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
128 | | void vperm_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
129 | | void vperm_key_schedule(const uint8_t key[], size_t length); |
130 | | #endif |
131 | | |
132 | | #if defined(BOTAN_HAS_AES_NI) |
133 | | void aesni_key_schedule(const uint8_t key[], size_t length); |
134 | | #endif |
135 | | |
136 | | #if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) |
137 | | void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
138 | | void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
139 | | #endif |
140 | | |
141 | | #if defined(BOTAN_HAS_AES_VAES) |
142 | | void x86_vaes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
143 | | void x86_vaes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
144 | | #endif |
145 | | |
146 | | void key_schedule(std::span<const uint8_t> key) override; |
147 | | |
148 | | secure_vector<uint32_t> m_EK, m_DK; |
149 | | }; |
150 | | |
151 | | } // namespace Botan |
152 | | |
153 | | #endif |