forked from gtkhash/gtkhash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
58 lines (41 loc) · 1.26 KB
/
main.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
#include <iostream>
#include <cstring>
#include "md6_easy_stub.hpp"
char _nibble2hex(unsigned char nibble) {
if (nibble < 10)
return '0' + nibble;
else
return 'a' + nibble - 10;
}
void _hexDigest(unsigned char* digest, char* hexdigest, int byteLen){
for(unsigned int i = 0,h=0; i < byteLen; i++){
int hi = (digest[i]&0xF0) >> 4;
int lo = digest[i]&0x0F;
hexdigest[h++]=_nibble2hex(hi);
hexdigest[h++]=_nibble2hex(lo);
// std::cout<<"[main] "<<_nibble2hex(hi)<<_nibble2hex(lo)<<std::endl;
}
}
void test(const char* inputS, int hashBitLen){
int hashByteLen = hashBitLen/8;
const unsigned char* input = (unsigned char*) inputS;
md6_state* ctx = md6_init_easy(hashBitLen);
md6_update(ctx, input, strlen(inputS)*8);
unsigned char* output2 = (unsigned char*) malloc(hashByteLen);
md6_final(ctx,output2);
char* output2h = (char*) malloc(hashByteLen*2 + 1);
output2h[hashByteLen*2]=0;
_hexDigest(output2,output2h,hashByteLen);
std::cout<<"md6-"<<hashBitLen<<" test output raw: "<<output2h<<std::endl;
// fnv0(input, strlen(input), output);
// printf("output %s",output);
free(output2);
free(output2h);
md6_cleanup_easy(ctx);
}
int main(){
test("test",128);
test("test",256);
test("test",512);
return 0;
}