diff options
author | joshua <> | 2022-11-06 14:56:08 +0000 |
---|---|---|
committer | joshua <> | 2022-11-06 14:56:08 +0000 |
commit | 95ecb38f6f3ca7712fa7241ecef50bb22b4390c9 (patch) | |
tree | ee0622b543bfbd19421a5458c96dccd8d0718628 | |
parent | 91eec534a4bd072b85f03073db2c5897c2254389 (diff) | |
download | openbsd-95ecb38f6f3ca7712fa7241ecef50bb22b4390c9.tar.gz openbsd-95ecb38f6f3ca7712fa7241ecef50bb22b4390c9.tar.bz2 openbsd-95ecb38f6f3ca7712fa7241ecef50bb22b4390c9.zip |
Replace existing Blowfish regress tests
ok tb@ jsing@
-rw-r--r-- | src/regress/lib/libcrypto/bf/Makefile | 4 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/bf/bf_test.c | 1368 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/bf/bftest.c | 513 |
3 files changed, 1370 insertions, 515 deletions
diff --git a/src/regress/lib/libcrypto/bf/Makefile b/src/regress/lib/libcrypto/bf/Makefile index 989b3bb8f4..c29cdf6925 100644 --- a/src/regress/lib/libcrypto/bf/Makefile +++ b/src/regress/lib/libcrypto/bf/Makefile | |||
@@ -1,6 +1,6 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | 1 | # $OpenBSD: Makefile,v 1.4 2022/11/06 14:56:08 joshua Exp $ |
2 | 2 | ||
3 | PROG= bftest | 3 | PROG= bf_test |
4 | LDADD= -lcrypto | 4 | LDADD= -lcrypto |
5 | DPADD= ${LIBCRYPTO} | 5 | DPADD= ${LIBCRYPTO} |
6 | WARNINGS= Yes | 6 | WARNINGS= Yes |
diff --git a/src/regress/lib/libcrypto/bf/bf_test.c b/src/regress/lib/libcrypto/bf/bf_test.c new file mode 100644 index 0000000000..c31bd865ba --- /dev/null +++ b/src/regress/lib/libcrypto/bf/bf_test.c | |||
@@ -0,0 +1,1368 @@ | |||
1 | /* $OpenBSD: bf_test.c,v 1.1 2022/11/06 14:56:08 joshua Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2022 Joshua Sing <joshua@hypera.dev> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <openssl/evp.h> | ||
19 | #include <openssl/blowfish.h> | ||
20 | |||
21 | #include <stdint.h> | ||
22 | #include <string.h> | ||
23 | |||
24 | struct bf_test { | ||
25 | const int mode; | ||
26 | const uint8_t key[64]; | ||
27 | const int key_len; | ||
28 | const uint8_t iv[64]; | ||
29 | const int iv_len; | ||
30 | const uint8_t in[64]; | ||
31 | const int in_len; | ||
32 | const uint8_t out[64]; | ||
33 | const int out_len; | ||
34 | const int padding; | ||
35 | }; | ||
36 | |||
37 | static const struct bf_test bf_tests[] = { | ||
38 | /* | ||
39 | * ECB - Test vectors from | ||
40 | * https://www.schneier.com/wp-content/uploads/2015/12/vectors-2.txt | ||
41 | */ | ||
42 | { | ||
43 | .mode = NID_bf_ecb, | ||
44 | .key = { | ||
45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
46 | }, | ||
47 | .key_len = 8, | ||
48 | .in = { | ||
49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
50 | }, | ||
51 | .in_len = 8, | ||
52 | .out = { | ||
53 | 0x4E, 0xF9, 0x97, 0x45, 0x61, 0x98, 0xDD, 0x78, | ||
54 | }, | ||
55 | .out_len = 8, | ||
56 | }, | ||
57 | { | ||
58 | .mode = NID_bf_ecb, | ||
59 | .key = { | ||
60 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
61 | }, | ||
62 | .key_len = 8, | ||
63 | .in = { | ||
64 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
65 | }, | ||
66 | .in_len = 8, | ||
67 | .out = { | ||
68 | 0x51, 0x86, 0x6F, 0xD5, 0xB8, 0x5E, 0xCB, 0x8A, | ||
69 | }, | ||
70 | .out_len = 8, | ||
71 | }, | ||
72 | { | ||
73 | .mode = NID_bf_ecb, | ||
74 | .key = { | ||
75 | 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
76 | }, | ||
77 | .key_len = 8, | ||
78 | .in = { | ||
79 | 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, | ||
80 | }, | ||
81 | .in_len = 8, | ||
82 | .out = { | ||
83 | 0x7D, 0x85, 0x6F, 0x9A, 0x61, 0x30, 0x63, 0xF2, | ||
84 | }, | ||
85 | .out_len = 8, | ||
86 | }, | ||
87 | { | ||
88 | .mode = NID_bf_ecb, | ||
89 | .key = { | ||
90 | 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, | ||
91 | }, | ||
92 | .key_len = 8, | ||
93 | .in = { | ||
94 | 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, | ||
95 | }, | ||
96 | .in_len = 8, | ||
97 | .out = { | ||
98 | 0x24, 0x66, 0xDD, 0x87, 0x8B, 0x96, 0x3C, 0x9D, | ||
99 | }, | ||
100 | .out_len = 8, | ||
101 | }, | ||
102 | { | ||
103 | .mode = NID_bf_ecb, | ||
104 | .key = { | ||
105 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | ||
106 | }, | ||
107 | .key_len = 8, | ||
108 | .in = { | ||
109 | 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, | ||
110 | }, | ||
111 | .in_len = 8, | ||
112 | .out = { | ||
113 | 0x61, 0xF9, 0xC3, 0x80, 0x22, 0x81, 0xB0, 0x96, | ||
114 | }, | ||
115 | .out_len = 8, | ||
116 | }, | ||
117 | { | ||
118 | .mode = NID_bf_ecb, | ||
119 | .key = { | ||
120 | 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, | ||
121 | }, | ||
122 | .key_len = 8, | ||
123 | .in = { | ||
124 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | ||
125 | }, | ||
126 | .in_len = 8, | ||
127 | .out = { | ||
128 | 0x7D, 0x0C, 0xC6, 0x30, 0xAF, 0xDA, 0x1E, 0xC7, | ||
129 | }, | ||
130 | .out_len = 8, | ||
131 | }, | ||
132 | { | ||
133 | .mode = NID_bf_ecb, | ||
134 | .key = { | ||
135 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 | ||
136 | }, | ||
137 | .key_len = 8, | ||
138 | .in = { | ||
139 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | ||
140 | }, | ||
141 | .in_len = 8, | ||
142 | .out = { | ||
143 | 0x0A, 0xCE, 0xAB, 0x0F, 0xC6, 0xA0, 0xA2, 0x8D, | ||
144 | }, | ||
145 | .out_len = 8, | ||
146 | }, | ||
147 | { | ||
148 | .mode = NID_bf_ecb, | ||
149 | .key = { | ||
150 | 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57, | ||
151 | }, | ||
152 | .key_len = 8, | ||
153 | .in = { | ||
154 | 0x01, 0xA1, 0xD6, 0xD0, 0x39, 0x77, 0x67, 0x42, | ||
155 | }, | ||
156 | .in_len = 8, | ||
157 | .out = { | ||
158 | 0x59, 0xC6, 0x82, 0x45, 0xEB, 0x05, 0x28, 0x2B, | ||
159 | }, | ||
160 | .out_len = 8, | ||
161 | }, | ||
162 | { | ||
163 | .mode = NID_bf_ecb, | ||
164 | .key = { | ||
165 | 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E, | ||
166 | }, | ||
167 | .key_len = 8, | ||
168 | .in = { | ||
169 | 0x5C, 0xD5, 0x4C, 0xA8, 0x3D, 0xEF, 0x57, 0xDA, | ||
170 | }, | ||
171 | .in_len = 8, | ||
172 | .out = { | ||
173 | 0xB1, 0xB8, 0xCC, 0x0B, 0x25, 0x0F, 0x09, 0xA0, | ||
174 | }, | ||
175 | .out_len = 8, | ||
176 | }, | ||
177 | { | ||
178 | .mode = NID_bf_ecb, | ||
179 | .key = { | ||
180 | 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86, | ||
181 | }, | ||
182 | .key_len = 8, | ||
183 | .in = { | ||
184 | 0x02, 0x48, 0xD4, 0x38, 0x06, 0xF6, 0x71, 0x72, | ||
185 | }, | ||
186 | .in_len = 8, | ||
187 | .out = { | ||
188 | 0x17, 0x30, 0xE5, 0x77, 0x8B, 0xEA, 0x1D, 0xA4, | ||
189 | }, | ||
190 | .out_len = 8, | ||
191 | }, | ||
192 | { | ||
193 | .mode = NID_bf_ecb, | ||
194 | .key = { | ||
195 | 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E, | ||
196 | }, | ||
197 | .key_len = 8, | ||
198 | .in = { | ||
199 | 0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A, | ||
200 | }, | ||
201 | .in_len = 8, | ||
202 | .out = { | ||
203 | 0xA2, 0x5E, 0x78, 0x56, 0xCF, 0x26, 0x51, 0xEB, | ||
204 | }, | ||
205 | .out_len = 8, | ||
206 | }, | ||
207 | { | ||
208 | .mode = NID_bf_ecb, | ||
209 | .key = { | ||
210 | 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6, | ||
211 | }, | ||
212 | .key_len = 8, | ||
213 | .in = { | ||
214 | 0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2, | ||
215 | }, | ||
216 | .in_len = 8, | ||
217 | .out = { | ||
218 | 0x35, 0x38, 0x82, 0xB1, 0x09, 0xCE, 0x8F, 0x1A, | ||
219 | }, | ||
220 | .out_len = 8, | ||
221 | }, | ||
222 | { | ||
223 | .mode = NID_bf_ecb, | ||
224 | .key = { | ||
225 | 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE, | ||
226 | }, | ||
227 | .key_len = 8, | ||
228 | .in = { | ||
229 | 0x05, 0x9B, 0x5E, 0x08, 0x51, 0xCF, 0x14, 0x3A, | ||
230 | }, | ||
231 | .in_len = 8, | ||
232 | .out = { | ||
233 | 0x48, 0xF4, 0xD0, 0x88, 0x4C, 0x37, 0x99, 0x18, | ||
234 | }, | ||
235 | .out_len = 8, | ||
236 | }, | ||
237 | { | ||
238 | .mode = NID_bf_ecb, | ||
239 | .key = { | ||
240 | 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6, | ||
241 | }, | ||
242 | .key_len = 8, | ||
243 | .in = { | ||
244 | 0x07, 0x56, 0xD8, 0xE0, 0x77, 0x47, 0x61, 0xD2, | ||
245 | }, | ||
246 | .in_len = 8, | ||
247 | .out = { | ||
248 | 0x43, 0x21, 0x93, 0xB7, 0x89, 0x51, 0xFC, 0x98, | ||
249 | }, | ||
250 | .out_len = 8, | ||
251 | }, | ||
252 | { | ||
253 | .mode = NID_bf_ecb, | ||
254 | .key = { | ||
255 | 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE, | ||
256 | }, | ||
257 | .key_len = 8, | ||
258 | .in = { | ||
259 | 0x76, 0x25, 0x14, 0xB8, 0x29, 0xBF, 0x48, 0x6A, | ||
260 | }, | ||
261 | .in_len = 8, | ||
262 | .out = { | ||
263 | 0x13, 0xF0, 0x41, 0x54, 0xD6, 0x9D, 0x1A, 0xE5, | ||
264 | }, | ||
265 | .out_len = 8, | ||
266 | }, | ||
267 | { | ||
268 | .mode = NID_bf_ecb, | ||
269 | .key = { | ||
270 | 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16, | ||
271 | }, | ||
272 | .key_len = 8, | ||
273 | .in = { | ||
274 | 0x3B, 0xDD, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02, | ||
275 | }, | ||
276 | .in_len = 8, | ||
277 | .out = { | ||
278 | 0x2E, 0xED, 0xDA, 0x93, 0xFF, 0xD3, 0x9C, 0x79, | ||
279 | }, | ||
280 | .out_len = 8, | ||
281 | }, | ||
282 | { | ||
283 | .mode = NID_bf_ecb, | ||
284 | .key = { | ||
285 | 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F, | ||
286 | }, | ||
287 | .key_len = 8, | ||
288 | .in = { | ||
289 | 0x26, 0x95, 0x5F, 0x68, 0x35, 0xAF, 0x60, 0x9A, | ||
290 | }, | ||
291 | .in_len = 8, | ||
292 | .out = { | ||
293 | 0xD8, 0x87, 0xE0, 0x39, 0x3C, 0x2D, 0xA6, 0xE3, | ||
294 | }, | ||
295 | .out_len = 8, | ||
296 | }, | ||
297 | { | ||
298 | .mode = NID_bf_ecb, | ||
299 | .key = { | ||
300 | 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46, | ||
301 | }, | ||
302 | .key_len = 8, | ||
303 | .in = { | ||
304 | 0x16, 0x4D, 0x5E, 0x40, 0x4F, 0x27, 0x52, 0x32, | ||
305 | }, | ||
306 | .in_len = 8, | ||
307 | .out = { | ||
308 | 0x5F, 0x99, 0xD0, 0x4F, 0x5B, 0x16, 0x39, 0x69, | ||
309 | }, | ||
310 | .out_len = 8, | ||
311 | }, | ||
312 | { | ||
313 | .mode = NID_bf_ecb, | ||
314 | .key = { | ||
315 | 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E, | ||
316 | }, | ||
317 | .key_len = 8, | ||
318 | .in = { | ||
319 | 0x6B, 0x05, 0x6E, 0x18, 0x75, 0x9F, 0x5C, 0xCA, | ||
320 | }, | ||
321 | .in_len = 8, | ||
322 | .out = { | ||
323 | 0x4A, 0x05, 0x7A, 0x3B, 0x24, 0xD3, 0x97, 0x7B, | ||
324 | }, | ||
325 | .out_len = 8, | ||
326 | }, | ||
327 | { | ||
328 | .mode = NID_bf_ecb, | ||
329 | .key = { | ||
330 | 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76, | ||
331 | }, | ||
332 | .key_len = 8, | ||
333 | .in = { | ||
334 | 0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62, | ||
335 | }, | ||
336 | .in_len = 8, | ||
337 | .out = { | ||
338 | 0x45, 0x20, 0x31, 0xC1, 0xE4, 0xFA, 0xDA, 0x8E, | ||
339 | }, | ||
340 | .out_len = 8, | ||
341 | }, | ||
342 | { | ||
343 | .mode = NID_bf_ecb, | ||
344 | .key = { | ||
345 | 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07, | ||
346 | }, | ||
347 | .key_len = 8, | ||
348 | .in = { | ||
349 | 0x48, 0x0D, 0x39, 0x00, 0x6E, 0xE7, 0x62, 0xF2, | ||
350 | }, | ||
351 | .in_len = 8, | ||
352 | .out = { | ||
353 | 0x75, 0x55, 0xAE, 0x39, 0xF5, 0x9B, 0x87, 0xBD, | ||
354 | }, | ||
355 | .out_len = 8, | ||
356 | }, | ||
357 | { | ||
358 | .mode = NID_bf_ecb, | ||
359 | .key = { | ||
360 | 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F, | ||
361 | }, | ||
362 | .key_len = 8, | ||
363 | .in = { | ||
364 | 0x43, 0x75, 0x40, 0xC8, 0x69, 0x8F, 0x3C, 0xFA, | ||
365 | }, | ||
366 | .in_len = 8, | ||
367 | .out = { | ||
368 | 0x53, 0xC5, 0x5F, 0x9C, 0xB4, 0x9F, 0xC0, 0x19, | ||
369 | }, | ||
370 | .out_len = 8, | ||
371 | }, | ||
372 | { | ||
373 | .mode = NID_bf_ecb, | ||
374 | .key = { | ||
375 | 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7, | ||
376 | }, | ||
377 | .key_len = 8, | ||
378 | .in = { | ||
379 | 0x07, 0x2D, 0x43, 0xA0, 0x77, 0x07, 0x52, 0x92, | ||
380 | }, | ||
381 | .in_len = 8, | ||
382 | .out = { | ||
383 | 0x7A, 0x8E, 0x7B, 0xFA, 0x93, 0x7E, 0x89, 0xA3, | ||
384 | }, | ||
385 | .out_len = 8, | ||
386 | }, | ||
387 | { | ||
388 | .mode = NID_bf_ecb, | ||
389 | .key = { | ||
390 | 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF, | ||
391 | }, | ||
392 | .key_len = 8, | ||
393 | .in = { | ||
394 | 0x02, 0xFE, 0x55, 0x77, 0x81, 0x17, 0xF1, 0x2A, | ||
395 | }, | ||
396 | .in_len = 8, | ||
397 | .out = { | ||
398 | 0xCF, 0x9C, 0x5D, 0x7A, 0x49, 0x86, 0xAD, 0xB5, | ||
399 | }, | ||
400 | .out_len = 8, | ||
401 | }, | ||
402 | { | ||
403 | .mode = NID_bf_ecb, | ||
404 | .key = { | ||
405 | 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6, | ||
406 | }, | ||
407 | .key_len = 8, | ||
408 | .in = { | ||
409 | 0x1D, 0x9D, 0x5C, 0x50, 0x18, 0xF7, 0x28, 0xC2, | ||
410 | }, | ||
411 | .in_len = 8, | ||
412 | .out = { | ||
413 | 0xD1, 0xAB, 0xB2, 0x90, 0x65, 0x8B, 0xC7, 0x78, | ||
414 | }, | ||
415 | .out_len = 8, | ||
416 | }, | ||
417 | { | ||
418 | .mode = NID_bf_ecb, | ||
419 | .key = { | ||
420 | 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF, | ||
421 | }, | ||
422 | .key_len = 8, | ||
423 | .in = { | ||
424 | 0x30, 0x55, 0x32, 0x28, 0x6D, 0x6F, 0x29, 0x5A, | ||
425 | }, | ||
426 | .in_len = 8, | ||
427 | .out = { | ||
428 | 0x55, 0xCB, 0x37, 0x74, 0xD1, 0x3E, 0xF2, 0x01, | ||
429 | }, | ||
430 | .out_len = 8, | ||
431 | }, | ||
432 | { | ||
433 | .mode = NID_bf_ecb, | ||
434 | .key = { | ||
435 | 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, | ||
436 | }, | ||
437 | .key_len = 8, | ||
438 | .in = { | ||
439 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | ||
440 | }, | ||
441 | .in_len = 8, | ||
442 | .out = { | ||
443 | 0xFA, 0x34, 0xEC, 0x48, 0x47, 0xB2, 0x68, 0xB2, | ||
444 | }, | ||
445 | .out_len = 8, | ||
446 | }, | ||
447 | { | ||
448 | .mode = NID_bf_ecb, | ||
449 | .key = { | ||
450 | 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E, | ||
451 | }, | ||
452 | .key_len = 8, | ||
453 | .in = { | ||
454 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | ||
455 | }, | ||
456 | .in_len = 8, | ||
457 | .out = { | ||
458 | 0xA7, 0x90, 0x79, 0x51, 0x08, 0xEA, 0x3C, 0xAE, | ||
459 | }, | ||
460 | .out_len = 8, | ||
461 | }, | ||
462 | { | ||
463 | .mode = NID_bf_ecb, | ||
464 | .key = { | ||
465 | 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE, | ||
466 | }, | ||
467 | .key_len = 8, | ||
468 | .in = { | ||
469 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | ||
470 | }, | ||
471 | .in_len = 8, | ||
472 | .out = { | ||
473 | 0xC3, 0x9E, 0x07, 0x2D, 0x9F, 0xAC, 0x63, 0x1D, | ||
474 | }, | ||
475 | .out_len = 8, | ||
476 | }, | ||
477 | { | ||
478 | .mode = NID_bf_ecb, | ||
479 | .key = { | ||
480 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
481 | }, | ||
482 | .key_len = 8, | ||
483 | .in = { | ||
484 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
485 | }, | ||
486 | .in_len = 8, | ||
487 | .out = { | ||
488 | 0x01, 0x49, 0x33, 0xE0, 0xCD, 0xAF, 0xF6, 0xE4, | ||
489 | }, | ||
490 | .out_len = 8, | ||
491 | }, | ||
492 | { | ||
493 | .mode = NID_bf_ecb, | ||
494 | .key = { | ||
495 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
496 | }, | ||
497 | .key_len = 8, | ||
498 | .in = { | ||
499 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
500 | }, | ||
501 | .in_len = 8, | ||
502 | .out = { | ||
503 | 0xF2, 0x1E, 0x9A, 0x77, 0xB7, 0x1C, 0x49, 0xBC, | ||
504 | }, | ||
505 | .out_len = 8, | ||
506 | }, | ||
507 | { | ||
508 | .mode = NID_bf_ecb, | ||
509 | .key = { | ||
510 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | ||
511 | }, | ||
512 | .key_len = 8, | ||
513 | .in = { | ||
514 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
515 | }, | ||
516 | .in_len = 8, | ||
517 | .out = { | ||
518 | 0x24, 0x59, 0x46, 0x88, 0x57, 0x54, 0x36, 0x9A, | ||
519 | }, | ||
520 | .out_len = 8, | ||
521 | }, | ||
522 | { | ||
523 | .mode = NID_bf_ecb, | ||
524 | .key = { | ||
525 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, | ||
526 | }, | ||
527 | .key_len = 8, | ||
528 | .in = { | ||
529 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, | ||
530 | }, | ||
531 | .in_len = 8, | ||
532 | .out = { | ||
533 | 0x6B, 0x5C, 0x5A, 0x9C, 0x5D, 0x9E, 0x0A, 0x5A, | ||
534 | }, | ||
535 | .out_len = 8, | ||
536 | }, | ||
537 | |||
538 | /* | ||
539 | * CBC - Test vector from | ||
540 | * https://www.schneier.com/wp-content/uploads/2015/12/vectors-2.txt | ||
541 | */ | ||
542 | { | ||
543 | .mode = NID_bf_cbc, | ||
544 | .key = { | ||
545 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | ||
546 | 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87, | ||
547 | }, | ||
548 | .key_len = 16, | ||
549 | .iv = { | ||
550 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, | ||
551 | }, | ||
552 | .iv_len = 8, | ||
553 | .in = { | ||
554 | 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, | ||
555 | 0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, | ||
556 | 0x68, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x20, | ||
557 | 0x66, 0x6F, 0x72, 0x20, 0x00, 0x00, 0x00, 0x00, | ||
558 | }, | ||
559 | .in_len = 32, | ||
560 | .out = { | ||
561 | 0x6B, 0x77, 0xB4, 0xD6, 0x30, 0x06, 0xDE, 0xE6, | ||
562 | 0x05, 0xB1, 0x56, 0xE2, 0x74, 0x03, 0x97, 0x93, | ||
563 | 0x58, 0xDE, 0xB9, 0xE7, 0x15, 0x46, 0x16, 0xD9, | ||
564 | 0x59, 0xF1, 0x65, 0x2B, 0xD5, 0xFF, 0x92, 0xCC, | ||
565 | }, | ||
566 | .out_len = 32, | ||
567 | .padding = 0, | ||
568 | }, | ||
569 | |||
570 | /* CBC (generated using https://github.com/joshuasing/libressl-test-gen) */ | ||
571 | { | ||
572 | .mode = NID_bf_cbc, | ||
573 | .key = { | ||
574 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
575 | }, | ||
576 | .key_len = 8, | ||
577 | .iv = { | ||
578 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
579 | }, | ||
580 | .iv_len = 8, | ||
581 | .in = { | ||
582 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
583 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
584 | }, | ||
585 | .in_len = 16, | ||
586 | .out = { | ||
587 | 0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78, | ||
588 | 0xe1, 0xc0, 0x30, 0xe7, 0x4c, 0x14, 0xd2, 0x61, | ||
589 | }, | ||
590 | .out_len = 16, | ||
591 | }, | ||
592 | { | ||
593 | .mode = NID_bf_cbc, | ||
594 | .key = { | ||
595 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
596 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
597 | }, | ||
598 | .key_len = 16, | ||
599 | .iv = { | ||
600 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
601 | }, | ||
602 | .iv_len = 8, | ||
603 | .in = { | ||
604 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
605 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
606 | }, | ||
607 | .in_len = 16, | ||
608 | .out = { | ||
609 | 0xb9, 0x95, 0xf2, 0x4d, 0xdf, 0xe8, 0x7b, 0xf0, | ||
610 | 0x05, 0x3c, 0x33, 0x39, 0x43, 0x35, 0x83, 0x62, | ||
611 | }, | ||
612 | .out_len = 16, | ||
613 | }, | ||
614 | { | ||
615 | .mode = NID_bf_cbc, | ||
616 | .key = { | ||
617 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
618 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
619 | }, | ||
620 | .key_len = 16, | ||
621 | .iv = { | ||
622 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
623 | }, | ||
624 | .iv_len = 8, | ||
625 | .in = { | ||
626 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
627 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
628 | }, | ||
629 | .in_len = 16, | ||
630 | .out = { | ||
631 | 0x86, 0x6f, 0x5e, 0x72, 0xe5, 0x9a, 0x19, 0x51, | ||
632 | 0x56, 0xf3, 0x2f, 0x5e, 0x95, 0xfb, 0xd6, 0x52, | ||
633 | }, | ||
634 | .out_len = 16, | ||
635 | }, | ||
636 | { | ||
637 | .mode = NID_bf_cbc, | ||
638 | .key = { | ||
639 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
640 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
641 | }, | ||
642 | .key_len = 16, | ||
643 | .iv = { | ||
644 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
645 | }, | ||
646 | .iv_len = 8, | ||
647 | .in = { | ||
648 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
649 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
650 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
651 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | ||
652 | }, | ||
653 | .in_len = 32, | ||
654 | .out = { | ||
655 | 0xb9, 0x95, 0xf2, 0x4d, 0xdf, 0xe8, 0x7b, 0xf0, | ||
656 | 0x00, 0xf6, 0x2e, 0xf6, 0x6a, 0x03, 0x2d, 0x40, | ||
657 | 0x9c, 0xc9, 0x06, 0x31, 0x67, 0x7f, 0x6e, 0x24, | ||
658 | 0xeb, 0x2d, 0x3b, 0x02, 0xa3, 0x53, 0x52, 0xe9, | ||
659 | }, | ||
660 | .out_len = 32, | ||
661 | }, | ||
662 | { | ||
663 | .mode = NID_bf_cbc, | ||
664 | .key = { | ||
665 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
666 | }, | ||
667 | .key_len = 8, | ||
668 | .iv = { | ||
669 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
670 | }, | ||
671 | .iv_len = 8, | ||
672 | .in = { | ||
673 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
674 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
675 | }, | ||
676 | .in_len = 16, | ||
677 | .out = { | ||
678 | 0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78, | ||
679 | 0xe1, 0xc0, 0x30, 0xe7, 0x4c, 0x14, 0xd2, 0x61, | ||
680 | 0x8b, 0xa5, 0x5d, 0x18, 0x27, 0x44, 0x9c, 0xd3, | ||
681 | }, | ||
682 | .out_len = 24, | ||
683 | .padding = 1, | ||
684 | }, | ||
685 | { | ||
686 | .mode = NID_bf_cbc, | ||
687 | .key = { | ||
688 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
689 | }, | ||
690 | .key_len = 8, | ||
691 | .iv = { | ||
692 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
693 | }, | ||
694 | .iv_len = 8, | ||
695 | .in = { | ||
696 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
697 | 0x00, 0x00, 0x00, 0x00, | ||
698 | }, | ||
699 | .in_len = 12, | ||
700 | .out = { | ||
701 | 0xc0, 0x1f, 0xae, 0x76, 0x86, 0x86, 0xe7, 0xb7, | ||
702 | 0x3b, 0x0d, 0xd9, 0x72, 0x33, 0x2b, 0x38, 0x5d, | ||
703 | }, | ||
704 | .out_len = 16, | ||
705 | .padding = 1, | ||
706 | }, | ||
707 | |||
708 | /* CFB64 (generated using https://github.com/joshuasing/libressl-test-gen) */ | ||
709 | { | ||
710 | .mode = NID_bf_cfb64, | ||
711 | .key = { | ||
712 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
713 | }, | ||
714 | .key_len = 8, | ||
715 | .iv = { | ||
716 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
717 | }, | ||
718 | .iv_len = 8, | ||
719 | .in = { | ||
720 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
721 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
722 | }, | ||
723 | .in_len = 16, | ||
724 | .out = { | ||
725 | 0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78, | ||
726 | 0xe1, 0xc0, 0x30, 0xe7, 0x4c, 0x14, 0xd2, 0x61, | ||
727 | }, | ||
728 | .out_len = 16, | ||
729 | }, | ||
730 | { | ||
731 | .mode = NID_bf_cfb64, | ||
732 | .key = { | ||
733 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
734 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
735 | }, | ||
736 | .key_len = 16, | ||
737 | .iv = { | ||
738 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
739 | }, | ||
740 | .iv_len = 8, | ||
741 | .in = { | ||
742 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
743 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
744 | }, | ||
745 | .in_len = 16, | ||
746 | .out = { | ||
747 | 0xb9, 0x95, 0xf2, 0x4d, 0xdf, 0xe8, 0x7b, 0xf0, | ||
748 | 0x05, 0x3c, 0x33, 0x39, 0x43, 0x35, 0x83, 0x62, | ||
749 | }, | ||
750 | .out_len = 16, | ||
751 | }, | ||
752 | { | ||
753 | .mode = NID_bf_cfb64, | ||
754 | .key = { | ||
755 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
756 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
757 | }, | ||
758 | .key_len = 16, | ||
759 | .iv = { | ||
760 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
761 | }, | ||
762 | .iv_len = 8, | ||
763 | .in = { | ||
764 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
765 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
766 | }, | ||
767 | .in_len = 16, | ||
768 | .out = { | ||
769 | 0xb9, 0x94, 0xf0, 0x4e, 0xdb, 0xed, 0x7d, 0xf7, | ||
770 | 0x0a, 0xf8, 0x96, 0xbf, 0x4d, 0x3c, 0x95, 0xdf, | ||
771 | }, | ||
772 | .out_len = 16, | ||
773 | }, | ||
774 | { | ||
775 | .mode = NID_bf_cfb64, | ||
776 | .key = { | ||
777 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
778 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
779 | }, | ||
780 | .key_len = 16, | ||
781 | .iv = { | ||
782 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
783 | }, | ||
784 | .iv_len = 8, | ||
785 | .in = { | ||
786 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
787 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
788 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
789 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | ||
790 | }, | ||
791 | .in_len = 32, | ||
792 | .out = { | ||
793 | 0x86, 0x6e, 0x5c, 0x71, 0xe1, 0x9f, 0x1f, 0x56, | ||
794 | 0x1f, 0x02, 0xaa, 0x8c, 0x09, 0xe0, 0x61, 0x43, | ||
795 | 0x91, 0x8d, 0xd2, 0x43, 0x70, 0x5d, 0xa3, 0xf1, | ||
796 | 0xc7, 0x96, 0x56, 0x77, 0xfc, 0x33, 0x74, 0x9e, | ||
797 | }, | ||
798 | .out_len = 32, | ||
799 | }, | ||
800 | { | ||
801 | .mode = NID_bf_cfb64, | ||
802 | .key = { | ||
803 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
804 | }, | ||
805 | .key_len = 8, | ||
806 | .iv = { | ||
807 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
808 | }, | ||
809 | .iv_len = 8, | ||
810 | .in = { | ||
811 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
812 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
813 | }, | ||
814 | .in_len = 16, | ||
815 | .out = { | ||
816 | 0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78, | ||
817 | 0xe1, 0xc0, 0x30, 0xe7, 0x4c, 0x14, 0xd2, 0x61, | ||
818 | }, | ||
819 | .out_len = 16, | ||
820 | }, | ||
821 | { | ||
822 | .mode = NID_bf_cfb64, | ||
823 | .key = { | ||
824 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
825 | }, | ||
826 | .key_len = 8, | ||
827 | .iv = { | ||
828 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
829 | }, | ||
830 | .iv_len = 8, | ||
831 | .in = { | ||
832 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
833 | 0x00, 0x00, 0x00, 0x00, | ||
834 | }, | ||
835 | .in_len = 12, | ||
836 | .out = { | ||
837 | 0xc0, 0x1f, 0xae, 0x76, 0x86, 0x86, 0xe7, 0xb7, | ||
838 | 0x05, 0xbb, 0xd4, 0x5e, | ||
839 | }, | ||
840 | .out_len = 12, | ||
841 | }, | ||
842 | |||
843 | /* OFB64 (generated using https://github.com/joshuasing/libressl-test-gen) */ | ||
844 | { | ||
845 | .mode = NID_bf_ofb64, | ||
846 | .key = { | ||
847 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
848 | }, | ||
849 | .key_len = 8, | ||
850 | .iv = { | ||
851 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
852 | }, | ||
853 | .iv_len = 8, | ||
854 | .in = { | ||
855 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
856 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
857 | }, | ||
858 | .in_len = 16, | ||
859 | .out = { | ||
860 | 0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78, | ||
861 | 0xe1, 0xc0, 0x30, 0xe7, 0x4c, 0x14, 0xd2, 0x61, | ||
862 | }, | ||
863 | .out_len = 16, | ||
864 | }, | ||
865 | { | ||
866 | .mode = NID_bf_ofb64, | ||
867 | .key = { | ||
868 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
869 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
870 | }, | ||
871 | .key_len = 16, | ||
872 | .iv = { | ||
873 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
874 | }, | ||
875 | .iv_len = 8, | ||
876 | .in = { | ||
877 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
878 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
879 | }, | ||
880 | .in_len = 16, | ||
881 | .out = { | ||
882 | 0xb9, 0x95, 0xf2, 0x4d, 0xdf, 0xe8, 0x7b, 0xf0, | ||
883 | 0x05, 0x3c, 0x33, 0x39, 0x43, 0x35, 0x83, 0x62, | ||
884 | }, | ||
885 | .out_len = 16, | ||
886 | }, | ||
887 | { | ||
888 | .mode = NID_bf_ofb64, | ||
889 | .key = { | ||
890 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
891 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
892 | }, | ||
893 | .key_len = 16, | ||
894 | .iv = { | ||
895 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
896 | }, | ||
897 | .iv_len = 8, | ||
898 | .in = { | ||
899 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
900 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
901 | }, | ||
902 | .in_len = 16, | ||
903 | .out = { | ||
904 | 0xb9, 0x94, 0xf0, 0x4e, 0xdb, 0xed, 0x7d, 0xf7, | ||
905 | 0x0d, 0x35, 0x39, 0x32, 0x4f, 0x38, 0x8d, 0x6d, | ||
906 | }, | ||
907 | .out_len = 16, | ||
908 | }, | ||
909 | { | ||
910 | .mode = NID_bf_ofb64, | ||
911 | .key = { | ||
912 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
913 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
914 | }, | ||
915 | .key_len = 16, | ||
916 | .iv = { | ||
917 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
918 | }, | ||
919 | .iv_len = 8, | ||
920 | .in = { | ||
921 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
922 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
923 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
924 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | ||
925 | }, | ||
926 | .in_len = 32, | ||
927 | .out = { | ||
928 | 0x86, 0x6e, 0x5c, 0x71, 0xe1, 0x9f, 0x1f, 0x56, | ||
929 | 0xbb, 0xcb, 0xd9, 0x35, 0x81, 0x57, 0xea, 0xb9, | ||
930 | 0xd7, 0x85, 0x28, 0x4a, 0xdc, 0xeb, 0x94, 0x99, | ||
931 | 0xf0, 0x87, 0x7c, 0x5a, 0x56, 0x60, 0xc7, 0x60, | ||
932 | }, | ||
933 | .out_len = 32, | ||
934 | }, | ||
935 | { | ||
936 | .mode = NID_bf_ofb64, | ||
937 | .key = { | ||
938 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
939 | }, | ||
940 | .key_len = 8, | ||
941 | .iv = { | ||
942 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
943 | }, | ||
944 | .iv_len = 8, | ||
945 | .in = { | ||
946 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
947 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
948 | }, | ||
949 | .in_len = 16, | ||
950 | .out = { | ||
951 | 0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78, | ||
952 | 0xe1, 0xc0, 0x30, 0xe7, 0x4c, 0x14, 0xd2, 0x61, | ||
953 | }, | ||
954 | .out_len = 16, | ||
955 | }, | ||
956 | { | ||
957 | .mode = NID_bf_ofb64, | ||
958 | .key = { | ||
959 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
960 | }, | ||
961 | .key_len = 8, | ||
962 | .iv = { | ||
963 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
964 | }, | ||
965 | .iv_len = 8, | ||
966 | .in = { | ||
967 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
968 | 0x00, 0x00, 0x00, 0x00, | ||
969 | }, | ||
970 | .in_len = 12, | ||
971 | .out = { | ||
972 | 0xc0, 0x1f, 0xae, 0x76, 0x86, 0x86, 0xe7, 0xb7, | ||
973 | 0x05, 0xbb, 0xd4, 0x5e, | ||
974 | }, | ||
975 | .out_len = 12, | ||
976 | }, | ||
977 | }; | ||
978 | |||
979 | #define N_BF_TESTS (sizeof(bf_tests) / sizeof(bf_tests[0])) | ||
980 | |||
981 | static int | ||
982 | bf_ecb_test(size_t test_number, const struct bf_test *bt) | ||
983 | { | ||
984 | if (bt->padding) { | ||
985 | /* XXX - Handle padding */ | ||
986 | return 1; | ||
987 | } | ||
988 | |||
989 | BF_KEY key; | ||
990 | uint8_t out[8]; | ||
991 | |||
992 | /* Encryption */ | ||
993 | memset(out, 0, sizeof(out)); | ||
994 | BF_set_key(&key, bt->key_len, bt->key); | ||
995 | BF_ecb_encrypt(bt->in, out, &key, 1); | ||
996 | |||
997 | if (memcmp(bt->out, out, bt->out_len) != 0) { | ||
998 | fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n", | ||
999 | SN_bf_ecb, test_number); | ||
1000 | return 0; | ||
1001 | } | ||
1002 | |||
1003 | /* Decryption */ | ||
1004 | memset(out, 0, sizeof(out)); | ||
1005 | BF_set_key(&key, bt->key_len, bt->key); | ||
1006 | BF_ecb_encrypt(bt->out, out, &key, 0); | ||
1007 | |||
1008 | if (memcmp(bt->in, out, bt->in_len) != 0) { | ||
1009 | fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n", | ||
1010 | SN_bf_ecb, test_number); | ||
1011 | return 0; | ||
1012 | } | ||
1013 | |||
1014 | return 1; | ||
1015 | } | ||
1016 | |||
1017 | static int | ||
1018 | bf_cbc_test(size_t test_number, const struct bf_test *bt) | ||
1019 | { | ||
1020 | if (bt->padding) { | ||
1021 | /* XXX - Handle padding */ | ||
1022 | return 1; | ||
1023 | } | ||
1024 | |||
1025 | BF_KEY key; | ||
1026 | uint8_t out[512]; | ||
1027 | uint8_t iv[64]; | ||
1028 | |||
1029 | /* Encryption */ | ||
1030 | memset(out, 0, sizeof(out)); | ||
1031 | memcpy(iv, bt->iv, bt->iv_len); | ||
1032 | BF_set_key(&key, bt->key_len, bt->key); | ||
1033 | BF_cbc_encrypt(bt->in, out, bt->in_len, &key, iv, 1); | ||
1034 | |||
1035 | if (memcmp(bt->out, out, bt->out_len) != 0) { | ||
1036 | fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n", | ||
1037 | SN_bf_cbc, test_number); | ||
1038 | return 0; | ||
1039 | } | ||
1040 | |||
1041 | /* Decryption */ | ||
1042 | memset(out, 0, sizeof(out)); | ||
1043 | memcpy(iv, bt->iv, bt->iv_len); | ||
1044 | BF_set_key(&key, bt->key_len, bt->key); | ||
1045 | BF_cbc_encrypt(bt->out, out, bt->out_len, &key, iv, 0); | ||
1046 | |||
1047 | if (memcmp(bt->in, out, bt->in_len) != 0) { | ||
1048 | fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n", | ||
1049 | SN_bf_cbc, test_number); | ||
1050 | return 0; | ||
1051 | } | ||
1052 | |||
1053 | return 1; | ||
1054 | } | ||
1055 | |||
1056 | static int | ||
1057 | bf_cfb64_test(size_t test_number, const struct bf_test *bt) | ||
1058 | { | ||
1059 | if (bt->padding) { | ||
1060 | /* XXX - Handle padding */ | ||
1061 | return 1; | ||
1062 | } | ||
1063 | |||
1064 | BF_KEY key; | ||
1065 | uint8_t out[512]; | ||
1066 | uint8_t iv[64]; | ||
1067 | int remainder = 0; | ||
1068 | |||
1069 | /* Encryption */ | ||
1070 | memset(out, 0, sizeof(out)); | ||
1071 | memcpy(iv, bt->iv, bt->iv_len); | ||
1072 | BF_set_key(&key, bt->key_len, bt->key); | ||
1073 | BF_cfb64_encrypt(bt->in, out, bt->in_len * 8, &key, iv, &remainder, 1); | ||
1074 | |||
1075 | if (memcmp(bt->out, out, bt->out_len) != 0) { | ||
1076 | fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n", | ||
1077 | SN_bf_cfb64, test_number); | ||
1078 | return 0; | ||
1079 | } | ||
1080 | |||
1081 | /* Decryption */ | ||
1082 | remainder = 0; | ||
1083 | memset(out, 0, sizeof(out)); | ||
1084 | memcpy(iv, bt->iv, bt->iv_len); | ||
1085 | BF_set_key(&key, bt->key_len, bt->key); | ||
1086 | BF_cfb64_encrypt(bt->out, out, bt->out_len, &key, iv, &remainder, 0); | ||
1087 | |||
1088 | if (memcmp(bt->in, out, bt->in_len) != 0) { | ||
1089 | fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n", | ||
1090 | SN_bf_cfb64, test_number); | ||
1091 | return 0; | ||
1092 | } | ||
1093 | |||
1094 | return 1; | ||
1095 | } | ||
1096 | |||
1097 | static int | ||
1098 | bf_ofb64_test(size_t test_number, const struct bf_test *bt) | ||
1099 | { | ||
1100 | if (bt->padding) { | ||
1101 | /* XXX - Handle padding */ | ||
1102 | return 1; | ||
1103 | } | ||
1104 | |||
1105 | BF_KEY key; | ||
1106 | uint8_t out[512]; | ||
1107 | uint8_t iv[64]; | ||
1108 | int remainder = 0; | ||
1109 | |||
1110 | /* Encryption */ | ||
1111 | memset(out, 0, sizeof(out)); | ||
1112 | memcpy(iv, bt->iv, bt->iv_len); | ||
1113 | BF_set_key(&key, bt->key_len, bt->key); | ||
1114 | BF_ofb64_encrypt(bt->in, out, bt->in_len, &key, iv, &remainder); | ||
1115 | |||
1116 | if (memcmp(bt->out, out, bt->out_len) != 0) { | ||
1117 | fprintf(stderr, "FAIL (%s:%zu): encryption mismatch\n", | ||
1118 | SN_bf_ofb64, test_number); | ||
1119 | return 0; | ||
1120 | } | ||
1121 | |||
1122 | /* Decryption */ | ||
1123 | remainder = 0; | ||
1124 | memset(out, 0, sizeof(out)); | ||
1125 | memcpy(iv, bt->iv, bt->iv_len); | ||
1126 | BF_set_key(&key, bt->key_len, bt->key); | ||
1127 | BF_ofb64_encrypt(bt->out, out, bt->out_len, &key, iv, &remainder); | ||
1128 | |||
1129 | if (memcmp(bt->in, out, bt->in_len) != 0) { | ||
1130 | fprintf(stderr, "FAIL (%s:%zu): decryption mismatch\n", | ||
1131 | SN_bf_ofb64, test_number); | ||
1132 | return 0; | ||
1133 | } | ||
1134 | |||
1135 | return 1; | ||
1136 | } | ||
1137 | |||
1138 | static int | ||
1139 | bf_evp_test(size_t test_number, const struct bf_test *bt, const char *label, | ||
1140 | const EVP_CIPHER *cipher) | ||
1141 | { | ||
1142 | EVP_CIPHER_CTX *ctx; | ||
1143 | uint8_t out[512]; | ||
1144 | int in_len, out_len, total_len; | ||
1145 | int i; | ||
1146 | int success = 0; | ||
1147 | |||
1148 | if ((ctx = EVP_CIPHER_CTX_new()) == NULL) { | ||
1149 | fprintf(stderr, "FAIL (%s:%zu): EVP_CIPHER_CTX_new failed\n", | ||
1150 | label, test_number); | ||
1151 | goto failed; | ||
1152 | } | ||
1153 | |||
1154 | /* EVP encryption */ | ||
1155 | total_len = 0; | ||
1156 | memset(out, 0, sizeof(out)); | ||
1157 | if (!EVP_EncryptInit(ctx, cipher, NULL, NULL)) { | ||
1158 | fprintf(stderr, "FAIL (%s:%zu): EVP_EncryptInit failed\n", | ||
1159 | label, test_number); | ||
1160 | goto failed; | ||
1161 | } | ||
1162 | |||
1163 | if (!EVP_CIPHER_CTX_set_key_length(ctx, bt->key_len)) { | ||
1164 | fprintf(stderr, | ||
1165 | "FAIL (%s:%zu): EVP_CIPHER_CTX_set_key_length failed\n", | ||
1166 | label, test_number); | ||
1167 | goto failed; | ||
1168 | } | ||
1169 | |||
1170 | if (!EVP_CIPHER_CTX_set_padding(ctx, bt->padding)) { | ||
1171 | fprintf(stderr, | ||
1172 | "FAIL (%s:%zu): EVP_CIPHER_CTX_set_padding failed\n", | ||
1173 | label, test_number); | ||
1174 | goto failed; | ||
1175 | } | ||
1176 | |||
1177 | if (!EVP_EncryptInit(ctx, NULL, bt->key, bt->iv)) { | ||
1178 | fprintf(stderr, "FAIL (%s:%zu): EVP_EncryptInit failed\n", | ||
1179 | label, test_number); | ||
1180 | goto failed; | ||
1181 | } | ||
1182 | |||
1183 | for (i = 0; i < bt->in_len;) { | ||
1184 | in_len = arc4random_uniform(bt->in_len / 2); | ||
1185 | if (in_len > bt->in_len - i) | ||
1186 | in_len = bt->in_len - i; | ||
1187 | |||
1188 | if (!EVP_EncryptUpdate(ctx, out + total_len, &out_len, | ||
1189 | bt->in + i, in_len)) { | ||
1190 | fprintf(stderr, | ||
1191 | "FAIL (%s:%zu): EVP_EncryptUpdate failed\n", | ||
1192 | label, test_number); | ||
1193 | goto failed; | ||
1194 | } | ||
1195 | |||
1196 | i += in_len; | ||
1197 | total_len += out_len; | ||
1198 | } | ||
1199 | |||
1200 | if (!EVP_EncryptFinal_ex(ctx, out + total_len, &out_len)) { | ||
1201 | fprintf(stderr, "FAIL (%s:%zu): EVP_EncryptFinal_ex failed\n", | ||
1202 | label, test_number); | ||
1203 | goto failed; | ||
1204 | } | ||
1205 | total_len += out_len; | ||
1206 | |||
1207 | if (!EVP_CIPHER_CTX_reset(ctx)) { | ||
1208 | fprintf(stderr, | ||
1209 | "FAIL (%s:%zu): EVP_CIPHER_CTX_reset failed\n", | ||
1210 | label, test_number); | ||
1211 | goto failed; | ||
1212 | } | ||
1213 | |||
1214 | if (total_len != bt->out_len) { | ||
1215 | fprintf(stderr, | ||
1216 | "FAIL (%s:%zu): EVP encryption length mismatch " | ||
1217 | "(%d != %d)\n", label, test_number, total_len, bt->out_len); | ||
1218 | goto failed; | ||
1219 | } | ||
1220 | |||
1221 | if (memcmp(bt->out, out, bt->out_len) != 0) { | ||
1222 | fprintf(stderr, "FAIL (%s:%zu): EVP encryption mismatch\n", | ||
1223 | label, test_number); | ||
1224 | goto failed; | ||
1225 | } | ||
1226 | |||
1227 | /* EVP decryption */ | ||
1228 | total_len = 0; | ||
1229 | memset(out, 0, sizeof(out)); | ||
1230 | if (!EVP_DecryptInit(ctx, cipher, NULL, NULL)) { | ||
1231 | fprintf(stderr, "FAIL (%s:%zu): EVP_DecryptInit failed\n", | ||
1232 | label, test_number); | ||
1233 | goto failed; | ||
1234 | } | ||
1235 | |||
1236 | if (!EVP_CIPHER_CTX_set_key_length(ctx, bt->key_len)) { | ||
1237 | fprintf(stderr, | ||
1238 | "FAIL (%s:%zu): EVP_CIPHER_CTX_set_key_length failed\n", | ||
1239 | label, test_number); | ||
1240 | goto failed; | ||
1241 | } | ||
1242 | |||
1243 | if (!EVP_CIPHER_CTX_set_padding(ctx, bt->padding)) { | ||
1244 | fprintf(stderr, | ||
1245 | "FAIL (%s:%zu): EVP_CIPHER_CTX_set_padding failed\n", | ||
1246 | label, test_number); | ||
1247 | goto failed; | ||
1248 | } | ||
1249 | |||
1250 | if (!EVP_DecryptInit(ctx, NULL, bt->key, bt->iv)) { | ||
1251 | fprintf(stderr, "FAIL (%s:%zu): EVP_DecryptInit failed\n", | ||
1252 | label, test_number); | ||
1253 | goto failed; | ||
1254 | } | ||
1255 | |||
1256 | for (i = 0; i < bt->out_len;) { | ||
1257 | in_len = arc4random_uniform(bt->out_len / 2); | ||
1258 | if (in_len > bt->out_len - i) | ||
1259 | in_len = bt->out_len - i; | ||
1260 | |||
1261 | if (!EVP_DecryptUpdate(ctx, out + total_len, &out_len, | ||
1262 | bt->out + i, in_len)) { | ||
1263 | fprintf(stderr, | ||
1264 | "FAIL (%s:%zu): EVP_DecryptUpdate failed\n", | ||
1265 | label, test_number); | ||
1266 | goto failed; | ||
1267 | } | ||
1268 | |||
1269 | i += in_len; | ||
1270 | total_len += out_len; | ||
1271 | } | ||
1272 | |||
1273 | if (!EVP_DecryptFinal_ex(ctx, out + total_len, &out_len)) { | ||
1274 | fprintf(stderr, "FAIL (%s:%zu): EVP_DecryptFinal_ex failed\n", | ||
1275 | label, test_number); | ||
1276 | goto failed; | ||
1277 | } | ||
1278 | total_len += out_len; | ||
1279 | |||
1280 | if (!EVP_CIPHER_CTX_reset(ctx)) { | ||
1281 | fprintf(stderr, | ||
1282 | "FAIL (%s:%zu): EVP_CIPHER_CTX_reset failed\n", | ||
1283 | label, test_number); | ||
1284 | goto failed; | ||
1285 | } | ||
1286 | |||
1287 | if (total_len != bt->in_len) { | ||
1288 | fprintf(stderr, | ||
1289 | "FAIL (%s:%zu): EVP decryption length mismatch\n", | ||
1290 | label, test_number); | ||
1291 | goto failed; | ||
1292 | } | ||
1293 | |||
1294 | if (memcmp(bt->in, out, bt->in_len) != 0) { | ||
1295 | fprintf(stderr, "FAIL (%s:%zu): EVP decryption mismatch\n", | ||
1296 | label, test_number); | ||
1297 | goto failed; | ||
1298 | } | ||
1299 | |||
1300 | success = 1; | ||
1301 | |||
1302 | failed: | ||
1303 | EVP_CIPHER_CTX_free(ctx); | ||
1304 | return success; | ||
1305 | } | ||
1306 | |||
1307 | static int | ||
1308 | bf_test(void) | ||
1309 | { | ||
1310 | const struct bf_test *bt; | ||
1311 | const char *label; | ||
1312 | const EVP_CIPHER *cipher; | ||
1313 | size_t i; | ||
1314 | int failed = 1; | ||
1315 | |||
1316 | for (i = 0; i < N_BF_TESTS; i++) { | ||
1317 | bt = &bf_tests[i]; | ||
1318 | switch (bt->mode) { | ||
1319 | case NID_bf_ecb: | ||
1320 | label = SN_bf_ecb; | ||
1321 | cipher = EVP_bf_ecb(); | ||
1322 | if (!bf_ecb_test(i, bt)) | ||
1323 | goto failed; | ||
1324 | break; | ||
1325 | case NID_bf_cbc: | ||
1326 | label = SN_bf_cbc; | ||
1327 | cipher = EVP_bf_cbc(); | ||
1328 | if (!bf_cbc_test(i, bt)) | ||
1329 | goto failed; | ||
1330 | break; | ||
1331 | case NID_bf_cfb64: | ||
1332 | label = SN_bf_cfb64; | ||
1333 | cipher = EVP_bf_cfb64(); | ||
1334 | if (!bf_cfb64_test(i, bt)) | ||
1335 | goto failed; | ||
1336 | break; | ||
1337 | case NID_bf_ofb64: | ||
1338 | label = SN_bf_ofb64; | ||
1339 | cipher = EVP_bf_ofb(); | ||
1340 | if (!bf_ofb64_test(i, bt)) | ||
1341 | goto failed; | ||
1342 | break; | ||
1343 | default: | ||
1344 | fprintf(stderr, "FAIL: unknown mode (%d)\n", | ||
1345 | bt->mode); | ||
1346 | goto failed; | ||
1347 | } | ||
1348 | |||
1349 | if (!bf_evp_test(i, bt, label, cipher)) | ||
1350 | goto failed; | ||
1351 | } | ||
1352 | |||
1353 | failed = 0; | ||
1354 | |||
1355 | failed: | ||
1356 | return failed; | ||
1357 | } | ||
1358 | |||
1359 | int | ||
1360 | main(int argc, char **argv) | ||
1361 | { | ||
1362 | int failed = 0; | ||
1363 | |||
1364 | failed |= bf_test(); | ||
1365 | |||
1366 | return failed; | ||
1367 | } | ||
1368 | |||
diff --git a/src/regress/lib/libcrypto/bf/bftest.c b/src/regress/lib/libcrypto/bf/bftest.c deleted file mode 100644 index 5239ffb250..0000000000 --- a/src/regress/lib/libcrypto/bf/bftest.c +++ /dev/null | |||
@@ -1,513 +0,0 @@ | |||
1 | /* $OpenBSD: bftest.c,v 1.3 2018/07/17 17:06:49 tb Exp $ */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* This has been a quickly hacked 'ideatest.c'. When I add tests for other | ||
60 | * RC2 modes, more of the code will be uncommented. */ | ||
61 | |||
62 | #include <stdio.h> | ||
63 | #include <string.h> | ||
64 | #include <stdlib.h> | ||
65 | |||
66 | #include <openssl/blowfish.h> | ||
67 | |||
68 | static char *bf_key[2]={ | ||
69 | "abcdefghijklmnopqrstuvwxyz", | ||
70 | "Who is John Galt?" | ||
71 | }; | ||
72 | |||
73 | /* big endian */ | ||
74 | static BF_LONG bf_plain[2][2]={ | ||
75 | {0x424c4f57L,0x46495348L}, | ||
76 | {0xfedcba98L,0x76543210L} | ||
77 | }; | ||
78 | |||
79 | static BF_LONG bf_cipher[2][2]={ | ||
80 | {0x324ed0feL,0xf413a203L}, | ||
81 | {0xcc91732bL,0x8022f684L} | ||
82 | }; | ||
83 | /************/ | ||
84 | |||
85 | /* Lets use the DES test vectors :-) */ | ||
86 | #define NUM_TESTS 34 | ||
87 | static unsigned char ecb_data[NUM_TESTS][8]={ | ||
88 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
89 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
90 | {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
91 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
92 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
93 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
94 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
95 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, | ||
96 | {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, | ||
97 | {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, | ||
98 | {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, | ||
99 | {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, | ||
100 | {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, | ||
101 | {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, | ||
102 | {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, | ||
103 | {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, | ||
104 | {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, | ||
105 | {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, | ||
106 | {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, | ||
107 | {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, | ||
108 | {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, | ||
109 | {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, | ||
110 | {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, | ||
111 | {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, | ||
112 | {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, | ||
113 | {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, | ||
114 | {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, | ||
115 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, | ||
116 | {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, | ||
117 | {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, | ||
118 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
119 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
120 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
121 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; | ||
122 | |||
123 | static unsigned char plain_data[NUM_TESTS][8]={ | ||
124 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
125 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
126 | {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, | ||
127 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
128 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
129 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
130 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
131 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
132 | {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, | ||
133 | {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, | ||
134 | {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, | ||
135 | {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, | ||
136 | {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, | ||
137 | {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, | ||
138 | {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, | ||
139 | {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, | ||
140 | {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, | ||
141 | {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, | ||
142 | {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, | ||
143 | {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, | ||
144 | {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, | ||
145 | {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, | ||
146 | {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, | ||
147 | {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, | ||
148 | {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, | ||
149 | {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, | ||
150 | {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, | ||
151 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
152 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
153 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
154 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
155 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
156 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
157 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; | ||
158 | |||
159 | static unsigned char cipher_data[NUM_TESTS][8]={ | ||
160 | {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, | ||
161 | {0x51,0x86,0x6F,0xD5,0xB8,0x5E,0xCB,0x8A}, | ||
162 | {0x7D,0x85,0x6F,0x9A,0x61,0x30,0x63,0xF2}, | ||
163 | {0x24,0x66,0xDD,0x87,0x8B,0x96,0x3C,0x9D}, | ||
164 | {0x61,0xF9,0xC3,0x80,0x22,0x81,0xB0,0x96}, | ||
165 | {0x7D,0x0C,0xC6,0x30,0xAF,0xDA,0x1E,0xC7}, | ||
166 | {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, | ||
167 | {0x0A,0xCE,0xAB,0x0F,0xC6,0xA0,0xA2,0x8D}, | ||
168 | {0x59,0xC6,0x82,0x45,0xEB,0x05,0x28,0x2B}, | ||
169 | {0xB1,0xB8,0xCC,0x0B,0x25,0x0F,0x09,0xA0}, | ||
170 | {0x17,0x30,0xE5,0x77,0x8B,0xEA,0x1D,0xA4}, | ||
171 | {0xA2,0x5E,0x78,0x56,0xCF,0x26,0x51,0xEB}, | ||
172 | {0x35,0x38,0x82,0xB1,0x09,0xCE,0x8F,0x1A}, | ||
173 | {0x48,0xF4,0xD0,0x88,0x4C,0x37,0x99,0x18}, | ||
174 | {0x43,0x21,0x93,0xB7,0x89,0x51,0xFC,0x98}, | ||
175 | {0x13,0xF0,0x41,0x54,0xD6,0x9D,0x1A,0xE5}, | ||
176 | {0x2E,0xED,0xDA,0x93,0xFF,0xD3,0x9C,0x79}, | ||
177 | {0xD8,0x87,0xE0,0x39,0x3C,0x2D,0xA6,0xE3}, | ||
178 | {0x5F,0x99,0xD0,0x4F,0x5B,0x16,0x39,0x69}, | ||
179 | {0x4A,0x05,0x7A,0x3B,0x24,0xD3,0x97,0x7B}, | ||
180 | {0x45,0x20,0x31,0xC1,0xE4,0xFA,0xDA,0x8E}, | ||
181 | {0x75,0x55,0xAE,0x39,0xF5,0x9B,0x87,0xBD}, | ||
182 | {0x53,0xC5,0x5F,0x9C,0xB4,0x9F,0xC0,0x19}, | ||
183 | {0x7A,0x8E,0x7B,0xFA,0x93,0x7E,0x89,0xA3}, | ||
184 | {0xCF,0x9C,0x5D,0x7A,0x49,0x86,0xAD,0xB5}, | ||
185 | {0xD1,0xAB,0xB2,0x90,0x65,0x8B,0xC7,0x78}, | ||
186 | {0x55,0xCB,0x37,0x74,0xD1,0x3E,0xF2,0x01}, | ||
187 | {0xFA,0x34,0xEC,0x48,0x47,0xB2,0x68,0xB2}, | ||
188 | {0xA7,0x90,0x79,0x51,0x08,0xEA,0x3C,0xAE}, | ||
189 | {0xC3,0x9E,0x07,0x2D,0x9F,0xAC,0x63,0x1D}, | ||
190 | {0x01,0x49,0x33,0xE0,0xCD,0xAF,0xF6,0xE4}, | ||
191 | {0xF2,0x1E,0x9A,0x77,0xB7,0x1C,0x49,0xBC}, | ||
192 | {0x24,0x59,0x46,0x88,0x57,0x54,0x36,0x9A}, | ||
193 | {0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A}, | ||
194 | }; | ||
195 | |||
196 | static unsigned char cbc_key [16]={ | ||
197 | 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, | ||
198 | 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | ||
199 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | ||
200 | static char cbc_data[40]="7654321 Now is the time for "; | ||
201 | static unsigned char cbc_ok[32]={ | ||
202 | 0x6B,0x77,0xB4,0xD6,0x30,0x06,0xDE,0xE6, | ||
203 | 0x05,0xB1,0x56,0xE2,0x74,0x03,0x97,0x93, | ||
204 | 0x58,0xDE,0xB9,0xE7,0x15,0x46,0x16,0xD9, | ||
205 | 0x59,0xF1,0x65,0x2B,0xD5,0xFF,0x92,0xCC}; | ||
206 | |||
207 | static unsigned char cfb64_ok[]={ | ||
208 | 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, | ||
209 | 0xF2,0x6E,0xCF,0x6D,0x2E,0xB9,0xE7,0x6E, | ||
210 | 0x3D,0xA3,0xDE,0x04,0xD1,0x51,0x72,0x00, | ||
211 | 0x51,0x9D,0x57,0xA6,0xC3}; | ||
212 | |||
213 | static unsigned char ofb64_ok[]={ | ||
214 | 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, | ||
215 | 0x62,0xB3,0x43,0xCC,0x5B,0x65,0x58,0x73, | ||
216 | 0x10,0xDD,0x90,0x8D,0x0C,0x24,0x1B,0x22, | ||
217 | 0x63,0xC2,0xCF,0x80,0xDA}; | ||
218 | |||
219 | #define KEY_TEST_NUM 25 | ||
220 | static unsigned char key_test[KEY_TEST_NUM]={ | ||
221 | 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87, | ||
222 | 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f, | ||
223 | 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, | ||
224 | 0x88}; | ||
225 | |||
226 | static unsigned char key_data[8]= | ||
227 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}; | ||
228 | |||
229 | static unsigned char key_out[KEY_TEST_NUM][8]={ | ||
230 | {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E}, | ||
231 | {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6}, | ||
232 | {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3}, | ||
233 | {0xBE,0x1E,0x63,0x94,0x08,0x64,0x0F,0x05}, | ||
234 | {0xB3,0x9E,0x44,0x48,0x1B,0xDB,0x1E,0x6E}, | ||
235 | {0x94,0x57,0xAA,0x83,0xB1,0x92,0x8C,0x0D}, | ||
236 | {0x8B,0xB7,0x70,0x32,0xF9,0x60,0x62,0x9D}, | ||
237 | {0xE8,0x7A,0x24,0x4E,0x2C,0xC8,0x5E,0x82}, | ||
238 | {0x15,0x75,0x0E,0x7A,0x4F,0x4E,0xC5,0x77}, | ||
239 | {0x12,0x2B,0xA7,0x0B,0x3A,0xB6,0x4A,0xE0}, | ||
240 | {0x3A,0x83,0x3C,0x9A,0xFF,0xC5,0x37,0xF6}, | ||
241 | {0x94,0x09,0xDA,0x87,0xA9,0x0F,0x6B,0xF2}, | ||
242 | {0x88,0x4F,0x80,0x62,0x50,0x60,0xB8,0xB4}, | ||
243 | {0x1F,0x85,0x03,0x1C,0x19,0xE1,0x19,0x68}, | ||
244 | {0x79,0xD9,0x37,0x3A,0x71,0x4C,0xA3,0x4F}, | ||
245 | {0x93,0x14,0x28,0x87,0xEE,0x3B,0xE1,0x5C}, | ||
246 | {0x03,0x42,0x9E,0x83,0x8C,0xE2,0xD1,0x4B}, | ||
247 | {0xA4,0x29,0x9E,0x27,0x46,0x9F,0xF6,0x7B}, | ||
248 | {0xAF,0xD5,0xAE,0xD1,0xC1,0xBC,0x96,0xA8}, | ||
249 | {0x10,0x85,0x1C,0x0E,0x38,0x58,0xDA,0x9F}, | ||
250 | {0xE6,0xF5,0x1E,0xD7,0x9B,0x9D,0xB2,0x1F}, | ||
251 | {0x64,0xA6,0xE1,0x4A,0xFD,0x36,0xB4,0x6F}, | ||
252 | {0x80,0xC7,0xD7,0xD4,0x5A,0x54,0x79,0xAD}, | ||
253 | {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80}, | ||
254 | }; | ||
255 | |||
256 | static int test(void ); | ||
257 | static int print_test_data(void ); | ||
258 | int main(int argc, char *argv[]) | ||
259 | { | ||
260 | int ret; | ||
261 | |||
262 | if (argc > 1) | ||
263 | ret=print_test_data(); | ||
264 | else | ||
265 | ret=test(); | ||
266 | |||
267 | return ret; | ||
268 | } | ||
269 | |||
270 | static int print_test_data(void) | ||
271 | { | ||
272 | unsigned int i,j; | ||
273 | |||
274 | printf("ecb test data\n"); | ||
275 | printf("key bytes\t\tclear bytes\t\tcipher bytes\n"); | ||
276 | for (i=0; i<NUM_TESTS; i++) | ||
277 | { | ||
278 | for (j=0; j<8; j++) | ||
279 | printf("%02X",ecb_data[i][j]); | ||
280 | printf("\t"); | ||
281 | for (j=0; j<8; j++) | ||
282 | printf("%02X",plain_data[i][j]); | ||
283 | printf("\t"); | ||
284 | for (j=0; j<8; j++) | ||
285 | printf("%02X",cipher_data[i][j]); | ||
286 | printf("\n"); | ||
287 | } | ||
288 | |||
289 | printf("set_key test data\n"); | ||
290 | printf("data[8]= "); | ||
291 | for (j=0; j<8; j++) | ||
292 | printf("%02X",key_data[j]); | ||
293 | printf("\n"); | ||
294 | for (i=0; i<KEY_TEST_NUM-1; i++) | ||
295 | { | ||
296 | printf("c="); | ||
297 | for (j=0; j<8; j++) | ||
298 | printf("%02X",key_out[i][j]); | ||
299 | printf(" k[%2u]=",i+1); | ||
300 | for (j=0; j<i+1; j++) | ||
301 | printf("%02X",key_test[j]); | ||
302 | printf("\n"); | ||
303 | } | ||
304 | |||
305 | printf("\nchaining mode test data\n"); | ||
306 | printf("key[16] = "); | ||
307 | for (j=0; j<16; j++) | ||
308 | printf("%02X",cbc_key[j]); | ||
309 | printf("\niv[8] = "); | ||
310 | for (j=0; j<8; j++) | ||
311 | printf("%02X",cbc_iv[j]); | ||
312 | printf("\ndata[%d] = '%s'",(int)strlen(cbc_data)+1,cbc_data); | ||
313 | printf("\ndata[%d] = ",(int)strlen(cbc_data)+1); | ||
314 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
315 | printf("%02X",cbc_data[j]); | ||
316 | printf("\n"); | ||
317 | printf("cbc cipher text\n"); | ||
318 | printf("cipher[%d]= ",32); | ||
319 | for (j=0; j<32; j++) | ||
320 | printf("%02X",cbc_ok[j]); | ||
321 | printf("\n"); | ||
322 | |||
323 | printf("cfb64 cipher text\n"); | ||
324 | printf("cipher[%d]= ",(int)strlen(cbc_data)+1); | ||
325 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
326 | printf("%02X",cfb64_ok[j]); | ||
327 | printf("\n"); | ||
328 | |||
329 | printf("ofb64 cipher text\n"); | ||
330 | printf("cipher[%d]= ",(int)strlen(cbc_data)+1); | ||
331 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
332 | printf("%02X",ofb64_ok[j]); | ||
333 | printf("\n"); | ||
334 | return(0); | ||
335 | } | ||
336 | |||
337 | static int test(void) | ||
338 | { | ||
339 | unsigned char cbc_in[40],cbc_out[40],iv[8]; | ||
340 | int i,n,err=0; | ||
341 | BF_KEY key; | ||
342 | BF_LONG data[2]; | ||
343 | unsigned char out[8]; | ||
344 | BF_LONG len; | ||
345 | |||
346 | printf("testing blowfish in raw ecb mode\n"); | ||
347 | for (n=0; n<2; n++) | ||
348 | { | ||
349 | BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]); | ||
350 | |||
351 | data[0]=bf_plain[n][0]; | ||
352 | data[1]=bf_plain[n][1]; | ||
353 | BF_encrypt(data,&key); | ||
354 | if (memcmp(&(bf_cipher[n][0]),&(data[0]), sizeof data) != 0) | ||
355 | { | ||
356 | printf("BF_encrypt error encrypting\n"); | ||
357 | printf("got :"); | ||
358 | for (i=0; i<2; i++) | ||
359 | printf("%08lX ",(unsigned long)data[i]); | ||
360 | printf("\n"); | ||
361 | printf("expected:"); | ||
362 | for (i=0; i<2; i++) | ||
363 | printf("%08lX ",(unsigned long)bf_cipher[n][i]); | ||
364 | err=1; | ||
365 | printf("\n"); | ||
366 | } | ||
367 | |||
368 | BF_decrypt(&(data[0]),&key); | ||
369 | if (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0) | ||
370 | { | ||
371 | printf("BF_encrypt error decrypting\n"); | ||
372 | printf("got :"); | ||
373 | for (i=0; i<2; i++) | ||
374 | printf("%08lX ",(unsigned long)data[i]); | ||
375 | printf("\n"); | ||
376 | printf("expected:"); | ||
377 | for (i=0; i<2; i++) | ||
378 | printf("%08lX ",(unsigned long)bf_plain[n][i]); | ||
379 | printf("\n"); | ||
380 | err=1; | ||
381 | } | ||
382 | } | ||
383 | |||
384 | printf("testing blowfish in ecb mode\n"); | ||
385 | |||
386 | for (n=0; n<NUM_TESTS; n++) | ||
387 | { | ||
388 | BF_set_key(&key,8,ecb_data[n]); | ||
389 | |||
390 | BF_ecb_encrypt(&(plain_data[n][0]),out,&key,BF_ENCRYPT); | ||
391 | if (memcmp(&(cipher_data[n][0]),out,8) != 0) | ||
392 | { | ||
393 | printf("BF_ecb_encrypt blowfish error encrypting\n"); | ||
394 | printf("got :"); | ||
395 | for (i=0; i<8; i++) | ||
396 | printf("%02X ",out[i]); | ||
397 | printf("\n"); | ||
398 | printf("expected:"); | ||
399 | for (i=0; i<8; i++) | ||
400 | printf("%02X ",cipher_data[n][i]); | ||
401 | err=1; | ||
402 | printf("\n"); | ||
403 | } | ||
404 | |||
405 | BF_ecb_encrypt(out,out,&key,BF_DECRYPT); | ||
406 | if (memcmp(&(plain_data[n][0]),out,8) != 0) | ||
407 | { | ||
408 | printf("BF_ecb_encrypt error decrypting\n"); | ||
409 | printf("got :"); | ||
410 | for (i=0; i<8; i++) | ||
411 | printf("%02X ",out[i]); | ||
412 | printf("\n"); | ||
413 | printf("expected:"); | ||
414 | for (i=0; i<8; i++) | ||
415 | printf("%02X ",plain_data[n][i]); | ||
416 | printf("\n"); | ||
417 | err=1; | ||
418 | } | ||
419 | } | ||
420 | |||
421 | printf("testing blowfish set_key\n"); | ||
422 | for (n=1; n<KEY_TEST_NUM; n++) | ||
423 | { | ||
424 | BF_set_key(&key,n,key_test); | ||
425 | BF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT); | ||
426 | if (memcmp(out,&(key_out[n-1][0]),8) != 0) | ||
427 | { | ||
428 | printf("blowfish setkey error\n"); | ||
429 | err=1; | ||
430 | } | ||
431 | } | ||
432 | |||
433 | printf("testing blowfish in cbc mode\n"); | ||
434 | len=strlen(cbc_data)+1; | ||
435 | |||
436 | BF_set_key(&key,16,cbc_key); | ||
437 | memset(cbc_in,0,sizeof cbc_in); | ||
438 | memset(cbc_out,0,sizeof cbc_out); | ||
439 | memcpy(iv,cbc_iv,sizeof iv); | ||
440 | BF_cbc_encrypt((unsigned char *)cbc_data,cbc_out,len, | ||
441 | &key,iv,BF_ENCRYPT); | ||
442 | if (memcmp(cbc_out,cbc_ok,32) != 0) | ||
443 | { | ||
444 | err=1; | ||
445 | printf("BF_cbc_encrypt encrypt error\n"); | ||
446 | for (i=0; i<32; i++) printf("0x%02X,",cbc_out[i]); | ||
447 | } | ||
448 | memcpy(iv,cbc_iv,8); | ||
449 | BF_cbc_encrypt(cbc_out,cbc_in,len, | ||
450 | &key,iv,BF_DECRYPT); | ||
451 | if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) | ||
452 | { | ||
453 | printf("BF_cbc_encrypt decrypt error\n"); | ||
454 | err=1; | ||
455 | } | ||
456 | |||
457 | printf("testing blowfish in cfb64 mode\n"); | ||
458 | |||
459 | BF_set_key(&key,16,cbc_key); | ||
460 | memset(cbc_in,0,40); | ||
461 | memset(cbc_out,0,40); | ||
462 | memcpy(iv,cbc_iv,8); | ||
463 | n=0; | ||
464 | BF_cfb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13, | ||
465 | &key,iv,&n,BF_ENCRYPT); | ||
466 | BF_cfb64_encrypt((unsigned char *)&(cbc_data[13]),&(cbc_out[13]),len-13, | ||
467 | &key,iv,&n,BF_ENCRYPT); | ||
468 | if (memcmp(cbc_out,cfb64_ok,(int)len) != 0) | ||
469 | { | ||
470 | err=1; | ||
471 | printf("BF_cfb64_encrypt encrypt error\n"); | ||
472 | for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]); | ||
473 | } | ||
474 | n=0; | ||
475 | memcpy(iv,cbc_iv,8); | ||
476 | BF_cfb64_encrypt(cbc_out,cbc_in,17, | ||
477 | &key,iv,&n,BF_DECRYPT); | ||
478 | BF_cfb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17, | ||
479 | &key,iv,&n,BF_DECRYPT); | ||
480 | if (memcmp(cbc_in,cbc_data,(int)len) != 0) | ||
481 | { | ||
482 | printf("BF_cfb64_encrypt decrypt error\n"); | ||
483 | err=1; | ||
484 | } | ||
485 | |||
486 | printf("testing blowfish in ofb64\n"); | ||
487 | |||
488 | BF_set_key(&key,16,cbc_key); | ||
489 | memset(cbc_in,0,40); | ||
490 | memset(cbc_out,0,40); | ||
491 | memcpy(iv,cbc_iv,8); | ||
492 | n=0; | ||
493 | BF_ofb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,&key,iv,&n); | ||
494 | BF_ofb64_encrypt((unsigned char *)&(cbc_data[13]), | ||
495 | &(cbc_out[13]),len-13,&key,iv,&n); | ||
496 | if (memcmp(cbc_out,ofb64_ok,(int)len) != 0) | ||
497 | { | ||
498 | err=1; | ||
499 | printf("BF_ofb64_encrypt encrypt error\n"); | ||
500 | for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]); | ||
501 | } | ||
502 | n=0; | ||
503 | memcpy(iv,cbc_iv,8); | ||
504 | BF_ofb64_encrypt(cbc_out,cbc_in,17,&key,iv,&n); | ||
505 | BF_ofb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,&key,iv,&n); | ||
506 | if (memcmp(cbc_in,cbc_data,(int)len) != 0) | ||
507 | { | ||
508 | printf("BF_ofb64_encrypt decrypt error\n"); | ||
509 | err=1; | ||
510 | } | ||
511 | |||
512 | return(err); | ||
513 | } | ||