Botan  2.6.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 #if defined(BOTAN_HAS_AES_POWER8)
52  void power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
53  void power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
54 #endif
55 
56  secure_vector<uint32_t> m_EK, m_DK;
57  secure_vector<uint8_t> m_ME, m_MD;
58  };
59 
60 /**
61 * AES-192
62 */
63 class BOTAN_PUBLIC_API(2,0) AES_192 final : public Block_Cipher_Fixed_Params<16, 24>
64  {
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  std::string name() const override { return "AES-192"; }
73  BlockCipher* clone() const override { return new AES_192; }
74  size_t parallelism() const override;
75 
76  private:
77 #if defined(BOTAN_HAS_AES_SSSE3)
78  void ssse3_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
79  void ssse3_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
80  void ssse3_key_schedule(const uint8_t key[], size_t length);
81 #endif
82 
83 #if defined(BOTAN_HAS_AES_NI)
84  void aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
85  void aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
86  void aesni_key_schedule(const uint8_t key[], size_t length);
87 #endif
88 
89 #if defined(BOTAN_HAS_AES_ARMV8)
90  void armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
91  void armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
92 #endif
93 
94 #if defined(BOTAN_HAS_AES_POWER8)
95  void power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
96  void power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
97 #endif
98 
99  void key_schedule(const uint8_t key[], size_t length) override;
100 
101  secure_vector<uint32_t> m_EK, m_DK;
102  secure_vector<uint8_t> m_ME, m_MD;
103  };
104 
105 /**
106 * AES-256
107 */
108 class BOTAN_PUBLIC_API(2,0) AES_256 final : public Block_Cipher_Fixed_Params<16, 32>
109  {
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  std::string name() const override { return "AES-256"; }
119  BlockCipher* clone() const override { return new AES_256; }
120  size_t parallelism() const override;
121 
122  private:
123 #if defined(BOTAN_HAS_AES_SSSE3)
124  void ssse3_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
125  void ssse3_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
126  void ssse3_key_schedule(const uint8_t key[], size_t length);
127 #endif
128 
129 #if defined(BOTAN_HAS_AES_NI)
130  void aesni_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
131  void aesni_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
132  void aesni_key_schedule(const uint8_t key[], size_t length);
133 #endif
134 
135 #if defined(BOTAN_HAS_AES_ARMV8)
136  void armv8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
137  void armv8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
138 #endif
139 
140 #if defined(BOTAN_HAS_AES_POWER8)
141  void power8_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
142  void power8_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
143 #endif
144 
145  void key_schedule(const uint8_t key[], size_t length) override;
146 
147  secure_vector<uint32_t> m_EK, m_DK;
148  secure_vector<uint8_t> m_ME, m_MD;
149  };
150 
151 }
152 
153 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
std::string name() const override
Definition: aes.h:118
BlockCipher * clone() const override
Definition: aes.h:119
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:73
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
std::string name() const override
Definition: aes.h:72