source: trunk/src/cutest_sh_tiger0.c@ 116

Last change on this file since 116 was 107, checked in by rainer, 17 years ago

Fix incorrect handling of files with zero size in GrowingLogFiles.

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