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 |
|
---|
11 | static 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 | 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 | {
|
---|
58 | perror(_("sh_init"));
|
---|
59 | _exit (EXIT_FAILURE);
|
---|
60 | }
|
---|
61 |
|
---|
62 | }
|
---|
63 |
|
---|
64 | void Test_tiger(CuTest *tc) {
|
---|
65 |
|
---|
66 | char * input;
|
---|
67 | char * actual;
|
---|
68 | char * expected;
|
---|
69 | char hashbuf[KEYBUF_SIZE];
|
---|
70 |
|
---|
71 | input = "";
|
---|
72 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
73 | expected = "24F0130C63AC933216166E76B1BB925FF373DE2D49584E7A";
|
---|
74 | CuAssertStrEquals(tc, expected, actual);
|
---|
75 |
|
---|
76 | input = "abc";
|
---|
77 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
78 | expected = "F258C1E88414AB2A527AB541FFC5B8BF935F7B951C132951";
|
---|
79 | CuAssertStrEquals(tc, expected, actual);
|
---|
80 |
|
---|
81 | input = "Tiger";
|
---|
82 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
83 | expected = "9F00F599072300DD276ABB38C8EB6DEC37790C116F9D2BDF";
|
---|
84 | CuAssertStrEquals(tc, expected, actual);
|
---|
85 |
|
---|
86 | input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
|
---|
87 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
88 | expected = "87FB2A9083851CF7470D2CF810E6DF9EB586445034A5A386";
|
---|
89 | CuAssertStrEquals(tc, expected, actual);
|
---|
90 |
|
---|
91 | input = "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789";
|
---|
92 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
93 | expected = "467DB80863EBCE488DF1CD1261655DE957896565975F9197";
|
---|
94 | CuAssertStrEquals(tc, expected, actual);
|
---|
95 |
|
---|
96 | input = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham";
|
---|
97 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
98 | expected = "0C410A042968868A1671DA5A3FD29A725EC1E457D3CDB303";
|
---|
99 | CuAssertStrEquals(tc, expected, actual);
|
---|
100 |
|
---|
101 | input = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge.";
|
---|
102 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
103 | expected = "EBF591D5AFA655CE7F22894FF87F54AC89C811B6B0DA3193";
|
---|
104 | CuAssertStrEquals(tc, expected, actual);
|
---|
105 |
|
---|
106 | input = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.";
|
---|
107 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
108 | expected = "3D9AEB03D1BD1A6357B2774DFD6D5B24DD68151D503974FC";
|
---|
109 | CuAssertStrEquals(tc, expected, actual);
|
---|
110 |
|
---|
111 | input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
|
---|
112 | actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
|
---|
113 | expected = "00B83EB4E53440C576AC6AAEE0A7485825FD15E70A59FFE4";
|
---|
114 | CuAssertStrEquals(tc, expected, actual);
|
---|
115 | }
|
---|
116 |
|
---|
117 | void Test_tiger_file(CuTest *tc) {
|
---|
118 |
|
---|
119 | SL_TICKET rval_open;
|
---|
120 | FILE * fp;
|
---|
121 | int result;
|
---|
122 | char * actual;
|
---|
123 | char * expected;
|
---|
124 | char hashbuf[KEYBUF_SIZE];
|
---|
125 |
|
---|
126 | init();
|
---|
127 |
|
---|
128 | fp = fopen("cutest_foo", "w");
|
---|
129 | CuAssertPtrNotNull(tc, fp);
|
---|
130 |
|
---|
131 | result = fprintf(fp, "%s\n",
|
---|
132 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789");
|
---|
133 | CuAssertTrue(tc, result >= 0);
|
---|
134 |
|
---|
135 | result = fclose(fp);
|
---|
136 | CuAssertTrue(tc, result == 0);
|
---|
137 |
|
---|
138 | result = sh_tiger_hashtype("TIGER192");
|
---|
139 | CuAssertTrue(tc, result == 0);
|
---|
140 |
|
---|
141 | /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
|
---|
142 | */
|
---|
143 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
144 | expected = "0E9321614C966A33608C2A15F156E0435CACFD1213B9F095";
|
---|
145 | CuAssertStrEquals(tc, expected, actual);
|
---|
146 |
|
---|
147 | rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
|
---|
148 | CuAssertTrue(tc, rval_open >= 0);
|
---|
149 |
|
---|
150 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
151 | expected = "0E9321614C966A33608C2A15F156E0435CACFD1213B9F095";
|
---|
152 | CuAssertStrEquals(tc, expected, actual);
|
---|
153 |
|
---|
154 | result = sl_close(rval_open);
|
---|
155 | CuAssertTrue(tc, result == 0);
|
---|
156 |
|
---|
157 | result = sh_tiger_hashtype("MD5");
|
---|
158 | CuAssertTrue(tc, result == 0);
|
---|
159 |
|
---|
160 | rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
|
---|
161 | CuAssertTrue(tc, rval_open >= 0);
|
---|
162 |
|
---|
163 | /* same result as GNU md5sum
|
---|
164 | */
|
---|
165 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
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 |
|
---|
178 | /* same result as gpg --print-md SHA1
|
---|
179 | */
|
---|
180 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
181 | expected = "2FE65D1D995B8F8BC8B13F798C07E7E935A787ED00000000";
|
---|
182 | CuAssertStrEquals(tc, expected, actual);
|
---|
183 |
|
---|
184 | result = sl_close(rval_open);
|
---|
185 | CuAssertTrue(tc, result == 0);
|
---|
186 |
|
---|
187 | result = remove("cutest_foo");
|
---|
188 | CuAssertTrue(tc, result == 0);
|
---|
189 |
|
---|
190 | /* --------------------------------------------------- */
|
---|
191 |
|
---|
192 | fp = fopen("cutest_foo", "w");
|
---|
193 | CuAssertPtrNotNull(tc, fp);
|
---|
194 |
|
---|
195 | result = fprintf(fp, "\n");
|
---|
196 | CuAssertTrue(tc, result >= 0);
|
---|
197 |
|
---|
198 | result = fclose(fp);
|
---|
199 | CuAssertTrue(tc, result == 0);
|
---|
200 |
|
---|
201 | result = sh_tiger_hashtype("TIGER192");
|
---|
202 | CuAssertTrue(tc, result == 0);
|
---|
203 |
|
---|
204 | /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
|
---|
205 | */
|
---|
206 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
207 | expected = "F987845A0EA784367BF9E4DB09014995810F27C99C891734";
|
---|
208 | CuAssertStrEquals(tc, expected, actual);
|
---|
209 |
|
---|
210 | result = remove("cutest_foo");
|
---|
211 | CuAssertTrue(tc, result == 0);
|
---|
212 |
|
---|
213 | /* --------------------------------------------------- */
|
---|
214 |
|
---|
215 | fp = fopen("cutest_foo", "w");
|
---|
216 | CuAssertPtrNotNull(tc, fp);
|
---|
217 |
|
---|
218 | result = fprintf(fp, "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.\n");
|
---|
219 | CuAssertTrue(tc, result >= 0);
|
---|
220 |
|
---|
221 | result = fclose(fp);
|
---|
222 | CuAssertTrue(tc, result == 0);
|
---|
223 |
|
---|
224 | result = sh_tiger_hashtype("TIGER192");
|
---|
225 | CuAssertTrue(tc, result == 0);
|
---|
226 |
|
---|
227 | /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
|
---|
228 | */
|
---|
229 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
230 | expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
|
---|
231 | CuAssertStrEquals(tc, expected, actual);
|
---|
232 |
|
---|
233 | result = remove("cutest_foo");
|
---|
234 | CuAssertTrue(tc, result == 0);
|
---|
235 |
|
---|
236 | }
|
---|
237 |
|
---|
238 | /* test checksum of file upto some given length
|
---|
239 | */
|
---|
240 | void Test_tiger_file_with_length(CuTest *tc) {
|
---|
241 |
|
---|
242 | SL_TICKET rval_open;
|
---|
243 | FILE * fp;
|
---|
244 | int result;
|
---|
245 | char * actual;
|
---|
246 | char * expected;
|
---|
247 | char hashbuf[KEYBUF_SIZE];
|
---|
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, 0, 0, hashbuf, sizeof(hashbuf));
|
---|
271 | expected = "24F0130C63AC933216166E76B1BB925FF373DE2D49584E7A";
|
---|
272 | CuAssertStrEquals(tc, expected, actual);
|
---|
273 |
|
---|
274 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
275 | expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
|
---|
276 | CuAssertStrEquals(tc, expected, actual);
|
---|
277 |
|
---|
278 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
279 | expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
|
---|
280 | CuAssertStrEquals(tc, expected, actual);
|
---|
281 |
|
---|
282 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
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, hashbuf, sizeof(hashbuf));
|
---|
294 | expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
|
---|
295 | CuAssertStrEquals(tc, expected, actual);
|
---|
296 |
|
---|
297 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
298 | expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
|
---|
299 | CuAssertStrEquals(tc, expected, actual);
|
---|
300 |
|
---|
301 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 3*testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
302 | expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
|
---|
303 | CuAssertStrEquals(tc, expected, actual);
|
---|
304 |
|
---|
305 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
306 | expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
|
---|
307 | CuAssertStrEquals(tc, expected, actual);
|
---|
308 |
|
---|
309 | actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 5, 0, hashbuf, sizeof(hashbuf));
|
---|
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 |
|
---|
321 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
322 | expected = "11E7E7EA486136273606BEE57C71F34B0000000000000000";
|
---|
323 | CuAssertStrEquals(tc, expected, actual);
|
---|
324 |
|
---|
325 | result = sl_rewind(rval_open);
|
---|
326 | CuAssertTrue(tc, rval_open >= 0);
|
---|
327 |
|
---|
328 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, 2*testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
329 | expected = "D49DAD474095D467E2E5EFCB2DC23A770000000000000000";
|
---|
330 | CuAssertStrEquals(tc, expected, actual);
|
---|
331 |
|
---|
332 | result = sl_rewind(rval_open);
|
---|
333 | CuAssertTrue(tc, rval_open >= 0);
|
---|
334 |
|
---|
335 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, 3*testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
336 | expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
|
---|
337 | CuAssertStrEquals(tc, expected, actual);
|
---|
338 |
|
---|
339 | result = sl_rewind(rval_open);
|
---|
340 | CuAssertTrue(tc, rval_open >= 0);
|
---|
341 |
|
---|
342 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
343 | expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
|
---|
344 | CuAssertStrEquals(tc, expected, actual);
|
---|
345 |
|
---|
346 | /* same result as gpg --print-md SHA1
|
---|
347 | */
|
---|
348 |
|
---|
349 | result = sh_tiger_hashtype("SHA1");
|
---|
350 | CuAssertTrue(tc, result == 0);
|
---|
351 |
|
---|
352 | result = sl_rewind(rval_open);
|
---|
353 | CuAssertTrue(tc, rval_open >= 0);
|
---|
354 |
|
---|
355 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
356 | expected = "F37DB4344CCD140EE315179E9A27512FB4704F0F00000000";
|
---|
357 | CuAssertStrEquals(tc, expected, actual);
|
---|
358 |
|
---|
359 | result = sl_rewind(rval_open);
|
---|
360 | CuAssertTrue(tc, rval_open >= 0);
|
---|
361 |
|
---|
362 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, 2*testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
363 | expected = "D2AD5FC366452D81400BAC31F96269DEEF314BC200000000";
|
---|
364 | CuAssertStrEquals(tc, expected, actual);
|
---|
365 |
|
---|
366 | result = sl_rewind(rval_open);
|
---|
367 | CuAssertTrue(tc, rval_open >= 0);
|
---|
368 |
|
---|
369 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, 3*testlen, 0, hashbuf, sizeof(hashbuf));
|
---|
370 | expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
|
---|
371 | CuAssertStrEquals(tc, expected, actual);
|
---|
372 |
|
---|
373 | result = sl_rewind(rval_open);
|
---|
374 | CuAssertTrue(tc, rval_open >= 0);
|
---|
375 |
|
---|
376 | actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
|
---|
377 | expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
|
---|
378 | CuAssertStrEquals(tc, expected, actual);
|
---|
379 |
|
---|
380 | result = sl_close(rval_open);
|
---|
381 | CuAssertTrue(tc, result == 0);
|
---|
382 |
|
---|
383 | result = remove("cutest_foo");
|
---|
384 | CuAssertTrue(tc, result == 0);
|
---|
385 | }
|
---|