blob: dce243ff658541d65744e6879d95f79f3a4fbe2e [file] [log] [blame]
Paul Bakker367dae42009-06-28 21:50:27 +00001BEGIN_HEADER
Paul Bakkerc1f3caa2009-10-04 15:25:48 +00002#include <polarssl/config.h>
Paul Bakker367dae42009-06-28 21:50:27 +00003#include <polarssl/md2.h>
4#include <polarssl/md4.h>
5#include <polarssl/md5.h>
6END_HEADER
7
8BEGIN_CASE
9md2_text:text_src_string:hex_hash_string
10{
11 unsigned char src_str[1000];
12 unsigned char hash_str[1000];
13 unsigned char output[33];
14
15 memset(src_str, 0x00, 1000);
16 memset(hash_str, 0x00, 1000);
17 memset(output, 0x00, 33);
18
19 strcpy( (char *) src_str, {text_src_string} );
20
21 md2( src_str, strlen( (char *) src_str ), output );
22 hexify( hash_str, output, 16 );
23
24 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
25}
26END_CASE
27
28BEGIN_CASE
29md4_text:text_src_string:hex_hash_string
30{
31 unsigned char src_str[1000];
32 unsigned char hash_str[1000];
33 unsigned char output[33];
34
35 memset(src_str, 0x00, 1000);
36 memset(hash_str, 0x00, 1000);
37 memset(output, 0x00, 33);
38
39 strcpy( (char *) src_str, {text_src_string} );
40
41 md4( src_str, strlen( (char *) src_str ), output );
42 hexify( hash_str, output, 16 );
43
44 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
45}
46END_CASE
47
48BEGIN_CASE
49md5_text:text_src_string:hex_hash_string
50{
51 unsigned char src_str[1000];
52 unsigned char hash_str[1000];
53 unsigned char output[33];
54
55 memset(src_str, 0x00, 1000);
56 memset(hash_str, 0x00, 1000);
57 memset(output, 0x00, 33);
58
59 strcpy( (char *) src_str, {text_src_string} );
60
61 md5( src_str, strlen( (char *) src_str ), output );
62 hexify( hash_str, output, 16 );
63
64 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
65}
66END_CASE
Paul Bakkere896fea2009-07-06 06:40:23 +000067
68BEGIN_CASE
69md2_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string
70{
71 unsigned char src_str[10000];
72 unsigned char key_str[10000];
73 unsigned char hash_str[10000];
74 unsigned char output[33];
Paul Bakker69998dd2009-07-11 19:15:20 +000075 int key_len, src_len;
Paul Bakkere896fea2009-07-06 06:40:23 +000076
77 memset(src_str, 0x00, 10000);
78 memset(key_str, 0x00, 10000);
79 memset(hash_str, 0x00, 10000);
80 memset(output, 0x00, 33);
81
Paul Bakker69998dd2009-07-11 19:15:20 +000082 key_len = unhexify( key_str, {hex_key_string} );
83 src_len = unhexify( src_str, {hex_src_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +000084
85 md2_hmac( key_str, key_len, src_str, src_len, output );
86 hexify( hash_str, output, 16 );
87
88 TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
89}
90END_CASE
91
92BEGIN_CASE
93md4_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string
94{
95 unsigned char src_str[10000];
96 unsigned char key_str[10000];
97 unsigned char hash_str[10000];
98 unsigned char output[33];
Paul Bakker69998dd2009-07-11 19:15:20 +000099 int key_len, src_len;
Paul Bakkere896fea2009-07-06 06:40:23 +0000100
101 memset(src_str, 0x00, 10000);
102 memset(key_str, 0x00, 10000);
103 memset(hash_str, 0x00, 10000);
104 memset(output, 0x00, 33);
105
Paul Bakker69998dd2009-07-11 19:15:20 +0000106 key_len = unhexify( key_str, {hex_key_string} );
107 src_len = unhexify( src_str, {hex_src_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +0000108
109 md4_hmac( key_str, key_len, src_str, src_len, output );
110 hexify( hash_str, output, 16 );
111
112 TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
113}
114END_CASE
115
116BEGIN_CASE
117md5_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string
118{
119 unsigned char src_str[10000];
120 unsigned char key_str[10000];
121 unsigned char hash_str[10000];
122 unsigned char output[33];
Paul Bakker69998dd2009-07-11 19:15:20 +0000123 int key_len, src_len;
Paul Bakkere896fea2009-07-06 06:40:23 +0000124
125 memset(src_str, 0x00, 10000);
126 memset(key_str, 0x00, 10000);
127 memset(hash_str, 0x00, 10000);
128 memset(output, 0x00, 33);
129
Paul Bakker69998dd2009-07-11 19:15:20 +0000130 key_len = unhexify( key_str, {hex_key_string} );
131 src_len = unhexify( src_str, {hex_src_string} );
Paul Bakkere896fea2009-07-06 06:40:23 +0000132
133 md5_hmac( key_str, key_len, src_str, src_len, output );
134 hexify( hash_str, output, 16 );
135
136 TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
137}
138END_CASE
139
140BEGIN_CASE
141md2_file:filename:hex_hash_string
142{
143 unsigned char hash_str[65];
144 unsigned char output[33];
145
146 memset(hash_str, 0x00, 65);
147 memset(output, 0x00, 33);
148
149 md2_file( {filename}, output);
150 hexify( hash_str, output, 16 );
151
152 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
153}
154END_CASE
155
156BEGIN_CASE
157md4_file:filename:hex_hash_string
158{
159 unsigned char hash_str[65];
160 unsigned char output[33];
161
162 memset(hash_str, 0x00, 65);
163 memset(output, 0x00, 33);
164
165 md4_file( {filename}, output);
166 hexify( hash_str, output, 16 );
167
168 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
169}
170END_CASE
171
172BEGIN_CASE
173md5_file:filename:hex_hash_string
174{
175 unsigned char hash_str[65];
176 unsigned char output[33];
177
178 memset(hash_str, 0x00, 65);
179 memset(output, 0x00, 33);
180
181 md5_file( {filename}, output);
182 hexify( hash_str, output, 16 );
183
184 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
185}
186END_CASE
187
188BEGIN_CASE
189md2_selftest:
190{
191 TEST_ASSERT( md2_self_test( 0 ) == 0 );
192}
193END_CASE
194
195BEGIN_CASE
196md4_selftest:
197{
198 TEST_ASSERT( md4_self_test( 0 ) == 0 );
199}
200END_CASE
201
202BEGIN_CASE
203md5_selftest:
204{
205 TEST_ASSERT( md5_self_test( 0 ) == 0 );
206}
207END_CASE