wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
aes_i.h
Go to the documentation of this file.
1 
5 #ifndef AES_I_H
6 #define AES_I_H
7 
8 #include "aes.h"
9 
10 /* #define FULL_UNROLL */
11 #define AES_SMALL_TABLES
12 
13 extern const u32 Te0[256];
14 extern const u32 Te1[256];
15 extern const u32 Te2[256];
16 extern const u32 Te3[256];
17 extern const u32 Te4[256];
18 extern const u32 Td0[256];
19 extern const u32 Td1[256];
20 extern const u32 Td2[256];
21 extern const u32 Td3[256];
22 extern const u32 Td4[256];
23 extern const u32 rcon[10];
24 extern const u8 Td4s[256];
25 extern const u8 rcons[10];
26 
27 #ifndef AES_SMALL_TABLES
28 
29 #define RCON(i) rcon[(i)]
30 
31 #define TE0(i) Te0[((i) >> 24) & 0xff]
32 #define TE1(i) Te1[((i) >> 16) & 0xff]
33 #define TE2(i) Te2[((i) >> 8) & 0xff]
34 #define TE3(i) Te3[(i) & 0xff]
35 #define TE41(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
36 #define TE42(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
37 #define TE43(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
38 #define TE44(i) (Te4[(i) & 0xff] & 0x000000ff)
39 #define TE421(i) (Te4[((i) >> 16) & 0xff] & 0xff000000)
40 #define TE432(i) (Te4[((i) >> 8) & 0xff] & 0x00ff0000)
41 #define TE443(i) (Te4[(i) & 0xff] & 0x0000ff00)
42 #define TE414(i) (Te4[((i) >> 24) & 0xff] & 0x000000ff)
43 #define TE411(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
44 #define TE422(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
45 #define TE433(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
46 #define TE444(i) (Te4[(i) & 0xff] & 0x000000ff)
47 #define TE4(i) (Te4[(i)] & 0x000000ff)
48 
49 #define TD0(i) Td0[((i) >> 24) & 0xff]
50 #define TD1(i) Td1[((i) >> 16) & 0xff]
51 #define TD2(i) Td2[((i) >> 8) & 0xff]
52 #define TD3(i) Td3[(i) & 0xff]
53 #define TD41(i) (Td4[((i) >> 24) & 0xff] & 0xff000000)
54 #define TD42(i) (Td4[((i) >> 16) & 0xff] & 0x00ff0000)
55 #define TD43(i) (Td4[((i) >> 8) & 0xff] & 0x0000ff00)
56 #define TD44(i) (Td4[(i) & 0xff] & 0x000000ff)
57 #define TD0_(i) Td0[(i) & 0xff]
58 #define TD1_(i) Td1[(i) & 0xff]
59 #define TD2_(i) Td2[(i) & 0xff]
60 #define TD3_(i) Td3[(i) & 0xff]
61 
62 #else /* AES_SMALL_TABLES */
63 
64 #define RCON(i) (rcons[(i)] << 24)
65 
66 static inline u32 rotr(u32 val, int bits)
67 {
68  return (val >> bits) | (val << (32 - bits));
69 }
70 
71 #define TE0(i) Te0[((i) >> 24) & 0xff]
72 #define TE1(i) rotr(Te0[((i) >> 16) & 0xff], 8)
73 #define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
74 #define TE3(i) rotr(Te0[(i) & 0xff], 24)
75 #define TE41(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
76 #define TE42(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
77 #define TE43(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
78 #define TE44(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
79 #define TE421(i) ((Te0[((i) >> 16) & 0xff] << 8) & 0xff000000)
80 #define TE432(i) (Te0[((i) >> 8) & 0xff] & 0x00ff0000)
81 #define TE443(i) (Te0[(i) & 0xff] & 0x0000ff00)
82 #define TE414(i) ((Te0[((i) >> 24) & 0xff] >> 8) & 0x000000ff)
83 #define TE411(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
84 #define TE422(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
85 #define TE433(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
86 #define TE444(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
87 #define TE4(i) ((Te0[(i)] >> 8) & 0x000000ff)
88 
89 #define TD0(i) Td0[((i) >> 24) & 0xff]
90 #define TD1(i) rotr(Td0[((i) >> 16) & 0xff], 8)
91 #define TD2(i) rotr(Td0[((i) >> 8) & 0xff], 16)
92 #define TD3(i) rotr(Td0[(i) & 0xff], 24)
93 #define TD41(i) (Td4s[((i) >> 24) & 0xff] << 24)
94 #define TD42(i) (Td4s[((i) >> 16) & 0xff] << 16)
95 #define TD43(i) (Td4s[((i) >> 8) & 0xff] << 8)
96 #define TD44(i) (Td4s[(i) & 0xff])
97 #define TD0_(i) Td0[(i) & 0xff]
98 #define TD1_(i) rotr(Td0[(i) & 0xff], 8)
99 #define TD2_(i) rotr(Td0[(i) & 0xff], 16)
100 #define TD3_(i) rotr(Td0[(i) & 0xff], 24)
101 
102 #endif /* AES_SMALL_TABLES */
103 
104 #ifdef _MSC_VER
105 #define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
106 #define GETU32(p) SWAP(*((u32 *)(p)))
107 #define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
108 #else
109 #define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
110 ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
111 #define PUTU32(ct, st) { \
112 (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
113 (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
114 #endif
115 
116 #define AES_PRIV_SIZE (4 * 4 * 15 + 4)
117 #define AES_PRIV_NR_POS (4 * 15)
118 
119 int rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits);
120 
121 #endif /* AES_I_H */
AES functions.
int rijndaelKeySetupEnc(u32 rk[], const u8 cipherKey[], int keyBits)
Expand the cipher key into the encryption key schedule.
Definition: aes-internal.c:775