source: branches/samhain-2_2-branch/src/cutest_sh_tiger0.c@ 427

Last change on this file since 427 was 19, checked in by rainer, 19 years ago

Rewrite of test suite, checksum for growing logs, fix for minor bug with dead client detection.

File size: 11.8 KB
Line 
1
2#include "config_xor.h"
3
4#include <string.h>
5#include <stdlib.h>
6#include <stdio.h>
7#include "CuTest.h"
8
9#include "sh_tiger.h"
10
11static void init() {
12
13 extern unsigned char TcpFlag[8][PW_LEN+1];
14 extern UINT32 ErrFlag[2];
15 unsigned char * dez = NULL;
16 int i;
17
18 skey = (sh_key_t *) malloc (sizeof(sh_key_t));
19 if (skey == NULL)
20 {
21 perror(_("sh_init"));
22 _exit (EXIT_FAILURE);
23 }
24
25 skey->mlock_failed = SL_FALSE;
26 skey->rngI = BAD;
27 /* properly initialized later
28 */
29 skey->rng0[0] = 0x03; skey->rng0[1] = 0x09; skey->rng0[2] = 0x17;
30 skey->rng1[0] = 0x03; skey->rng1[1] = 0x09; skey->rng1[2] = 0x17;
31 skey->rng2[0] = 0x03; skey->rng2[1] = 0x09; skey->rng2[2] = 0x17;
32
33 for (i = 0; i < KEY_BYT; ++i)
34 skey->poolv[i] = '\0';
35
36 skey->poolc = 0;
37
38 skey->ErrFlag[0] = ErrFlag[0];
39 ErrFlag[0] = 0;
40 skey->ErrFlag[1] = ErrFlag[1];
41 ErrFlag[1] = 0;
42
43 dez = &(TcpFlag[POS_TF-1][0]);
44 for (i = 0; i < PW_LEN; ++i)
45 {
46 skey->pw[i] = (char) (*dez);
47 (*dez) = '\0';
48 ++dez;
49 }
50
51 skey->sh_sockpass[0] = '\0';
52 skey->sigkey_old[0] = '\0';
53 skey->sigkey_new[0] = '\0';
54 skey->mailkey_old[0] = '\0';
55 skey->mailkey_new[0] = '\0';
56 skey->crypt[0] = '\0';
57 skey->session[0] = '\0';
58 skey->vernam[0] = '\0';
59
60}
61
62void Test_tiger(CuTest *tc) {
63
64 char * input;
65 char * actual;
66 char * expected;
67
68 input = "";
69 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
70 expected = "24F0130C63AC933216166E76B1BB925FF373DE2D49584E7A";
71 CuAssertStrEquals(tc, expected, actual);
72
73 input = "abc";
74 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
75 expected = "F258C1E88414AB2A527AB541FFC5B8BF935F7B951C132951";
76 CuAssertStrEquals(tc, expected, actual);
77
78 input = "Tiger";
79 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
80 expected = "9F00F599072300DD276ABB38C8EB6DEC37790C116F9D2BDF";
81 CuAssertStrEquals(tc, expected, actual);
82
83 input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
84 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
85 expected = "87FB2A9083851CF7470D2CF810E6DF9EB586445034A5A386";
86 CuAssertStrEquals(tc, expected, actual);
87
88 input = "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789";
89 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
90 expected = "467DB80863EBCE488DF1CD1261655DE957896565975F9197";
91 CuAssertStrEquals(tc, expected, actual);
92
93 input = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham";
94 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
95 expected = "0C410A042968868A1671DA5A3FD29A725EC1E457D3CDB303";
96 CuAssertStrEquals(tc, expected, actual);
97
98 input = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge.";
99 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
100 expected = "EBF591D5AFA655CE7F22894FF87F54AC89C811B6B0DA3193";
101 CuAssertStrEquals(tc, expected, actual);
102
103 input = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.";
104 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
105 expected = "3D9AEB03D1BD1A6357B2774DFD6D5B24DD68151D503974FC";
106 CuAssertStrEquals(tc, expected, actual);
107
108 input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
109 actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
110 expected = "00B83EB4E53440C576AC6AAEE0A7485825FD15E70A59FFE4";
111 CuAssertStrEquals(tc, expected, actual);
112}
113
114void Test_tiger_file(CuTest *tc) {
115
116 SL_TICKET rval_open;
117 FILE * fp;
118 int result;
119 char * actual;
120 char * expected;
121
122 init();
123
124 fp = fopen("cutest_foo", "w");
125 CuAssertPtrNotNull(tc, fp);
126
127 result = fprintf(fp, "%s\n",
128 "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789");
129 CuAssertTrue(tc, result >= 0);
130
131 result = fclose(fp);
132 CuAssertTrue(tc, result == 0);
133
134 result = sh_tiger_hashtype("TIGER192");
135 CuAssertTrue(tc, result == 0);
136
137 /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
138 */
139 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
140 expected = "0E9321614C966A33608C2A15F156E0435CACFD1213B9F095";
141 CuAssertStrEquals(tc, expected, actual);
142
143 rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
144 CuAssertTrue(tc, rval_open >= 0);
145 tiger_fd = rval_open;
146
147 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
148 expected = "0E9321614C966A33608C2A15F156E0435CACFD1213B9F095";
149 CuAssertStrEquals(tc, expected, actual);
150
151 result = sl_close(rval_open);
152 CuAssertTrue(tc, result == 0);
153
154 result = sh_tiger_hashtype("MD5");
155 CuAssertTrue(tc, result == 0);
156
157 rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
158 CuAssertTrue(tc, rval_open >= 0);
159 tiger_fd = rval_open;
160
161 /* same result as GNU md5sum
162 */
163 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
164 expected = "AEEC4DDA496BCFBA691F4E8863BA84C00000000000000000";
165 CuAssertStrEquals(tc, expected, actual);
166
167 result = sl_close(rval_open);
168 CuAssertTrue(tc, result == 0);
169
170 result = sh_tiger_hashtype("SHA1");
171 CuAssertTrue(tc, result == 0);
172
173 rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
174 CuAssertTrue(tc, rval_open >= 0);
175 tiger_fd = rval_open;
176
177 /* same result as gpg --print-md SHA1
178 */
179 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
180 expected = "2FE65D1D995B8F8BC8B13F798C07E7E935A787ED00000000";
181 CuAssertStrEquals(tc, expected, actual);
182
183 result = sl_close(rval_open);
184 CuAssertTrue(tc, result == 0);
185
186 result = remove("cutest_foo");
187 CuAssertTrue(tc, result == 0);
188
189 /* --------------------------------------------------- */
190
191 fp = fopen("cutest_foo", "w");
192 CuAssertPtrNotNull(tc, fp);
193
194 result = fprintf(fp, "\n");
195 CuAssertTrue(tc, result >= 0);
196
197 result = fclose(fp);
198 CuAssertTrue(tc, result == 0);
199
200 result = sh_tiger_hashtype("TIGER192");
201 CuAssertTrue(tc, result == 0);
202
203 /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
204 */
205 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
206 expected = "F987845A0EA784367BF9E4DB09014995810F27C99C891734";
207 CuAssertStrEquals(tc, expected, actual);
208
209 result = remove("cutest_foo");
210 CuAssertTrue(tc, result == 0);
211
212 /* --------------------------------------------------- */
213
214 fp = fopen("cutest_foo", "w");
215 CuAssertPtrNotNull(tc, fp);
216
217 result = fprintf(fp, "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.\n");
218 CuAssertTrue(tc, result >= 0);
219
220 result = fclose(fp);
221 CuAssertTrue(tc, result == 0);
222
223 result = sh_tiger_hashtype("TIGER192");
224 CuAssertTrue(tc, result == 0);
225
226 /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
227 */
228 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
229 expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
230 CuAssertStrEquals(tc, expected, actual);
231
232 result = remove("cutest_foo");
233 CuAssertTrue(tc, result == 0);
234
235}
236
237/* test checksum of file upto some given length
238 */
239void Test_tiger_file_with_length(CuTest *tc) {
240
241 SL_TICKET rval_open;
242 FILE * fp;
243 int result;
244 char * actual;
245 char * expected;
246
247 char * teststring = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.\n";
248 int testlen = strlen(teststring);
249
250 init();
251
252 fp = fopen("cutest_foo", "w");
253 CuAssertPtrNotNull(tc, fp);
254
255 result = fprintf(fp, "%s", teststring);
256 CuAssertTrue(tc, result >= 0);
257 result = fprintf(fp, "%s", teststring);
258 CuAssertTrue(tc, result >= 0);
259
260 result = fclose(fp);
261 CuAssertTrue(tc, result == 0);
262
263 result = sh_tiger_hashtype("TIGER192");
264 CuAssertTrue(tc, result == 0);
265
266 /* same as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
267 */
268 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0);
269 expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
270 CuAssertStrEquals(tc, expected, actual);
271
272 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0);
273 expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
274 CuAssertStrEquals(tc, expected, actual);
275
276 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
277 expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
278 CuAssertStrEquals(tc, expected, actual);
279
280 fp = fopen("cutest_foo", "a");
281 CuAssertPtrNotNull(tc, fp);
282 result = fprintf(fp, "%s", teststring);
283 CuAssertTrue(tc, result >= 0);
284 result = fclose(fp);
285 CuAssertTrue(tc, result == 0);
286
287 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0);
288 expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
289 CuAssertStrEquals(tc, expected, actual);
290
291 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0);
292 expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
293 CuAssertStrEquals(tc, expected, actual);
294
295 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 3*testlen, 0);
296 expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
297 CuAssertStrEquals(tc, expected, actual);
298
299 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
300 expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
301 CuAssertStrEquals(tc, expected, actual);
302
303 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 5, 0);
304 expected = "9F00F599072300DD276ABB38C8EB6DEC37790C116F9D2BDF";
305 CuAssertStrEquals(tc, expected, actual);
306
307 /* same results as GNU md5sum */
308
309 result = sh_tiger_hashtype("MD5");
310 CuAssertTrue(tc, result == 0);
311
312 rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
313 CuAssertTrue(tc, rval_open >= 0);
314 tiger_fd = rval_open;
315
316 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, testlen, 0);
317 expected = "11E7E7EA486136273606BEE57C71F34B0000000000000000";
318 CuAssertStrEquals(tc, expected, actual);
319
320 result = sl_rewind(rval_open);
321 CuAssertTrue(tc, rval_open >= 0);
322
323 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 2*testlen, 0);
324 expected = "D49DAD474095D467E2E5EFCB2DC23A770000000000000000";
325 CuAssertStrEquals(tc, expected, actual);
326
327 result = sl_rewind(rval_open);
328 CuAssertTrue(tc, rval_open >= 0);
329
330 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 3*testlen, 0);
331 expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
332 CuAssertStrEquals(tc, expected, actual);
333
334 result = sl_rewind(rval_open);
335 CuAssertTrue(tc, rval_open >= 0);
336
337 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
338 expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
339 CuAssertStrEquals(tc, expected, actual);
340
341 /* same result as gpg --print-md SHA1
342 */
343
344 result = sh_tiger_hashtype("SHA1");
345 CuAssertTrue(tc, result == 0);
346
347 result = sl_rewind(rval_open);
348 CuAssertTrue(tc, rval_open >= 0);
349
350 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, testlen, 0);
351 expected = "F37DB4344CCD140EE315179E9A27512FB4704F0F00000000";
352 CuAssertStrEquals(tc, expected, actual);
353
354 result = sl_rewind(rval_open);
355 CuAssertTrue(tc, rval_open >= 0);
356
357 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 2*testlen, 0);
358 expected = "D2AD5FC366452D81400BAC31F96269DEEF314BC200000000";
359 CuAssertStrEquals(tc, expected, actual);
360
361 result = sl_rewind(rval_open);
362 CuAssertTrue(tc, rval_open >= 0);
363
364 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 3*testlen, 0);
365 expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
366 CuAssertStrEquals(tc, expected, actual);
367
368 result = sl_rewind(rval_open);
369 CuAssertTrue(tc, rval_open >= 0);
370
371 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
372 expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
373 CuAssertStrEquals(tc, expected, actual);
374
375 result = sl_close(rval_open);
376 CuAssertTrue(tc, result == 0);
377
378 result = remove("cutest_foo");
379 CuAssertTrue(tc, result == 0);
380}
Note: See TracBrowser for help on using the repository browser.