1 /* crypto.c Shishi crypto self tests.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
38 "\xd3\xf8\x29\x8c\xcb\x16\x64\x38\xdc\xb9\xb9\x3e"
39 "\xe5\xa7\x62\x92\x86\xa4\x91\xf8\x38\xf8\x02\xfb",
42 "\x22\x70\xdb\x56\x5d\x2a\x3d\x64\xcf\xbf"
43 "\xdc\x53\x05\xd4\xf7\x78\xa6\xde\x42\xd9\xda",
44 "\x23\x70\xda\x57\x5d\x2a\x3d\xa8\x64\xce\xbf\xdc"
45 "\x52\x04\xd5\x6d\xf7\x79\xa7\xdf\x43\xd9\xda\x43",}
48 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
49 "\xdc\xe0\x6b\x1f\x64\xc8\x57\xa1\x1c\x3d\xb5\x7c"
50 "\x51\x89\x9b\x2c\xc1\x79\x10\x08\xce\x97\x3b\x92",
52 "\x00\x00\x00\x01\x55",
53 "\x93\x50\x79\xd1\x44\x90\xa7\x5c\x30\x93"
54 "\xc4\xa6\xe8\xc3\xb0\x49\xc7\x1e\x6e\xe7\x05",
55 "\x92\x51\x79\xd0\x45\x91\xa7\x9b\x5d\x31\x92\xc4"
56 "\xa7\xe9\xc2\x89\xb0\x49\xc7\x1f\x6e\xe6\x04\xcd"}
59 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
60 "\x5e\x13\xd3\x1c\x70\xef\x76\x57\x46\x57\x85\x31"
61 "\xcb\x51\xc1\x5b\xf1\x1c\xa8\x2c\x97\xce\xe9\xf2",
63 "\x00\x00\x00\x01\xaa",
64 "\x9f\x58\xe5\xa0\x47\xd8\x94\x10\x1c\x46"
65 "\x98\x45\xd6\x7a\xe3\xc5\x24\x9e\xd8\x12\xf2",
66 "\x9e\x58\xe5\xa1\x46\xd9\x94\x2a\x10\x1c\x46\x98"
67 "\x45\xd6\x7a\x20\xe3\xc4\x25\x9e\xd9\x13\xf2\x07",}
70 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
71 "\x98\xe6\xfd\x8a\x04\xa4\xb6\x85\x9b\x75\xa1\x76"
72 "\x54\x0b\x97\x52\xba\xd3\xec\xd6\x10\xa2\x52\xbc",
74 "\x00\x00\x00\x01\x55",
75 "\x12\xff\xf9\x0c\x77\x3f\x95\x6d\x13\xfc"
76 "\x2c\xa0\xd0\x84\x03\x49\xdb\xd3\x99\x08\xeb",
77 "\x13\xfe\xf8\x0d\x76\x3e\x94\xec\x6d\x13\xfd\x2c"
78 "\xa1\xd0\x85\x07\x02\x49\xda\xd3\x98\x08\xea\xbf",}
81 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
82 "\x62\x2a\xec\x25\xa2\xfe\x2c\xad\x70\x94\x68\x0b"
83 "\x7c\x64\x94\x02\x80\x08\x4c\x1a\x7c\xec\x92\xb5",
85 "\x00\x00\x00\x01\xaa",
86 "\xf8\xde\xbf\x05\xb0\x97\xe7\xdc\x06\x03"
87 "\x68\x6a\xca\x35\xd9\x1f\xd9\xa5\x51\x6a\x70",
88 "\xf8\xdf\xbf\x04\xb0\x97\xe6\xd9\xdc\x07\x02\x68"
89 "\x6b\xcb\x34\x89\xd9\x1f\xd9\xa4\x51\x6b\x70\x3e",}
92 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
93 "\xc1\x08\x16\x49\xad\xa7\x43\x62\xe6\xa1\x45\x9d"
94 "\x01\xdf\xd3\x0d\x67\xc2\x23\x4c\x94\x07\x04\xda",
96 "\x00\x00\x00\x01\x55",
97 "\x34\x80\x56\xec\x98\xfc\xc5\x17\x17\x1d"
98 "\x2b\x4d\x7a\x94\x93\xaf\x48\x2d\x99\x91\x75",
99 "\x34\x80\x57\xec\x98\xfd\xc4\x80\x16\x16\x1c\x2a"
100 "\x4c\x7a\x94\x3e\x92\xae\x49\x2c\x98\x91\x75\xf7",}
103 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
104 "\x5d\x15\x4a\xf2\x38\xf4\x67\x13\x15\x57\x19\xd5"
105 "\x5e\x2f\x1f\x79\x0d\xd6\x61\xf2\x79\xa7\x91\x7c",
107 "\x00\x00\x00\x01\xaa",
108 "\xa8\x81\x8b\xc3\x67\xda\xda\xcb\xe9\xa6"
109 "\xc8\x46\x27\xfb\x60\xc2\x94\xb0\x12\x15\xe5",
110 "\xa8\x80\x8a\xc2\x67\xda\xda\x3d\xcb\xe9\xa7\xc8"
111 "\x46\x26\xfb\xc7\x61\xc2\x94\xb0\x13\x15\xe5\xc1",}
114 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
115 "\x79\x85\x62\xe0\x49\x85\x2f\x57\xdc\x8c\x34\x3b"
116 "\xa1\x7f\x2c\xa1\xd9\x73\x94\xef\xc8\xad\xc4\x43",
118 "\x00\x00\x00\x01\x55",
119 "\xc8\x13\xf8\x8b\x3b\xe2\xb2\xf7\x54\x24"
120 "\xce\x91\x75\xfb\xc8\x48\x3b\x88\xc8\x71\x3a",
121 "\xc8\x13\xf8\x8a\x3b\xe3\xb3\x34\xf7\x54\x25\xce"
122 "\x91\x75\xfb\xe3\xc8\x49\x3b\x89\xc8\x70\x3b\x49",}
125 SHISHI_DES3_CBC_HMAC_SHA1_KD
,
126 "\x26\xdc\xe3\x34\xb5\x45\x29\x2f\x2f\xea\xb9\xa8"
127 "\x70\x1a\x89\xa4\xb9\x9e\xb9\x94\x2c\xec\xd0\x16",
129 "\x00\x00\x00\x01\xaa",
130 "\xf5\x8e\xfc\x6f\x83\xf9\x3e\x55\xe6\x95"
131 "\xfd\x25\x2c\xf8\xfe\x59\xf7\xd5\xba\x37\xec",
132 "\xf4\x8f\xfd\x6e\x83\xf8\x3e\x73\x54\xe6\x94\xfd"
133 "\x25\x2c\xf8\x3b\xfe\x58\xf7\xd5\xba\x37\xec\x5d",}
145 64, "012345", "\xBE\x07\x26\x31\x27\x6B\x19\x55"}
148 56, "password", "\x78\xA0\x7B\x6C\xAF\x85\xFA"}
151 64, "Rough Consensus, and Running Code",
152 "\xBB\x6E\xD3\x08\x70\xB7\xF0\xE0"}
156 "\x59\xE4\xA8\xCA\x7C\x03\x85\xC3\xC3\x7B"
157 "\x3F\x6D\x20\x00\x24\x7C\xB6\xE6\xBD\x5B\x3E"}
160 192, "MASSACHVSETTS INSTITVTE OF TECHNOLOGY",
161 "\xDB\x3B\x0D\x8F\x0B\x06\x1E\x60\x32\x82\xB3\x08"
162 "\xA5\x08\x41\x22\x9A\xD7\x98\xFA\xB9\x54\x0C\x1B"}
165 64, "kerberos", "\x6b\x65\x72\x62\x65\x72\x6f\x73"}
169 "\x6b\x65\x72\x62\x65\x72\x6f\x73\x7b\x9b\x5b\x2b\x93\x13\x2b\x93"}
173 "\x83\x72\xc2\x36\x34\x4e\x5f\x15\x50\xcd"
174 "\x07\x47\xe1\x5d\x62\xca\x7a\x5a\x3b\xce\xa4"}
178 "\x6b\x65\x72\x62\x65\x72\x6f\x73\x7b\x9b\x5b\x2b\x93\x13\x2b\x93"
179 "\x5c\x9b\xdc\xda\xd9\x5c\x98\x99\xc4\xca\xe4\xde\xe6\xd6\xca\xe4"}
183 "\x51\x8a\x54\xa2\x15\xa8\x45\x2a\x51\x8a"
184 "\x54\xa2\x15\xa8\x45\x2a\x51\x8a\x54\xa2\x15"}
188 "\x51\x8a\x54\xa2\x15\xa8\x45\x2a\x51\x8a\x54\xa2"
189 "\x15\xa8\x45\x2a\x51\x8a\x54\xa2\x15\xa8\x45\x2a"}
193 "\xba\x24\xcf\x29\x7f\x49\xf5\x4b\xab\x62"
194 "\x5d\x12\xe7\x94\x3f\xa4\xfb\x25\xd5\x31\xae"}
198 "\x61\x62\x0b\x13\x58\x98\xc4\xc2\x26\x16\x30\xb1"
199 "\x85\x89\x2c\x4c\x62\x61\x13\x0b\x98\x58\xc2\xc4"}
212 #define ESZETT "\xC3\x9F"
213 #define S_CARON "\xC5\xA1"
214 #define C_ACUTE "\xC4\x87"
215 #define G_CLEF "\xF0\x9D\x84\x9E"
219 "ATHENA.MIT.EDUraeburn",
220 "\xCB\xC2\x2F\xAE\x23\x52\x98\xE3", SHISHI_DES_CBC_MD5
}
224 "WHITEHOUSE.GOVdanny",
225 "\xDF\x3D\x32\xA7\x4F\xD9\x2A\x01", SHISHI_DES_CBC_MD5
}
229 "EXAMPLE.COMpianist",
230 "\x4F\xFB\x26\xBA\xB0\xCD\x94\x13", SHISHI_DES_CBC_MD5
}
234 "ATHENA.MIT.EDUJuri" S_CARON
"i" C_ACUTE
,
235 "\x62\xC8\x1A\x52\x32\xB5\xE6\x9D", SHISHI_DES_CBC_MD5
}
239 "AAAAAAAA", "\x98\x40\x54\xD0\xF1\xA7\x3E\x31", SHISHI_DES_CBC_MD5
}
243 "FFFFAAAA", "\xC4\xBF\x6B\x25\xAD\xF7\xA4\xF8", SHISHI_DES_CBC_MD5
}
248 "ATHENA.MIT.EDUraeburn",
249 "\x85\x0b\xb5\x13\x58\x54\x8c\xd0\x5e\x86\x76\x8c"
250 "\x31\x3e\x3b\xfe\xf7\x51\x19\x37\xdc\xf7\x2c\x3e",
251 SHISHI_DES3_CBC_HMAC_SHA1_KD
}
255 "WHITEHOUSE.GOVdanny",
256 "\xdf\xcd\x23\x3d\xd0\xa4\x32\x04\xea\x6d\xc4\x37"
257 "\xfb\x15\xe0\x61\xb0\x29\x79\xc1\xf7\x4f\x37\x7a",
258 SHISHI_DES3_CBC_HMAC_SHA1_KD
}
262 "EXAMPLE.COMbuckaroo",
263 "\x6d\x2f\xcd\xf2\xd6\xfb\xbc\x3d\xdc\xad\xb5\xda"
264 "\x57\x10\xa2\x34\x89\xb0\xd3\xb6\x9d\x5d\x9d\x4a",
265 SHISHI_DES3_CBC_HMAC_SHA1_KD
}
269 "ATHENA.MIT.EDUJuri" S_CARON
"i" C_ACUTE
,
270 "\x16\xd5\xa4\x0e\x1c\xe3\xba\xcb\x61\xb9\xdc\xe0"
271 "\x04\x70\x32\x4c\x83\x19\x73\xa7\xb9\x52\xfe\xb0",
272 SHISHI_DES3_CBC_HMAC_SHA1_KD
}
276 "EXAMPLE.COMpianist",
277 "\x85\x76\x37\x26\x58\x5d\xbc\x1c\xce\x6e\xc4\x3e"
278 "\x1f\x75\x1f\x07\xf1\xc4\xcb\xb0\x98\xf4\x0b\x19",
279 SHISHI_DES3_CBC_HMAC_SHA1_KD
}
283 "ATHENA.MIT.EDUraeburn",
284 "\x42\x26\x3c\x6e\x89\xf4\xfc\x28\xb8\xdf\x68\xee\x09\x79\x9f\x15",
285 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x01"}
289 "ATHENA.MIT.EDUraeburn",
290 "\xfe\x69\x7b\x52\xbc\x0d\x3c\xe1\x44\x32\xba\x03\x6a\x92\xe6\x5b"
291 "\xbb\x52\x28\x09\x90\xa2\xfa\x27\x88\x39\x98\xd7\x2a\xf3\x01\x61",
292 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x01"}
296 "ATHENA.MIT.EDUraeburn",
297 "\xc6\x51\xbf\x29\xe2\x30\x0a\xc2\x7f\xa4\x69\xd6\x93\xbd\xda\x13",
298 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x02"}
302 "ATHENA.MIT.EDUraeburn",
303 "\xa2\xe1\x6d\x16\xb3\x60\x69\xc1\x35\xd5\xe9\xd2\xe2\x5f\x89\x61"
304 "\x02\x68\x56\x18\xb9\x59\x14\xb4\x67\xc6\x76\x22\x22\x58\x24\xff",
305 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x02"}
309 "ATHENA.MIT.EDUraeburn",
310 "\x4c\x01\xcd\x46\xd6\x32\xd0\x1e\x6d\xbe\x23\x0a\x01\xed\x64\x2a",
311 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"}
315 "ATHENA.MIT.EDUraeburn",
316 "\x55\xa6\xac\x74\x0a\xd1\x7b\x48\x46\x94\x10\x51\xe1\xe8\xb0\xa7"
317 "\x54\x8d\x93\xb0\xab\x30\xa8\xbc\x3f\xf1\x62\x80\x38\x2b\x8c\x2a",
318 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"}
322 "\x12\x34\x56\x78\x78\x56\x34\x12",
323 "\xe9\xb2\x3d\x52\x27\x37\x47\xdd\x5c\x35\xcb\x55\xbe\x61\x9d\x8e",
324 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x05"}
328 "\x12\x34\x56\x78\x78\x56\x34\x12",
329 "\x97\xa4\xe7\x86\xbe\x20\xd8\x1a\x38\x2d\x5e\xbc\x96\xd5\x90\x9c"
330 "\xab\xcd\xad\xc8\x7c\xa4\x8f\x57\x45\x04\x15\x9f\x16\xc3\x6e\x31",
331 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x05"}
334 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
335 "pass phrase equals block size",
336 "\x59\xd1\xbb\x78\x9a\x82\x8b\x1a\xa5\x4e\xf9\xc2\x88\x3f\x69\xed",
337 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"}
340 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
341 "pass phrase equals block size",
342 "\x89\xad\xee\x36\x08\xdb\x8b\xc7\x1f\x1b\xfb\xfe\x45\x94\x86\xb0"
343 "\x56\x18\xb7\x0c\xba\xe2\x20\x92\x53\x4e\x56\xc5\x53\xba\x4b\x34",
344 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"}
347 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
348 "pass phrase exceeds block size",
349 "\xcb\x80\x05\xdc\x5f\x90\x17\x9a\x7f\x02\x10\x4c\x00\x18\x75\x1d",
350 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"}
353 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
354 "pass phrase exceeds block size",
355 "\xd7\x8c\x5c\x9c\xb8\x72\xa8\xc9\xda\xd4\x69\x7f\x0b\xb5\xb2\xd2"
356 "\x14\x96\xc8\x2b\xeb\x2c\xae\xda\x21\x12\xfc\xee\xa0\x57\x40\x1b",
357 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"}
361 "EXAMPLE.COMpianist",
362 "\xf1\x49\xc1\xf2\xe1\x54\xa7\x34\x52\xd4\x3e\x7f\xe6\x2a\x56\xe5",
363 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x32"}
367 "EXAMPLE.COMpianist",
368 "\x4b\x6d\x98\x39\xf8\x44\x06\xdf\x1f\x09\xcc\x16\x6d\xb4\xb8\x3c"
369 "\x57\x18\x48\xb7\x84\xa3\xd6\xbd\xc3\x46\x58\x9a\x3e\x39\x3f\x9e",
370 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x32"}
384 1, "password", "ATHENA.MIT.EDUraeburn", 16,
385 "\xCD\xED\xB5\x28\x1B\xB2\xF8\x01\x56\x5A\x11\x22\xB2\x56\x35\x15"}
388 2, "password", "ATHENA.MIT.EDUraeburn", 16,
389 "\x01\xdb\xee\x7f\x4a\x9e\x24\x3e\x98\x8b\x62\xc7\x3c\xda\x93\x5d"}
392 2, "password", "ATHENA.MIT.EDUraeburn", 32,
393 "\x01\xdb\xee\x7f\x4a\x9e\x24\x3e\x98\x8b\x62\xc7\x3c\xda\x93\x5d"
394 "\xa0\x53\x78\xb9\x32\x44\xec\x8f\x48\xa9\x9e\x61\xad\x79\x9d\x86"}
397 1200, "password", "ATHENA.MIT.EDUraeburn", 16,
398 "\x5c\x08\xeb\x61\xfd\xf7\x1e\x4e\x4e\xc3\xcf\x6b\xa1\xf5\x51\x2b"}
401 1200, "password", "ATHENA.MIT.EDUraeburn", 32,
402 "\x5c\x08\xeb\x61\xfd\xf7\x1e\x4e\x4e\xc3\xcf\x6b\xa1\xf5\x51\x2b"
403 "\xa7\xe5\x2d\xdb\xc5\xe5\x14\x2f\x70\x8a\x31\xe2\xe6\x2b\x1e\x13"}
406 5, "password", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 16,
407 "\xd1\xda\xa7\x86\x15\xf2\x87\xe6\xa1\xc8\xb1\x20\xd7\x06\x2a\x49"}
410 5, "password", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 32,
411 "\xd1\xda\xa7\x86\x15\xf2\x87\xe6\xa1\xc8\xb1\x20\xd7\x06\x2a\x49"
412 "\x3f\x98\xd2\x03\xe6\xbe\x49\xa6\xad\xf4\xfa\x57\x4b\x6e\x64\xee"}
415 1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
416 "pass phrase equals block size", 16,
417 "\x13\x9c\x30\xc0\x96\x6b\xc3\x2b\xa5\x5f\xdb\xf2\x12\x53\x0a\xc9"}
420 1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
421 "pass phrase equals block size", 32,
422 "\x13\x9c\x30\xc0\x96\x6b\xc3\x2b\xa5\x5f\xdb\xf2\x12\x53\x0a\xc9"
423 "\xc5\xec\x59\xf1\xa4\x52\xf5\xcc\x9a\xd9\x40\xfe\xa0\x59\x8e\xd1"}
426 1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
427 "pass phrase exceeds block size", 16,
428 "\x9c\xca\xd6\xd4\x68\x77\x0c\xd5\x1b\x10\xe6\xa6\x87\x21\xbe\x61"}
431 1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
432 "pass phrase exceeds block size", 32,
433 "\x9c\xca\xd6\xd4\x68\x77\x0c\xd5\x1b\x10\xe6\xa6\x87\x21\xbe\x61"
434 "\x1a\x8b\x4d\x28\x26\x01\xdb\x3b\x36\xbe\x92\x46\x91\x5e\xc8\x2a"}
437 50, G_CLEF
"\x00", "EXAMPLE.COMpianist", 16,
438 "\x6b\x9c\xf2\x6d\x45\x45\x5a\x43\xa5\xb8\xbb\x27\x6a\x40\x3b\x39"}
441 50, G_CLEF
"\x00", "EXAMPLE.COMpianist", 32,
442 "\x6b\x9c\xf2\x6d\x45\x45\x5a\x43\xa5\xb8\xbb\x27\x6a\x40\x3b\x39"
443 "\xe7\xfe\x37\xa0\xc4\x1e\x02\xc2\x81\xff\x30\x69\xe1\xe9\x4f\x52"}
446 500, "All n-entities must communicate with other n-entities via n-1 "
447 "entiteeheehees", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 16,
448 "\x6A\x89\x70\xBF\x68\xC9\x2C\xAE\xA8\x4A\x8D\xF2\x85\x10\x85\x86"}
452 main (int argc
, char *argv
[])
455 Shishi_key
*key
, *key2
;
456 unsigned char out
[BUFSIZ
];
461 if (strcmp (argv
[argc
- 1], "-v") == 0 ||
462 strcmp (argv
[argc
- 1], "--verbose") == 0)
464 else if (strcmp (argv
[argc
- 1], "-d") == 0 ||
465 strcmp (argv
[argc
- 1], "--debug") == 0)
467 else if (strcmp (argv
[argc
- 1], "-b") == 0 ||
468 strcmp (argv
[argc
- 1], "--break-on-error") == 0)
470 else if (strcmp (argv
[argc
- 1], "-h") == 0 ||
471 strcmp (argv
[argc
- 1], "-?") == 0 ||
472 strcmp (argv
[argc
- 1], "--help") == 0)
474 printf ("Usage: %s [-vdbh?] [--verbose] [--debug] "
475 "[--break-on-error] [--help]\n", argv
[0]);
483 fail ("Could not initialize shishi\n");
488 shishi_cfg (handle
, strdup ("verbose,verbose-crypto"));
490 for (i
= 0; i
< sizeof (drdk
) / sizeof (drdk
[0]); i
++)
493 printf ("DR entry %d\n", i
);
495 res
= shishi_key_from_value (handle
, drdk
[i
].type
, drdk
[i
].key
, &key
);
497 if (res
== SHISHI_OK
)
498 res
= shishi_dr (handle
, key
, drdk
[i
].usage
, drdk
[i
].nusage
,
499 out
, strlen (drdk
[i
].dr
));
501 shishi_key_done (&key
);
503 if (res
!= SHISHI_OK
)
505 fail ("shishi_dr() entry %d failed (%s)\n",
506 i
, shishi_strerror_details (handle
));
512 printf ("DR(%s, key, usage)\n", shishi_cipher_name (drdk
[i
].type
));
515 escapeprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
516 hexprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
518 binprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
522 escapeprint (drdk
[i
].usage
, drdk
[i
].nusage
);
523 hexprint (drdk
[i
].usage
, drdk
[i
].nusage
);
525 binprint (drdk
[i
].usage
, drdk
[i
].nusage
);
528 printf ("computed DR:\n");
529 escapeprint (out
, strlen (drdk
[i
].dr
));
530 hexprint (out
, strlen (drdk
[i
].dr
));
532 binprint (out
, strlen (drdk
[i
].dr
));
535 printf ("expected DR:\n");
536 escapeprint (drdk
[i
].dr
, strlen (drdk
[i
].dr
));
537 hexprint (drdk
[i
].dr
, strlen (drdk
[i
].dr
));
539 binprint (drdk
[i
].dr
, strlen (drdk
[i
].dr
));
543 if (memcmp (drdk
[i
].dr
, out
, strlen (drdk
[i
].dr
)) != 0)
545 fail ("shishi_dr() entry %d failed\n", i
);
552 res
= shishi_key_from_value (handle
, drdk
[i
].type
, drdk
[i
].key
, &key
);
554 if (res
== SHISHI_OK
)
555 res
= shishi_key_from_value (handle
, drdk
[i
].type
, NULL
, &key2
);
557 if (res
== SHISHI_OK
)
558 res
= shishi_dk (handle
, key
, drdk
[i
].usage
, drdk
[i
].nusage
, key2
);
560 shishi_key_done (&key
);
562 if (res
!= SHISHI_OK
)
564 fail ("shishi_dk() entry %d failed (%s)\n",
565 i
, shishi_strerror_details (handle
));
571 printf ("DK(%s, key, usage)\n", shishi_cipher_name (drdk
[i
].type
));
574 escapeprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
575 hexprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
577 binprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
581 escapeprint (drdk
[i
].usage
, drdk
[i
].nusage
);
582 hexprint (drdk
[i
].usage
, drdk
[i
].nusage
);
584 binprint (drdk
[i
].usage
, drdk
[i
].nusage
);
587 printf ("computed DK:\n");
588 escapeprint (shishi_key_value (key2
), shishi_key_length (key2
));
589 hexprint (shishi_key_value (key2
), shishi_key_length (key2
));
591 binprint (shishi_key_value (key2
), shishi_key_length (key2
));
594 printf ("expected DK:\n");
595 escapeprint (drdk
[i
].dk
, strlen (drdk
[i
].dk
));
596 hexprint (drdk
[i
].dk
, strlen (drdk
[i
].dk
));
598 binprint (drdk
[i
].dk
, strlen (drdk
[i
].dk
));
602 if (!(shishi_key_length (key2
) == strlen (drdk
[i
].dk
) &&
603 memcmp (drdk
[i
].dk
, shishi_key_value (key2
),
604 strlen (drdk
[i
].dk
)) == 0))
606 fail ("shishi_dk() entry %d failed\n", i
);
614 for (i
= 0; i
< sizeof (nfold
) / sizeof (nfold
[0]); i
++)
617 printf ("N-FOLD entry %d\n", i
);
619 res
= shishi_n_fold (handle
,
620 nfold
[i
].in
, strlen (nfold
[i
].in
),
621 out
, nfold
[i
].n
/ 8);
622 if (res
!= SHISHI_OK
)
624 fail ("shishi_n_fold() entry %d failed (%s)\n",
625 i
, shishi_strerror_details (handle
));
632 escapeprint (nfold
[i
].in
, strlen (nfold
[i
].in
));
633 hexprint (nfold
[i
].in
, strlen (nfold
[i
].in
));
635 binprint (nfold
[i
].in
, strlen (nfold
[i
].in
));
639 escapeprint (out
, nfold
[i
].n
/ 8);
640 hexprint (out
, nfold
[i
].n
/ 8);
642 binprint (out
, nfold
[i
].n
/ 8);
645 printf ("expected out:\n");
646 escapeprint (nfold
[i
].out
, nfold
[i
].n
/ 8);
647 hexprint (nfold
[i
].out
, nfold
[i
].n
/ 8);
649 binprint (nfold
[i
].out
, nfold
[i
].n
/ 8);
653 if (memcmp (nfold
[i
].out
, out
, nfold
[i
].n
/ 8) != 0)
655 fail ("shishi_n_fold() entry %d failed\n", i
);
663 for (i
= 0; i
< sizeof (str2key
) / sizeof (str2key
[0]); i
++)
665 int n_password
= strlen (str2key
[i
].password
);
666 int saltlen
= strlen (str2key
[i
].salt
);
667 int keylen
= sizeof (key
);
668 const char *name
= shishi_cipher_name (str2key
[i
].etype
);
671 printf ("STRING-TO-KEY entry %d (key type %s)\n", i
,
672 name
? name
: "NO NAME");
674 res
= shishi_key_from_string (handle
, str2key
[i
].etype
,
675 str2key
[i
].password
, n_password
,
676 str2key
[i
].salt
, saltlen
,
677 str2key
[i
].parameters
, &key
);
678 if (res
!= SHISHI_OK
)
680 fail ("shishi_string_to_key() entry %d failed (%s)\n",
681 i
, shishi_strerror_details (handle
));
687 printf ("password:\n");
688 escapeprint (str2key
[i
].password
, n_password
);
689 hexprint (str2key
[i
].password
, n_password
);
691 binprint (str2key
[i
].password
, n_password
);
695 escapeprint (str2key
[i
].salt
, saltlen
);
696 hexprint (str2key
[i
].salt
, saltlen
);
698 binprint (str2key
[i
].salt
, saltlen
);
701 printf ("computed key:\n");
702 escapeprint (shishi_key_value (key
), shishi_key_length (key
));
703 hexprint (shishi_key_value (key
), shishi_key_length (key
));
705 binprint (shishi_key_value (key
), shishi_key_length (key
));
708 printf ("expected key:\n");
709 escapeprint (str2key
[i
].key
, strlen (str2key
[i
].key
));
710 hexprint (str2key
[i
].key
, strlen (str2key
[i
].key
));
712 binprint (str2key
[i
].key
, strlen (str2key
[i
].key
));
716 if (memcmp (str2key
[i
].key
, shishi_key_value (key
), keylen
) != 0)
718 fail ("shishi_string_to_key() entry %d failed\n", i
);
727 for (i
= 0; i
< sizeof (pkcs5
) / sizeof (pkcs5
[0]); i
++)
730 printf ("PKCS5 entry %d\n", i
);
732 res
= shishi_pbkdf2_sha1 (pkcs5
[i
].password
,
733 strlen (pkcs5
[i
].password
),
735 strlen (pkcs5
[i
].salt
),
736 pkcs5
[i
].iterations
, pkcs5
[i
].dklen
, out
);
737 if (res
!= SHISHI_OK
)
739 fail ("PKCS5 entry %d failed fatally: %d\n", i
, res
);
745 printf ("password:\n");
746 escapeprint (pkcs5
[i
].password
, strlen (pkcs5
[i
].password
));
747 hexprint (pkcs5
[i
].password
, strlen (pkcs5
[i
].password
));
749 binprint (pkcs5
[i
].password
, strlen (pkcs5
[i
].password
));
753 escapeprint (pkcs5
[i
].salt
, strlen (pkcs5
[i
].salt
));
754 hexprint (pkcs5
[i
].salt
, strlen (pkcs5
[i
].salt
));
756 binprint (pkcs5
[i
].salt
, strlen (pkcs5
[i
].salt
));
759 printf ("computed key:\n");
760 escapeprint (out
, pkcs5
[i
].dklen
);
761 hexprint (out
, pkcs5
[i
].dklen
);
763 binprint (out
, pkcs5
[i
].dklen
);
766 printf ("expected key:\n");
767 escapeprint (pkcs5
[i
].expected
, pkcs5
[i
].dklen
);
768 hexprint (pkcs5
[i
].expected
, pkcs5
[i
].dklen
);
770 binprint (pkcs5
[i
].expected
, pkcs5
[i
].dklen
);
774 if (memcmp (pkcs5
[i
].expected
, out
, pkcs5
[i
].dklen
) != 0)
776 fail ("PKCS5 entry %d failed\n", i
);
786 printf ("Crypt self tests done with %d errors\n", error_count
);
788 return error_count
? 1 : 0;