1 /* low-crypto.c --- Shishi crypto primitives self tests.
2 * Copyright (C) 2002, 2003, 2004, 2006 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 test (Shishi
* handle
)
31 shishi_cfg (handle
, strdup ("verbose-crypto"));
33 err
= shishi_crc (handle
, "abcdefgh", 8, &out
);
35 fail ("shishi_crc() failed: %d\n", err
);
38 if (memcmp (out
, "\x39\xf5\xcd\xcb", 4) == 0)
39 success ("shishi_crc() OK\n");
43 fail ("shishi_crc() failure\n");
48 err
= shishi_md4 (handle
, "abcdefgh", 8, &out
);
50 fail ("shishi_md4() failed: %d\n", err
);
53 if (memcmp (out
, "\xad\x9d\xaf\x8d\x49\xd8\x19\x88"
54 "\x59\x0a\x6f\x0e\x74\x5d\x15\xdd", 16) == 0)
55 success ("shishi_md4() OK\n");
59 fail ("shishi_md4() failure\n");
64 err
= shishi_md5 (handle
, "abcdefgh", 8, &out
);
66 fail ("shishi_md5() failed: %d\n", err
);
69 if (memcmp (out
, "\xe8\xdc\x40\x81\xb1\x34\x34\xb4"
70 "\x51\x89\xa7\x20\xb7\x7b\x68\x18", 16) == 0)
71 success ("shishi_md5() OK\n");
75 fail ("shishi_md5() failure\n");
80 err
= shishi_hmac_md5 (handle
, "keykeykey", 9, "abcdefgh", 8, &out
);
82 fail ("shishi_hmac_md5() failed: %d\n", err
);
85 if (memcmp (out
, "\x3c\xb0\x9d\x83\x28\x01\xef\xc0"
86 "\x7b\xb3\xaf\x42\x69\xe5\x93\x9a", 16) == 0)
87 success ("shishi_hmac_md5() OK\n");
91 fail ("shishi_hmac_md5() failure\n");
96 err
= shishi_hmac_sha1 (handle
, "keykeykey", 9, "abcdefgh", 8, &out
);
98 fail ("shishi_hmac_sha1() failed: %d\n", err
);
101 if (memcmp (out
, "\x58\x93\x7a\x58\xfe\xea\x82\xf8"
102 "\x0e\x64\x62\x01\x40\x2b\x2c\xed\x5d\x54\xc1\xfa",
104 success ("shishi_hmac_sha1() OK\n");
108 fail ("shishi_hmac_sha1() failure\n");
113 err
= shishi_des_cbc_mac (handle
, "kdykdykd", NULL
, "abcdefgh", 8, &out
);
115 fail ("shishi_des_cbc_mac() failed: %d\n", err
);
118 if (memcmp (out
, "\xb9\xf1\x38\x36\x37\x7a\x6f\x4c", 8) == 0)
119 success ("shishi_des_cbc_mac() OK\n");
123 fail ("shishi_des_cbc_mac() failure\n");
128 err
= shishi_des_cbc_mac (handle
, "kdykdykd", "iviviviv",
129 "abcdefgh", 8, &out
);
131 fail ("shishi_des_cbc_mac() failed: %d\n", err
);
134 if (memcmp (out
, "\x7b\x66\x2d\x4d\x54\xc9\xc1\x01", 8) == 0)
135 success ("shishi_des_cbc_mac() OK\n");
139 fail ("shishi_des_cbc_mac() failure\n");
144 err
= shishi_arcfour (handle
, 0, "keykeykey", 9, NULL
, NULL
,
145 "abcdefgh", 8, &out
);
147 fail ("shishi_arcfour() failed: %d\n", err
);
150 if (memcmp (out
, "\x6a\x0e\x57\x89\x41\xe9\x1c\x22", 8) == 0)
151 success ("shishi_arcfour() OK\n");
155 fail ("shishi_arcfour() failure\n");
160 err
= shishi_arcfour (handle
, 0, "keykeyke", 8, NULL
, &ivout
,
161 "abcdefghi", 9, &out
);
163 fail ("shishi_arcfour() failed: %d\n", err
);
166 if (memcmp (out
, "\x17\x52\xf3\xd8\x61\x14\xe6\x76", 8) == 0)
167 success ("shishi_arcfour() OK\n");
171 fail ("shishi_arcfour() failure\n");
174 "\x6b\xdf\xca\xe7\x4c\xe8\x79\x53"
175 "\xd0\x4e\xe2\x37\xc9\x52\xc6\x3c"
176 "\x24\xf2\x9e\x5b\x32\x50\x07\x2e"
177 "\xee\x0f\xc2\x38\x86\x89\x4b\x21"
178 "\xd2\xc0\xa2\x7a\xb7\xae\xf1\xcb"
179 "\x03\x19\x78\x41\x9f\x74\xab\x35"
180 "\x12\x30\xe9\x04\x1c\x05\x66\x58"
181 "\x25\x62\x77\xa5\x42\x44\xd6\x6d"
182 "\x85\xc8\x43\x94\xcf\xfb\x06\x0b"
183 "\xde\x7f\x15\xa1\x8e\xaa\x70\x1b"
184 "\x98\xb0\x13\x27\x73\x4f\x2a\x3d"
185 "\x81\x29\x83\xd8\x99\x36\xd3\x54"
186 "\x4a\x31\xf0\xbe\x18\xe1\x6f\x28"
187 "\x3a\x64\x6a\x68\xef\x59\x22\xbc"
188 "\xb5\x47\x76\x63\xec\x48\x3b\x71"
189 "\x10\xc4\x87\x5f\xea\xc1\xf6\x5d"
190 "\xc5\x8b\xda\xac\xe0\xa9\x8a\xa6"
191 "\x11\x09\x0c\x72\xad\xb3\x46\xe5"
192 "\x9b\x91\x16\x93\x51\x49\xe6\xbf"
193 "\x95\xf5\xd1\x20\xe3\x90\x5a\x39"
194 "\x7b\x7e\x7c\xb9\x40\xbd\x08\x9a"
195 "\x45\xb4\xd7\x1f\x2c\x61\xb8\xcc"
196 "\xb6\x33\x92\x0e\xf9\x0a\xba\x55"
197 "\x75\x14\x5e\xb1\x26\xf8\x84\xed"
198 "\xa4\x1e\x7d\x60\xe4\xdd\x2b\xff"
199 "\xeb\xfe\xd4\x57\x8c\xa0\x88\x8d"
200 "\xdc\x00\x34\x23\xc7\xfd\x0d\x97"
201 "\x56\x96\xaf\xcd\x3f\xf7\xc3\xa7"
202 "\x6c\x65\xbb\xf3\x3e\xdb\x4d\xd9"
203 "\x1d\xa3\x9d\xf4\x17\x69\x6e\x82"
204 "\x02\xa8\x2d\x9c\xce\x1a\xb2\xfc"
205 "\xfa\x5c\x67\x2f\x8f\x01\x80\xd5" "\x09\xa2", 258) == 0)
206 success ("shishi_arcfour() OK IV\n");
209 hexprint (ivout
, 258);
210 fail ("shishi_arcfour() failure IV\n");
216 err
= shishi_des (handle
, 0, "kdykdykd", NULL
, NULL
, "abcdefgh", 8, &out
);
218 fail ("shishi_des() failed: %d\n", err
);
221 if (memcmp (out
, "\xb9\xf1\x38\x36\x37\x7a\x6f\x4c", 8) == 0)
222 success ("shishi_des() OK\n");
226 fail ("shishi_des() failure\n");
231 err
= shishi_des (handle
, 0, "kdykdykd", "iviviviv", NULL
,
232 "abcdefgh", 8, &out
);
234 fail ("shishi_des() failed: %d\n", err
);
237 if (memcmp (out
, "\x7b\x66\x2d\x4d\x54\xc9\xc1\x01", 8) == 0)
238 success ("shishi_des() OK\n");
242 fail ("shishi_des() failure\n");
247 err
= shishi_des (handle
, 0, "kdykdykd", "iviviviv", &ivout
,
248 "abcdefgh", 8, &out
);
250 fail ("shishi_des() failed: %d\n", err
);
253 if (memcmp (out
, "\x7b\x66\x2d\x4d\x54\xc9\xc1\x01", 8) == 0)
254 success ("shishi_des() OK\n");
258 fail ("shishi_des() failure\n");
261 if (memcmp (ivout
, "\x7b\x66\x2d\x4d\x54\xc9\xc1\x01", 8) == 0)
262 success ("shishi_des() OK IV\n");
266 fail ("shishi_des() failure IV\n");
272 err
= shishi_3des (handle
, 0, "kdykdykdykdykdykdykdykdy", NULL
, NULL
,
273 "abcdefgh", 8, &out
);
275 fail ("shishi_3des() failed: %d\n", err
);
278 if (memcmp (out
, "\xd9\x4a\xd9\xa4\x92\xb1\x70\x60", 8) == 0)
279 success ("shishi_3des() OK\n");
283 fail ("shishi_3des() failure\n");
288 err
= shishi_3des (handle
, 0, "kdykdykdykdykdykdykdykdy",
289 "iviviviviviviviviviviviv", NULL
, "abcdefgh", 8, &out
);
291 fail ("shishi_3des() failed: %d\n", err
);
294 if (memcmp (out
, "\x45\xba\x34\xb4\xda\xd7\x53\x6f", 8) == 0)
295 success ("shishi_3des() OK\n");
299 fail ("shishi_3des() failure\n");
304 err
= shishi_3des (handle
, 0, "kdykdykdykdykdykdykdykdy",
305 "iviviviviviviviviviviviv", &ivout
,
306 "abcdefghijklmnopqrstuvxy", 24, &out
);
308 fail ("shishi_3des() failed: %d\n", err
);
311 if (memcmp (out
, "\x45\xba\x34\xb4\xda\xd7\x53\x6f"
312 "\x4e\x4b\xe8\x14\x44\x25\xf2\x19"
313 "\x46\x57\x6b\x16\xd9\x5d\xf2\x38", 24) == 0)
314 success ("shishi_3des() OK\n");
318 fail ("shishi_3des() failure\n");
321 if (memcmp (ivout
, "\x46\x57\x6b\x16\xd9\x5d\xf2\x38", 8) == 0)
322 success ("shishi_3des() OK IV\n");
326 fail ("shishi_3des() failure IV\n");
332 err
= shishi_aes_cts (handle
, 0, "keykeykeykeykeyk", 16,
333 "iviviviviviviviv", &ivout
,
334 "abcdefghijklmnop", 16, &out
);
336 fail ("shishi_aes_cts(16) failed: %d\n", err
);
339 if (memcmp (out
, "\x89\xee\x53\x33\x54\xa8\xb0\xb7"
340 "\xb6\x36\xbf\x80\xb0\xba\x6a\x4a", 16) == 0)
341 success ("shishi_aes_cts(16) OK\n");
345 fail ("shishi_aes_cts(16) failure\n");
348 if (memcmp (ivout
, "\x89\xee\x53\x33\x54\xa8\xb0\xb7"
349 "\xb6\x36\xbf\x80\xb0\xba\x6a\x4a", 16) == 0)
350 success ("shishi_aes_cts(16) OK IV\n");
353 hexprint (ivout
, 16);
354 fail ("shishi_aes_cts(16) failure IV\n");
360 err
= shishi_aes_cts (handle
, 0, "keykeykeykeykeyk", 16,
361 "iviviviviviviviv", &ivout
,
362 "abcdefghijklmnopqrstuvxy", 24, &out
);
364 fail ("shishi_aes_cts(24) failed: %d\n", err
);
367 if (memcmp (out
, "\x22\x8f\x1a\xc5\xd4\x74\xd2\x74"
368 "\x96\x4d\x2d\xcd\x0b\xa3\x0d\x8f"
369 "\x89\xee\x53\x33\x54\xa8\xb0\xb7", 24) == 0)
370 success ("shishi_aes_cts(24) OK\n");
374 fail ("shishi_aes_cts(24) failure\n");
377 if (memcmp (ivout
, "\x22\x8f\x1a\xc5\xd4\x74\xd2\x74"
378 "\x96\x4d\x2d\xcd\x0b\xa3\x0d\x8f", 16) == 0)
379 success ("shishi_aes_cts(24) OK IV\n");
382 hexprint (ivout
, 16);
383 fail ("shishi_aes_cts(24) failure IV\n");
389 err
= shishi_aes_cts (handle
, 0, "keykeykeykeykeyk", 16,
390 "iviviviviviviviv", &ivout
,
391 "abcdefghijklmnopqrstuvx", 23, &out
);
393 fail ("shishi_aes_cts(23) failed: %d\n", err
);
396 if (memcmp (out
, "\x45\x23\x5a\x0c\x6b\x8a\x0c\xad"
397 "\xe6\x50\xff\xe1\x08\x17\x9a\x6d"
398 "\x89\xee\x53\x33\x54\xa8\xb0", 23) == 0)
399 success ("shishi_aes_cts(23) OK\n");
403 fail ("shishi_aes_cts(23) failure\n");
406 if (memcmp (ivout
, "\x45\x23\x5a\x0c\x6b\x8a\x0c\xad"
407 "\xe6\x50\xff\xe1\x08\x17\x9a\x6d", 16) == 0)
408 success ("shishi_aes_cts(23) OK IV\n");
411 hexprint (ivout
, 16);
412 fail ("shishi_aes_cts(23) failure IV\n");
418 err
= shishi_aes_cts (handle
, 0, "keykeykeykeykeyk", 16,
419 "iviviviviviviviv", &ivout
,
420 "abcdefghijklmnopqrstuvxyz", 25, &out
);
422 fail ("shishi_aes_cts(25) failed: %d\n", err
);
425 if (memcmp (out
, "\xa9\x50\xdd\xcb\xa8\x5b\x5c\xb6"
426 "\x84\x7d\x38\x65\x4a\xc1\x63\xd7"
427 "\x89\xee\x53\x33\x54\xa8\xb0\xb7\xb6", 25) == 0)
428 success ("shishi_aes_cts(25) OK\n");
432 fail ("shishi_aes_cts(25) failure\n");
435 if (memcmp (ivout
, "\xa9\x50\xdd\xcb\xa8\x5b\x5c\xb6"
436 "\x84\x7d\x38\x65\x4a\xc1\x63\xd7", 16) == 0)
437 success ("shishi_aes_cts(25) OK IV\n");
440 hexprint (ivout
, 16);
441 fail ("shishi_aes_cts(25) failure IV\n");