114 lines
4.3 KiB
C
114 lines
4.3 KiB
C
#ifndef AES_INTERNAL_H
|
|
#define AES_INTERNAL_H
|
|
|
|
extern const aes_uint Te0[256];
|
|
extern const aes_uint Te1[256];
|
|
extern const aes_uint Te2[256];
|
|
extern const aes_uint Te3[256];
|
|
extern const aes_uint Te4[256];
|
|
extern const aes_uint Td0[256];
|
|
extern const aes_uint Td1[256];
|
|
extern const aes_uint Td2[256];
|
|
extern const aes_uint Td3[256];
|
|
extern const aes_uint Td4[256];
|
|
extern const aes_uint rcon[10];
|
|
extern const aes_uchar Td4s[256];
|
|
extern const aes_uchar rcons[10];
|
|
|
|
#ifndef AES_SMALL_TABLES
|
|
|
|
#define RCON(i) rcon[(i)]
|
|
|
|
#define TE0(i) Te0[((i) >> 24) & 0xff]
|
|
#define TE1(i) Te1[((i) >> 16) & 0xff]
|
|
#define TE2(i) Te2[((i) >> 8) & 0xff]
|
|
#define TE3(i) Te3[(i) & 0xff]
|
|
#define TE41(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
|
|
#define TE42(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
|
|
#define TE43(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
|
|
#define TE44(i) (Te4[(i) & 0xff] & 0x000000ff)
|
|
#define TE421(i) (Te4[((i) >> 16) & 0xff] & 0xff000000)
|
|
#define TE432(i) (Te4[((i) >> 8) & 0xff] & 0x00ff0000)
|
|
#define TE443(i) (Te4[(i) & 0xff] & 0x0000ff00)
|
|
#define TE414(i) (Te4[((i) >> 24) & 0xff] & 0x000000ff)
|
|
#define TE411(i) (Te4[((i) >> 24) & 0xff] & 0xff000000)
|
|
#define TE422(i) (Te4[((i) >> 16) & 0xff] & 0x00ff0000)
|
|
#define TE433(i) (Te4[((i) >> 8) & 0xff] & 0x0000ff00)
|
|
#define TE444(i) (Te4[(i) & 0xff] & 0x000000ff)
|
|
#define TE4(i) (Te4[(i)] & 0x000000ff)
|
|
|
|
#define TD0(i) Td0[((i) >> 24) & 0xff]
|
|
#define TD1(i) Td1[((i) >> 16) & 0xff]
|
|
#define TD2(i) Td2[((i) >> 8) & 0xff]
|
|
#define TD3(i) Td3[(i) & 0xff]
|
|
#define TD41(i) (Td4[((i) >> 24) & 0xff] & 0xff000000)
|
|
#define TD42(i) (Td4[((i) >> 16) & 0xff] & 0x00ff0000)
|
|
#define TD43(i) (Td4[((i) >> 8) & 0xff] & 0x0000ff00)
|
|
#define TD44(i) (Td4[(i) & 0xff] & 0x000000ff)
|
|
#define TD0_(i) Td0[(i) & 0xff]
|
|
#define TD1_(i) Td1[(i) & 0xff]
|
|
#define TD2_(i) Td2[(i) & 0xff]
|
|
#define TD3_(i) Td3[(i) & 0xff]
|
|
|
|
#else /* AES_SMALL_TABLES */
|
|
|
|
#define RCON(i) (rcons[(i)] << 24)
|
|
|
|
static inline aes_uint rotr(aes_uint val, int bits)
|
|
{
|
|
return (val >> bits) | (val << (32 - bits));
|
|
}
|
|
|
|
#define TE0(i) Te0[((i) >> 24) & 0xff]
|
|
#define TE1(i) rotr(Te0[((i) >> 16) & 0xff], 8)
|
|
#define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
|
|
#define TE3(i) rotr(Te0[(i) & 0xff], 24)
|
|
#define TE41(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
|
|
#define TE42(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
|
|
#define TE43(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
|
|
#define TE44(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
|
|
#define TE421(i) ((Te0[((i) >> 16) & 0xff] << 8) & 0xff000000)
|
|
#define TE432(i) (Te0[((i) >> 8) & 0xff] & 0x00ff0000)
|
|
#define TE443(i) (Te0[(i) & 0xff] & 0x0000ff00)
|
|
#define TE414(i) ((Te0[((i) >> 24) & 0xff] >> 8) & 0x000000ff)
|
|
#define TE411(i) ((Te0[((i) >> 24) & 0xff] << 8) & 0xff000000)
|
|
#define TE422(i) (Te0[((i) >> 16) & 0xff] & 0x00ff0000)
|
|
#define TE433(i) (Te0[((i) >> 8) & 0xff] & 0x0000ff00)
|
|
#define TE444(i) ((Te0[(i) & 0xff] >> 8) & 0x000000ff)
|
|
#define TE4(i) ((Te0[(i)] >> 8) & 0x000000ff)
|
|
|
|
#define TD0(i) Td0[((i) >> 24) & 0xff]
|
|
#define TD1(i) rotr(Td0[((i) >> 16) & 0xff], 8)
|
|
#define TD2(i) rotr(Td0[((i) >> 8) & 0xff], 16)
|
|
#define TD3(i) rotr(Td0[(i) & 0xff], 24)
|
|
#define TD41(i) (Td4s[((i) >> 24) & 0xff] << 24)
|
|
#define TD42(i) (Td4s[((i) >> 16) & 0xff] << 16)
|
|
#define TD43(i) (Td4s[((i) >> 8) & 0xff] << 8)
|
|
#define TD44(i) (Td4s[(i) & 0xff])
|
|
#define TD0_(i) Td0[(i) & 0xff]
|
|
#define TD1_(i) rotr(Td0[(i) & 0xff], 8)
|
|
#define TD2_(i) rotr(Td0[(i) & 0xff], 16)
|
|
#define TD3_(i) rotr(Td0[(i) & 0xff], 24)
|
|
|
|
#endif /* AES_SMALL_TABLES */
|
|
|
|
#define GETU32(pt) (((aes_uint)(pt)[0] << 24) ^ \
|
|
((aes_uint)(pt)[1] << 16) ^ \
|
|
((aes_uint)(pt)[2] << 8) ^ \
|
|
((aes_uint)(pt)[3]))
|
|
#define PUTU32(ct, st) { \
|
|
(ct)[0] = (aes_uchar)((st) >> 24); \
|
|
(ct)[1] = (aes_uchar)((st) >> 16); \
|
|
(ct)[2] = (aes_uchar)((st) >> 8); \
|
|
(ct)[3] = (aes_uchar)(st); }
|
|
|
|
#define AES_PRIV_SIZE (4 * 4 * 15 + 4)
|
|
#define AES_PRIV_NR_POS (4 * 15)
|
|
|
|
void aes_rijndael_encrypt(const aes_uint rk[], int Nr, const aes_uchar pt[16], aes_uchar ct[16]);
|
|
void aes_rijndael_decrypt(const aes_uint rk[], int Nr, const aes_uchar ct[16], aes_uchar pt[16]);
|
|
int aes_rijndael_key_setup_dec(aes_uint rk[], const aes_uchar cipherKey[], size_t keyBits);
|
|
int aes_rijndael_key_setup_enc(aes_uint rk[], const aes_uchar cipherKey[], size_t keyBits);
|
|
|
|
#endif /* AES_I_H */
|