xref: /aosp_15_r20/external/lzma/C/Sha1.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 /* Sha1.h -- SHA-1 Hash
2 : Igor Pavlov : Public domain */
3 
4 #ifndef ZIP7_INC_SHA1_H
5 #define ZIP7_INC_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 
18 
19 
20 typedef void (Z7_FASTCALL *SHA1_FUNC_UPDATE_BLOCKS)(UInt32 state[5], const Byte *data, size_t numBlocks);
21 
22 /*
23   if (the system supports different SHA1 code implementations)
24   {
25     (CSha1::func_UpdateBlocks) will be used
26     (CSha1::func_UpdateBlocks) can be set by
27        Sha1_Init()        - to default (fastest)
28        Sha1_SetFunction() - to any algo
29   }
30   else
31   {
32     (CSha1::func_UpdateBlocks) is ignored.
33   }
34 */
35 
36 typedef struct
37 {
38   union
39   {
40     struct
41     {
42       SHA1_FUNC_UPDATE_BLOCKS func_UpdateBlocks;
43       UInt64 count;
44     } vars;
45     UInt64 _pad_64bit[4];
46     void *_pad_align_ptr[2];
47   } v;
48   UInt32 state[SHA1_NUM_DIGEST_WORDS];
49   UInt32 _pad_3[3];
50   Byte buffer[SHA1_BLOCK_SIZE];
51 } CSha1;
52 
53 
54 #define SHA1_ALGO_DEFAULT 0
55 #define SHA1_ALGO_SW      1
56 #define SHA1_ALGO_HW      2
57 
58 /*
59 Sha1_SetFunction()
60 return:
61   0 - (algo) value is not supported, and func_UpdateBlocks was not changed
62   1 - func_UpdateBlocks was set according (algo) value.
63 */
64 
65 BoolInt Sha1_SetFunction(CSha1 *p, unsigned algo);
66 
67 void Sha1_InitState(CSha1 *p);
68 void Sha1_Init(CSha1 *p);
69 void Sha1_Update(CSha1 *p, const Byte *data, size_t size);
70 void Sha1_Final(CSha1 *p, Byte *digest);
71 
72 void Sha1_PrepareBlock(const CSha1 *p, Byte *block, unsigned size);
73 void Sha1_GetBlockDigest(const CSha1 *p, const Byte *data, Byte *destDigest);
74 
75 // void Z7_FASTCALL Sha1_UpdateBlocks(UInt32 state[5], const Byte *data, size_t numBlocks);
76 
77 /*
78 call Sha1Prepare() once at program start.
79 It prepares all supported implementations, and detects the fastest implementation.
80 */
81 
82 void Sha1Prepare(void);
83 
84 EXTERN_C_END
85 
86 #endif
87