-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAES.h
executable file
·92 lines (76 loc) · 3.39 KB
/
AES.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA *
* *
***************************************************************************
* *
* (c) Copyright, 1997-2012, ANSR *
* *
***************************************************************************
* *
* Filename: AES.h *
* *
***************************************************************************/
#ifndef AES_H
#define AES_H
/**
* @defgroup library Generic Library Functions
*
* @{
*/
/**
* AES encryption/decryption engine.
*/
class AES
{
public:
/// Allowable key sizes.
typedef enum
{
/// AES 128-bit standard.
Key128Bits = 128,
/// AES 192-bit standard.
Key192Bits = 192,
/// AES 256-bit standard.
Key256Bits = 256
} KEY_SIZE;
/// Encryption/decryption mode.
typedef enum
{
/// Decrypt the data set.
Decrypt = 0,
/// Encrypt the data set.
Encrypt = 1
} EncryptionMode;
/// Number of bytes in the input and output blocks.
static const uint32_t BlockSize = 16;
/// Constant IV set to all zeros.
static const uint8_t ZeroIV[BlockSize];
void CryptCBC(EncryptionMode mode, uint32_t length, const uint8_t iv[BlockSize], const uint8_t *input, uint8_t *output);
void CryptECB(EncryptionMode mode, uint8_t const input[BlockSize], uint8_t output[BlockSize]);
void SetDecryptionKey(const AESKey *key);
void SetDecryptionKey(const uint8_t *key, KEY_SIZE keysize);
void SetEncryptionKey(const AESKey *key);
void SetEncryptionKey(const uint8_t *key, KEY_SIZE keysize);
private:
/// Number of rounds.
int32_t numberOfRounds;
/// AES round keys.
uint32_t *roundKey;
/// Expanded key buffer.
uint32_t expandedKey[68];
};
/** @} */
#endif // #ifndef AES256_H