4fe5428c46eb210d0872a6e4fca14cb8f77327db
[bertos.git] / bertos / sec / hash / ripemd_test.c
1
2 #include <cfg/test.h>
3 #include <cfg/debug.h>
4
5 #include "RIPEMD.h"
6 #include <string.h>
7
8 int RIPEMD_testSetup(void)
9 {
10         kdbg_init();
11         return 0;
12 }
13
14 int RIPEMD_testTearDown(void)
15 {
16         return 0;
17 }
18
19 int RIPEMD_testRun(void)
20 {
21         Hash *h = RIPEMD_stackinit();
22
23         hash_begin(h);
24         ASSERT(memcmp(hash_final(h), "\x9c\x11\x85\xa5\xc5\xe9\xfc\x54\x61\x28\x08\x97\x7e\xe8\xf5\x48\xb2\x25\x8d\x31", 20) == 0);
25
26         hash_begin(h);
27         hash_update(h, "a", 1);
28         ASSERT(memcmp(hash_final(h), "\x0b\xdc\x9d\x2d\x25\x6b\x3e\xe9\xda\xae\x34\x7b\xe6\xf4\xdc\x83\x5a\x46\x7f\xfe", 20) == 0);
29         
30         hash_begin(h);
31         hash_update(h, "abc", 3);
32         ASSERT(memcmp(hash_final(h), "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6\xb0\x87\xf1\x5a\x0b\xfc", 20) == 0);
33
34         hash_begin(h);
35         hash_update(h, "message digest", 14);
36         ASSERT(memcmp(hash_final(h), "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8\x5f\xfa\x21\x59\x5f\x36", 20) == 0);
37
38         hash_begin(h);
39         hash_update(h, "abcdefghijklmnopqrstuvwxyz", 26);
40         ASSERT(memcmp(hash_final(h), "\xf7\x1c\x27\x10\x9c\x69\x2c\x1b\x56\xbb\xdc\xeb\x5b\x9d\x28\x65\xb3\x70\x8d\xbc", 20) == 0);
41
42         hash_begin(h);
43         hash_update(h, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56);
44         ASSERT(memcmp(hash_final(h), "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc\xf4\x9a\xda\x62\xeb\x2b", 20) == 0);
45
46         hash_begin(h);
47         hash_update(h, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62);
48         ASSERT(memcmp(hash_final(h), "\xb0\xe2\x0b\x6e\x31\x16\x64\x02\x86\xed\x3a\x87\xa5\x71\x30\x79\xb2\x1f\x51\x89", 20) == 0);
49
50         hash_begin(h);
51         for (int i=0;i<8;++i)
52                 hash_update(h, "1234567890", 10);
53         ASSERT(memcmp(hash_final(h), "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab\x82\xbf\x63\x32\x6b\xfb", 20) == 0);
54
55         hash_begin(h);
56         for (int i=0;i<1000000;++i)
57                 hash_update(h, "a", 1);
58         ASSERT(memcmp(hash_final(h), "\x52\x78\x32\x43\xc1\x69\x7b\xdb\xe1\x6d\x37\xf9\x7f\x68\xf0\x83\x25\xdc\x15\x28", 20) == 0);
59
60         return 0;
61 }
62
63 TEST_MAIN(RIPEMD);