Botan  2.4.0
Crypto and TLS for C++11
aes.h
Go to the documentation of this file.
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 BOTAN_PUBLIC_API(2,0) 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  std::string name() const override { return "AES-128"; }
28  BlockCipher* clone() const override { return new AES_128; }
29  size_t parallelism() const override;
30 
31  private:
32  void key_schedule(const uint8_t key[], size_t length) override;
33 
34 #if defined(BOTAN_HAS_AES_SSSE3)
35  void ssse3_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
36  void ssse3_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
37  void ssse3_key_schedule(const uint8_t key[], size_t length);
38 #endif
39 
40 #if defined(BOTAN_HAS_AES_NI)
41  void aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
42  void aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
43  void aesni_key_schedule(const uint8_t key[], size_t length);
44 #endif
45 
46 #if defined(BOTAN_HAS_AES_ARMV8)
47  void armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
48  void armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
49 #endif
50 
51  secure_vector<uint32_t> m_EK, m_DK;
52  secure_vector<uint8_t> m_ME, m_MD;
53  };
54 
55 /**
56 * AES-192
57 */
58 class BOTAN_PUBLIC_API(2,0) AES_192 final : public Block_Cipher_Fixed_Params<16, 24>
59  {
60  public:
61  void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
62  void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
63 
64  void clear() override;
65 
66  std::string provider() const override;
67  std::string name() const override { return "AES-192"; }
68  BlockCipher* clone() const override { return new AES_192; }
69  size_t parallelism() const override;
70 
71  private:
72 #if defined(BOTAN_HAS_AES_SSSE3)
73  void ssse3_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
74  void ssse3_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
75  void ssse3_key_schedule(const uint8_t key[], size_t length);
76 #endif
77 
78 #if defined(BOTAN_HAS_AES_NI)
79  void aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
80  void aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
81  void aesni_key_schedule(const uint8_t key[], size_t length);
82 #endif
83 
84 #if defined(BOTAN_HAS_AES_ARMV8)
85  void armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
86  void armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
87 #endif
88 
89  void key_schedule(const uint8_t key[], size_t length) override;
90 
91  secure_vector<uint32_t> m_EK, m_DK;
92  secure_vector<uint8_t> m_ME, m_MD;
93  };
94 
95 /**
96 * AES-256
97 */
98 class BOTAN_PUBLIC_API(2,0) AES_256 final : public Block_Cipher_Fixed_Params<16, 32>
99  {
100  public:
101  void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
102  void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override;
103 
104  void clear() override;
105 
106  std::string provider() const override;
107 
108  std::string name() const override { return "AES-256"; }
109  BlockCipher* clone() const override { return new AES_256; }
110  size_t parallelism() const override;
111 
112  private:
113 #if defined(BOTAN_HAS_AES_SSSE3)
114  void ssse3_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
115  void ssse3_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
116  void ssse3_key_schedule(const uint8_t key[], size_t length);
117 #endif
118 
119 #if defined(BOTAN_HAS_AES_NI)
120  void aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
121  void aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
122  void aesni_key_schedule(const uint8_t key[], size_t length);
123 #endif
124 
125 #if defined(BOTAN_HAS_AES_ARMV8)
126  void armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
127  void armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
128 #endif
129 
130  void key_schedule(const uint8_t key[], size_t length) override;
131 
132  secure_vector<uint32_t> m_EK, m_DK;
133  secure_vector<uint8_t> m_ME, m_MD;
134  };
135 
136 }
137 
138 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
std::string name() const override
Definition: aes.h:108
BlockCipher * clone() const override
Definition: aes.h:109
std::string name() const override
Definition: aes.h:27
BlockCipher * clone() const override
Definition: aes.h:28
Definition: alg_id.cpp:13
BlockCipher * clone() const override
Definition: aes.h:68
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
std::string name() const override
Definition: aes.h:67