MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aes.hpp
1 /*
2  Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; see the file COPYING. If not, write to the
15  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
16  MA 02110-1301 USA.
17 */
18 
19 /* aes.hpp defines AES
20 */
21 
22 
23 #ifndef TAO_CRYPT_AES_HPP
24 #define TAO_CRYPT_AES_HPP
25 
26 #include "misc.hpp"
27 #include "modes.hpp"
28 
29 
30 #if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
31  #define DO_AES_ASM
32 #endif
33 
34 
35 
36 namespace TaoCrypt {
37 
38 
39 enum { AES_BLOCK_SIZE = 16 };
40 
41 
42 // AES encryption and decryption, see FIPS-197
43 class AES : public Mode_BASE {
44 public:
45  enum { BLOCK_SIZE = AES_BLOCK_SIZE };
46 
47  AES(CipherDir DIR, Mode MODE)
48  : Mode_BASE(BLOCK_SIZE, DIR, MODE) {}
49 
50 #ifdef DO_AES_ASM
51  void Process(byte*, const byte*, word32);
52 #endif
53  void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION);
54  void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); }
55 private:
56  static const word32 rcon_[];
57 
58  word32 rounds_;
59  word32 key_[60]; // max size
60 
61  static const word32 Te[5][256];
62  static const word32 Td[5][256];
63 
64  static const word32* Te0;
65  static const word32* Te1;
66  static const word32* Te2;
67  static const word32* Te3;
68  static const word32* Te4;
69 
70  static const word32* Td0;
71  static const word32* Td1;
72  static const word32* Td2;
73  static const word32* Td3;
74  static const word32* Td4;
75 
76  void encrypt(const byte*, const byte*, byte*) const;
77  void AsmEncrypt(const byte*, byte*, void*) const;
78  void decrypt(const byte*, const byte*, byte*) const;
79  void AsmDecrypt(const byte*, byte*, void*) const;
80 
81  void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
82 
83  AES(const AES&); // hide copy
84  AES& operator=(const AES&); // and assign
85 };
86 
87 
90 
93 
94 
95 } // naemspace
96 
97 #endif // TAO_CRYPT_AES_HPP