source: trunk/src/cutest_sh_tiger0.c@ 18

Last change on this file since 18 was 17, checked in by katerina, 19 years ago

Optimized version of tiger algorithm, and basic ingredients for unit testing (part 1)

File size: 7.0 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}
Note: See TracBrowser for help on using the repository browser.