1 #include <uhub.h>
2
3 #define DEBUG_HASH
4
byte_to_hex(char * dest,uint8_t c)5 static char* byte_to_hex(char* dest, uint8_t c)
6 {
7 static const char* hexchars = "0123456789abcdef";
8 *dest = hexchars[c / 16]; dest++;
9 *dest = hexchars[c % 16]; dest++;
10 return dest;
11 }
12
13
test_tiger_hex(char * input,char * expected)14 static int test_tiger_hex(char* input, char* expected) {
15 char buf[TIGERSIZE*2+1];
16 uint64_t tiger_res[3];
17 int i = 0;
18 #ifdef DEBUG_HASH
19 int res = 0;
20 #endif
21 char* ptr = buf;
22 buf[TIGERSIZE*2] = 0;
23
24 tiger((uint64_t*) input, strlen(input), (uint64_t*) tiger_res);
25 for (i = 0; i < TIGERSIZE; i++)
26 ptr = byte_to_hex(ptr, (char) (((uint8_t*) tiger_res)[i]) );
27
28 #ifdef DEBUG_HASH
29 res = strcasecmp(buf, expected) == 0 ? 1 : 0;
30
31 if (!res)
32 {
33 printf("Expected: '%s', Got: '%s'\n", expected, buf);
34 }
35 return res;
36 #else
37 return strcasecmp(buf, expected) == 0;
38 #endif
39 }
40
41
42 EXO_TEST(hash_tiger_1, {
43 return test_tiger_hex("", "3293AC630C13F0245F92BBB1766E16167A4E58492DDE73F3");
44 });
45
46 EXO_TEST(hash_tiger_2, {
47 return test_tiger_hex("a", "77BEFBEF2E7EF8AB2EC8F93BF587A7FC613E247F5F247809");
48 });
49
50 EXO_TEST(hash_tiger_3, {
51 return test_tiger_hex("abc", "2AAB1484E8C158F2BFB8C5FF41B57A525129131C957B5F93");
52 });
53
54 EXO_TEST(hash_tiger_4, {
55 return test_tiger_hex("message digest", "D981F8CB78201A950DCF3048751E441C517FCA1AA55A29F6");
56 });
57
58 EXO_TEST(hash_tiger_5, {
59 return test_tiger_hex("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "0F7BF9A19B9C58F2B7610DF7E84F0AC3A71C631E7B53F78E");
60 });
61
62 EXO_TEST(hash_tiger_6, {
63 return test_tiger_hex("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "8DCEA680A17583EE502BA38A3C368651890FFBCCDC49A8CC");
64 });
65
66 EXO_TEST(hash_tiger_7, {
67 return test_tiger_hex("12345678901234567890123456789012345678901234567890123456789012345678901234567890", "1C14795529FD9F207A958F84C52F11E887FA0CABDFD91BFD");
68 });
69
70