-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha1.h
100 lines (83 loc) · 2.12 KB
/
sha1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* File: sha1.h
* Author: frans
*
* Created on 1 maart 2016, 9:21
*/
#ifndef SHA1_H
#define SHA1_H
typedef unsigned long DWORD;
typedef unsigned int WORD;
typedef unsigned char BYTE;
typedef union _DWORD_VAL
{
DWORD Val;
WORD w[2];
BYTE v[4];
struct
{
WORD LW;
WORD HW;
} word;
struct
{
BYTE LB;
BYTE HB;
BYTE UB;
BYTE MB;
} byte;
struct
{
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
unsigned char b8:1;
unsigned char b9:1;
unsigned char b10:1;
unsigned char b11:1;
unsigned char b12:1;
unsigned char b13:1;
unsigned char b14:1;
unsigned char b15:1;
unsigned char b16:1;
unsigned char b17:1;
unsigned char b18:1;
unsigned char b19:1;
unsigned char b20:1;
unsigned char b21:1;
unsigned char b22:1;
unsigned char b23:1;
unsigned char b24:1;
unsigned char b25:1;
unsigned char b26:1;
unsigned char b27:1;
unsigned char b28:1;
unsigned char b29:1;
unsigned char b30:1;
unsigned char b31:1;
} bits;
} DWORD_VAL;
typedef enum {
HASH_MD5 = 0u, // MD5 is being calculated
HASH_SHA1 // SHA-1 is being calculated
} HASH_TYPE;
typedef struct
{
DWORD h0; // Hash state h0
DWORD h1; // Hash state h1
DWORD h2; // Hash state h2
DWORD h3; // Hash state h3
DWORD h4; // Hash state h4
DWORD bytesSoFar; // Total number of bytes hashed so far
BYTE partialBlock[64]; // Beginning of next 64 byte block
HASH_TYPE hashType; // Type of hash being calculated
} HASH_SUM;
void SHA1Initialize(HASH_SUM* theSum);
void SHA1AddData(HASH_SUM* theSum, BYTE* data, WORD len);
void SHA1Calculate(HASH_SUM* theSum, BYTE* result);
#endif /* SHA1_H */