2
Copyright (C) 2000-2007 MySQL AB
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.
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.
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,
19
/* aes.hpp defines AES
23
#ifndef TAO_CRYPT_AES_HPP
24
#define TAO_CRYPT_AES_HPP
30
#if defined(TAOCRYPT_X86ASM_AVAILABLE) && defined(TAO_ASM)
39
enum { AES_BLOCK_SIZE = 16 };
42
// AES encryption and decryption, see FIPS-197
43
class AES : public Mode_BASE {
45
enum { BLOCK_SIZE = AES_BLOCK_SIZE };
47
AES(CipherDir DIR, Mode MODE)
48
: Mode_BASE(BLOCK_SIZE, DIR, MODE) {}
51
void Process(byte*, const byte*, word32);
53
void SetKey(const byte* key, word32 sz, CipherDir fake = ENCRYPTION);
54
void SetIV(const byte* iv) { memcpy(r_, iv, BLOCK_SIZE); }
56
static const word32 rcon_[];
59
word32 key_[60]; // max size
61
static const word32 Te[5][256];
62
static const word32 Td[5][256];
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;
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;
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;
81
void ProcessAndXorBlock(const byte*, const byte*, byte*) const;
83
AES(const AES&); // hide copy
84
AES& operator=(const AES&); // and assign
88
typedef BlockCipher<ENCRYPTION, AES, ECB> AES_ECB_Encryption;
89
typedef BlockCipher<DECRYPTION, AES, ECB> AES_ECB_Decryption;
91
typedef BlockCipher<ENCRYPTION, AES, CBC> AES_CBC_Encryption;
92
typedef BlockCipher<DECRYPTION, AES, CBC> AES_CBC_Decryption;
98
#endif // TAO_CRYPT_AES_HPP