rlm@1
|
1 /* Aes.h -- AES encryption / decryption
|
rlm@1
|
2 2008-08-05
|
rlm@1
|
3 Igor Pavlov
|
rlm@1
|
4 Public domain */
|
rlm@1
|
5
|
rlm@1
|
6 #ifndef __AES_H
|
rlm@1
|
7 #define __AES_H
|
rlm@1
|
8
|
rlm@1
|
9 #include "Types.h"
|
rlm@1
|
10
|
rlm@1
|
11 #define AES_BLOCK_SIZE 16
|
rlm@1
|
12
|
rlm@1
|
13 typedef struct
|
rlm@1
|
14 {
|
rlm@1
|
15 unsigned numRounds2; /* = numRounds / 2 */
|
rlm@1
|
16 UInt32 rkey[(14 + 1) * 4];
|
rlm@1
|
17 } CAes;
|
rlm@1
|
18
|
rlm@1
|
19 /* Call AesGenTables one time before other AES functions */
|
rlm@1
|
20 void AesGenTables(void);
|
rlm@1
|
21
|
rlm@1
|
22 /* keySize = 16 or 24 or 32 (bytes) */
|
rlm@1
|
23 void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize);
|
rlm@1
|
24 void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize);
|
rlm@1
|
25
|
rlm@1
|
26 /* Aes_Encode32 and Aes_Decode32 functions work with little-endian words.
|
rlm@1
|
27 src and dest are pointers to 4 UInt32 words.
|
rlm@1
|
28 arc and dest can point to same block */
|
rlm@1
|
29 void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src);
|
rlm@1
|
30 void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src);
|
rlm@1
|
31
|
rlm@1
|
32 typedef struct
|
rlm@1
|
33 {
|
rlm@1
|
34 UInt32 prev[4];
|
rlm@1
|
35 CAes aes;
|
rlm@1
|
36 } CAesCbc;
|
rlm@1
|
37
|
rlm@1
|
38 void AesCbc_Init(CAesCbc *p, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
|
rlm@1
|
39
|
rlm@1
|
40 /* AesCbc_Encode and AesCbc_Decode:
|
rlm@1
|
41 if (res <= size): Filter have converted res bytes
|
rlm@1
|
42 if (res > size): Filter have not converted anything. And it needs at
|
rlm@1
|
43 least res = AES_BLOCK_SIZE bytes to convert one block */
|
rlm@1
|
44
|
rlm@1
|
45 SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size);
|
rlm@1
|
46 SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size);
|
rlm@1
|
47
|
rlm@1
|
48 #endif
|