~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to extra/yassl/taocrypt/include/aes.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2000-2007 MySQL AB
 
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
 
 
88
typedef BlockCipher<ENCRYPTION, AES, ECB> AES_ECB_Encryption;
 
89
typedef BlockCipher<DECRYPTION, AES, ECB> AES_ECB_Decryption;
 
90
 
 
91
typedef BlockCipher<ENCRYPTION, AES, CBC> AES_CBC_Encryption;
 
92
typedef BlockCipher<DECRYPTION, AES, CBC> AES_CBC_Decryption;
 
93
 
 
94
 
 
95
 
 
96
} // naemspace
 
97
 
 
98
#endif // TAO_CRYPT_AES_HPP