Hash.h
3.78 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* Copyright (C) 2010-2012 kaosu (qiupf2000@gmail.com)
* This file is part of the Interactive Text Hooker.
* Interactive Text Hooker is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory.h>
#include <intrin.h>
#define HASH_SIZE_MD5 0x10
#define HASH_BLOCK_MD5 0x40
struct MD5_Context
{
union{
unsigned __int64 len;
struct {
unsigned int len_low,len_high;
};
};
unsigned int h0,h1,h2,h3;
unsigned int remain_len;
unsigned char remain[0x40];
}; //0x5C
void HashMD5Block(void* block, MD5_Context* ctx);
void HashMD5(void* msg, unsigned int len, void* hash);
void HashMD5Init(MD5_Context* ctx);
void HashMD5Update(MD5_Context* ctx, void* msg, int len);
void HashMD5Final(MD5_Context* ctx, void* hash);
#define HASH_SIZE_SHA1 0x14
#define HASH_BLOCK_SHA1 0x40
struct SHA1_Context
{
union{
unsigned __int64 len;
struct {
unsigned int len_low,len_high;
};
};
unsigned int h0,h1,h2,h3,h4;
unsigned int remain_len;
unsigned char remain[0x40];
}; //0x60
void HashSHA1Block(void* block, SHA1_Context* ctx);
void HashSHA1(void* msg, unsigned int len, void* hash);
void HashSHA1Init(SHA1_Context* ctx);
void HashSHA1Update(SHA1_Context* ctx, void* msg, int len);
void HashSHA1Final(SHA1_Context* ctx, void* hash);
#define HASH_SIZE_SHA256 32
#define HASH_BLOCK_SHA256 0x40
struct SHA256_Context
{
union{
unsigned __int64 len;
struct {
unsigned int len_low,len_high;
};
};
unsigned int h0,h1,h2,h3,h4,h5,h6,h7;
unsigned int remain_len;
unsigned char remain[0x40];
}; //0x6C
void HashSHA256Block(void* block, SHA256_Context* ctx);
void HashSHA256(void* msg, unsigned int len, void* hash);
void HashSHA256Init(SHA256_Context* ctx);
void HashSHA256Update(SHA256_Context* ctx, void* msg, int len);
void HashSHA256Final(SHA256_Context* ctx, void* hash);
#ifndef ITH_TLS_HASH_CALC
#define ITH_TLS_HASH_CALC
class HashCalculator
{
public:
HashCalculator() {}
virtual ~HashCalculator() {}
virtual void HashInit() {}
virtual void HashUpdate(void* msg, int len) {}
virtual void HashFinal(void* hash) {}
virtual int HashValueSize() const {return 0;}
virtual int HashBlockSize() const {return 0;}
};
enum HashType
{
HashTypeMD5 = 0,
HashTypeSHA1,
HashTypeSHA256
};
#endif
class MD5Calc : public HashCalculator
{
public:
MD5Calc();
virtual ~MD5Calc();
virtual void HashInit();
virtual void HashUpdate(void* msg, int len);
virtual void HashFinal(void* hash);
virtual int HashValueSize() const;
virtual int HashBlockSize() const;
private:
MD5_Context ctx;
};
class SHA1Calc : public HashCalculator
{
public:
SHA1Calc();
virtual ~SHA1Calc();
virtual void HashInit();
virtual void HashUpdate(void* msg, int len);
virtual void HashFinal(void* hash);
virtual int HashValueSize() const;
virtual int HashBlockSize() const;
private:
SHA1_Context ctx;
};
class SHA256Calc : public HashCalculator
{
public:
SHA256Calc();
virtual ~SHA256Calc();
virtual void HashInit();
virtual void HashUpdate(void* msg, int len);
virtual void HashFinal(void* hash);
virtual int HashValueSize() const;
virtual int HashBlockSize() const;
private:
SHA256_Context ctx;
};