1 /* Aes.h -- AES encryption / decryption 2 2009-02-07 : Igor Pavlov : Public domain */ 3 4 #ifndef __AES_H 5 #define __AES_H 6 7 #include "Types.h" 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #define AES_BLOCK_SIZE 16 14 15 typedef struct 16 { 17 unsigned numRounds2; /* = numRounds / 2 */ 18 UInt32 rkey[(14 + 1) * 4]; 19 } CAes; 20 21 /* Call AesGenTables one time before other AES functions */ 22 void AesGenTables(void); 23 24 /* keySize = 16 or 24 or 32 (bytes) */ 25 void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize); 26 void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize); 27 28 /* Aes_Encode32 and Aes_Decode32 functions work with little-endian words. 29 src and dest are pointers to 4 UInt32 words. 30 arc and dest can point to same block */ 31 void Aes_Encode32(const CAes *p, UInt32 *dest, const UInt32 *src); 32 void Aes_Decode32(const CAes *p, UInt32 *dest, const UInt32 *src); 33 34 typedef struct 35 { 36 UInt32 prev[4]; 37 CAes aes; 38 } CAesCbc; 39 40 void AesCbc_Init(CAesCbc *p, const Byte *iv); /* iv size is AES_BLOCK_SIZE */ 41 42 /* AesCbc_Encode and AesCbc_Decode: 43 if (res <= size): Filter have converted res bytes 44 if (res > size): Filter have not converted anything. And it needs at 45 least res = AES_BLOCK_SIZE bytes to convert one block */ 46 47 SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size); 48 SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size); 49 50 #ifdef __cplusplus 51 } 52 #endif 53 54 #endif 55