diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /C/Aes.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.gz 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.bz2 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.zip |
'21.07'21.07
Diffstat (limited to 'C/Aes.h')
-rw-r--r-- | C/Aes.h | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -0,0 +1,60 @@ | |||
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 | ||