Home | History | Annotate | Download | only in C
      1 /* Aes.h -- AES encryption / decryption
      2 2013-01-18 : Igor Pavlov : Public domain */
      3 
      4 #ifndef __AES_H
      5 #define __AES_H
      6 
      7 #include "7zTypes.h"
      8 
      9 EXTERN_C_BEGIN
     10 
     11 #define AES_BLOCK_SIZE 16
     12 
     13 /* Call AesGenTables one time before other AES functions */
     14 void AesGenTables(void);
     15 
     16 /* UInt32 pointers must be 16-byte aligned */
     17 
     18 /* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */
     19 #define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4)
     20 
     21 /* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */
     22 /* keySize = 16 or 24 or 32 (bytes) */
     23 typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize);
     24 void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize);
     25 void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize);
     26 
     27 /* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */
     28 void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
     29 /* data - 16-byte aligned pointer to data */
     30 /* numBlocks - the number of 16-byte blocks in data array */
     31 typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks);
     32 extern AES_CODE_FUNC g_AesCbc_Encode;
     33 extern AES_CODE_FUNC g_AesCbc_Decode;
     34 extern AES_CODE_FUNC g_AesCtr_Code;
     35 
     36 EXTERN_C_END
     37 
     38 #endif
     39