source: trunk/src/cutest_sh_tiger0.c@ 100

Last change on this file since 100 was 96, checked in by rainer, 18 years ago

Fix for ticket #54 (samhain_hide module does not work under kernel 2.6.20).

File size: 11.9 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 */
141 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
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
149 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
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 */
165 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
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 */
181 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
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 */
207 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
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 */
230 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
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 */
270 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0);
271 expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
272 CuAssertStrEquals(tc, expected, actual);
273
274 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0);
275 expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
276 CuAssertStrEquals(tc, expected, actual);
277
278 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
279 expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
280 CuAssertStrEquals(tc, expected, actual);
281
282 fp = fopen("cutest_foo", "a");
283 CuAssertPtrNotNull(tc, fp);
284 result = fprintf(fp, "%s", teststring);
285 CuAssertTrue(tc, result >= 0);
286 result = fclose(fp);
287 CuAssertTrue(tc, result == 0);
288
289 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0);
290 expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
291 CuAssertStrEquals(tc, expected, actual);
292
293 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0);
294 expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
295 CuAssertStrEquals(tc, expected, actual);
296
297 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 3*testlen, 0);
298 expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
299 CuAssertStrEquals(tc, expected, actual);
300
301 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
302 expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
303 CuAssertStrEquals(tc, expected, actual);
304
305 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 5, 0);
306 expected = "9F00F599072300DD276ABB38C8EB6DEC37790C116F9D2BDF";
307 CuAssertStrEquals(tc, expected, actual);
308
309 /* same results as GNU md5sum */
310
311 result = sh_tiger_hashtype("MD5");
312 CuAssertTrue(tc, result == 0);
313
314 rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
315 CuAssertTrue(tc, rval_open >= 0);
316 tiger_fd = rval_open;
317
318 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, testlen, 0);
319 expected = "11E7E7EA486136273606BEE57C71F34B0000000000000000";
320 CuAssertStrEquals(tc, expected, actual);
321
322 result = sl_rewind(rval_open);
323 CuAssertTrue(tc, rval_open >= 0);
324
325 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 2*testlen, 0);
326 expected = "D49DAD474095D467E2E5EFCB2DC23A770000000000000000";
327 CuAssertStrEquals(tc, expected, actual);
328
329 result = sl_rewind(rval_open);
330 CuAssertTrue(tc, rval_open >= 0);
331
332 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 3*testlen, 0);
333 expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
334 CuAssertStrEquals(tc, expected, actual);
335
336 result = sl_rewind(rval_open);
337 CuAssertTrue(tc, rval_open >= 0);
338
339 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
340 expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
341 CuAssertStrEquals(tc, expected, actual);
342
343 /* same result as gpg --print-md SHA1
344 */
345
346 result = sh_tiger_hashtype("SHA1");
347 CuAssertTrue(tc, result == 0);
348
349 result = sl_rewind(rval_open);
350 CuAssertTrue(tc, rval_open >= 0);
351
352 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, testlen, 0);
353 expected = "F37DB4344CCD140EE315179E9A27512FB4704F0F00000000";
354 CuAssertStrEquals(tc, expected, actual);
355
356 result = sl_rewind(rval_open);
357 CuAssertTrue(tc, rval_open >= 0);
358
359 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 2*testlen, 0);
360 expected = "D2AD5FC366452D81400BAC31F96269DEEF314BC200000000";
361 CuAssertStrEquals(tc, expected, actual);
362
363 result = sl_rewind(rval_open);
364 CuAssertTrue(tc, rval_open >= 0);
365
366 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 3*testlen, 0);
367 expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
368 CuAssertStrEquals(tc, expected, actual);
369
370 result = sl_rewind(rval_open);
371 CuAssertTrue(tc, rval_open >= 0);
372
373 actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 0, 0);
374 expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
375 CuAssertStrEquals(tc, expected, actual);
376
377 result = sl_close(rval_open);
378 CuAssertTrue(tc, result == 0);
379
380 result = remove("cutest_foo");
381 CuAssertTrue(tc, result == 0);
382}
Note: See TracBrowser for help on using the repository browser.