]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * Test program for MD4 (test vectors from RFC 1320) | |
e280cf66 | 3 | * Copyright (c) 2006-2009, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
9 | #include "includes.h" | |
10 | ||
11 | #include "common.h" | |
03da66bd | 12 | #include "crypto/crypto.h" |
6fc6879b JM |
13 | |
14 | int main(int argc, char *argv[]) | |
15 | { | |
16 | struct { | |
17 | char *data; | |
e280cf66 | 18 | char *hash; |
6fc6879b JM |
19 | } tests[] = { |
20 | { | |
21 | "", | |
22 | "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31" | |
23 | "\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0" | |
24 | }, | |
25 | { | |
26 | "a", | |
27 | "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46" | |
28 | "\x24\x5e\x05\xfb\xdb\xd6\xfb\x24" | |
29 | }, | |
30 | { | |
31 | "abc", | |
32 | "\xa4\x48\x01\x7a\xaf\x21\xd8\x52" | |
33 | "\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d" | |
34 | }, | |
35 | { | |
36 | "message digest", | |
37 | "\xd9\x13\x0a\x81\x64\x54\x9f\xe8" | |
38 | "\x18\x87\x48\x06\xe1\xc7\x01\x4b" | |
39 | }, | |
40 | { | |
41 | "abcdefghijklmnopqrstuvwxyz", | |
42 | "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd" | |
43 | "\xee\xa8\xed\x63\xdf\x41\x2d\xa9" | |
44 | }, | |
45 | { | |
46 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
47 | "0123456789", | |
48 | "\x04\x3f\x85\x82\xf2\x41\xdb\x35" | |
49 | "\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4" | |
50 | }, | |
51 | { | |
52 | "12345678901234567890123456789012345678901234567890" | |
53 | "123456789012345678901234567890", | |
54 | "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19" | |
55 | "\x9c\x3e\x7b\x16\x4f\xcc\x05\x36" | |
56 | } | |
57 | }; | |
58 | unsigned int i; | |
59 | u8 hash[16]; | |
60 | const u8 *addr[2]; | |
61 | size_t len[2]; | |
62 | int errors = 0; | |
63 | ||
e7ecab4a | 64 | for (i = 0; i < ARRAY_SIZE(tests); i++) { |
6fc6879b JM |
65 | printf("MD4 test case %d:", i); |
66 | ||
e280cf66 | 67 | addr[0] = (u8 *) tests[i].data; |
6fc6879b JM |
68 | len[0] = strlen(tests[i].data); |
69 | md4_vector(1, addr, len, hash); | |
70 | if (memcmp(hash, tests[i].hash, 16) != 0) { | |
71 | printf(" FAIL"); | |
72 | errors++; | |
73 | } else | |
74 | printf(" OK"); | |
75 | ||
76 | if (len[0]) { | |
e280cf66 | 77 | addr[0] = (u8 *) tests[i].data; |
6fc6879b | 78 | len[0] = strlen(tests[i].data); |
e280cf66 | 79 | addr[1] = (u8 *) tests[i].data + 1; |
6fc6879b JM |
80 | len[1] = strlen(tests[i].data) - 1; |
81 | md4_vector(1, addr, len, hash); | |
82 | if (memcmp(hash, tests[i].hash, 16) != 0) { | |
83 | printf(" FAIL"); | |
84 | errors++; | |
85 | } else | |
86 | printf(" OK"); | |
87 | } | |
88 | ||
89 | printf("\n"); | |
90 | } | |
91 | ||
92 | return errors; | |
93 | } |