c3102d10b440fbcf56bd8ead57fe046068208f71
[bertos.git] / bertos / sec / hash / md5_test.c
1
2 #include <cfg/test.h>
3 #include <cfg/debug.h>
4
5 #include "md5.h"
6 #include <string.h>
7
8 int MD5_testSetup(void)
9 {
10         kdbg_init();
11         return 0;
12 }
13
14 int MD5_testTearDown(void)
15 {
16         return 0;
17 }
18
19 int MD5_testRun(void)
20 {
21         int i;
22         MD5_Context context;
23         MD5_init(&context);
24
25         hash_begin(&context.h);
26         hash_update(&context.h, "abc", 3);
27         ASSERT(memcmp(hash_final(&context.h), "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72", 16) == 0);
28
29         hash_begin(&context.h);
30         hash_update(&context.h, "aaa", 3);
31         ASSERT(memcmp(hash_final(&context.h), "\x47\xBC\xE5\xC7\x4F\x58\x9F\x48\x67\xDB\xD5\x7E\x9C\xA9\xF8\x08", 16) == 0);
32
33         hash_begin(&context.h);
34         hash_update(&context.h, "abcdefghijklmnopqrstuvwxyz", 26);
35         ASSERT(memcmp(hash_final(&context.h), "\xC3\xFC\xD3\xD7\x61\x92\xE4\x00\x7D\xFB\x49\x6C\xCA\x67\xE1\x3B", 16) == 0);
36
37         hash_begin(&context.h);
38         hash_update(&context.h, "0123456789", 10);
39         ASSERT(memcmp(hash_final(&context.h), "\x78\x1E\x5E\x24\x5D\x69\xB5\x66\x97\x9B\x86\xE2\x8D\x23\xF2\xC7", 16) == 0);
40
41         hash_begin(&context.h);
42         for (i = 0; i < 1000; i++)
43                 hash_update(&context.h, "a", 1);
44         ASSERT(memcmp(hash_final(&context.h), "\xCA\xBE\x45\xDC\xC9\xAE\x5B\x66\xBA\x86\x60\x0C\xCA\x6B\x8B\xA8", 16) == 0);
45
46         hash_begin(&context.h);
47         for (i = 0; i < 1000000; i++)
48                 hash_update(&context.h, "a", 1);
49         ASSERT(memcmp(hash_final(&context.h), "\x77\x07\xd6\xae\x4e\x02\x7c\x70\xee\xa2\xa9\x35\xc2\x29\x6f\x21", 16) == 0);
50         
51         return 0;
52 }
53
54 TEST_MAIN(MD5);