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