1 /* Aes.h -- AES encryption / decryption
2 2018-04-28 : 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 
30 /* data - 16-byte aligned pointer to data */
31 /* numBlocks - the number of 16-byte blocks in data array */
32 typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks);
33 
34 extern AES_CODE_FUNC g_AesCbc_Decode;
35 #ifndef _SFX
36 extern AES_CODE_FUNC g_AesCbc_Encode;
37 extern AES_CODE_FUNC g_AesCtr_Code;
38 #define k_Aes_SupportedFunctions_HW     (1 << 2)
39 #define k_Aes_SupportedFunctions_HW_256 (1 << 3)
40 extern UInt32 g_Aes_SupportedFunctions_Flags;
41 #endif
42 
43 
44 #define DECLARE__AES_CODE_FUNC(funcName) \
45     void MY_FAST_CALL funcName(UInt32 *ivAes, Byte *data, size_t numBlocks);
46 
47 DECLARE__AES_CODE_FUNC (AesCbc_Encode)
48 DECLARE__AES_CODE_FUNC (AesCbc_Decode)
49 DECLARE__AES_CODE_FUNC (AesCtr_Code)
50 
51 DECLARE__AES_CODE_FUNC (AesCbc_Encode_HW)
52 DECLARE__AES_CODE_FUNC (AesCbc_Decode_HW)
53 DECLARE__AES_CODE_FUNC (AesCtr_Code_HW)
54 
55 DECLARE__AES_CODE_FUNC (AesCbc_Decode_HW_256)
56 DECLARE__AES_CODE_FUNC (AesCtr_Code_HW_256)
57 
58 EXTERN_C_END
59 
60 #endif
61