iPXE
des_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /** @file
27  *
28  * DES tests
29  *
30  * These test vectors are originally provided by NBS (the precursor of
31  * NIST) in SP 500-20, downloadable as a scan of the typewritten
32  * original from:
33  *
34  * https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nbsspecialpublication500-20e1980.pdf
35  */
36 
37 /* Forcibly enable assertions */
38 #undef NDEBUG
39 
40 #include <assert.h>
41 #include <ipxe/des.h>
42 #include <ipxe/test.h>
43 #include "cipher_test.h"
44 
45 /** Define a DES 64-bit test value */
46 #define DES_VALUE(value) { \
47  ( ( ( ( uint64_t ) (value) ) >> 56 ) & 0xff ), \
48  ( ( ( ( uint64_t ) (value) ) >> 48 ) & 0xff ), \
49  ( ( ( ( uint64_t ) (value) ) >> 40 ) & 0xff ), \
50  ( ( ( ( uint64_t ) (value) ) >> 32 ) & 0xff ), \
51  ( ( ( ( uint64_t ) (value) ) >> 24 ) & 0xff ), \
52  ( ( ( ( uint64_t ) (value) ) >> 16 ) & 0xff ), \
53  ( ( ( ( uint64_t ) (value) ) >> 8 ) & 0xff ), \
54  ( ( ( ( uint64_t ) (value) ) >> 0 ) & 0xff ) \
55  }
56 
57 /** Define a DES test */
58 #define DES_TEST( name, key, plaintext, ciphertext ) \
59  CIPHER_TEST ( name, &des_ecb_algorithm, DES_VALUE ( key ), \
60  IV(), ADDITIONAL(), DES_VALUE ( plaintext ), \
61  DES_VALUE ( ciphertext ), AUTH() )
62 
63 /* Sample round outputs (page 9) */
64 DES_TEST ( des_round_sample,
65  0x10316e028c8f3b4a, 0x0000000000000000, 0x82dcbafbdeab6602 );
66 
67 /* Test 1: Initial permutation and expansion tests
68  *
69  * "Set Key=0 and encrypt the 64-bit data vectors e[i]: i=1,...,64"
70  *
71  * Appendix B, page 28 ("IP and E test")
72  */
73 DES_TEST ( des_test1_1,
74  0x0101010101010101, 0x8000000000000000, 0x95f8a5e5dd31d900 );
75 DES_TEST ( des_test1_2,
76  0x0101010101010101, 0x4000000000000000, 0xdd7f121ca5015619 );
77 DES_TEST ( des_test1_3,
78  0x0101010101010101, 0x2000000000000000, 0x2e8653104f3834ea );
79 DES_TEST ( des_test1_4,
80  0x0101010101010101, 0x1000000000000000, 0x4bd388ff6cd81d4f );
81 DES_TEST ( des_test1_5,
82  0x0101010101010101, 0x0800000000000000, 0x20b9e767b2fb1456 );
83 DES_TEST ( des_test1_6,
84  0x0101010101010101, 0x0400000000000000, 0x55579380d77138ef );
85 DES_TEST ( des_test1_7,
86  0x0101010101010101, 0x0200000000000000, 0x6cc5defaaf04512f );
87 DES_TEST ( des_test1_8,
88  0x0101010101010101, 0x0100000000000000, 0x0d9f279ba5d87260 );
89 DES_TEST ( des_test1_9,
90  0x0101010101010101, 0x0080000000000000, 0xd9031b0271bd5a0a );
91 DES_TEST ( des_test1_10,
92  0x0101010101010101, 0x0040000000000000, 0x424250b37c3dd951 );
93 DES_TEST ( des_test1_11,
94  0x0101010101010101, 0x0020000000000000, 0xb8061b7ecd9a21e5 );
95 DES_TEST ( des_test1_12,
96  0x0101010101010101, 0x0010000000000000, 0xf15d0f286b65bd28 );
97 DES_TEST ( des_test1_13,
98  0x0101010101010101, 0x0008000000000000, 0xadd0cc8d6e5deba1 );
99 DES_TEST ( des_test1_14,
100  0x0101010101010101, 0x0004000000000000, 0xe6d5f82752ad63d1 );
101 DES_TEST ( des_test1_15,
102  0x0101010101010101, 0x0002000000000000, 0xecbfe3bd3f591a5e );
103 DES_TEST ( des_test1_16,
104  0x0101010101010101, 0x0001000000000000, 0xf356834379d165cd );
105 DES_TEST ( des_test1_17,
106  0x0101010101010101, 0x0000800000000000, 0x2b9f982f20037fa9 );
107 DES_TEST ( des_test1_18,
108  0x0101010101010101, 0x0000400000000000, 0x889de068a16f0be6 );
109 DES_TEST ( des_test1_19,
110  0x0101010101010101, 0x0000200000000000, 0xe19e275d846a1298 );
111 DES_TEST ( des_test1_20,
112  0x0101010101010101, 0x0000100000000000, 0x329a8ed523d71aec );
113 DES_TEST ( des_test1_21,
114  0x0101010101010101, 0x0000080000000000, 0xe7fce22557d23c97 );
115 DES_TEST ( des_test1_22,
116  0x0101010101010101, 0x0000040000000000, 0x12a9f5817ff2d65d );
117 DES_TEST ( des_test1_23,
118  0x0101010101010101, 0x0000020000000000, 0xa484c3ad38dc9c19 );
119 DES_TEST ( des_test1_24,
120  0x0101010101010101, 0x0000010000000000, 0xfbe00a8a1ef8ad72 );
121 DES_TEST ( des_test1_25,
122  0x0101010101010101, 0x0000008000000000, 0x750d079407521363 );
123 DES_TEST ( des_test1_26,
124  0x0101010101010101, 0x0000004000000000, 0x64feed9c724c2faf );
125 DES_TEST ( des_test1_27,
126  0x0101010101010101, 0x0000002000000000, 0xf02b263b328e2b60 );
127 DES_TEST ( des_test1_28,
128  0x0101010101010101, 0x0000001000000000, 0x9d64555a9a10b852 );
129 DES_TEST ( des_test1_29,
130  0x0101010101010101, 0x0000000800000000, 0xd106ff0bed5255d7 );
131 DES_TEST ( des_test1_30,
132  0x0101010101010101, 0x0000000400000000, 0xe1652c6b138c64a5 );
133 DES_TEST ( des_test1_31,
134  0x0101010101010101, 0x0000000200000000, 0xe428581186ec8f46 );
135 DES_TEST ( des_test1_32,
136  0x0101010101010101, 0x0000000100000000, 0xaeb5f5ede22d1a36 );
137 DES_TEST ( des_test1_33,
138  0x0101010101010101, 0x0000000080000000, 0xe943d7568aec0c5c );
139 DES_TEST ( des_test1_34,
140  0x0101010101010101, 0x0000000040000000, 0xdf98c8276f54b04b );
141 DES_TEST ( des_test1_35,
142  0x0101010101010101, 0x0000000020000000, 0xb160e4680f6c696f );
143 DES_TEST ( des_test1_36,
144  0x0101010101010101, 0x0000000010000000, 0xfa0752b07d9c4ab8 );
145 DES_TEST ( des_test1_37,
146  0x0101010101010101, 0x0000000008000000, 0xca3a2b036dbc8502 );
147 DES_TEST ( des_test1_38,
148  0x0101010101010101, 0x0000000004000000, 0x5e0905517bb59bcf );
149 DES_TEST ( des_test1_39,
150  0x0101010101010101, 0x0000000002000000, 0x814eeb3b91d90726 );
151 DES_TEST ( des_test1_40,
152  0x0101010101010101, 0x0000000001000000, 0x4d49db1532919c9f );
153 DES_TEST ( des_test1_41,
154  0x0101010101010101, 0x0000000000800000, 0x25eb5fc3f8cf0621 );
155 DES_TEST ( des_test1_42,
156  0x0101010101010101, 0x0000000000400000, 0xab6a20c0620d1c6f );
157 DES_TEST ( des_test1_43,
158  0x0101010101010101, 0x0000000000200000, 0x79e90dbc98f92cca );
159 DES_TEST ( des_test1_44,
160  0x0101010101010101, 0x0000000000100000, 0x866ecedd8072bb0e );
161 DES_TEST ( des_test1_45,
162  0x0101010101010101, 0x0000000000080000, 0x8b54536f2f3e64a8 );
163 DES_TEST ( des_test1_46,
164  0x0101010101010101, 0x0000000000040000, 0xea51d3975595b86b );
165 DES_TEST ( des_test1_47,
166  0x0101010101010101, 0x0000000000020000, 0xcaffc6ac4542de31 );
167 DES_TEST ( des_test1_48,
168  0x0101010101010101, 0x0000000000010000, 0x8dd45a2ddf90796c );
169 DES_TEST ( des_test1_49,
170  0x0101010101010101, 0x0000000000008000, 0x1029d55e880ec2d0 );
171 DES_TEST ( des_test1_50,
172  0x0101010101010101, 0x0000000000004000, 0x5d86cb23639dbea9 );
173 DES_TEST ( des_test1_51,
174  0x0101010101010101, 0x0000000000002000, 0x1d1ca853ae7c0c5f );
175 DES_TEST ( des_test1_52,
176  0x0101010101010101, 0x0000000000001000, 0xce332329248f3228 );
177 DES_TEST ( des_test1_53,
178  0x0101010101010101, 0x0000000000000800, 0x8405d1abe24fb942 );
179 DES_TEST ( des_test1_54,
180  0x0101010101010101, 0x0000000000000400, 0xe643d78090ca4207 );
181 DES_TEST ( des_test1_55,
182  0x0101010101010101, 0x0000000000000200, 0x48221b9937748a23 );
183 DES_TEST ( des_test1_56,
184  0x0101010101010101, 0x0000000000000100, 0xdd7c0bbd61fafd54 );
185 DES_TEST ( des_test1_57,
186  0x0101010101010101, 0x0000000000000080, 0x2fbc291a570db5c4 );
187 DES_TEST ( des_test1_58,
188  0x0101010101010101, 0x0000000000000040, 0xe07c30d7e4e26e12 );
189 DES_TEST ( des_test1_59,
190  0x0101010101010101, 0x0000000000000020, 0x0953e2258e8e90a1 );
191 DES_TEST ( des_test1_60,
192  0x0101010101010101, 0x0000000000000010, 0x5b711bc4ceebf2ee );
193 DES_TEST ( des_test1_61,
194  0x0101010101010101, 0x0000000000000008, 0xcc083f1e6d9e85f6 );
195 DES_TEST ( des_test1_62,
196  0x0101010101010101, 0x0000000000000004, 0xd2fd8867d50d2dfe );
197 DES_TEST ( des_test1_63,
198  0x0101010101010101, 0x0000000000000002, 0x06e7ea22ce92708f );
199 DES_TEST ( des_test1_64,
200  0x0101010101010101, 0x0000000000000001, 0x166b40b44aba4bd6 );
201 
202 /* Test 2: Inverse permutation and expansion tests
203  *
204  * "Set Key=0 and encrypt the results c[i] obtained in Test 1"
205  *
206  * Appendix B, page 28 ("IP and E test")
207  */
208 DES_TEST ( des_test2_1,
209  0x0101010101010101, 0x95f8a5e5dd31d900, 0x8000000000000000 );
210 DES_TEST ( des_test2_2,
211  0x0101010101010101, 0xdd7f121ca5015619, 0x4000000000000000 );
212 DES_TEST ( des_test2_3,
213  0x0101010101010101, 0x2e8653104f3834ea, 0x2000000000000000 );
214 DES_TEST ( des_test2_4,
215  0x0101010101010101, 0x4bd388ff6cd81d4f, 0x1000000000000000 );
216 DES_TEST ( des_test2_5,
217  0x0101010101010101, 0x20b9e767b2fb1456, 0x0800000000000000 );
218 DES_TEST ( des_test2_6,
219  0x0101010101010101, 0x55579380d77138ef, 0x0400000000000000 );
220 DES_TEST ( des_test2_7,
221  0x0101010101010101, 0x6cc5defaaf04512f, 0x0200000000000000 );
222 DES_TEST ( des_test2_8,
223  0x0101010101010101, 0x0d9f279ba5d87260, 0x0100000000000000 );
224 DES_TEST ( des_test2_9,
225  0x0101010101010101, 0xd9031b0271bd5a0a, 0x0080000000000000 );
226 DES_TEST ( des_test2_10,
227  0x0101010101010101, 0x424250b37c3dd951, 0x0040000000000000 );
228 DES_TEST ( des_test2_11,
229  0x0101010101010101, 0xb8061b7ecd9a21e5, 0x0020000000000000 );
230 DES_TEST ( des_test2_12,
231  0x0101010101010101, 0xf15d0f286b65bd28, 0x0010000000000000 );
232 DES_TEST ( des_test2_13,
233  0x0101010101010101, 0xadd0cc8d6e5deba1, 0x0008000000000000 );
234 DES_TEST ( des_test2_14,
235  0x0101010101010101, 0xe6d5f82752ad63d1, 0x0004000000000000 );
236 DES_TEST ( des_test2_15,
237  0x0101010101010101, 0xecbfe3bd3f591a5e, 0x0002000000000000 );
238 DES_TEST ( des_test2_16,
239  0x0101010101010101, 0xf356834379d165cd, 0x0001000000000000 );
240 DES_TEST ( des_test2_17,
241  0x0101010101010101, 0x2b9f982f20037fa9, 0x0000800000000000 );
242 DES_TEST ( des_test2_18,
243  0x0101010101010101, 0x889de068a16f0be6, 0x0000400000000000 );
244 DES_TEST ( des_test2_19,
245  0x0101010101010101, 0xe19e275d846a1298, 0x0000200000000000 );
246 DES_TEST ( des_test2_20,
247  0x0101010101010101, 0x329a8ed523d71aec, 0x0000100000000000 );
248 DES_TEST ( des_test2_21,
249  0x0101010101010101, 0xe7fce22557d23c97, 0x0000080000000000 );
250 DES_TEST ( des_test2_22,
251  0x0101010101010101, 0x12a9f5817ff2d65d, 0x0000040000000000 );
252 DES_TEST ( des_test2_23,
253  0x0101010101010101, 0xa484c3ad38dc9c19, 0x0000020000000000 );
254 DES_TEST ( des_test2_24,
255  0x0101010101010101, 0xfbe00a8a1ef8ad72, 0x0000010000000000 );
256 DES_TEST ( des_test2_25,
257  0x0101010101010101, 0x750d079407521363, 0x0000008000000000 );
258 DES_TEST ( des_test2_26,
259  0x0101010101010101, 0x64feed9c724c2faf, 0x0000004000000000 );
260 DES_TEST ( des_test2_27,
261  0x0101010101010101, 0xf02b263b328e2b60, 0x0000002000000000 );
262 DES_TEST ( des_test2_28,
263  0x0101010101010101, 0x9d64555a9a10b852, 0x0000001000000000 );
264 DES_TEST ( des_test2_29,
265  0x0101010101010101, 0xd106ff0bed5255d7, 0x0000000800000000 );
266 DES_TEST ( des_test2_30,
267  0x0101010101010101, 0xe1652c6b138c64a5, 0x0000000400000000 );
268 DES_TEST ( des_test2_31,
269  0x0101010101010101, 0xe428581186ec8f46, 0x0000000200000000 );
270 DES_TEST ( des_test2_32,
271  0x0101010101010101, 0xaeb5f5ede22d1a36, 0x0000000100000000 );
272 DES_TEST ( des_test2_33,
273  0x0101010101010101, 0xe943d7568aec0c5c, 0x0000000080000000 );
274 DES_TEST ( des_test2_34,
275  0x0101010101010101, 0xdf98c8276f54b04b, 0x0000000040000000 );
276 DES_TEST ( des_test2_35,
277  0x0101010101010101, 0xb160e4680f6c696f, 0x0000000020000000 );
278 DES_TEST ( des_test2_36,
279  0x0101010101010101, 0xfa0752b07d9c4ab8, 0x0000000010000000 );
280 DES_TEST ( des_test2_37,
281  0x0101010101010101, 0xca3a2b036dbc8502, 0x0000000008000000 );
282 DES_TEST ( des_test2_38,
283  0x0101010101010101, 0x5e0905517bb59bcf, 0x0000000004000000 );
284 DES_TEST ( des_test2_39,
285  0x0101010101010101, 0x814eeb3b91d90726, 0x0000000002000000 );
286 DES_TEST ( des_test2_40,
287  0x0101010101010101, 0x4d49db1532919c9f, 0x0000000001000000 );
288 DES_TEST ( des_test2_41,
289  0x0101010101010101, 0x25eb5fc3f8cf0621, 0x0000000000800000 );
290 DES_TEST ( des_test2_42,
291  0x0101010101010101, 0xab6a20c0620d1c6f, 0x0000000000400000 );
292 DES_TEST ( des_test2_43,
293  0x0101010101010101, 0x79e90dbc98f92cca, 0x0000000000200000 );
294 DES_TEST ( des_test2_44,
295  0x0101010101010101, 0x866ecedd8072bb0e, 0x0000000000100000 );
296 DES_TEST ( des_test2_45,
297  0x0101010101010101, 0x8b54536f2f3e64a8, 0x0000000000080000 );
298 DES_TEST ( des_test2_46,
299  0x0101010101010101, 0xea51d3975595b86b, 0x0000000000040000 );
300 DES_TEST ( des_test2_47,
301  0x0101010101010101, 0xcaffc6ac4542de31, 0x0000000000020000 );
302 DES_TEST ( des_test2_48,
303  0x0101010101010101, 0x8dd45a2ddf90796c, 0x0000000000010000 );
304 DES_TEST ( des_test2_49,
305  0x0101010101010101, 0x1029d55e880ec2d0, 0x0000000000008000 );
306 DES_TEST ( des_test2_50,
307  0x0101010101010101, 0x5d86cb23639dbea9, 0x0000000000004000 );
308 DES_TEST ( des_test2_51,
309  0x0101010101010101, 0x1d1ca853ae7c0c5f, 0x0000000000002000 );
310 DES_TEST ( des_test2_52,
311  0x0101010101010101, 0xce332329248f3228, 0x0000000000001000 );
312 DES_TEST ( des_test2_53,
313  0x0101010101010101, 0x8405d1abe24fb942, 0x0000000000000800 );
314 DES_TEST ( des_test2_54,
315  0x0101010101010101, 0xe643d78090ca4207, 0x0000000000000400 );
316 DES_TEST ( des_test2_55,
317  0x0101010101010101, 0x48221b9937748a23, 0x0000000000000200 );
318 DES_TEST ( des_test2_56,
319  0x0101010101010101, 0xdd7c0bbd61fafd54, 0x0000000000000100 );
320 DES_TEST ( des_test2_57,
321  0x0101010101010101, 0x2fbc291a570db5c4, 0x0000000000000080 );
322 DES_TEST ( des_test2_58,
323  0x0101010101010101, 0xe07c30d7e4e26e12, 0x0000000000000040 );
324 DES_TEST ( des_test2_59,
325  0x0101010101010101, 0x0953e2258e8e90a1, 0x0000000000000020 );
326 DES_TEST ( des_test2_60,
327  0x0101010101010101, 0x5b711bc4ceebf2ee, 0x0000000000000010 );
328 DES_TEST ( des_test2_61,
329  0x0101010101010101, 0xcc083f1e6d9e85f6, 0x0000000000000008 );
330 DES_TEST ( des_test2_62,
331  0x0101010101010101, 0xd2fd8867d50d2dfe, 0x0000000000000004 );
332 DES_TEST ( des_test2_63,
333  0x0101010101010101, 0x06e7ea22ce92708f, 0x0000000000000002 );
334 DES_TEST ( des_test2_64,
335  0x0101010101010101, 0x166b40b44aba4bd6, 0x0000000000000001 );
336 
337 /* Test 3: Data permutation tests
338  *
339  * "Set the plaintext to zero and process the 32 keys in PTEST"
340  *
341  * Appendix B, page 32 ("PTEST")
342  */
343 DES_TEST ( des_test3_1,
344  0x1046913489980131, 0x0000000000000000, 0x88d55e54f54c97b4 );
345 DES_TEST ( des_test3_2,
346  0x1007103489988020, 0x0000000000000000, 0x0c0cc00c83ea48fd );
347 DES_TEST ( des_test3_3,
348  0x10071034c8980120, 0x0000000000000000, 0x83bc8ef3a6570183 );
349 DES_TEST ( des_test3_4,
350  0x1046103489988020, 0x0000000000000000, 0xdf725dcad94ea2e9 );
351 DES_TEST ( des_test3_5,
352  0x1086911519190101, 0x0000000000000000, 0xe652b53b550be8b0 );
353 DES_TEST ( des_test3_6,
354  0x1086911519580101, 0x0000000000000000, 0xaf527120c485cbb0 );
355 DES_TEST ( des_test3_7,
356  0x5107b01519580101, 0x0000000000000000, 0x0f04ce393db926d5 );
357 DES_TEST ( des_test3_8,
358  0x1007b01519190101, 0x0000000000000000, 0xc9f00ffc74079067 );
359 DES_TEST ( des_test3_9,
360  0x3107915498080101, 0x0000000000000000, 0x7cfd82a593252b4e );
361 DES_TEST ( des_test3_10,
362  0x3107919498080101, 0x0000000000000000, 0xcb49a2f9e91363e3 );
363 DES_TEST ( des_test3_11,
364  0x10079115b9080140, 0x0000000000000000, 0x00b588be70d23f56 );
365 DES_TEST ( des_test3_12,
366  0x3107911598080140, 0x0000000000000000, 0x406a9a6ab43399ae );
367 DES_TEST ( des_test3_13,
368  0x1007d01589980101, 0x0000000000000000, 0x6cb773611dca9ada );
369 DES_TEST ( des_test3_14,
370  0x9107911589980101, 0x0000000000000000, 0x67fd21c17dbb5d70 );
371 DES_TEST ( des_test3_15,
372  0x9107d01589190101, 0x0000000000000000, 0x9592cb4110430787 );
373 DES_TEST ( des_test3_16,
374  0x1007d01598980120, 0x0000000000000000, 0xa6b7ff68a318ddd3 );
375 DES_TEST ( des_test3_17,
376  0x1007940498190101, 0x0000000000000000, 0x4d102196c914ca16 );
377 DES_TEST ( des_test3_18,
378  0x0107910491190401, 0x0000000000000000, 0x2dfa9f4573594965 );
379 DES_TEST ( des_test3_19,
380  0x0107910491190101, 0x0000000000000000, 0xb46604816c0e0774 );
381 DES_TEST ( des_test3_20,
382  0x0107940491190401, 0x0000000000000000, 0x6e7e6221a4f34e87 );
383 DES_TEST ( des_test3_21,
384  0x19079210981a0101, 0x0000000000000000, 0xaa85e74643233199 );
385 DES_TEST ( des_test3_22,
386  0x1007911998190801, 0x0000000000000000, 0x2e5a19db4d1962d6 );
387 DES_TEST ( des_test3_23,
388  0x10079119981a0801, 0x0000000000000000, 0x23a866a809d30894 );
389 DES_TEST ( des_test3_24,
390  0x1007921098190101, 0x0000000000000000, 0xd812d961f017d320 );
391 DES_TEST ( des_test3_25,
392  0x100791159819010b, 0x0000000000000000, 0x055605816e58608f );
393 DES_TEST ( des_test3_26,
394  0x1004801598190101, 0x0000000000000000, 0xabd88e8b1b7716f1 );
395 DES_TEST ( des_test3_27,
396  0x1004801598190102, 0x0000000000000000, 0x537ac95be69da1e1 );
397 DES_TEST ( des_test3_28,
398  0x1004801598190108, 0x0000000000000000, 0xaed0f6ae3c25cdd8 );
399 DES_TEST ( des_test3_29,
400  0x1002911498100104, 0x0000000000000000, 0xb3e35a5ee53e7b8d );
401 DES_TEST ( des_test3_30,
402  0x1002911598190104, 0x0000000000000000, 0x61c79c71921a2ef8 );
403 DES_TEST ( des_test3_31,
404  0x1002911598100201, 0x0000000000000000, 0xe2f5728f0995013c );
405 DES_TEST ( des_test3_32,
406  0x1002911698100101, 0x0000000000000000, 0x1aeac39a61f0a464 );
407 
408 /* Test 4: Key permutation tests
409  *
410  * "Set Data=0 and use the keys e[i]: i=1,...,64 ignoring i=8,16,...,64"
411  *
412  * Test 4 part 1 is the forward direction as described above. Test 4
413  * part 2 ("set data=c[i] from part 1 ... then decipher") is carried
414  * out for us automatically, since CIPHER_TEST() performs both
415  * encryption and decryption tests.
416  *
417  * Appendix B, page 30 ("PC1 and PC2 test")
418  */
419 DES_TEST ( des_test4_1,
420  0x8001010101010101, 0x0000000000000000, 0x95a8d72813daa94d );
421 DES_TEST ( des_test4_2,
422  0x4001010101010101, 0x0000000000000000, 0x0eec1487dd8c26d5 );
423 DES_TEST ( des_test4_3,
424  0x2001010101010101, 0x0000000000000000, 0x7ad16ffb79c45926 );
425 DES_TEST ( des_test4_4,
426  0x1001010101010101, 0x0000000000000000, 0xd3746294ca6a6cf3 );
427 DES_TEST ( des_test4_5,
428  0x0801010101010101, 0x0000000000000000, 0x809f5f873c1fd761 );
429 DES_TEST ( des_test4_6,
430  0x0401010101010101, 0x0000000000000000, 0xc02faffec989d1fc );
431 DES_TEST ( des_test4_7,
432  0x0201010101010101, 0x0000000000000000, 0x4615aa1d33e72f10 );
433 DES_TEST ( des_test4_8,
434  0x0180010101010101, 0x0000000000000000, 0x2055123350c00858 );
435 DES_TEST ( des_test4_9,
436  0x0140010101010101, 0x0000000000000000, 0xdf3b99d6577397c8 );
437 DES_TEST ( des_test4_10,
438  0x0120010101010101, 0x0000000000000000, 0x31fe17369b5288c9 );
439 DES_TEST ( des_test4_11,
440  0x0110010101010101, 0x0000000000000000, 0xdfdd3cc64dae1642 );
441 DES_TEST ( des_test4_12,
442  0x0108010101010101, 0x0000000000000000, 0x178c83ce2b399d94 );
443 DES_TEST ( des_test4_13,
444  0x0104010101010101, 0x0000000000000000, 0x50f636324a9b7f80 );
445 DES_TEST ( des_test4_14,
446  0x0102010101010101, 0x0000000000000000, 0xa8468ee3bc18f06d );
447 DES_TEST ( des_test4_15,
448  0x0101800101010101, 0x0000000000000000, 0xa2dc9e92fd3cde92 );
449 DES_TEST ( des_test4_16,
450  0x0101400101010101, 0x0000000000000000, 0xcac09f797d031287 );
451 DES_TEST ( des_test4_17,
452  0x0101200101010101, 0x0000000000000000, 0x90ba680b22aeb525 );
453 DES_TEST ( des_test4_18,
454  0x0101100101010101, 0x0000000000000000, 0xce7a24f350e280b6 );
455 DES_TEST ( des_test4_19,
456  0x0101080101010101, 0x0000000000000000, 0x882bff0aa01a0b87 );
457 DES_TEST ( des_test4_20,
458  0x0101040101010101, 0x0000000000000000, 0x25610288924511c2 );
459 DES_TEST ( des_test4_21,
460  0x0101020101010101, 0x0000000000000000, 0xc71516c29c75d170 );
461 DES_TEST ( des_test4_22,
462  0x0101018001010101, 0x0000000000000000, 0x5199c29a52c9f059 );
463 DES_TEST ( des_test4_23,
464  0x0101014001010101, 0x0000000000000000, 0xc22f0a294a71f29f );
465 DES_TEST ( des_test4_24,
466  0x0101012001010101, 0x0000000000000000, 0xee371483714c02ea );
467 DES_TEST ( des_test4_25,
468  0x0101011001010101, 0x0000000000000000, 0xa81fbd448f9e522f );
469 DES_TEST ( des_test4_26,
470  0x0101010801010101, 0x0000000000000000, 0x4f644c92e192dfed );
471 DES_TEST ( des_test4_27,
472  0x0101010401010101, 0x0000000000000000, 0x1afa9a66a6df92ae );
473 DES_TEST ( des_test4_28,
474  0x0101010201010101, 0x0000000000000000, 0xb3c1cc715cb879d8 );
475 DES_TEST ( des_test4_29,
476  0x0101010180010101, 0x0000000000000000, 0x19d032e64ab0bd8b );
477 DES_TEST ( des_test4_30,
478  0x0101010140010101, 0x0000000000000000, 0x3cfaa7a7dc8720dc );
479 DES_TEST ( des_test4_31,
480  0x0101010120010101, 0x0000000000000000, 0xb7265f7f447ac6f3 );
481 DES_TEST ( des_test4_32,
482  0x0101010110010101, 0x0000000000000000, 0x9db73b3c0d163f54 );
483 DES_TEST ( des_test4_33,
484  0x0101010108010101, 0x0000000000000000, 0x8181b65babf4a975 );
485 DES_TEST ( des_test4_34,
486  0x0101010104010101, 0x0000000000000000, 0x93c9b64042eaa240 );
487 DES_TEST ( des_test4_35,
488  0x0101010102010101, 0x0000000000000000, 0x5570530829705592 );
489 DES_TEST ( des_test4_36,
490  0x0101010101800101, 0x0000000000000000, 0x8638809e878787a0 );
491 DES_TEST ( des_test4_37,
492  0x0101010101400101, 0x0000000000000000, 0x41b9a79af79ac208 );
493 DES_TEST ( des_test4_38,
494  0x0101010101200101, 0x0000000000000000, 0x7a9be42f2009a892 );
495 DES_TEST ( des_test4_39,
496  0x0101010101100101, 0x0000000000000000, 0x29038d56ba6d2745 );
497 DES_TEST ( des_test4_40,
498  0x0101010101080101, 0x0000000000000000, 0x5495c6abf1e5df51 );
499 DES_TEST ( des_test4_41,
500  0x0101010101040101, 0x0000000000000000, 0xae13dbd561488933 );
501 DES_TEST ( des_test4_42,
502  0x0101010101020101, 0x0000000000000000, 0x024d1ffa8904e389 );
503 DES_TEST ( des_test4_43,
504  0x0101010101018001, 0x0000000000000000, 0xd1399712f99bf02e );
505 DES_TEST ( des_test4_44,
506  0x0101010101014001, 0x0000000000000000, 0x14c1d7c1cffec79e );
507 DES_TEST ( des_test4_45,
508  0x0101010101012001, 0x0000000000000000, 0x1de5279dae3bed6f );
509 DES_TEST ( des_test4_46,
510  0x0101010101011001, 0x0000000000000000, 0xe941a33f85501303 );
511 DES_TEST ( des_test4_47,
512  0x0101010101010801, 0x0000000000000000, 0xda99dbbc9a03f379 );
513 DES_TEST ( des_test4_48,
514  0x0101010101010401, 0x0000000000000000, 0xb7fc92f91d8e92e9 );
515 DES_TEST ( des_test4_49,
516  0x0101010101010201, 0x0000000000000000, 0xae8e5caa3ca04e85 );
517 DES_TEST ( des_test4_50,
518  0x0101010101010180, 0x0000000000000000, 0x9cc62df43b6eed74 );
519 DES_TEST ( des_test4_51,
520  0x0101010101010140, 0x0000000000000000, 0xd863dbb5c59a91a0 );
521 DES_TEST ( des_test4_52,
522  0x0101010101010120, 0x0000000000000000, 0xa1ab2190545b91d7 );
523 DES_TEST ( des_test4_53,
524  0x0101010101010110, 0x0000000000000000, 0x0875041e64c570f7 );
525 DES_TEST ( des_test4_54,
526  0x0101010101010108, 0x0000000000000000, 0x5a594528bebef1cc );
527 DES_TEST ( des_test4_55,
528  0x0101010101010104, 0x0000000000000000, 0xfcdb3291de21f0c0 );
529 DES_TEST ( des_test4_56,
530  0x0101010101010102, 0x0000000000000000, 0x869efd7f9f265a09 );
531 
532 /* Test 5: S-box tests
533  *
534  * "Set Data and Key equal to the inputs defined in the Substitution
535  * Table test"
536  *
537  * Appendix B, page 33 ("19 key data pairs which exercise every S-box entry")
538  */
539 DES_TEST ( des_test5_1,
540  0x7ca110454a1a6e57, 0x01a1d6d039776742, 0x690f5b0d9a26939b );
541 DES_TEST ( des_test5_2,
542  0x0131d9619dc1376e, 0x5cd54ca83def57da, 0x7a389d10354bd271 );
543 DES_TEST ( des_test5_3,
544  0x07a1133e4a0b2686, 0x0248d43806f67172, 0x868ebb51cab4599a );
545 DES_TEST ( des_test5_4,
546  0x3849674c2602319e, 0x51454b582ddf440a, 0x7178876e01f19b2a );
547 DES_TEST ( des_test5_5,
548  0x04b915ba43feb5b6, 0x42fd443059577fa2, 0xaf37fb421f8c4095 );
549 DES_TEST ( des_test5_6,
550  0x0113b970fd34f2ce, 0x059b5e0851cf143a, 0x86a560f10ec6d85b );
551 DES_TEST ( des_test5_7,
552  0x0170f175468fb5e6, 0x0756d8e0774761d2, 0x0cd3da020021dc09 );
553 DES_TEST ( des_test5_8,
554  0x43297fad38e373fe, 0x762514b829bf486a, 0xea676b2cb7db2b7a );
555 DES_TEST ( des_test5_9,
556  0x07a7137045da2a16, 0x3bdd119049372802, 0xdfd64a815caf1a0f );
557 DES_TEST ( des_test5_10,
558  0x04689104c2fd3b2f, 0x26955f6835af609a, 0x5c513c9c4886c088 );
559 DES_TEST ( des_test5_11,
560  0x37d06bb516cb7546, 0x164d5e404f275232, 0x0a2aeeae3ff4ab77 );
561 DES_TEST ( des_test5_12,
562  0x1f08260d1ac2465e, 0x6b056e18759f5cca, 0xef1bf03e5dfa575a );
563 DES_TEST ( des_test5_13,
564  0x584023641aba6176, 0x004bd6ef09176062, 0x88bf0db6d70dee56 );
565 DES_TEST ( des_test5_14,
566  0x025816164629b007, 0x480d39006ee762f2, 0xa1f9915541020b56 );
567 DES_TEST ( des_test5_15,
568  0x49793ebc79b3258f, 0x437540c8698f3cfa, 0x6fbf1cafcffd0556 );
569 DES_TEST ( des_test5_16,
570  0x4fb05e1515ab73a7, 0x072d43a077075292, 0x2f22e49bab7ca1ac );
571 DES_TEST ( des_test5_17,
572  0x49e95d6d4ca229bf, 0x02fe55778117f12a, 0x5a6b612cc26cce4a );
573 DES_TEST ( des_test5_18,
574  0x018310dc409b26d6, 0x1d9d5c5018f728c2, 0x5f4c038ed12b2e41 );
575 DES_TEST ( des_test5_19,
576  0x1c587f1c13924fef, 0x305532286d6f295a, 0x63fac0d034d9f793 );
577 
578 /* Unofficial tests
579  *
580  * The official tests are all exactly one block in length. Add some
581  * multi-block tests (generated in Python).
582  */
583 CIPHER_TEST ( des_unofficial_ecb, &des_ecb_algorithm,
584  KEY ( 0x6e, 0x6f, 0x70, 0x61, 0x72, 0x69, 0x74, 0x79 ),
585  IV(), ADDITIONAL(),
586  PLAINTEXT ( 0x53, 0x6f, 0x20, 0x63, 0x75, 0x74, 0x65, 0x20,
587  0x74, 0x6f, 0x20, 0x73, 0x65, 0x65, 0x20, 0x61,
588  0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69,
589  0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x77,
590  0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x6f,
591  0x6e, 0x20, 0x61, 0x6e, 0x20, 0x61, 0x63, 0x74,
592  0x75, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65,
593  0x77, 0x72, 0x69, 0x74, 0x65, 0x72, 0x21, 0x21 ),
594  CIPHERTEXT ( 0x1a, 0x02, 0x17, 0xcb, 0x93, 0xa3, 0xd2, 0xf2,
595  0xf9, 0x45, 0x71, 0x1c, 0x33, 0xb1, 0x5c, 0xa4,
596  0x8b, 0x6b, 0x11, 0x7a, 0x7c, 0x86, 0x7c, 0x7f,
597  0x9f, 0x56, 0x61, 0x46, 0x7f, 0xa6, 0xae, 0xf1,
598  0x49, 0xf7, 0x53, 0xe0, 0xbc, 0x15, 0x6a, 0x30,
599  0xe7, 0xf8, 0xf3, 0x29, 0x11, 0xd8, 0x7d, 0x04,
600  0x62, 0x5a, 0xaa, 0xa1, 0x89, 0x61, 0x4c, 0xf6,
601  0x5a, 0x47, 0x3b, 0xc6, 0x04, 0x15, 0xce, 0xf6 ),
602  AUTH() );
603 CIPHER_TEST ( des_unofficial_cbc, &des_cbc_algorithm,
604  KEY ( 0x6e, 0x6f, 0x70, 0x61, 0x72, 0x69, 0x74, 0x79 ),
605  IV ( 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 ),
606  ADDITIONAL(),
607  PLAINTEXT ( 0x53, 0x6f, 0x20, 0x63, 0x75, 0x74, 0x65, 0x20,
608  0x74, 0x6f, 0x20, 0x73, 0x65, 0x65, 0x20, 0x61,
609  0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69,
610  0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x77,
611  0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x6f,
612  0x6e, 0x20, 0x61, 0x6e, 0x20, 0x61, 0x63, 0x74,
613  0x75, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65,
614  0x77, 0x72, 0x69, 0x74, 0x65, 0x72, 0x21, 0x21 ),
615  CIPHERTEXT ( 0x4c, 0x5f, 0x62, 0xfc, 0xf4, 0x93, 0x09, 0xb5,
616  0x1d, 0x52, 0x25, 0xec, 0xc7, 0x42, 0x3c, 0x29,
617  0x33, 0x67, 0xf5, 0xe9, 0xd6, 0x3c, 0x27, 0x5b,
618  0x49, 0x69, 0xc5, 0xa9, 0x08, 0xa3, 0x14, 0x66,
619  0x3c, 0x95, 0x33, 0x30, 0xcf, 0x3c, 0x7c, 0xaf,
620  0xa3, 0xe4, 0xf8, 0x2e, 0xc3, 0x55, 0x57, 0x81,
621  0x33, 0xd9, 0x90, 0xe2, 0x99, 0xdc, 0x32, 0x10,
622  0x13, 0x21, 0xb6, 0xc1, 0x6b, 0x0f, 0x22, 0xa9 ),
623  AUTH() );
624 
625 /**
626  * Perform DES self-test
627  *
628  */
629 static void des_test_exec ( void ) {
630 
631  /* Sample round outputs (page 9) */
632  cipher_ok ( &des_round_sample );
633 
634  /* Test 1: Initial permutation and expansion tests */
635  cipher_ok ( &des_test1_1 );
636  cipher_ok ( &des_test1_2 );
637  cipher_ok ( &des_test1_3 );
638  cipher_ok ( &des_test1_4 );
639  cipher_ok ( &des_test1_5 );
640  cipher_ok ( &des_test1_6 );
641  cipher_ok ( &des_test1_7 );
642  cipher_ok ( &des_test1_8 );
643  cipher_ok ( &des_test1_9 );
644  cipher_ok ( &des_test1_10 );
645  cipher_ok ( &des_test1_11 );
646  cipher_ok ( &des_test1_12 );
647  cipher_ok ( &des_test1_13 );
648  cipher_ok ( &des_test1_14 );
649  cipher_ok ( &des_test1_15 );
650  cipher_ok ( &des_test1_16 );
651  cipher_ok ( &des_test1_17 );
652  cipher_ok ( &des_test1_18 );
653  cipher_ok ( &des_test1_19 );
654  cipher_ok ( &des_test1_20 );
655  cipher_ok ( &des_test1_21 );
656  cipher_ok ( &des_test1_22 );
657  cipher_ok ( &des_test1_23 );
658  cipher_ok ( &des_test1_24 );
659  cipher_ok ( &des_test1_25 );
660  cipher_ok ( &des_test1_26 );
661  cipher_ok ( &des_test1_27 );
662  cipher_ok ( &des_test1_28 );
663  cipher_ok ( &des_test1_29 );
664  cipher_ok ( &des_test1_30 );
665  cipher_ok ( &des_test1_31 );
666  cipher_ok ( &des_test1_32 );
667  cipher_ok ( &des_test1_33 );
668  cipher_ok ( &des_test1_34 );
669  cipher_ok ( &des_test1_35 );
670  cipher_ok ( &des_test1_36 );
671  cipher_ok ( &des_test1_37 );
672  cipher_ok ( &des_test1_38 );
673  cipher_ok ( &des_test1_39 );
674  cipher_ok ( &des_test1_40 );
675  cipher_ok ( &des_test1_41 );
676  cipher_ok ( &des_test1_42 );
677  cipher_ok ( &des_test1_43 );
678  cipher_ok ( &des_test1_44 );
679  cipher_ok ( &des_test1_45 );
680  cipher_ok ( &des_test1_46 );
681  cipher_ok ( &des_test1_47 );
682  cipher_ok ( &des_test1_48 );
683  cipher_ok ( &des_test1_49 );
684  cipher_ok ( &des_test1_50 );
685  cipher_ok ( &des_test1_51 );
686  cipher_ok ( &des_test1_52 );
687  cipher_ok ( &des_test1_53 );
688  cipher_ok ( &des_test1_54 );
689  cipher_ok ( &des_test1_55 );
690  cipher_ok ( &des_test1_56 );
691  cipher_ok ( &des_test1_57 );
692  cipher_ok ( &des_test1_58 );
693  cipher_ok ( &des_test1_59 );
694  cipher_ok ( &des_test1_60 );
695  cipher_ok ( &des_test1_61 );
696  cipher_ok ( &des_test1_62 );
697  cipher_ok ( &des_test1_63 );
698  cipher_ok ( &des_test1_64 );
699 
700  /* Test 2: Inverse permutation and expansion tests */
701  cipher_ok ( &des_test2_1 );
702  cipher_ok ( &des_test2_2 );
703  cipher_ok ( &des_test2_3 );
704  cipher_ok ( &des_test2_4 );
705  cipher_ok ( &des_test2_5 );
706  cipher_ok ( &des_test2_6 );
707  cipher_ok ( &des_test2_7 );
708  cipher_ok ( &des_test2_8 );
709  cipher_ok ( &des_test2_9 );
710  cipher_ok ( &des_test2_10 );
711  cipher_ok ( &des_test2_11 );
712  cipher_ok ( &des_test2_12 );
713  cipher_ok ( &des_test2_13 );
714  cipher_ok ( &des_test2_14 );
715  cipher_ok ( &des_test2_15 );
716  cipher_ok ( &des_test2_16 );
717  cipher_ok ( &des_test2_17 );
718  cipher_ok ( &des_test2_18 );
719  cipher_ok ( &des_test2_19 );
720  cipher_ok ( &des_test2_20 );
721  cipher_ok ( &des_test2_21 );
722  cipher_ok ( &des_test2_22 );
723  cipher_ok ( &des_test2_23 );
724  cipher_ok ( &des_test2_24 );
725  cipher_ok ( &des_test2_25 );
726  cipher_ok ( &des_test2_26 );
727  cipher_ok ( &des_test2_27 );
728  cipher_ok ( &des_test2_28 );
729  cipher_ok ( &des_test2_29 );
730  cipher_ok ( &des_test2_30 );
731  cipher_ok ( &des_test2_31 );
732  cipher_ok ( &des_test2_32 );
733  cipher_ok ( &des_test2_33 );
734  cipher_ok ( &des_test2_34 );
735  cipher_ok ( &des_test2_35 );
736  cipher_ok ( &des_test2_36 );
737  cipher_ok ( &des_test2_37 );
738  cipher_ok ( &des_test2_38 );
739  cipher_ok ( &des_test2_39 );
740  cipher_ok ( &des_test2_40 );
741  cipher_ok ( &des_test2_41 );
742  cipher_ok ( &des_test2_42 );
743  cipher_ok ( &des_test2_43 );
744  cipher_ok ( &des_test2_44 );
745  cipher_ok ( &des_test2_45 );
746  cipher_ok ( &des_test2_46 );
747  cipher_ok ( &des_test2_47 );
748  cipher_ok ( &des_test2_48 );
749  cipher_ok ( &des_test2_49 );
750  cipher_ok ( &des_test2_50 );
751  cipher_ok ( &des_test2_51 );
752  cipher_ok ( &des_test2_52 );
753  cipher_ok ( &des_test2_53 );
754  cipher_ok ( &des_test2_54 );
755  cipher_ok ( &des_test2_55 );
756  cipher_ok ( &des_test2_56 );
757  cipher_ok ( &des_test2_57 );
758  cipher_ok ( &des_test2_58 );
759  cipher_ok ( &des_test2_59 );
760  cipher_ok ( &des_test2_60 );
761  cipher_ok ( &des_test2_61 );
762  cipher_ok ( &des_test2_62 );
763  cipher_ok ( &des_test2_63 );
764  cipher_ok ( &des_test2_64 );
765 
766  /* Test 3: Data permutation tests */
767  cipher_ok ( &des_test3_1 );
768  cipher_ok ( &des_test3_2 );
769  cipher_ok ( &des_test3_3 );
770  cipher_ok ( &des_test3_4 );
771  cipher_ok ( &des_test3_5 );
772  cipher_ok ( &des_test3_6 );
773  cipher_ok ( &des_test3_7 );
774  cipher_ok ( &des_test3_8 );
775  cipher_ok ( &des_test3_9 );
776  cipher_ok ( &des_test3_10 );
777  cipher_ok ( &des_test3_11 );
778  cipher_ok ( &des_test3_12 );
779  cipher_ok ( &des_test3_13 );
780  cipher_ok ( &des_test3_14 );
781  cipher_ok ( &des_test3_15 );
782  cipher_ok ( &des_test3_16 );
783  cipher_ok ( &des_test3_17 );
784  cipher_ok ( &des_test3_18 );
785  cipher_ok ( &des_test3_19 );
786  cipher_ok ( &des_test3_20 );
787  cipher_ok ( &des_test3_21 );
788  cipher_ok ( &des_test3_22 );
789  cipher_ok ( &des_test3_23 );
790  cipher_ok ( &des_test3_24 );
791  cipher_ok ( &des_test3_25 );
792  cipher_ok ( &des_test3_26 );
793  cipher_ok ( &des_test3_27 );
794  cipher_ok ( &des_test3_28 );
795  cipher_ok ( &des_test3_29 );
796  cipher_ok ( &des_test3_30 );
797  cipher_ok ( &des_test3_31 );
798  cipher_ok ( &des_test3_32 );
799 
800  /* Test 4: Key permutation tests */
801  cipher_ok ( &des_test4_1 );
802  cipher_ok ( &des_test4_2 );
803  cipher_ok ( &des_test4_3 );
804  cipher_ok ( &des_test4_4 );
805  cipher_ok ( &des_test4_5 );
806  cipher_ok ( &des_test4_6 );
807  cipher_ok ( &des_test4_7 );
808  cipher_ok ( &des_test4_8 );
809  cipher_ok ( &des_test4_9 );
810  cipher_ok ( &des_test4_10 );
811  cipher_ok ( &des_test4_11 );
812  cipher_ok ( &des_test4_12 );
813  cipher_ok ( &des_test4_13 );
814  cipher_ok ( &des_test4_14 );
815  cipher_ok ( &des_test4_15 );
816  cipher_ok ( &des_test4_16 );
817  cipher_ok ( &des_test4_17 );
818  cipher_ok ( &des_test4_18 );
819  cipher_ok ( &des_test4_19 );
820  cipher_ok ( &des_test4_20 );
821  cipher_ok ( &des_test4_21 );
822  cipher_ok ( &des_test4_22 );
823  cipher_ok ( &des_test4_23 );
824  cipher_ok ( &des_test4_24 );
825  cipher_ok ( &des_test4_25 );
826  cipher_ok ( &des_test4_26 );
827  cipher_ok ( &des_test4_27 );
828  cipher_ok ( &des_test4_28 );
829  cipher_ok ( &des_test4_29 );
830  cipher_ok ( &des_test4_30 );
831  cipher_ok ( &des_test4_31 );
832  cipher_ok ( &des_test4_32 );
833  cipher_ok ( &des_test4_33 );
834  cipher_ok ( &des_test4_34 );
835  cipher_ok ( &des_test4_35 );
836  cipher_ok ( &des_test4_36 );
837  cipher_ok ( &des_test4_37 );
838  cipher_ok ( &des_test4_38 );
839  cipher_ok ( &des_test4_39 );
840  cipher_ok ( &des_test4_40 );
841  cipher_ok ( &des_test4_41 );
842  cipher_ok ( &des_test4_42 );
843  cipher_ok ( &des_test4_43 );
844  cipher_ok ( &des_test4_44 );
845  cipher_ok ( &des_test4_45 );
846  cipher_ok ( &des_test4_46 );
847  cipher_ok ( &des_test4_47 );
848  cipher_ok ( &des_test4_48 );
849  cipher_ok ( &des_test4_49 );
850  cipher_ok ( &des_test4_50 );
851  cipher_ok ( &des_test4_51 );
852  cipher_ok ( &des_test4_52 );
853  cipher_ok ( &des_test4_53 );
854  cipher_ok ( &des_test4_54 );
855  cipher_ok ( &des_test4_55 );
856  cipher_ok ( &des_test4_56 );
857 
858  /* Test 5: S-box tests */
859  cipher_ok ( &des_test5_1 );
860  cipher_ok ( &des_test5_2 );
861  cipher_ok ( &des_test5_3 );
862  cipher_ok ( &des_test5_4 );
863  cipher_ok ( &des_test5_5 );
864  cipher_ok ( &des_test5_6 );
865  cipher_ok ( &des_test5_7 );
866  cipher_ok ( &des_test5_8 );
867  cipher_ok ( &des_test5_9 );
868  cipher_ok ( &des_test5_10 );
869  cipher_ok ( &des_test5_11 );
870  cipher_ok ( &des_test5_12 );
871  cipher_ok ( &des_test5_13 );
872  cipher_ok ( &des_test5_14 );
873  cipher_ok ( &des_test5_15 );
874  cipher_ok ( &des_test5_16 );
875  cipher_ok ( &des_test5_17 );
876  cipher_ok ( &des_test5_18 );
877  cipher_ok ( &des_test5_19 );
878 
879  /* Multi-block tests */
880  cipher_ok ( &des_unofficial_ecb );
881  cipher_ok ( &des_unofficial_cbc );
882 
883  /* Speed tests */
884  DBG ( "DES-ECB encryption required %ld cycles per byte\n",
886  DBG ( "DES-ECB decryption required %ld cycles per byte\n",
888  DBG ( "DES-CBC encryption required %ld cycles per byte\n",
890  DBG ( "DES-CBC decryption required %ld cycles per byte\n",
892 }
893 
894 /** DES self-test */
895 struct self_test des_test __self_test = {
896  .name = "des",
897  .exec = des_test_exec,
898 };
#define AUTH(...)
Define inline authentication tag.
Definition: cipher_test.h:60
#define IV(...)
Define inline initialisation vector.
Definition: cipher_test.h:48
#define DES_TEST(name, key, plaintext, ciphertext)
Define a DES test.
Definition: des_test.c:58
#define CIPHERTEXT(...)
Define inline ciphertext data.
Definition: cipher_test.h:57
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define PLAINTEXT(...)
Define inline plaintext data.
Definition: cipher_test.h:54
Self-test infrastructure.
const char * name
Test set name.
Definition: test.h:17
struct cipher_algorithm des_cbc_algorithm
A self-test set.
Definition: test.h:15
CIPHER_TEST(des_unofficial_ecb, &des_ecb_algorithm, KEY(0x6e, 0x6f, 0x70, 0x61, 0x72, 0x69, 0x74, 0x79), IV(), ADDITIONAL(), PLAINTEXT(0x53, 0x6f, 0x20, 0x63, 0x75, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x73, 0x65, 0x65, 0x20, 0x61, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x77, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x6f, 0x6e, 0x20, 0x61, 0x6e, 0x20, 0x61, 0x63, 0x74, 0x75, 0x61, 0x6c, 0x20, 0x74, 0x79, 0x70, 0x65, 0x77, 0x72, 0x69, 0x74, 0x65, 0x72, 0x21, 0x21), CIPHERTEXT(0x1a, 0x02, 0x17, 0xcb, 0x93, 0xa3, 0xd2, 0xf2, 0xf9, 0x45, 0x71, 0x1c, 0x33, 0xb1, 0x5c, 0xa4, 0x8b, 0x6b, 0x11, 0x7a, 0x7c, 0x86, 0x7c, 0x7f, 0x9f, 0x56, 0x61, 0x46, 0x7f, 0xa6, 0xae, 0xf1, 0x49, 0xf7, 0x53, 0xe0, 0xbc, 0x15, 0x6a, 0x30, 0xe7, 0xf8, 0xf3, 0x29, 0x11, 0xd8, 0x7d, 0x04, 0x62, 0x5a, 0xaa, 0xa1, 0x89, 0x61, 0x4c, 0xf6, 0x5a, 0x47, 0x3b, 0xc6, 0x04, 0x15, 0xce, 0xf6), AUTH())
unsigned long cipher_cost_decrypt(struct cipher_algorithm *cipher, size_t key_len)
Calculate cipher decryption cost.
Definition: cipher_test.c:258
#define KEY(...)
Define inline key.
Definition: cipher_test.h:45
Assertions.
static void des_test_exec(void)
Perform DES self-test.
Definition: des_test.c:629
struct cipher_algorithm des_ecb_algorithm
#define cipher_ok(test)
Report a cipher encryption and decryption test result.
Definition: cipher_test.h:131
DES algorithm.
Cipher self-tests.
struct self_test des_test __self_test
DES self-test.
Definition: des_test.c:895
#define ADDITIONAL(...)
Define inline additional data.
Definition: cipher_test.h:51
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
unsigned long cipher_cost_encrypt(struct cipher_algorithm *cipher, size_t key_len)
Calculate cipher encryption cost.
Definition: cipher_test.c:246