1 /* crypto.c Shishi crypto 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
33 const struct drdk drdk
[] = {
35 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
36 "\xd3\xf8\x29\x8c\xcb\x16\x64\x38\xdc\xb9\xb9\x3e"
37 "\xe5\xa7\x62\x92\x86\xa4\x91\xf8\x38\xf8\x02\xfb",
40 "\x22\x70\xdb\x56\x5d\x2a\x3d\x64\xcf\xbf"
41 "\xdc\x53\x05\xd4\xf7\x78\xa6\xde\x42\xd9\xda",
42 "\x23\x70\xda\x57\x5d\x2a\x3d\xa8\x64\xce\xbf\xdc"
43 "\x52\x04\xd5\x6d\xf7\x79\xa7\xdf\x43\xd9\xda\x43"},
44 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
45 "\xdc\xe0\x6b\x1f\x64\xc8\x57\xa1\x1c\x3d\xb5\x7c"
46 "\x51\x89\x9b\x2c\xc1\x79\x10\x08\xce\x97\x3b\x92",
48 "\x00\x00\x00\x01\x55",
49 "\x93\x50\x79\xd1\x44\x90\xa7\x5c\x30\x93"
50 "\xc4\xa6\xe8\xc3\xb0\x49\xc7\x1e\x6e\xe7\x05",
51 "\x92\x51\x79\xd0\x45\x91\xa7\x9b\x5d\x31\x92\xc4"
52 "\xa7\xe9\xc2\x89\xb0\x49\xc7\x1f\x6e\xe6\x04\xcd"},
53 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
54 "\x5e\x13\xd3\x1c\x70\xef\x76\x57\x46\x57\x85\x31"
55 "\xcb\x51\xc1\x5b\xf1\x1c\xa8\x2c\x97\xce\xe9\xf2",
57 "\x00\x00\x00\x01\xaa",
58 "\x9f\x58\xe5\xa0\x47\xd8\x94\x10\x1c\x46"
59 "\x98\x45\xd6\x7a\xe3\xc5\x24\x9e\xd8\x12\xf2",
60 "\x9e\x58\xe5\xa1\x46\xd9\x94\x2a\x10\x1c\x46\x98"
61 "\x45\xd6\x7a\x20\xe3\xc4\x25\x9e\xd9\x13\xf2\x07"},
62 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
63 "\x98\xe6\xfd\x8a\x04\xa4\xb6\x85\x9b\x75\xa1\x76"
64 "\x54\x0b\x97\x52\xba\xd3\xec\xd6\x10\xa2\x52\xbc",
66 "\x00\x00\x00\x01\x55",
67 "\x12\xff\xf9\x0c\x77\x3f\x95\x6d\x13\xfc"
68 "\x2c\xa0\xd0\x84\x03\x49\xdb\xd3\x99\x08\xeb",
69 "\x13\xfe\xf8\x0d\x76\x3e\x94\xec\x6d\x13\xfd\x2c"
70 "\xa1\xd0\x85\x07\x02\x49\xda\xd3\x98\x08\xea\xbf"},
71 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
72 "\x62\x2a\xec\x25\xa2\xfe\x2c\xad\x70\x94\x68\x0b"
73 "\x7c\x64\x94\x02\x80\x08\x4c\x1a\x7c\xec\x92\xb5",
75 "\x00\x00\x00\x01\xaa",
76 "\xf8\xde\xbf\x05\xb0\x97\xe7\xdc\x06\x03"
77 "\x68\x6a\xca\x35\xd9\x1f\xd9\xa5\x51\x6a\x70",
78 "\xf8\xdf\xbf\x04\xb0\x97\xe6\xd9\xdc\x07\x02\x68"
79 "\x6b\xcb\x34\x89\xd9\x1f\xd9\xa4\x51\x6b\x70\x3e"},
80 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
81 "\xc1\x08\x16\x49\xad\xa7\x43\x62\xe6\xa1\x45\x9d"
82 "\x01\xdf\xd3\x0d\x67\xc2\x23\x4c\x94\x07\x04\xda",
84 "\x00\x00\x00\x01\x55",
85 "\x34\x80\x56\xec\x98\xfc\xc5\x17\x17\x1d"
86 "\x2b\x4d\x7a\x94\x93\xaf\x48\x2d\x99\x91\x75",
87 "\x34\x80\x57\xec\x98\xfd\xc4\x80\x16\x16\x1c\x2a"
88 "\x4c\x7a\x94\x3e\x92\xae\x49\x2c\x98\x91\x75\xf7"},
89 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
90 "\x5d\x15\x4a\xf2\x38\xf4\x67\x13\x15\x57\x19\xd5"
91 "\x5e\x2f\x1f\x79\x0d\xd6\x61\xf2\x79\xa7\x91\x7c",
93 "\x00\x00\x00\x01\xaa",
94 "\xa8\x81\x8b\xc3\x67\xda\xda\xcb\xe9\xa6"
95 "\xc8\x46\x27\xfb\x60\xc2\x94\xb0\x12\x15\xe5",
96 "\xa8\x80\x8a\xc2\x67\xda\xda\x3d\xcb\xe9\xa7\xc8"
97 "\x46\x26\xfb\xc7\x61\xc2\x94\xb0\x13\x15\xe5\xc1"},
98 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
99 "\x79\x85\x62\xe0\x49\x85\x2f\x57\xdc\x8c\x34\x3b"
100 "\xa1\x7f\x2c\xa1\xd9\x73\x94\xef\xc8\xad\xc4\x43",
102 "\x00\x00\x00\x01\x55",
103 "\xc8\x13\xf8\x8b\x3b\xe2\xb2\xf7\x54\x24"
104 "\xce\x91\x75\xfb\xc8\x48\x3b\x88\xc8\x71\x3a",
105 "\xc8\x13\xf8\x8a\x3b\xe3\xb3\x34\xf7\x54\x25\xce"
106 "\x91\x75\xfb\xe3\xc8\x49\x3b\x89\xc8\x70\x3b\x49"},
107 {SHISHI_DES3_CBC_HMAC_SHA1_KD
,
108 "\x26\xdc\xe3\x34\xb5\x45\x29\x2f\x2f\xea\xb9\xa8"
109 "\x70\x1a\x89\xa4\xb9\x9e\xb9\x94\x2c\xec\xd0\x16",
111 "\x00\x00\x00\x01\xaa",
112 "\xf5\x8e\xfc\x6f\x83\xf9\x3e\x55\xe6\x95"
113 "\xfd\x25\x2c\xf8\xfe\x59\xf7\xd5\xba\x37\xec",
114 "\xf4\x8f\xfd\x6e\x83\xf8\x3e\x73\x54\xe6\x94\xfd"
115 "\x25\x2c\xf8\x3b\xfe\x58\xf7\xd5\xba\x37\xec\x5d"}
125 const struct nfold nfold
[] = {
126 {64, "012345", "\xBE\x07\x26\x31\x27\x6B\x19\x55"},
127 {56, "password", "\x78\xA0\x7B\x6C\xAF\x85\xFA"},
128 {64, "Rough Consensus, and Running Code",
129 "\xBB\x6E\xD3\x08\x70\xB7\xF0\xE0"},
130 {168, "password", "\x59\xE4\xA8\xCA\x7C\x03\x85\xC3\xC3\x7B"
131 "\x3F\x6D\x20\x00\x24\x7C\xB6\xE6\xBD\x5B\x3E"},
132 {192, "MASSACHVSETTS INSTITVTE OF TECHNOLOGY",
133 "\xDB\x3B\x0D\x8F\x0B\x06\x1E\x60\x32\x82\xB3\x08"
134 "\xA5\x08\x41\x22\x9A\xD7\x98\xFA\xB9\x54\x0C\x1B"},
135 {64, "kerberos", "\x6b\x65\x72\x62\x65\x72\x6f\x73"},
137 "\x6b\x65\x72\x62\x65\x72\x6f\x73\x7b\x9b\x5b\x2b\x93\x13\x2b\x93"},
139 "\x83\x72\xc2\x36\x34\x4e\x5f\x15\x50\xcd"
140 "\x07\x47\xe1\x5d\x62\xca\x7a\x5a\x3b\xce\xa4"},
142 "\x6b\x65\x72\x62\x65\x72\x6f\x73\x7b\x9b\x5b\x2b\x93\x13\x2b\x93"
143 "\x5c\x9b\xdc\xda\xd9\x5c\x98\x99\xc4\xca\xe4\xde\xe6\xd6\xca\xe4"},
145 "\x51\x8a\x54\xa2\x15\xa8\x45\x2a\x51\x8a"
146 "\x54\xa2\x15\xa8\x45\x2a\x51\x8a\x54\xa2\x15"},
148 "\x51\x8a\x54\xa2\x15\xa8\x45\x2a\x51\x8a\x54\xa2"
149 "\x15\xa8\x45\x2a\x51\x8a\x54\xa2\x15\xa8\x45\x2a"},
151 "\xba\x24\xcf\x29\x7f\x49\xf5\x4b\xab\x62"
152 "\x5d\x12\xe7\x94\x3f\xa4\xfb\x25\xd5\x31\xae"},
154 "\x61\x62\x0b\x13\x58\x98\xc4\xc2\x26\x16\x30\xb1"
155 "\x85\x89\x2c\x4c\x62\x61\x13\x0b\x98\x58\xc2\xc4"}
160 const char *password
;
164 const char *parameters
;
166 const struct str2key str2key
[] = {
167 #define ESZETT "\xC3\x9F"
168 #define S_CARON "\xC5\xA1"
169 #define C_ACUTE "\xC4\x87"
170 #define G_CLEF "\xF0\x9D\x84\x9E"
173 "ATHENA.MIT.EDUraeburn",
174 "\xCB\xC2\x2F\xAE\x23\x52\x98\xE3", SHISHI_DES_CBC_MD5
},
176 "WHITEHOUSE.GOVdanny",
177 "\xDF\x3D\x32\xA7\x4F\xD9\x2A\x01", SHISHI_DES_CBC_MD5
},
179 "EXAMPLE.COMpianist",
180 "\x4F\xFB\x26\xBA\xB0\xCD\x94\x13", SHISHI_DES_CBC_MD5
},
182 "ATHENA.MIT.EDUJuri" S_CARON
"i" C_ACUTE
,
183 "\x62\xC8\x1A\x52\x32\xB5\xE6\x9D", SHISHI_DES_CBC_MD5
},
185 "AAAAAAAA", "\x98\x40\x54\xD0\xF1\xA7\x3E\x31", SHISHI_DES_CBC_MD5
},
187 "FFFFAAAA", "\xC4\xBF\x6B\x25\xAD\xF7\xA4\xF8", SHISHI_DES_CBC_MD5
},
191 "ATHENA.MIT.EDUraeburn",
192 "\x85\x0b\xb5\x13\x58\x54\x8c\xd0\x5e\x86\x76\x8c"
193 "\x31\x3e\x3b\xfe\xf7\x51\x19\x37\xdc\xf7\x2c\x3e",
194 SHISHI_DES3_CBC_HMAC_SHA1_KD
},
196 "WHITEHOUSE.GOVdanny",
197 "\xdf\xcd\x23\x3d\xd0\xa4\x32\x04\xea\x6d\xc4\x37"
198 "\xfb\x15\xe0\x61\xb0\x29\x79\xc1\xf7\x4f\x37\x7a",
199 SHISHI_DES3_CBC_HMAC_SHA1_KD
},
201 "EXAMPLE.COMbuckaroo",
202 "\x6d\x2f\xcd\xf2\xd6\xfb\xbc\x3d\xdc\xad\xb5\xda"
203 "\x57\x10\xa2\x34\x89\xb0\xd3\xb6\x9d\x5d\x9d\x4a",
204 SHISHI_DES3_CBC_HMAC_SHA1_KD
},
206 "ATHENA.MIT.EDUJuri" S_CARON
"i" C_ACUTE
,
207 "\x16\xd5\xa4\x0e\x1c\xe3\xba\xcb\x61\xb9\xdc\xe0"
208 "\x04\x70\x32\x4c\x83\x19\x73\xa7\xb9\x52\xfe\xb0",
209 SHISHI_DES3_CBC_HMAC_SHA1_KD
},
211 "EXAMPLE.COMpianist",
212 "\x85\x76\x37\x26\x58\x5d\xbc\x1c\xce\x6e\xc4\x3e"
213 "\x1f\x75\x1f\x07\xf1\xc4\xcb\xb0\x98\xf4\x0b\x19",
214 SHISHI_DES3_CBC_HMAC_SHA1_KD
},
218 "ATHENA.MIT.EDUraeburn",
219 "\x42\x26\x3c\x6e\x89\xf4\xfc\x28\xb8\xdf\x68\xee\x09\x79\x9f\x15",
220 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x01"},
222 "ATHENA.MIT.EDUraeburn",
223 "\xfe\x69\x7b\x52\xbc\x0d\x3c\xe1\x44\x32\xba\x03\x6a\x92\xe6\x5b"
224 "\xbb\x52\x28\x09\x90\xa2\xfa\x27\x88\x39\x98\xd7\x2a\xf3\x01\x61",
225 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x01"},
227 "ATHENA.MIT.EDUraeburn",
228 "\xc6\x51\xbf\x29\xe2\x30\x0a\xc2\x7f\xa4\x69\xd6\x93\xbd\xda\x13",
229 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x02"},
231 "ATHENA.MIT.EDUraeburn",
232 "\xa2\xe1\x6d\x16\xb3\x60\x69\xc1\x35\xd5\xe9\xd2\xe2\x5f\x89\x61"
233 "\x02\x68\x56\x18\xb9\x59\x14\xb4\x67\xc6\x76\x22\x22\x58\x24\xff",
234 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x02"},
236 "ATHENA.MIT.EDUraeburn",
237 "\x4c\x01\xcd\x46\xd6\x32\xd0\x1e\x6d\xbe\x23\x0a\x01\xed\x64\x2a",
238 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"},
240 "ATHENA.MIT.EDUraeburn",
241 "\x55\xa6\xac\x74\x0a\xd1\x7b\x48\x46\x94\x10\x51\xe1\xe8\xb0\xa7"
242 "\x54\x8d\x93\xb0\xab\x30\xa8\xbc\x3f\xf1\x62\x80\x38\x2b\x8c\x2a",
243 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"},
245 "\x12\x34\x56\x78\x78\x56\x34\x12",
246 "\xe9\xb2\x3d\x52\x27\x37\x47\xdd\x5c\x35\xcb\x55\xbe\x61\x9d\x8e",
247 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x05"},
249 "\x12\x34\x56\x78\x78\x56\x34\x12",
250 "\x97\xa4\xe7\x86\xbe\x20\xd8\x1a\x38\x2d\x5e\xbc\x96\xd5\x90\x9c"
251 "\xab\xcd\xad\xc8\x7c\xa4\x8f\x57\x45\x04\x15\x9f\x16\xc3\x6e\x31",
252 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x05"},
253 {"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
254 "pass phrase equals block size",
255 "\x59\xd1\xbb\x78\x9a\x82\x8b\x1a\xa5\x4e\xf9\xc2\x88\x3f\x69\xed",
256 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"},
257 {"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
258 "pass phrase equals block size",
259 "\x89\xad\xee\x36\x08\xdb\x8b\xc7\x1f\x1b\xfb\xfe\x45\x94\x86\xb0"
260 "\x56\x18\xb7\x0c\xba\xe2\x20\x92\x53\x4e\x56\xc5\x53\xba\x4b\x34",
261 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"},
262 {"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
263 "pass phrase exceeds block size",
264 "\xcb\x80\x05\xdc\x5f\x90\x17\x9a\x7f\x02\x10\x4c\x00\x18\x75\x1d",
265 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"},
266 {"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
267 "pass phrase exceeds block size",
268 "\xd7\x8c\x5c\x9c\xb8\x72\xa8\xc9\xda\xd4\x69\x7f\x0b\xb5\xb2\xd2"
269 "\x14\x96\xc8\x2b\xeb\x2c\xae\xda\x21\x12\xfc\xee\xa0\x57\x40\x1b",
270 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x04\xB0"},
272 "EXAMPLE.COMpianist",
273 "\xf1\x49\xc1\xf2\xe1\x54\xa7\x34\x52\xd4\x3e\x7f\xe6\x2a\x56\xe5",
274 SHISHI_AES128_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x32"},
276 "EXAMPLE.COMpianist",
277 "\x4b\x6d\x98\x39\xf8\x44\x06\xdf\x1f\x09\xcc\x16\x6d\xb4\xb8\x3c"
278 "\x57\x18\x48\xb7\x84\xa3\xd6\xbd\xc3\x46\x58\x9a\x3e\x39\x3f\x9e",
279 SHISHI_AES256_CTS_HMAC_SHA1_96
, "\x00\x00\x00\x32"},
283 "\xac\x8e\x65\x7f\x83\xdf\x82\xbe\xea\x5d\x43\xbd\xaf\x78\x00\xcc",
291 const char *password
;
294 const char *expected
;
296 const struct pkcs5 pkcs5
[] = {
297 {1, "password", "ATHENA.MIT.EDUraeburn", 16,
298 "\xCD\xED\xB5\x28\x1B\xB2\xF8\x01\x56\x5A\x11\x22\xB2\x56\x35\x15"},
299 {2, "password", "ATHENA.MIT.EDUraeburn", 16,
300 "\x01\xdb\xee\x7f\x4a\x9e\x24\x3e\x98\x8b\x62\xc7\x3c\xda\x93\x5d"},
301 {2, "password", "ATHENA.MIT.EDUraeburn", 32,
302 "\x01\xdb\xee\x7f\x4a\x9e\x24\x3e\x98\x8b\x62\xc7\x3c\xda\x93\x5d"
303 "\xa0\x53\x78\xb9\x32\x44\xec\x8f\x48\xa9\x9e\x61\xad\x79\x9d\x86"},
304 {1200, "password", "ATHENA.MIT.EDUraeburn", 16,
305 "\x5c\x08\xeb\x61\xfd\xf7\x1e\x4e\x4e\xc3\xcf\x6b\xa1\xf5\x51\x2b"},
306 {1200, "password", "ATHENA.MIT.EDUraeburn", 32,
307 "\x5c\x08\xeb\x61\xfd\xf7\x1e\x4e\x4e\xc3\xcf\x6b\xa1\xf5\x51\x2b"
308 "\xa7\xe5\x2d\xdb\xc5\xe5\x14\x2f\x70\x8a\x31\xe2\xe6\x2b\x1e\x13"},
309 {5, "password", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 16,
310 "\xd1\xda\xa7\x86\x15\xf2\x87\xe6\xa1\xc8\xb1\x20\xd7\x06\x2a\x49"},
311 {5, "password", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 32,
312 "\xd1\xda\xa7\x86\x15\xf2\x87\xe6\xa1\xc8\xb1\x20\xd7\x06\x2a\x49"
313 "\x3f\x98\xd2\x03\xe6\xbe\x49\xa6\xad\xf4\xfa\x57\x4b\x6e\x64\xee"},
314 {1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
315 "pass phrase equals block size", 16,
316 "\x13\x9c\x30\xc0\x96\x6b\xc3\x2b\xa5\x5f\xdb\xf2\x12\x53\x0a\xc9"},
317 {1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
318 "pass phrase equals block size", 32,
319 "\x13\x9c\x30\xc0\x96\x6b\xc3\x2b\xa5\x5f\xdb\xf2\x12\x53\x0a\xc9"
320 "\xc5\xec\x59\xf1\xa4\x52\xf5\xcc\x9a\xd9\x40\xfe\xa0\x59\x8e\xd1"},
321 {1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
322 "pass phrase exceeds block size", 16,
323 "\x9c\xca\xd6\xd4\x68\x77\x0c\xd5\x1b\x10\xe6\xa6\x87\x21\xbe\x61"},
324 {1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
325 "pass phrase exceeds block size", 32,
326 "\x9c\xca\xd6\xd4\x68\x77\x0c\xd5\x1b\x10\xe6\xa6\x87\x21\xbe\x61"
327 "\x1a\x8b\x4d\x28\x26\x01\xdb\x3b\x36\xbe\x92\x46\x91\x5e\xc8\x2a"},
328 {50, G_CLEF
"\x00", "EXAMPLE.COMpianist", 16,
329 "\x6b\x9c\xf2\x6d\x45\x45\x5a\x43\xa5\xb8\xbb\x27\x6a\x40\x3b\x39"},
330 {50, G_CLEF
"\x00", "EXAMPLE.COMpianist", 32,
331 "\x6b\x9c\xf2\x6d\x45\x45\x5a\x43\xa5\xb8\xbb\x27\x6a\x40\x3b\x39"
332 "\xe7\xfe\x37\xa0\xc4\x1e\x02\xc2\x81\xff\x30\x69\xe1\xe9\x4f\x52"},
333 {500, "All n-entities must communicate with other n-entities via n-1 "
334 "entiteeheehees", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 16,
335 "\x6A\x89\x70\xBF\x68\xC9\x2C\xAE\xA8\x4A\x8D\xF2\x85\x10\x85\x86"}
339 test (Shishi
* handle
)
341 Shishi_key
*key
, *key2
;
347 shishi_cfg (handle
, strdup ("verbose-crypto,verbose-crypto-noise"));
349 for (i
= 0; i
< sizeof (drdk
) / sizeof (drdk
[0]); i
++)
352 printf ("DR entry %d\n", i
);
354 res
= shishi_key_from_value (handle
, drdk
[i
].type
, drdk
[i
].key
, &key
);
356 if (res
== SHISHI_OK
)
357 res
= shishi_dr (handle
, key
, drdk
[i
].usage
, drdk
[i
].nusage
,
358 out
, strlen (drdk
[i
].dr
));
360 shishi_key_done (key
);
362 if (res
!= SHISHI_OK
)
364 fail ("shishi_dr() entry %d failed (%s)\n",
365 i
, shishi_error (handle
));
371 printf ("DR(%s, key, usage)\n", shishi_cipher_name (drdk
[i
].type
));
374 escapeprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
375 hexprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
377 binprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
381 escapeprint (drdk
[i
].usage
, drdk
[i
].nusage
);
382 hexprint (drdk
[i
].usage
, drdk
[i
].nusage
);
384 binprint (drdk
[i
].usage
, drdk
[i
].nusage
);
387 printf ("computed DR:\n");
388 escapeprint (out
, strlen (drdk
[i
].dr
));
389 hexprint (out
, strlen (drdk
[i
].dr
));
391 binprint (out
, strlen (drdk
[i
].dr
));
394 printf ("expected DR:\n");
395 escapeprint (drdk
[i
].dr
, strlen (drdk
[i
].dr
));
396 hexprint (drdk
[i
].dr
, strlen (drdk
[i
].dr
));
398 binprint (drdk
[i
].dr
, strlen (drdk
[i
].dr
));
402 if (memcmp (drdk
[i
].dr
, out
, strlen (drdk
[i
].dr
)) != 0)
404 fail ("shishi_dr() entry %d failed\n", i
);
411 res
= shishi_key_from_value (handle
, drdk
[i
].type
, drdk
[i
].key
, &key
);
413 if (res
== SHISHI_OK
)
414 res
= shishi_key_from_value (handle
, drdk
[i
].type
, NULL
, &key2
);
416 if (res
== SHISHI_OK
)
417 res
= shishi_dk (handle
, key
, drdk
[i
].usage
, drdk
[i
].nusage
, key2
);
419 shishi_key_done (key
);
421 if (res
!= SHISHI_OK
)
423 fail ("shishi_dk() entry %d failed (%s)\n",
424 i
, shishi_error (handle
));
430 printf ("DK(%s, key, usage)\n", shishi_cipher_name (drdk
[i
].type
));
433 escapeprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
434 hexprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
436 binprint (drdk
[i
].key
, strlen (drdk
[i
].key
));
440 escapeprint (drdk
[i
].usage
, drdk
[i
].nusage
);
441 hexprint (drdk
[i
].usage
, drdk
[i
].nusage
);
443 binprint (drdk
[i
].usage
, drdk
[i
].nusage
);
446 printf ("computed DK:\n");
447 escapeprint (shishi_key_value (key2
), shishi_key_length (key2
));
448 hexprint (shishi_key_value (key2
), shishi_key_length (key2
));
450 binprint (shishi_key_value (key2
), shishi_key_length (key2
));
453 printf ("expected DK:\n");
454 escapeprint (drdk
[i
].dk
, strlen (drdk
[i
].dk
));
455 hexprint (drdk
[i
].dk
, strlen (drdk
[i
].dk
));
457 binprint (drdk
[i
].dk
, strlen (drdk
[i
].dk
));
461 if (!(shishi_key_length (key2
) == strlen (drdk
[i
].dk
) &&
462 memcmp (drdk
[i
].dk
, shishi_key_value (key2
),
463 strlen (drdk
[i
].dk
)) == 0))
465 fail ("shishi_dk() entry %d failed\n", i
);
472 shishi_key_done (key2
);
475 for (i
= 0; i
< sizeof (nfold
) / sizeof (nfold
[0]); i
++)
478 printf ("N-FOLD entry %d\n", i
);
480 res
= shishi_n_fold (handle
,
481 nfold
[i
].in
, strlen (nfold
[i
].in
),
482 out
, nfold
[i
].n
/ 8);
483 if (res
!= SHISHI_OK
)
485 fail ("shishi_n_fold() entry %d failed (%s)\n",
486 i
, shishi_error (handle
));
493 escapeprint (nfold
[i
].in
, strlen (nfold
[i
].in
));
494 hexprint (nfold
[i
].in
, strlen (nfold
[i
].in
));
496 binprint (nfold
[i
].in
, strlen (nfold
[i
].in
));
500 escapeprint (out
, nfold
[i
].n
/ 8);
501 hexprint (out
, nfold
[i
].n
/ 8);
503 binprint (out
, nfold
[i
].n
/ 8);
506 printf ("expected out:\n");
507 escapeprint (nfold
[i
].out
, nfold
[i
].n
/ 8);
508 hexprint (nfold
[i
].out
, nfold
[i
].n
/ 8);
510 binprint (nfold
[i
].out
, nfold
[i
].n
/ 8);
514 if (memcmp (nfold
[i
].out
, out
, nfold
[i
].n
/ 8) != 0)
516 fail ("shishi_n_fold() entry %d failed\n", i
);
524 for (i
= 0; i
< sizeof (str2key
) / sizeof (str2key
[0]); i
++)
526 int n_password
= strlen (str2key
[i
].password
);
527 int saltlen
= strlen (str2key
[i
].salt
);
528 int keylen
= sizeof (key
);
529 const char *name
= shishi_cipher_name (str2key
[i
].etype
);
532 printf ("STRING-TO-KEY entry %d (key type %s)\n", i
,
533 name
? name
: "NO NAME");
535 res
= shishi_key_from_string (handle
, str2key
[i
].etype
,
536 str2key
[i
].password
, n_password
,
537 str2key
[i
].salt
, saltlen
,
538 str2key
[i
].parameters
, &key
);
539 if (res
!= SHISHI_OK
)
541 fail ("shishi_string_to_key() entry %d failed (%s)\n",
542 i
, shishi_error (handle
));
548 printf ("password:\n");
549 escapeprint (str2key
[i
].password
, n_password
);
550 hexprint (str2key
[i
].password
, n_password
);
552 binprint (str2key
[i
].password
, n_password
);
556 escapeprint (str2key
[i
].salt
, saltlen
);
557 hexprint (str2key
[i
].salt
, saltlen
);
559 binprint (str2key
[i
].salt
, saltlen
);
562 printf ("computed key:\n");
563 escapeprint (shishi_key_value (key
), shishi_key_length (key
));
564 hexprint (shishi_key_value (key
), shishi_key_length (key
));
566 binprint (shishi_key_value (key
), shishi_key_length (key
));
569 printf ("expected key:\n");
570 escapeprint (str2key
[i
].key
, strlen (str2key
[i
].key
));
571 hexprint (str2key
[i
].key
, strlen (str2key
[i
].key
));
573 binprint (str2key
[i
].key
, strlen (str2key
[i
].key
));
577 if (memcmp (str2key
[i
].key
, shishi_key_value (key
), keylen
) != 0)
579 fail ("shishi_string_to_key() entry %d failed\n", i
);
587 shishi_key_done (key
);
590 for (i
= 0; i
< sizeof (pkcs5
) / sizeof (pkcs5
[0]); i
++)
593 printf ("PKCS5 entry %d\n", i
);
595 res
= shishi_pbkdf2_sha1 (handle
,
596 pkcs5
[i
].password
, strlen (pkcs5
[i
].password
),
597 pkcs5
[i
].salt
, strlen (pkcs5
[i
].salt
),
598 pkcs5
[i
].iterations
, pkcs5
[i
].dklen
, out
);
599 if (res
!= SHISHI_OK
)
601 fail ("PKCS5 entry %d failed fatally: %d\n", i
, res
);
607 printf ("password:\n");
608 escapeprint (pkcs5
[i
].password
, strlen (pkcs5
[i
].password
));
609 hexprint (pkcs5
[i
].password
, strlen (pkcs5
[i
].password
));
611 binprint (pkcs5
[i
].password
, strlen (pkcs5
[i
].password
));
615 escapeprint (pkcs5
[i
].salt
, strlen (pkcs5
[i
].salt
));
616 hexprint (pkcs5
[i
].salt
, strlen (pkcs5
[i
].salt
));
618 binprint (pkcs5
[i
].salt
, strlen (pkcs5
[i
].salt
));
621 printf ("computed key:\n");
622 escapeprint (out
, pkcs5
[i
].dklen
);
623 hexprint (out
, pkcs5
[i
].dklen
);
625 binprint (out
, pkcs5
[i
].dklen
);
628 printf ("expected key:\n");
629 escapeprint (pkcs5
[i
].expected
, pkcs5
[i
].dklen
);
630 hexprint (pkcs5
[i
].expected
, pkcs5
[i
].dklen
);
632 binprint (pkcs5
[i
].expected
, pkcs5
[i
].dklen
);
636 if (memcmp (pkcs5
[i
].expected
, out
, pkcs5
[i
].dklen
) != 0)
638 fail ("PKCS5 entry %d failed\n", i
);