rlm@1: /* Aes.h -- AES encryption / decryption rlm@1: 2008-08-05 rlm@1: Igor Pavlov rlm@1: Public domain */ rlm@1: rlm@1: #ifndef __AES_H rlm@1: #define __AES_H rlm@1: rlm@1: #include "Types.h" rlm@1: rlm@1: #define AES_BLOCK_SIZE 16 rlm@1: rlm@1: typedef struct rlm@1: { rlm@1: unsigned numRounds2; /* = numRounds / 2 */ rlm@1: UInt32 rkey[(14 + 1) * 4]; rlm@1: } CAes; rlm@1: rlm@1: /* Call AesGenTables one time before other AES functions */ rlm@1: void AesGenTables(void); rlm@1: rlm@1: /* keySize = 16 or 24 or 32 (bytes) */ rlm@1: void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize); rlm@1: void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize); rlm@1: rlm@1: /* Aes_Encode32 and Aes_Decode32 functions work with little-endian words. rlm@1: src and dest are pointers to 4 UInt32 words. rlm@1: arc and dest can point to same block */ rlm@1: void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src); rlm@1: void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src); rlm@1: rlm@1: typedef struct rlm@1: { rlm@1: UInt32 prev[4]; rlm@1: CAes aes; rlm@1: } CAesCbc; rlm@1: rlm@1: void AesCbc_Init(CAesCbc *p, const Byte *iv); /* iv size is AES_BLOCK_SIZE */ rlm@1: rlm@1: /* AesCbc_Encode and AesCbc_Decode: rlm@1: if (res <= size): Filter have converted res bytes rlm@1: if (res > size): Filter have not converted anything. And it needs at rlm@1: least res = AES_BLOCK_SIZE bytes to convert one block */ rlm@1: rlm@1: SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size); rlm@1: SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size); rlm@1: rlm@1: #endif