Branch data Line data Source code
1 : : /* crypto.c --- Shishi crypto self tests.
2 : : * Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2010 Simon Josefsson
3 : : *
4 : : * This file is part of Shishi.
5 : : *
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 3 of the License, or
9 : : * (at your option) any later version.
10 : : *
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.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 : : * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 : : * Floor, Boston, MA 02110-1301, USA
20 : : *
21 : : */
22 : :
23 : : #include "utils.c"
24 : :
25 : : struct drdk
26 : : {
27 : : int type;
28 : : const char *key;
29 : : int nusage;
30 : : const char *usage;
31 : : const char *dr;
32 : : const char *dk;
33 : : };
34 : : const struct drdk drdk[] = {
35 : : #if WITH_3DES
36 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
37 : : "\xd3\xf8\x29\x8c\xcb\x16\x64\x38\xdc\xb9\xb9\x3e"
38 : : "\xe5\xa7\x62\x92\x86\xa4\x91\xf8\x38\xf8\x02\xfb",
39 : : 8,
40 : : "kerberos",
41 : : "\x22\x70\xdb\x56\x5d\x2a\x3d\x64\xcf\xbf"
42 : : "\xdc\x53\x05\xd4\xf7\x78\xa6\xde\x42\xd9\xda",
43 : : "\x23\x70\xda\x57\x5d\x2a\x3d\xa8\x64\xce\xbf\xdc"
44 : : "\x52\x04\xd5\x6d\xf7\x79\xa7\xdf\x43\xd9\xda\x43"},
45 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
46 : : "\xdc\xe0\x6b\x1f\x64\xc8\x57\xa1\x1c\x3d\xb5\x7c"
47 : : "\x51\x89\x9b\x2c\xc1\x79\x10\x08\xce\x97\x3b\x92",
48 : : 5,
49 : : "\x00\x00\x00\x01\x55",
50 : : "\x93\x50\x79\xd1\x44\x90\xa7\x5c\x30\x93"
51 : : "\xc4\xa6\xe8\xc3\xb0\x49\xc7\x1e\x6e\xe7\x05",
52 : : "\x92\x51\x79\xd0\x45\x91\xa7\x9b\x5d\x31\x92\xc4"
53 : : "\xa7\xe9\xc2\x89\xb0\x49\xc7\x1f\x6e\xe6\x04\xcd"},
54 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
55 : : "\x5e\x13\xd3\x1c\x70\xef\x76\x57\x46\x57\x85\x31"
56 : : "\xcb\x51\xc1\x5b\xf1\x1c\xa8\x2c\x97\xce\xe9\xf2",
57 : : 5,
58 : : "\x00\x00\x00\x01\xaa",
59 : : "\x9f\x58\xe5\xa0\x47\xd8\x94\x10\x1c\x46"
60 : : "\x98\x45\xd6\x7a\xe3\xc5\x24\x9e\xd8\x12\xf2",
61 : : "\x9e\x58\xe5\xa1\x46\xd9\x94\x2a\x10\x1c\x46\x98"
62 : : "\x45\xd6\x7a\x20\xe3\xc4\x25\x9e\xd9\x13\xf2\x07"},
63 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
64 : : "\x98\xe6\xfd\x8a\x04\xa4\xb6\x85\x9b\x75\xa1\x76"
65 : : "\x54\x0b\x97\x52\xba\xd3\xec\xd6\x10\xa2\x52\xbc",
66 : : 5,
67 : : "\x00\x00\x00\x01\x55",
68 : : "\x12\xff\xf9\x0c\x77\x3f\x95\x6d\x13\xfc"
69 : : "\x2c\xa0\xd0\x84\x03\x49\xdb\xd3\x99\x08\xeb",
70 : : "\x13\xfe\xf8\x0d\x76\x3e\x94\xec\x6d\x13\xfd\x2c"
71 : : "\xa1\xd0\x85\x07\x02\x49\xda\xd3\x98\x08\xea\xbf"},
72 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
73 : : "\x62\x2a\xec\x25\xa2\xfe\x2c\xad\x70\x94\x68\x0b"
74 : : "\x7c\x64\x94\x02\x80\x08\x4c\x1a\x7c\xec\x92\xb5",
75 : : 5,
76 : : "\x00\x00\x00\x01\xaa",
77 : : "\xf8\xde\xbf\x05\xb0\x97\xe7\xdc\x06\x03"
78 : : "\x68\x6a\xca\x35\xd9\x1f\xd9\xa5\x51\x6a\x70",
79 : : "\xf8\xdf\xbf\x04\xb0\x97\xe6\xd9\xdc\x07\x02\x68"
80 : : "\x6b\xcb\x34\x89\xd9\x1f\xd9\xa4\x51\x6b\x70\x3e"},
81 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
82 : : "\xc1\x08\x16\x49\xad\xa7\x43\x62\xe6\xa1\x45\x9d"
83 : : "\x01\xdf\xd3\x0d\x67\xc2\x23\x4c\x94\x07\x04\xda",
84 : : 5,
85 : : "\x00\x00\x00\x01\x55",
86 : : "\x34\x80\x56\xec\x98\xfc\xc5\x17\x17\x1d"
87 : : "\x2b\x4d\x7a\x94\x93\xaf\x48\x2d\x99\x91\x75",
88 : : "\x34\x80\x57\xec\x98\xfd\xc4\x80\x16\x16\x1c\x2a"
89 : : "\x4c\x7a\x94\x3e\x92\xae\x49\x2c\x98\x91\x75\xf7"},
90 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
91 : : "\x5d\x15\x4a\xf2\x38\xf4\x67\x13\x15\x57\x19\xd5"
92 : : "\x5e\x2f\x1f\x79\x0d\xd6\x61\xf2\x79\xa7\x91\x7c",
93 : : 5,
94 : : "\x00\x00\x00\x01\xaa",
95 : : "\xa8\x81\x8b\xc3\x67\xda\xda\xcb\xe9\xa6"
96 : : "\xc8\x46\x27\xfb\x60\xc2\x94\xb0\x12\x15\xe5",
97 : : "\xa8\x80\x8a\xc2\x67\xda\xda\x3d\xcb\xe9\xa7\xc8"
98 : : "\x46\x26\xfb\xc7\x61\xc2\x94\xb0\x13\x15\xe5\xc1"},
99 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
100 : : "\x79\x85\x62\xe0\x49\x85\x2f\x57\xdc\x8c\x34\x3b"
101 : : "\xa1\x7f\x2c\xa1\xd9\x73\x94\xef\xc8\xad\xc4\x43",
102 : : 5,
103 : : "\x00\x00\x00\x01\x55",
104 : : "\xc8\x13\xf8\x8b\x3b\xe2\xb2\xf7\x54\x24"
105 : : "\xce\x91\x75\xfb\xc8\x48\x3b\x88\xc8\x71\x3a",
106 : : "\xc8\x13\xf8\x8a\x3b\xe3\xb3\x34\xf7\x54\x25\xce"
107 : : "\x91\x75\xfb\xe3\xc8\x49\x3b\x89\xc8\x70\x3b\x49"},
108 : : {SHISHI_DES3_CBC_HMAC_SHA1_KD,
109 : : "\x26\xdc\xe3\x34\xb5\x45\x29\x2f\x2f\xea\xb9\xa8"
110 : : "\x70\x1a\x89\xa4\xb9\x9e\xb9\x94\x2c\xec\xd0\x16",
111 : : 5,
112 : : "\x00\x00\x00\x01\xaa",
113 : : "\xf5\x8e\xfc\x6f\x83\xf9\x3e\x55\xe6\x95"
114 : : "\xfd\x25\x2c\xf8\xfe\x59\xf7\xd5\xba\x37\xec",
115 : : "\xf4\x8f\xfd\x6e\x83\xf8\x3e\x73\x54\xe6\x94\xfd"
116 : : "\x25\x2c\xf8\x3b\xfe\x58\xf7\xd5\xba\x37\xec\x5d"}
117 : : #endif
118 : : };
119 : :
120 : : struct nfold
121 : : {
122 : : int n;
123 : : const char *in;
124 : : const char *out;
125 : : };
126 : : const struct nfold nfold[] = {
127 : : {64, "012345", "\xBE\x07\x26\x31\x27\x6B\x19\x55"},
128 : : {56, "password", "\x78\xA0\x7B\x6C\xAF\x85\xFA"},
129 : : {64, "Rough Consensus, and Running Code",
130 : : "\xBB\x6E\xD3\x08\x70\xB7\xF0\xE0"},
131 : : {168, "password", "\x59\xE4\xA8\xCA\x7C\x03\x85\xC3\xC3\x7B"
132 : : "\x3F\x6D\x20\x00\x24\x7C\xB6\xE6\xBD\x5B\x3E"},
133 : : {192, "MASSACHVSETTS INSTITVTE OF TECHNOLOGY",
134 : : "\xDB\x3B\x0D\x8F\x0B\x06\x1E\x60\x32\x82\xB3\x08"
135 : : "\xA5\x08\x41\x22\x9A\xD7\x98\xFA\xB9\x54\x0C\x1B"},
136 : : {64, "kerberos", "\x6b\x65\x72\x62\x65\x72\x6f\x73"},
137 : : {128, "kerberos",
138 : : "\x6b\x65\x72\x62\x65\x72\x6f\x73\x7b\x9b\x5b\x2b\x93\x13\x2b\x93"},
139 : : {168, "kerberos",
140 : : "\x83\x72\xc2\x36\x34\x4e\x5f\x15\x50\xcd"
141 : : "\x07\x47\xe1\x5d\x62\xca\x7a\x5a\x3b\xce\xa4"},
142 : : {256, "kerberos",
143 : : "\x6b\x65\x72\x62\x65\x72\x6f\x73\x7b\x9b\x5b\x2b\x93\x13\x2b\x93"
144 : : "\x5c\x9b\xdc\xda\xd9\x5c\x98\x99\xc4\xca\xe4\xde\xe6\xd6\xca\xe4"},
145 : : {168, "Q",
146 : : "\x51\x8a\x54\xa2\x15\xa8\x45\x2a\x51\x8a"
147 : : "\x54\xa2\x15\xa8\x45\x2a\x51\x8a\x54\xa2\x15"},
148 : : {192, "Q",
149 : : "\x51\x8a\x54\xa2\x15\xa8\x45\x2a\x51\x8a\x54\xa2"
150 : : "\x15\xa8\x45\x2a\x51\x8a\x54\xa2\x15\xa8\x45\x2a"},
151 : : {168, "ab",
152 : : "\xba\x24\xcf\x29\x7f\x49\xf5\x4b\xab\x62"
153 : : "\x5d\x12\xe7\x94\x3f\xa4\xfb\x25\xd5\x31\xae"},
154 : : {192, "ab",
155 : : "\x61\x62\x0b\x13\x58\x98\xc4\xc2\x26\x16\x30\xb1"
156 : : "\x85\x89\x2c\x4c\x62\x61\x13\x0b\x98\x58\xc2\xc4"}
157 : : };
158 : :
159 : : struct str2key
160 : : {
161 : : const char *password;
162 : : const char *salt;
163 : : const char *key;
164 : : int etype;
165 : : const char *parameters;
166 : : };
167 : : const struct str2key str2key[] = {
168 : : #define ESZETT "\xC3\x9F"
169 : : #define S_CARON "\xC5\xA1"
170 : : #define C_ACUTE "\xC4\x87"
171 : : #define G_CLEF "\xF0\x9D\x84\x9E"
172 : : #if WITH_DES
173 : : {"password",
174 : : "ATHENA.MIT.EDUraeburn",
175 : : "\xCB\xC2\x2F\xAE\x23\x52\x98\xE3", SHISHI_DES_CBC_MD5, NULL},
176 : : {"potatoe",
177 : : "WHITEHOUSE.GOVdanny",
178 : : "\xDF\x3D\x32\xA7\x4F\xD9\x2A\x01", SHISHI_DES_CBC_MD5, NULL},
179 : : {"\xF0\x9D\x84\x9E",
180 : : "EXAMPLE.COMpianist",
181 : : "\x4F\xFB\x26\xBA\xB0\xCD\x94\x13", SHISHI_DES_CBC_MD5, NULL},
182 : : {ESZETT,
183 : : "ATHENA.MIT.EDUJuri" S_CARON "i" C_ACUTE,
184 : : "\x62\xC8\x1A\x52\x32\xB5\xE6\x9D", SHISHI_DES_CBC_MD5, NULL},
185 : : {"11119999",
186 : : "AAAAAAAA", "\x98\x40\x54\xD0\xF1\xA7\x3E\x31", SHISHI_DES_CBC_MD5, NULL},
187 : : {"NNNN6666",
188 : : "FFFFAAAA", "\xC4\xBF\x6B\x25\xAD\xF7\xA4\xF8", SHISHI_DES_CBC_MD5, NULL},
189 : : #endif
190 : : #if WITH_3DES
191 : : {"password",
192 : : "ATHENA.MIT.EDUraeburn",
193 : : "\x85\x0b\xb5\x13\x58\x54\x8c\xd0\x5e\x86\x76\x8c"
194 : : "\x31\x3e\x3b\xfe\xf7\x51\x19\x37\xdc\xf7\x2c\x3e",
195 : : SHISHI_DES3_CBC_HMAC_SHA1_KD, NULL},
196 : : {"potatoe",
197 : : "WHITEHOUSE.GOVdanny",
198 : : "\xdf\xcd\x23\x3d\xd0\xa4\x32\x04\xea\x6d\xc4\x37"
199 : : "\xfb\x15\xe0\x61\xb0\x29\x79\xc1\xf7\x4f\x37\x7a",
200 : : SHISHI_DES3_CBC_HMAC_SHA1_KD, NULL},
201 : : {"penny",
202 : : "EXAMPLE.COMbuckaroo",
203 : : "\x6d\x2f\xcd\xf2\xd6\xfb\xbc\x3d\xdc\xad\xb5\xda"
204 : : "\x57\x10\xa2\x34\x89\xb0\xd3\xb6\x9d\x5d\x9d\x4a",
205 : : SHISHI_DES3_CBC_HMAC_SHA1_KD, NULL},
206 : : {ESZETT,
207 : : "ATHENA.MIT.EDUJuri" S_CARON "i" C_ACUTE,
208 : : "\x16\xd5\xa4\x0e\x1c\xe3\xba\xcb\x61\xb9\xdc\xe0"
209 : : "\x04\x70\x32\x4c\x83\x19\x73\xa7\xb9\x52\xfe\xb0",
210 : : SHISHI_DES3_CBC_HMAC_SHA1_KD, NULL},
211 : : {G_CLEF,
212 : : "EXAMPLE.COMpianist",
213 : : "\x85\x76\x37\x26\x58\x5d\xbc\x1c\xce\x6e\xc4\x3e"
214 : : "\x1f\x75\x1f\x07\xf1\xc4\xcb\xb0\x98\xf4\x0b\x19",
215 : : SHISHI_DES3_CBC_HMAC_SHA1_KD, NULL},
216 : : #endif
217 : : #if WITH_AES
218 : : {"password",
219 : : "ATHENA.MIT.EDUraeburn",
220 : : "\x42\x26\x3c\x6e\x89\xf4\xfc\x28\xb8\xdf\x68\xee\x09\x79\x9f\x15",
221 : : SHISHI_AES128_CTS_HMAC_SHA1_96, "\x00\x00\x00\x01"},
222 : : {"password",
223 : : "ATHENA.MIT.EDUraeburn",
224 : : "\xfe\x69\x7b\x52\xbc\x0d\x3c\xe1\x44\x32\xba\x03\x6a\x92\xe6\x5b"
225 : : "\xbb\x52\x28\x09\x90\xa2\xfa\x27\x88\x39\x98\xd7\x2a\xf3\x01\x61",
226 : : SHISHI_AES256_CTS_HMAC_SHA1_96, "\x00\x00\x00\x01"},
227 : : {"password",
228 : : "ATHENA.MIT.EDUraeburn",
229 : : "\xc6\x51\xbf\x29\xe2\x30\x0a\xc2\x7f\xa4\x69\xd6\x93\xbd\xda\x13",
230 : : SHISHI_AES128_CTS_HMAC_SHA1_96, "\x00\x00\x00\x02"},
231 : : {"password",
232 : : "ATHENA.MIT.EDUraeburn",
233 : : "\xa2\xe1\x6d\x16\xb3\x60\x69\xc1\x35\xd5\xe9\xd2\xe2\x5f\x89\x61"
234 : : "\x02\x68\x56\x18\xb9\x59\x14\xb4\x67\xc6\x76\x22\x22\x58\x24\xff",
235 : : SHISHI_AES256_CTS_HMAC_SHA1_96, "\x00\x00\x00\x02"},
236 : : {"password",
237 : : "ATHENA.MIT.EDUraeburn",
238 : : "\x4c\x01\xcd\x46\xd6\x32\xd0\x1e\x6d\xbe\x23\x0a\x01\xed\x64\x2a",
239 : : SHISHI_AES128_CTS_HMAC_SHA1_96, "\x00\x00\x04\xB0"},
240 : : {"password",
241 : : "ATHENA.MIT.EDUraeburn",
242 : : "\x55\xa6\xac\x74\x0a\xd1\x7b\x48\x46\x94\x10\x51\xe1\xe8\xb0\xa7"
243 : : "\x54\x8d\x93\xb0\xab\x30\xa8\xbc\x3f\xf1\x62\x80\x38\x2b\x8c\x2a",
244 : : SHISHI_AES256_CTS_HMAC_SHA1_96, "\x00\x00\x04\xB0"},
245 : : {"password",
246 : : "\x12\x34\x56\x78\x78\x56\x34\x12",
247 : : "\xe9\xb2\x3d\x52\x27\x37\x47\xdd\x5c\x35\xcb\x55\xbe\x61\x9d\x8e",
248 : : SHISHI_AES128_CTS_HMAC_SHA1_96, "\x00\x00\x00\x05"},
249 : : {"password",
250 : : "\x12\x34\x56\x78\x78\x56\x34\x12",
251 : : "\x97\xa4\xe7\x86\xbe\x20\xd8\x1a\x38\x2d\x5e\xbc\x96\xd5\x90\x9c"
252 : : "\xab\xcd\xad\xc8\x7c\xa4\x8f\x57\x45\x04\x15\x9f\x16\xc3\x6e\x31",
253 : : SHISHI_AES256_CTS_HMAC_SHA1_96, "\x00\x00\x00\x05"},
254 : : {"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
255 : : "pass phrase equals block size",
256 : : "\x59\xd1\xbb\x78\x9a\x82\x8b\x1a\xa5\x4e\xf9\xc2\x88\x3f\x69\xed",
257 : : SHISHI_AES128_CTS_HMAC_SHA1_96, "\x00\x00\x04\xB0"},
258 : : {"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
259 : : "pass phrase equals block size",
260 : : "\x89\xad\xee\x36\x08\xdb\x8b\xc7\x1f\x1b\xfb\xfe\x45\x94\x86\xb0"
261 : : "\x56\x18\xb7\x0c\xba\xe2\x20\x92\x53\x4e\x56\xc5\x53\xba\x4b\x34",
262 : : SHISHI_AES256_CTS_HMAC_SHA1_96, "\x00\x00\x04\xB0"},
263 : : {"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
264 : : "pass phrase exceeds block size",
265 : : "\xcb\x80\x05\xdc\x5f\x90\x17\x9a\x7f\x02\x10\x4c\x00\x18\x75\x1d",
266 : : SHISHI_AES128_CTS_HMAC_SHA1_96, "\x00\x00\x04\xB0"},
267 : : {"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
268 : : "pass phrase exceeds block size",
269 : : "\xd7\x8c\x5c\x9c\xb8\x72\xa8\xc9\xda\xd4\x69\x7f\x0b\xb5\xb2\xd2"
270 : : "\x14\x96\xc8\x2b\xeb\x2c\xae\xda\x21\x12\xfc\xee\xa0\x57\x40\x1b",
271 : : SHISHI_AES256_CTS_HMAC_SHA1_96, "\x00\x00\x04\xB0"},
272 : : {G_CLEF,
273 : : "EXAMPLE.COMpianist",
274 : : "\xf1\x49\xc1\xf2\xe1\x54\xa7\x34\x52\xd4\x3e\x7f\xe6\x2a\x56\xe5",
275 : : SHISHI_AES128_CTS_HMAC_SHA1_96, "\x00\x00\x00\x32"},
276 : : {G_CLEF,
277 : : "EXAMPLE.COMpianist",
278 : : "\x4b\x6d\x98\x39\xf8\x44\x06\xdf\x1f\x09\xcc\x16\x6d\xb4\xb8\x3c"
279 : : "\x57\x18\x48\xb7\x84\xa3\xd6\xbd\xc3\x46\x58\x9a\x3e\x39\x3f\x9e",
280 : : SHISHI_AES256_CTS_HMAC_SHA1_96, "\x00\x00\x00\x32"},
281 : : #endif
282 : : #if WITH_ARCFOUR
283 : : {"foo", "",
284 : : "\xac\x8e\x65\x7f\x83\xdf\x82\xbe\xea\x5d\x43\xbd\xaf\x78\x00\xcc",
285 : : SHISHI_ARCFOUR_HMAC, NULL}
286 : : #endif
287 : : };
288 : :
289 : : struct pkcs5
290 : : {
291 : : int iterations;
292 : : const char *password;
293 : : const char *salt;
294 : : int dklen;
295 : : const char *expected;
296 : : };
297 : : const struct pkcs5 pkcs5[] = {
298 : : {1, "password", "ATHENA.MIT.EDUraeburn", 16,
299 : : "\xCD\xED\xB5\x28\x1B\xB2\xF8\x01\x56\x5A\x11\x22\xB2\x56\x35\x15"},
300 : : {2, "password", "ATHENA.MIT.EDUraeburn", 16,
301 : : "\x01\xdb\xee\x7f\x4a\x9e\x24\x3e\x98\x8b\x62\xc7\x3c\xda\x93\x5d"},
302 : : {2, "password", "ATHENA.MIT.EDUraeburn", 32,
303 : : "\x01\xdb\xee\x7f\x4a\x9e\x24\x3e\x98\x8b\x62\xc7\x3c\xda\x93\x5d"
304 : : "\xa0\x53\x78\xb9\x32\x44\xec\x8f\x48\xa9\x9e\x61\xad\x79\x9d\x86"},
305 : : {1200, "password", "ATHENA.MIT.EDUraeburn", 16,
306 : : "\x5c\x08\xeb\x61\xfd\xf7\x1e\x4e\x4e\xc3\xcf\x6b\xa1\xf5\x51\x2b"},
307 : : {1200, "password", "ATHENA.MIT.EDUraeburn", 32,
308 : : "\x5c\x08\xeb\x61\xfd\xf7\x1e\x4e\x4e\xc3\xcf\x6b\xa1\xf5\x51\x2b"
309 : : "\xa7\xe5\x2d\xdb\xc5\xe5\x14\x2f\x70\x8a\x31\xe2\xe6\x2b\x1e\x13"},
310 : : {5, "password", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 16,
311 : : "\xd1\xda\xa7\x86\x15\xf2\x87\xe6\xa1\xc8\xb1\x20\xd7\x06\x2a\x49"},
312 : : {5, "password", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 32,
313 : : "\xd1\xda\xa7\x86\x15\xf2\x87\xe6\xa1\xc8\xb1\x20\xd7\x06\x2a\x49"
314 : : "\x3f\x98\xd2\x03\xe6\xbe\x49\xa6\xad\xf4\xfa\x57\x4b\x6e\x64\xee"},
315 : : {1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
316 : : "pass phrase equals block size", 16,
317 : : "\x13\x9c\x30\xc0\x96\x6b\xc3\x2b\xa5\x5f\xdb\xf2\x12\x53\x0a\xc9"},
318 : : {1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
319 : : "pass phrase equals block size", 32,
320 : : "\x13\x9c\x30\xc0\x96\x6b\xc3\x2b\xa5\x5f\xdb\xf2\x12\x53\x0a\xc9"
321 : : "\xc5\xec\x59\xf1\xa4\x52\xf5\xcc\x9a\xd9\x40\xfe\xa0\x59\x8e\xd1"},
322 : : {1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
323 : : "pass phrase exceeds block size", 16,
324 : : "\x9c\xca\xd6\xd4\x68\x77\x0c\xd5\x1b\x10\xe6\xa6\x87\x21\xbe\x61"},
325 : : {1200, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
326 : : "pass phrase exceeds block size", 32,
327 : : "\x9c\xca\xd6\xd4\x68\x77\x0c\xd5\x1b\x10\xe6\xa6\x87\x21\xbe\x61"
328 : : "\x1a\x8b\x4d\x28\x26\x01\xdb\x3b\x36\xbe\x92\x46\x91\x5e\xc8\x2a"},
329 : : {50, G_CLEF "\x00", "EXAMPLE.COMpianist", 16,
330 : : "\x6b\x9c\xf2\x6d\x45\x45\x5a\x43\xa5\xb8\xbb\x27\x6a\x40\x3b\x39"},
331 : : {50, G_CLEF "\x00", "EXAMPLE.COMpianist", 32,
332 : : "\x6b\x9c\xf2\x6d\x45\x45\x5a\x43\xa5\xb8\xbb\x27\x6a\x40\x3b\x39"
333 : : "\xe7\xfe\x37\xa0\xc4\x1e\x02\xc2\x81\xff\x30\x69\xe1\xe9\x4f\x52"},
334 : : {500, "All n-entities must communicate with other n-entities via n-1 "
335 : : "entiteeheehees", "\x12\x34\x56\x78\x78\x56\x34\x12\x00", 16,
336 : : "\x6A\x89\x70\xBF\x68\xC9\x2C\xAE\xA8\x4A\x8D\xF2\x85\x10\x85\x86"}
337 : : };
338 : :
339 : : void
340 : 1 : test (Shishi * handle)
341 : : {
342 : : Shishi_key *key, *key2;
343 : : char out[BUFSIZ];
344 : : size_t i;
345 : : int res;
346 : :
347 [ - + ]: 1 : if (debug)
348 : 0 : shishi_cfg (handle, strdup ("verbose-crypto,verbose-crypto-noise"));
349 : :
350 : 1 : res = shishi_cipher_parse ("3des");
351 [ - + ]: 1 : if (res != SHISHI_DES3_CBC_HMAC_SHA1_KD)
352 : 0 : fail ("shishi_cipher_parse (\"3des\") == %d\n", res);
353 : :
354 [ + + ]: 10 : for (i = 0; i < sizeof (drdk) / sizeof (drdk[0]); i++)
355 : : {
356 [ - + ]: 9 : if (debug)
357 : 0 : printf ("DR entry %d\n", i);
358 : :
359 : 9 : res = shishi_key_from_value (handle, drdk[i].type, drdk[i].key, &key);
360 : :
361 [ + - ]: 9 : if (res == SHISHI_OK)
362 : 9 : res = shishi_dr (handle, key, drdk[i].usage, drdk[i].nusage,
363 : : out, strlen (drdk[i].dr));
364 : :
365 : 9 : shishi_key_done (key);
366 : :
367 [ - + ]: 9 : if (res != SHISHI_OK)
368 : : {
369 : 0 : fail ("shishi_dr() entry %d failed (%s)\n",
370 : : i, shishi_error (handle));
371 : 0 : continue;
372 : : }
373 : :
374 [ - + ]: 9 : if (debug)
375 : : {
376 : 0 : printf ("DR(%s, key, usage)\n", shishi_cipher_name (drdk[i].type));
377 : :
378 : 0 : printf ("key:\n");
379 : 0 : escapeprint (drdk[i].key, strlen (drdk[i].key));
380 : 0 : hexprint (drdk[i].key, strlen (drdk[i].key));
381 : 0 : puts ("");
382 : 0 : binprint (drdk[i].key, strlen (drdk[i].key));
383 : 0 : puts ("");
384 : :
385 : 0 : printf ("usage:\n");
386 : 0 : escapeprint (drdk[i].usage, drdk[i].nusage);
387 : 0 : hexprint (drdk[i].usage, drdk[i].nusage);
388 : 0 : puts ("");
389 : 0 : binprint (drdk[i].usage, drdk[i].nusage);
390 : 0 : puts ("");
391 : :
392 : 0 : printf ("computed DR:\n");
393 : 0 : escapeprint (out, strlen (drdk[i].dr));
394 : 0 : hexprint (out, strlen (drdk[i].dr));
395 : 0 : puts ("");
396 : 0 : binprint (out, strlen (drdk[i].dr));
397 : 0 : puts ("");
398 : :
399 : 0 : printf ("expected DR:\n");
400 : 0 : escapeprint (drdk[i].dr, strlen (drdk[i].dr));
401 : 0 : hexprint (drdk[i].dr, strlen (drdk[i].dr));
402 : 0 : puts ("");
403 : 0 : binprint (drdk[i].dr, strlen (drdk[i].dr));
404 : 0 : puts ("");
405 : : }
406 : :
407 [ - + ]: 9 : if (memcmp (drdk[i].dr, out, strlen (drdk[i].dr)) != 0)
408 : : {
409 : 0 : fail ("shishi_dr() entry %d failed\n", i);
410 [ # # ]: 0 : if (debug)
411 : 0 : printf ("ERROR\n");
412 : : }
413 [ - + ]: 9 : else if (debug)
414 : 0 : success ("OK\n");
415 : :
416 : 9 : res = shishi_key_from_value (handle, drdk[i].type, drdk[i].key, &key);
417 : :
418 [ + - ]: 9 : if (res == SHISHI_OK)
419 : 9 : res = shishi_key_from_value (handle, drdk[i].type, NULL, &key2);
420 : :
421 [ + - ]: 9 : if (res == SHISHI_OK)
422 : 9 : res = shishi_dk (handle, key, drdk[i].usage, drdk[i].nusage, key2);
423 : :
424 : 9 : shishi_key_done (key);
425 : :
426 [ - + ]: 9 : if (res != SHISHI_OK)
427 : : {
428 : 0 : fail ("shishi_dk() entry %d failed (%s)\n",
429 : : i, shishi_error (handle));
430 : 0 : continue;
431 : : }
432 : :
433 [ - + ]: 9 : if (debug)
434 : : {
435 : 0 : printf ("DK(%s, key, usage)\n", shishi_cipher_name (drdk[i].type));
436 : :
437 : 0 : printf ("key:\n");
438 : 0 : escapeprint (drdk[i].key, strlen (drdk[i].key));
439 : 0 : hexprint (drdk[i].key, strlen (drdk[i].key));
440 : 0 : puts ("");
441 : 0 : binprint (drdk[i].key, strlen (drdk[i].key));
442 : 0 : puts ("");
443 : :
444 : 0 : printf ("usage:\n");
445 : 0 : escapeprint (drdk[i].usage, drdk[i].nusage);
446 : 0 : hexprint (drdk[i].usage, drdk[i].nusage);
447 : 0 : puts ("");
448 : 0 : binprint (drdk[i].usage, drdk[i].nusage);
449 : 0 : puts ("");
450 : :
451 : 0 : printf ("computed DK:\n");
452 : 0 : escapeprint (shishi_key_value (key2), shishi_key_length (key2));
453 : 0 : hexprint (shishi_key_value (key2), shishi_key_length (key2));
454 : 0 : puts ("");
455 : 0 : binprint (shishi_key_value (key2), shishi_key_length (key2));
456 : 0 : puts ("");
457 : :
458 : 0 : printf ("expected DK:\n");
459 : 0 : escapeprint (drdk[i].dk, strlen (drdk[i].dk));
460 : 0 : hexprint (drdk[i].dk, strlen (drdk[i].dk));
461 : 0 : puts ("");
462 : 0 : binprint (drdk[i].dk, strlen (drdk[i].dk));
463 : 0 : puts ("");
464 : : }
465 : :
466 [ + - - + ]: 18 : if (!(shishi_key_length (key2) == strlen (drdk[i].dk) &&
467 : 9 : memcmp (drdk[i].dk, shishi_key_value (key2),
468 : : strlen (drdk[i].dk)) == 0))
469 : : {
470 : 0 : fail ("shishi_dk() entry %d failed\n", i);
471 [ # # ]: 0 : if (debug)
472 : 0 : printf ("ERROR\n");
473 : : }
474 [ - + ]: 9 : else if (debug)
475 : 0 : success ("OK\n");
476 : :
477 : 9 : shishi_key_done (key2);
478 : : }
479 : :
480 [ + + ]: 14 : for (i = 0; i < sizeof (nfold) / sizeof (nfold[0]); i++)
481 : : {
482 [ - + ]: 13 : if (debug)
483 : 0 : printf ("N-FOLD entry %d\n", i);
484 : :
485 : 13 : res = shishi_n_fold (handle,
486 : : nfold[i].in, strlen (nfold[i].in),
487 : 13 : out, nfold[i].n / 8);
488 [ - + ]: 13 : if (res != SHISHI_OK)
489 : : {
490 : 0 : fail ("shishi_n_fold() entry %d failed (%s)\n",
491 : : i, shishi_error (handle));
492 : 0 : continue;
493 : : }
494 : :
495 [ - + ]: 13 : if (debug)
496 : : {
497 : 0 : printf ("in:\n");
498 : 0 : escapeprint (nfold[i].in, strlen (nfold[i].in));
499 : 0 : hexprint (nfold[i].in, strlen (nfold[i].in));
500 : 0 : puts ("");
501 : 0 : binprint (nfold[i].in, strlen (nfold[i].in));
502 : 0 : puts ("");
503 : :
504 : 0 : printf ("out:\n");
505 : 0 : escapeprint (out, nfold[i].n / 8);
506 : 0 : hexprint (out, nfold[i].n / 8);
507 : 0 : puts ("");
508 : 0 : binprint (out, nfold[i].n / 8);
509 : 0 : puts ("");
510 : :
511 : 0 : printf ("expected out:\n");
512 : 0 : escapeprint (nfold[i].out, nfold[i].n / 8);
513 : 0 : hexprint (nfold[i].out, nfold[i].n / 8);
514 : 0 : puts ("");
515 : 0 : binprint (nfold[i].out, nfold[i].n / 8);
516 : 0 : puts ("");
517 : : }
518 : :
519 [ - + ]: 13 : if (memcmp (nfold[i].out, out, nfold[i].n / 8) != 0)
520 : : {
521 : 0 : fail ("shishi_n_fold() entry %d failed\n", i);
522 [ # # ]: 0 : if (debug)
523 : 0 : printf ("ERROR\n");
524 : : }
525 [ - + ]: 13 : else if (debug)
526 : 0 : success ("OK\n");
527 : : }
528 : :
529 [ + + ]: 27 : for (i = 0; i < sizeof (str2key) / sizeof (str2key[0]); i++)
530 : : {
531 : 26 : int n_password = strlen (str2key[i].password);
532 : 26 : int saltlen = strlen (str2key[i].salt);
533 : 26 : int keylen = sizeof (key);
534 : 26 : const char *name = shishi_cipher_name (str2key[i].etype);
535 : :
536 [ - + ]: 26 : if (debug)
537 [ # # ]: 0 : printf ("STRING-TO-KEY entry %d (key type %s)\n", i,
538 : : name ? name : "NO NAME");
539 : :
540 : 26 : res = shishi_key_from_string (handle, str2key[i].etype,
541 : : str2key[i].password, n_password,
542 : : str2key[i].salt, saltlen,
543 : : str2key[i].parameters, &key);
544 [ - + ]: 26 : if (res != SHISHI_OK)
545 : : {
546 : 0 : fail ("shishi_string_to_key() entry %d failed (%s)\n",
547 : : i, shishi_error (handle));
548 : 0 : continue;
549 : : }
550 : :
551 [ - + ]: 26 : if (debug)
552 : : {
553 : 0 : printf ("password:\n");
554 : 0 : escapeprint (str2key[i].password, n_password);
555 : 0 : hexprint (str2key[i].password, n_password);
556 : 0 : puts ("");
557 : 0 : binprint (str2key[i].password, n_password);
558 : 0 : puts ("");
559 : :
560 : 0 : printf ("salt:\n");
561 : 0 : escapeprint (str2key[i].salt, saltlen);
562 : 0 : hexprint (str2key[i].salt, saltlen);
563 : 0 : puts ("");
564 : 0 : binprint (str2key[i].salt, saltlen);
565 : 0 : puts ("");
566 : :
567 : 0 : printf ("computed key:\n");
568 : 0 : escapeprint (shishi_key_value (key), shishi_key_length (key));
569 : 0 : hexprint (shishi_key_value (key), shishi_key_length (key));
570 : 0 : puts ("");
571 : 0 : binprint (shishi_key_value (key), shishi_key_length (key));
572 : 0 : puts ("");
573 : :
574 : 0 : printf ("expected key:\n");
575 : 0 : escapeprint (str2key[i].key, strlen (str2key[i].key));
576 : 0 : hexprint (str2key[i].key, strlen (str2key[i].key));
577 : 0 : puts ("");
578 : 0 : binprint (str2key[i].key, strlen (str2key[i].key));
579 : 0 : puts ("");
580 : : }
581 : :
582 [ - + ]: 26 : if (memcmp (str2key[i].key, shishi_key_value (key), keylen) != 0)
583 : : {
584 : 0 : fail ("shishi_string_to_key() entry %d failed\n", i);
585 : :
586 [ # # ]: 0 : if (debug)
587 : 0 : printf ("ERROR\n");
588 : : }
589 [ - + ]: 26 : else if (debug)
590 : 0 : success ("OK\n");
591 : :
592 : 26 : shishi_key_done (key);
593 : : }
594 : :
595 [ + + ]: 15 : for (i = 0; i < sizeof (pkcs5) / sizeof (pkcs5[0]); i++)
596 : : {
597 [ - + ]: 14 : if (debug)
598 : 0 : printf ("PKCS5 entry %d\n", i);
599 : :
600 : 14 : res = shishi_pbkdf2_sha1 (handle,
601 : : pkcs5[i].password, strlen (pkcs5[i].password),
602 : : pkcs5[i].salt, strlen (pkcs5[i].salt),
603 : 28 : pkcs5[i].iterations, pkcs5[i].dklen, out);
604 [ - + ]: 14 : if (res != SHISHI_OK)
605 : : {
606 : 0 : fail ("PKCS5 entry %d failed fatally: %d\n", i, res);
607 : 0 : continue;
608 : : }
609 : :
610 [ - + ]: 14 : if (debug)
611 : : {
612 : 0 : printf ("password:\n");
613 : 0 : escapeprint (pkcs5[i].password, strlen (pkcs5[i].password));
614 : 0 : hexprint (pkcs5[i].password, strlen (pkcs5[i].password));
615 : 0 : puts ("");
616 : 0 : binprint (pkcs5[i].password, strlen (pkcs5[i].password));
617 : 0 : puts ("");
618 : :
619 : 0 : printf ("salt:\n");
620 : 0 : escapeprint (pkcs5[i].salt, strlen (pkcs5[i].salt));
621 : 0 : hexprint (pkcs5[i].salt, strlen (pkcs5[i].salt));
622 : 0 : puts ("");
623 : 0 : binprint (pkcs5[i].salt, strlen (pkcs5[i].salt));
624 : 0 : puts ("");
625 : :
626 : 0 : printf ("computed key:\n");
627 : 0 : escapeprint (out, pkcs5[i].dklen);
628 : 0 : hexprint (out, pkcs5[i].dklen);
629 : 0 : puts ("");
630 : 0 : binprint (out, pkcs5[i].dklen);
631 : 0 : puts ("");
632 : :
633 : 0 : printf ("expected key:\n");
634 : 0 : escapeprint (pkcs5[i].expected, pkcs5[i].dklen);
635 : 0 : hexprint (pkcs5[i].expected, pkcs5[i].dklen);
636 : 0 : puts ("");
637 : 0 : binprint (pkcs5[i].expected, pkcs5[i].dklen);
638 : 0 : puts ("");
639 : : }
640 : :
641 [ - + ]: 14 : if (memcmp (pkcs5[i].expected, out, pkcs5[i].dklen) != 0)
642 : : {
643 : 0 : fail ("PKCS5 entry %d failed\n", i);
644 : :
645 [ # # ]: 0 : if (debug)
646 : 0 : printf ("ERROR\n");
647 : : }
648 [ - + ]: 14 : else if (debug)
649 : 0 : success ("OK\n");
650 : : }
651 : 1 : }
|