1 | #ifndef HEADER_AES_H
|
---|
2 | #define HEADER_AES_H
|
---|
3 |
|
---|
4 | #define AES_ENCRYPT 1
|
---|
5 | #define AES_DECRYPT 0
|
---|
6 |
|
---|
7 | /* Because array size can't be a const in C, the following two are macros.
|
---|
8 | Both sizes are in bytes. */
|
---|
9 | #define AES_MAXNR 14
|
---|
10 | #define AES_BLOCK_SIZE 16
|
---|
11 |
|
---|
12 | #ifdef __cplusplus
|
---|
13 | extern "C" {
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #if defined(_MSC_VER) && !defined(OPENSSL_SYS_WINCE)
|
---|
17 | # define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
|
---|
18 | # define GETU32(p) SWAP(*((u32 *)(p)))
|
---|
19 | # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
|
---|
20 | #else
|
---|
21 | # define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
|
---|
22 | # define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | typedef unsigned long u32;
|
---|
26 | typedef unsigned short u16;
|
---|
27 | typedef unsigned char u8;
|
---|
28 |
|
---|
29 | #define MAXKC (256/32)
|
---|
30 | #define MAXKB (256/8)
|
---|
31 | #define MAXNR 14
|
---|
32 |
|
---|
33 | /* This controls loop-unrolling in aes_core.c */
|
---|
34 | #undef FULL_UNROLL
|
---|
35 |
|
---|
36 | /* This should be a hidden type, but EVP requires that the size be known */
|
---|
37 | struct aes_key_st {
|
---|
38 | unsigned long rd_key[4 *(AES_MAXNR + 1)];
|
---|
39 | int rounds;
|
---|
40 | };
|
---|
41 | typedef struct aes_key_st AES_KEY;
|
---|
42 |
|
---|
43 | int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
|
---|
44 | AES_KEY *key);
|
---|
45 | int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
|
---|
46 | AES_KEY *key);
|
---|
47 |
|
---|
48 | void AES_encrypt(const unsigned char *in, unsigned char *out,
|
---|
49 | const AES_KEY *key);
|
---|
50 | void AES_decrypt(const unsigned char *in, unsigned char *out,
|
---|
51 | const AES_KEY *key);
|
---|
52 |
|
---|
53 | #ifdef __cplusplus
|
---|
54 | }
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | #endif /* !HEADER_AES_H */
|
---|