aboutsummaryrefslogtreecommitdiff
path: root/C/Aes.h
diff options
context:
space:
mode:
Diffstat (limited to 'C/Aes.h')
-rw-r--r--C/Aes.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/C/Aes.h b/C/Aes.h
new file mode 100644
index 0000000..2aa2256
--- /dev/null
+++ b/C/Aes.h
@@ -0,0 +1,60 @@
1/* Aes.h -- AES encryption / decryption
22018-04-28 : Igor Pavlov : Public domain */
3
4#ifndef __AES_H
5#define __AES_H
6
7#include "7zTypes.h"
8
9EXTERN_C_BEGIN
10
11#define AES_BLOCK_SIZE 16
12
13/* Call AesGenTables one time before other AES functions */
14void 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) */
23typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize);
24void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize);
25void 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] */
28void 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 */
32typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks);
33
34extern AES_CODE_FUNC g_AesCbc_Decode;
35#ifndef _SFX
36extern AES_CODE_FUNC g_AesCbc_Encode;
37extern AES_CODE_FUNC g_AesCtr_Code;
38#define k_Aes_SupportedFunctions_HW (1 << 2)
39#define k_Aes_SupportedFunctions_HW_256 (1 << 3)
40extern 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
47DECLARE__AES_CODE_FUNC (AesCbc_Encode)
48DECLARE__AES_CODE_FUNC (AesCbc_Decode)
49DECLARE__AES_CODE_FUNC (AesCtr_Code)
50
51DECLARE__AES_CODE_FUNC (AesCbc_Encode_HW)
52DECLARE__AES_CODE_FUNC (AesCbc_Decode_HW)
53DECLARE__AES_CODE_FUNC (AesCtr_Code_HW)
54
55DECLARE__AES_CODE_FUNC (AesCbc_Decode_HW_256)
56DECLARE__AES_CODE_FUNC (AesCtr_Code_HW_256)
57
58EXTERN_C_END
59
60#endif