blob: c810c50036b4f8411396043af42e289a65bcc0c4 [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];
74
75 memset(src_str, 0x00, 10000);
76 memset(key_str, 0x00, 10000);
77 memset(hash_str, 0x00, 10000);
78 memset(output, 0x00, 33);
79
80 int key_len = unhexify( key_str, {hex_key_string} );
81 int src_len = unhexify( src_str, {hex_src_string} );
82
83 md2_hmac( key_str, key_len, src_str, src_len, output );
84 hexify( hash_str, output, 16 );
85
86 TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
87}
88END_CASE
89
90BEGIN_CASE
91md4_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string
92{
93 unsigned char src_str[10000];
94 unsigned char key_str[10000];
95 unsigned char hash_str[10000];
96 unsigned char output[33];
97
98 memset(src_str, 0x00, 10000);
99 memset(key_str, 0x00, 10000);
100 memset(hash_str, 0x00, 10000);
101 memset(output, 0x00, 33);
102
103 int key_len = unhexify( key_str, {hex_key_string} );
104 int src_len = unhexify( src_str, {hex_src_string} );
105
106 md4_hmac( key_str, key_len, src_str, src_len, output );
107 hexify( hash_str, output, 16 );
108
109 TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
110}
111END_CASE
112
113BEGIN_CASE
114md5_hmac:trunc_size:hex_key_string:hex_src_string:hex_hash_string
115{
116 unsigned char src_str[10000];
117 unsigned char key_str[10000];
118 unsigned char hash_str[10000];
119 unsigned char output[33];
120
121 memset(src_str, 0x00, 10000);
122 memset(key_str, 0x00, 10000);
123 memset(hash_str, 0x00, 10000);
124 memset(output, 0x00, 33);
125
126 int key_len = unhexify( key_str, {hex_key_string} );
127 int src_len = unhexify( src_str, {hex_src_string} );
128
129 md5_hmac( key_str, key_len, src_str, src_len, output );
130 hexify( hash_str, output, 16 );
131
132 TEST_ASSERT( strncmp( (char *) hash_str, {hex_hash_string}, {trunc_size} * 2 ) == 0 );
133}
134END_CASE
135
136BEGIN_CASE
137md2_file:filename:hex_hash_string
138{
139 unsigned char hash_str[65];
140 unsigned char output[33];
141
142 memset(hash_str, 0x00, 65);
143 memset(output, 0x00, 33);
144
145 md2_file( {filename}, output);
146 hexify( hash_str, output, 16 );
147
148 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
149}
150END_CASE
151
152BEGIN_CASE
153md4_file:filename:hex_hash_string
154{
155 unsigned char hash_str[65];
156 unsigned char output[33];
157
158 memset(hash_str, 0x00, 65);
159 memset(output, 0x00, 33);
160
161 md4_file( {filename}, output);
162 hexify( hash_str, output, 16 );
163
164 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
165}
166END_CASE
167
168BEGIN_CASE
169md5_file:filename:hex_hash_string
170{
171 unsigned char hash_str[65];
172 unsigned char output[33];
173
174 memset(hash_str, 0x00, 65);
175 memset(output, 0x00, 33);
176
177 md5_file( {filename}, output);
178 hexify( hash_str, output, 16 );
179
180 TEST_ASSERT( strcmp( (char *) hash_str, {hex_hash_string} ) == 0 );
181}
182END_CASE
183
184BEGIN_CASE
185md2_selftest:
186{
187 TEST_ASSERT( md2_self_test( 0 ) == 0 );
188}
189END_CASE
190
191BEGIN_CASE
192md4_selftest:
193{
194 TEST_ASSERT( md4_self_test( 0 ) == 0 );
195}
196END_CASE
197
198BEGIN_CASE
199md5_selftest:
200{
201 TEST_ASSERT( md5_self_test( 0 ) == 0 );
202}
203END_CASE