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