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