aboutsummaryrefslogtreecommitdiff
path: root/C/Sha512.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-11-29 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-11-30 15:27:15 +0500
commite5431fa6f5505e385c6f9367260717e9c47dc2ee (patch)
tree4cd2c2c3b225b48c8e7053432c41d7b6b6a3d5f8 /C/Sha512.h
parente008ce3976c087bfd21344af8f00a23cf69d4174 (diff)
download7zip-24.09.tar.gz
7zip-24.09.tar.bz2
7zip-24.09.zip
Diffstat (limited to 'C/Sha512.h')
-rw-r--r--C/Sha512.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/C/Sha512.h b/C/Sha512.h
new file mode 100644
index 0000000..1f3a4d1
--- /dev/null
+++ b/C/Sha512.h
@@ -0,0 +1,86 @@
1/* Sha512.h -- SHA-512 Hash
2: Igor Pavlov : Public domain */
3
4#ifndef ZIP7_INC_SHA512_H
5#define ZIP7_INC_SHA512_H
6
7#include "7zTypes.h"
8
9EXTERN_C_BEGIN
10
11#define SHA512_NUM_BLOCK_WORDS 16
12#define SHA512_NUM_DIGEST_WORDS 8
13
14#define SHA512_BLOCK_SIZE (SHA512_NUM_BLOCK_WORDS * 8)
15#define SHA512_DIGEST_SIZE (SHA512_NUM_DIGEST_WORDS * 8)
16#define SHA512_224_DIGEST_SIZE (224 / 8)
17#define SHA512_256_DIGEST_SIZE (256 / 8)
18#define SHA512_384_DIGEST_SIZE (384 / 8)
19
20typedef void (Z7_FASTCALL *SHA512_FUNC_UPDATE_BLOCKS)(UInt64 state[8], const Byte *data, size_t numBlocks);
21
22/*
23 if (the system supports different SHA512 code implementations)
24 {
25 (CSha512::func_UpdateBlocks) will be used
26 (CSha512::func_UpdateBlocks) can be set by
27 Sha512_Init() - to default (fastest)
28 Sha512_SetFunction() - to any algo
29 }
30 else
31 {
32 (CSha512::func_UpdateBlocks) is ignored.
33 }
34*/
35
36typedef struct
37{
38 union
39 {
40 struct
41 {
42 SHA512_FUNC_UPDATE_BLOCKS func_UpdateBlocks;
43 UInt64 count;
44 } vars;
45 UInt64 _pad_64bit[8];
46 void *_pad_align_ptr[2];
47 } v;
48 UInt64 state[SHA512_NUM_DIGEST_WORDS];
49
50 Byte buffer[SHA512_BLOCK_SIZE];
51} CSha512;
52
53
54#define SHA512_ALGO_DEFAULT 0
55#define SHA512_ALGO_SW 1
56#define SHA512_ALGO_HW 2
57
58/*
59Sha512_SetFunction()
60return:
61 0 - (algo) value is not supported, and func_UpdateBlocks was not changed
62 1 - func_UpdateBlocks was set according (algo) value.
63*/
64
65BoolInt Sha512_SetFunction(CSha512 *p, unsigned algo);
66// we support only these (digestSize) values: 224/8, 256/8, 384/8, 512/8
67void Sha512_InitState(CSha512 *p, unsigned digestSize);
68void Sha512_Init(CSha512 *p, unsigned digestSize);
69void Sha512_Update(CSha512 *p, const Byte *data, size_t size);
70void Sha512_Final(CSha512 *p, Byte *digest, unsigned digestSize);
71
72
73
74
75// void Z7_FASTCALL Sha512_UpdateBlocks(UInt64 state[8], const Byte *data, size_t numBlocks);
76
77/*
78call Sha512Prepare() once at program start.
79It prepares all supported implementations, and detects the fastest implementation.
80*/
81
82void Sha512Prepare(void);
83
84EXTERN_C_END
85
86#endif