Botan 3.5.0
Crypto and TLS for C&
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
13namespace Botan {
14
15/**
16* AES-128
17*/
18class 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 std::string name() const override { return "AES-128"; }
28
29 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 secure_vector<uint32_t> m_EK, m_DK;
54};
55
56/**
57* AES-192
58*/
59class AES_192 final : public Block_Cipher_Fixed_Params<16, 24> {
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
68 std::string name() const override { return "AES-192"; }
69
70 std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<AES_192>(); }
71
72 size_t parallelism() const override;
73 bool has_keying_material() const override;
74
75 private:
76#if defined(BOTAN_HAS_AES_VPERM)
77 void vperm_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
78 void vperm_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
79 void vperm_key_schedule(const uint8_t key[], size_t length);
80#endif
81
82#if defined(BOTAN_HAS_AES_NI)
83 void aesni_key_schedule(const uint8_t key[], size_t length);
84#endif
85
86#if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI)
87 void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
88 void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
89#endif
90
91 void key_schedule(std::span<const uint8_t> key) override;
92
93 secure_vector<uint32_t> m_EK, m_DK;
94};
95
96/**
97* AES-256
98*/
99class AES_256 final : public Block_Cipher_Fixed_Params<16, 32> {
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
110 std::unique_ptr<BlockCipher> new_object() const override { return std::make_unique<AES_256>(); }
111
112 size_t parallelism() const override;
113 bool has_keying_material() const override;
114
115 private:
116#if defined(BOTAN_HAS_AES_VPERM)
117 void vperm_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
118 void vperm_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
119 void vperm_key_schedule(const uint8_t key[], size_t length);
120#endif
121
122#if defined(BOTAN_HAS_AES_NI)
123 void aesni_key_schedule(const uint8_t key[], size_t length);
124#endif
125
126#if defined(BOTAN_HAS_AES_POWER8) || defined(BOTAN_HAS_AES_ARMV8) || defined(BOTAN_HAS_AES_NI)
127 void hw_aes_encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
128 void hw_aes_decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const;
129#endif
130
131 void key_schedule(std::span<const uint8_t> key) override;
132
133 secure_vector<uint32_t> m_EK, m_DK;
134};
135
136} // namespace Botan
137
138#endif
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition aes.cpp:831
std::string provider() const override
Definition aes.cpp:777
size_t parallelism() const override
Definition aes.cpp:789
bool has_keying_material() const override
Definition aes.cpp:801
std::unique_ptr< BlockCipher > new_object() const override
Definition aes.h:29
std::string name() const override
Definition aes.h:27
void clear() override
Definition aes.cpp:871
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition aes.cpp:813
bool has_keying_material() const override
Definition aes.cpp:805
std::string name() const override
Definition aes.h:68
std::unique_ptr< BlockCipher > new_object() const override
Definition aes.h:70
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition aes.cpp:894
std::string provider() const override
Definition aes.cpp:781
size_t parallelism() const override
Definition aes.cpp:793
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition aes.cpp:876
void clear() override
Definition aes.cpp:934
bool has_keying_material() const override
Definition aes.cpp:809
void clear() override
Definition aes.cpp:997
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition aes.cpp:939
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
Definition aes.cpp:957
std::string name() const override
Definition aes.h:108
std::string provider() const override
Definition aes.cpp:785
size_t parallelism() const override
Definition aes.cpp:797
std::unique_ptr< BlockCipher > new_object() const override
Definition aes.h:110
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61