]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/test-md5.c
Add initial parts for SAE
[thirdparty/hostap.git] / tests / test-md5.c
CommitLineData
6fc6879b
JM
1/*
2 * Test program for MD5 (test vectors from RFC 1321)
3 * Copyright (c) 2006, Jouni Malinen <j@w1.fi>
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
14int main(int argc, char *argv[])
15{
16 struct {
17 char *data;
1767f7c1 18 char *hash;
6fc6879b
JM
19 } tests[] = {
20 {
21 "",
22 "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04"
23 "\xe9\x80\x09\x98\xec\xf8\x42\x7e"
24 },
25 {
26 "a",
27 "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8"
28 "\x31\xc3\x99\xe2\x69\x77\x26\x61"
29 },
30 {
31 "abc",
32 "\x90\x01\x50\x98\x3c\xd2\x4f\xb0"
33 "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72"
34 },
35 {
36 "message digest",
37 "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d"
38 "\x52\x5a\x2f\x31\xaa\xf1\x61\xd0"
39 },
40 {
41 "abcdefghijklmnopqrstuvwxyz",
42 "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00"
43 "\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"
44 },
45 {
46 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
47 "0123456789",
48 "\xd1\x74\xab\x98\xd2\x77\xd9\xf5"
49 "\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f"
50 },
51 {
52 "12345678901234567890123456789012345678901234567890"
53 "123456789012345678901234567890",
54 "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55"
55 "\xac\x49\xda\x2e\x21\x07\xb6\x7a"
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
64 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
65 printf("MD5 test case %d:", i);
66
1767f7c1 67 addr[0] = (u8 *) tests[i].data;
6fc6879b
JM
68 len[0] = strlen(tests[i].data);
69 md5_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]) {
1767f7c1 77 addr[0] = (u8 *) tests[i].data;
6fc6879b 78 len[0] = strlen(tests[i].data);
1767f7c1 79 addr[1] = (u8 *) tests[i].data + 1;
6fc6879b
JM
80 len[1] = strlen(tests[i].data) - 1;
81 md5_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}