wpa_supplicant / hostapd 2.0

aes_i.h

Go to the documentation of this file.
00001 
00010 #ifndef AES_I_H
00011 #define AES_I_H
00012 
00013 #include "aes.h"
00014 
00015 /* #define FULL_UNROLL */
00016 #define AES_SMALL_TABLES
00017 
00018 extern const u32 Te0[256];
00019 extern const u32 Te1[256];
00020 extern const u32 Te2[256];
00021 extern const u32 Te3[256];
00022 extern const u32 Te4[256];
00023 extern const u32 Td0[256];
00024 extern const u32 Td1[256];
00025 extern const u32 Td2[256];
00026 extern const u32 Td3[256];
00027 extern const u32 Td4[256];
00028 extern const u32 rcon[10];
00029 extern const u8 Td4s[256];
00030 extern const u8 rcons[10];
00031 
00032 #ifndef AES_SMALL_TABLES
00033 
00034 #define RCON(i) rcon[(i)]
00035 
00036 #define TE0(i) Te0[((i) >> 24) & 0xff]
00037 #define TE1(i) Te1[((i) >> 16) & 0xff]
00038 #define TE2(i) Te2[((i) >> 8) & 0xff]
00039 #define TE3(i) Te3[(i) & 0xff]
00040 #define TE41(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
00041 #define TE42(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
00042 #define TE43(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
00043 #define TE44(i) (Te4[(i) & 0xff] & 0x000000ff)
00044 #define TE421(i) (Te4[((i) >> 16) & 0xff] & 0xff000000)
00045 #define TE432(i) (Te4[((i) >> 8) & 0xff] & 0x00ff0000)
00046 #define TE443(i) (Te4[(i) & 0xff] & 0x0000ff00)
00047 #define TE414(i) (Te4[((i) >> 24) & 0xff] & 0x000000ff)
00048 #define TE4(i) (Te4[(i)] & 0x000000ff)
00049 
00050 #define TD0(i) Td0[((i) >> 24) & 0xff]
00051 #define TD1(i) Td1[((i) >> 16) & 0xff]
00052 #define TD2(i) Td2[((i) >> 8) & 0xff]
00053 #define TD3(i) Td3[(i) & 0xff]
00054 #define TD41(i) (Td4[((i) >> 24) & 0xff] & 0xff000000)
00055 #define TD42(i) (Td4[((i) >> 16) & 0xff] & 0x00ff0000)
00056 #define TD43(i) (Td4[((i) >> 8) & 0xff] & 0x0000ff00)
00057 #define TD44(i) (Td4[(i) & 0xff] & 0x000000ff)
00058 #define TD0_(i) Td0[(i) & 0xff]
00059 #define TD1_(i) Td1[(i) & 0xff]
00060 #define TD2_(i) Td2[(i) & 0xff]
00061 #define TD3_(i) Td3[(i) & 0xff]
00062 
00063 #else /* AES_SMALL_TABLES */
00064 
00065 #define RCON(i) (rcons[(i)] << 24)
00066 
00067 static inline u32 rotr(u32 val, int bits)
00068 {
00069         return (val >> bits) | (val << (32 - bits));
00070 }
00071 
00072 #define TE0(i) Te0[((i) >> 24) & 0xff]
00073 #define TE1(i) rotr(Te0[((i) >> 16) & 0xff], 8)
00074 #define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
00075 #define TE3(i) rotr(Te0[(i) & 0xff], 24)
00076 #define TE41(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
00077 #define TE42(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
00078 #define TE43(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
00079 #define TE44(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
00080 #define TE421(i) ((Te0[((i) >> 16) & 0xff] << 8) & 0xff000000)
00081 #define TE432(i) (Te0[((i) >> 8) & 0xff] & 0x00ff0000)
00082 #define TE443(i) (Te0[(i) & 0xff] & 0x0000ff00)
00083 #define TE414(i) ((Te0[((i) >> 24) & 0xff] >> 8) & 0x000000ff)
00084 #define TE4(i) ((Te0[(i)] >> 8) & 0x000000ff)
00085 
00086 #define TD0(i) Td0[((i) >> 24) & 0xff]
00087 #define TD1(i) rotr(Td0[((i) >> 16) & 0xff], 8)
00088 #define TD2(i) rotr(Td0[((i) >> 8) & 0xff], 16)
00089 #define TD3(i) rotr(Td0[(i) & 0xff], 24)
00090 #define TD41(i) (Td4s[((i) >> 24) & 0xff] << 24)
00091 #define TD42(i) (Td4s[((i) >> 16) & 0xff] << 16)
00092 #define TD43(i) (Td4s[((i) >> 8) & 0xff] << 8)
00093 #define TD44(i) (Td4s[(i) & 0xff])
00094 #define TD0_(i) Td0[(i) & 0xff]
00095 #define TD1_(i) rotr(Td0[(i) & 0xff], 8)
00096 #define TD2_(i) rotr(Td0[(i) & 0xff], 16)
00097 #define TD3_(i) rotr(Td0[(i) & 0xff], 24)
00098 
00099 #endif /* AES_SMALL_TABLES */
00100 
00101 #ifdef _MSC_VER
00102 #define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
00103 #define GETU32(p) SWAP(*((u32 *)(p)))
00104 #define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
00105 #else
00106 #define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
00107 ((u32)(pt)[2] <<  8) ^ ((u32)(pt)[3]))
00108 #define PUTU32(ct, st) { \
00109 (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
00110 (ct)[2] = (u8)((st) >>  8); (ct)[3] = (u8)(st); }
00111 #endif
00112 
00113 #define AES_PRIV_SIZE (4 * 44)
00114 
00115 void rijndaelKeySetupEnc(u32 rk[/*44*/], const u8 cipherKey[]);
00116 
00117 #endif /* AES_I_H */
00118 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines