-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathed2k_hash.cpp
64 lines (56 loc) · 1.29 KB
/
ed2k_hash.cpp
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
/* implementations for ed2k_hash.h */
#include "ed2k_hash.h"
CEd2kHash::CEd2kHash() {
part_count = 0;
current_bytes = 0;
}
CEd2kHash::~CEd2kHash(){
}
void CEd2kHash::restart_calc(){
md4_hashes.clear();
md4class.Reset();
part_count = 0;
current_bytes = 0;
}
void CEd2kHash::add_data(BYTE* data,const unsigned int size){
unsigned int count;
MD4 current_hash;
if(current_bytes + size >= BLOCKSIZE) {
count = BLOCKSIZE - current_bytes;
md4class.Add(data,count);
md4class.Finish();
md4class.GetHash(current_hash.b);
md4class.Reset();
md4_hashes.push_back(current_hash);
current_bytes = 0;
part_count++;
this->add_data(data + count,size-count);
} else {
md4class.Add(data,size);
current_bytes += size;
}
}
void CEd2kHash::finish_calc(){
MD4 current_hash;
list<MD4>::iterator it;
if(current_bytes > 0) {
md4class.Finish();
md4class.GetHash(current_hash.b);
md4_hashes.push_back(current_hash);
part_count++;
}
if(part_count == 1)
memcpy(ed2k_hash,(md4_hashes.begin())->b,16);
else {
md4class.Reset();
for(it=md4_hashes.begin();it!=md4_hashes.end();it++) {
md4class.Add(it->b,16);
}
md4class.Finish();
md4class.GetHash(current_hash.b);
memcpy(ed2k_hash,current_hash.b,16);
}
}
void CEd2kHash::get_hash(BYTE ed2khash[16]){
memcpy(ed2khash,ed2k_hash,16);
}