/src/botan/build/include/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 | | { |
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 | 998 | std::string name() const override { return "AES-128"; } |
28 | 3.63k | std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<AES_128>(); } |
29 | | size_t parallelism() const override; |
30 | | |
31 | | bool has_keying_material() const override; |
32 | | private: |
33 | | void key_schedule(const uint8_t key[], size_t length) override; |
34 | | |
35 | | #if defined(BOTAN_HAS_AES_VPERM) |
36 | | void vperm_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
37 | | void vperm_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
38 | | void vperm_key_schedule(const uint8_t key[], size_t length); |
39 | | #endif |
40 | | |
41 | | #if defined(BOTAN_HAS_AES_NI) |
42 | | void aesni_key_schedule(const uint8_t key[], size_t length); |
43 | | #endif |
44 | | |
45 | | #if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) |
46 | | void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
47 | | void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
48 | | #endif |
49 | | |
50 | | secure_vector<uint32_t> m_EK, m_DK; |
51 | | }; |
52 | | |
53 | | /** |
54 | | * AES-192 |
55 | | */ |
56 | | class AES_192 final : public Block_Cipher_Fixed_Params<16, 24> |
57 | | { |
58 | | public: |
59 | | void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
60 | | void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
61 | | |
62 | | void clear() override; |
63 | | |
64 | | std::string provider() const override; |
65 | 489 | std::string name() const override { return "AES-192"; } |
66 | 0 | std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<AES_192>(); } |
67 | | size_t parallelism() const override; |
68 | | bool has_keying_material() const override; |
69 | | |
70 | | private: |
71 | | #if defined(BOTAN_HAS_AES_VPERM) |
72 | | void vperm_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
73 | | void vperm_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
74 | | void vperm_key_schedule(const uint8_t key[], size_t length); |
75 | | #endif |
76 | | |
77 | | #if defined(BOTAN_HAS_AES_NI) |
78 | | void aesni_key_schedule(const uint8_t key[], size_t length); |
79 | | #endif |
80 | | |
81 | | #if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) |
82 | | void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
83 | | void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
84 | | #endif |
85 | | |
86 | | void key_schedule(const uint8_t key[], size_t length) override; |
87 | | |
88 | | secure_vector<uint32_t> m_EK, m_DK; |
89 | | }; |
90 | | |
91 | | /** |
92 | | * AES-256 |
93 | | */ |
94 | | class AES_256 final : public Block_Cipher_Fixed_Params<16, 32> |
95 | | { |
96 | | public: |
97 | | void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
98 | | void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; |
99 | | |
100 | | void clear() override; |
101 | | |
102 | | std::string provider() const override; |
103 | | |
104 | 448 | std::string name() const override { return "AES-256"; } |
105 | 484 | std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<AES_256>(); } |
106 | | size_t parallelism() const override; |
107 | | bool has_keying_material() const override; |
108 | | |
109 | | private: |
110 | | #if defined(BOTAN_HAS_AES_VPERM) |
111 | | void vperm_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
112 | | void vperm_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
113 | | void vperm_key_schedule(const uint8_t key[], size_t length); |
114 | | #endif |
115 | | |
116 | | #if defined(BOTAN_HAS_AES_NI) |
117 | | void aesni_key_schedule(const uint8_t key[], size_t length); |
118 | | #endif |
119 | | |
120 | | #if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI) |
121 | | void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
122 | | void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const; |
123 | | #endif |
124 | | |
125 | | void key_schedule(const uint8_t key[], size_t length) override; |
126 | | |
127 | | secure_vector<uint32_t> m_EK, m_DK; |
128 | | }; |
129 | | |
130 | | } |
131 | | |
132 | | #endif |