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/Sha1.h | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.gz 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.bz2 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.zip |
'21.07'21.07
Diffstat (limited to 'C/Sha1.h')
-rw-r--r-- | C/Sha1.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/C/Sha1.h b/C/Sha1.h new file mode 100644 index 0000000..345a816 --- /dev/null +++ b/C/Sha1.h | |||
@@ -0,0 +1,76 @@ | |||
1 | /* Sha1.h -- SHA-1 Hash | ||
2 | 2021-02-08 : Igor Pavlov : Public domain */ | ||
3 | |||
4 | #ifndef __7Z_SHA1_H | ||
5 | #define __7Z_SHA1_H | ||
6 | |||
7 | #include "7zTypes.h" | ||
8 | |||
9 | EXTERN_C_BEGIN | ||
10 | |||
11 | #define SHA1_NUM_BLOCK_WORDS 16 | ||
12 | #define SHA1_NUM_DIGEST_WORDS 5 | ||
13 | |||
14 | #define SHA1_BLOCK_SIZE (SHA1_NUM_BLOCK_WORDS * 4) | ||
15 | #define SHA1_DIGEST_SIZE (SHA1_NUM_DIGEST_WORDS * 4) | ||
16 | |||
17 | typedef void (MY_FAST_CALL *SHA1_FUNC_UPDATE_BLOCKS)(UInt32 state[5], const Byte *data, size_t numBlocks); | ||
18 | |||
19 | /* | ||
20 | if (the system supports different SHA1 code implementations) | ||
21 | { | ||
22 | (CSha1::func_UpdateBlocks) will be used | ||
23 | (CSha1::func_UpdateBlocks) can be set by | ||
24 | Sha1_Init() - to default (fastest) | ||
25 | Sha1_SetFunction() - to any algo | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | (CSha1::func_UpdateBlocks) is ignored. | ||
30 | } | ||
31 | */ | ||
32 | |||
33 | typedef struct | ||
34 | { | ||
35 | SHA1_FUNC_UPDATE_BLOCKS func_UpdateBlocks; | ||
36 | UInt64 count; | ||
37 | UInt64 __pad_2[2]; | ||
38 | UInt32 state[SHA1_NUM_DIGEST_WORDS]; | ||
39 | UInt32 __pad_3[3]; | ||
40 | Byte buffer[SHA1_BLOCK_SIZE]; | ||
41 | } CSha1; | ||
42 | |||
43 | |||
44 | #define SHA1_ALGO_DEFAULT 0 | ||
45 | #define SHA1_ALGO_SW 1 | ||
46 | #define SHA1_ALGO_HW 2 | ||
47 | |||
48 | /* | ||
49 | Sha1_SetFunction() | ||
50 | return: | ||
51 | 0 - (algo) value is not supported, and func_UpdateBlocks was not changed | ||
52 | 1 - func_UpdateBlocks was set according (algo) value. | ||
53 | */ | ||
54 | |||
55 | BoolInt Sha1_SetFunction(CSha1 *p, unsigned algo); | ||
56 | |||
57 | void Sha1_InitState(CSha1 *p); | ||
58 | void Sha1_Init(CSha1 *p); | ||
59 | void Sha1_Update(CSha1 *p, const Byte *data, size_t size); | ||
60 | void Sha1_Final(CSha1 *p, Byte *digest); | ||
61 | |||
62 | void Sha1_PrepareBlock(const CSha1 *p, Byte *block, unsigned size); | ||
63 | void Sha1_GetBlockDigest(const CSha1 *p, const Byte *data, Byte *destDigest); | ||
64 | |||
65 | // void MY_FAST_CALL Sha1_UpdateBlocks(UInt32 state[5], const Byte *data, size_t numBlocks); | ||
66 | |||
67 | /* | ||
68 | call Sha1Prepare() once at program start. | ||
69 | It prepares all supported implementations, and detects the fastest implementation. | ||
70 | */ | ||
71 | |||
72 | void Sha1Prepare(void); | ||
73 | |||
74 | EXTERN_C_END | ||
75 | |||
76 | #endif | ||