ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / crypto / tcrypt.h
1 /*
2  * Quick & dirty crypto testing module.
3  *
4  * This will only exist until we have a better testing mechanism
5  * (e.g. a char device).
6  *
7  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8  * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License as published by the Free
12  * Software Foundation; either version 2 of the License, or (at your option) 
13  * any later version.
14  *
15  * 14 - 09 - 2003 Changes by Kartikey Mahendra Bhatt
16  *
17  */
18 #ifndef _CRYPTO_TCRYPT_H
19 #define _CRYPTO_TCRYPT_H
20
21 #define MAX_DIGEST_SIZE         64
22 #define MAX_TAP                 8
23
24 #define MAX_KEYLEN              56
25 #define MAX_IVLEN               32
26
27 struct hash_testvec {
28         char plaintext[128];
29         unsigned char psize;
30         char digest[MAX_DIGEST_SIZE];
31         unsigned char np;
32         unsigned char tap[MAX_TAP];             
33         char key[128]; /* only used with keyed hash algorithms */
34         unsigned char ksize;
35 };
36
37 struct hmac_testvec {   
38         char key[128];
39         unsigned char ksize;
40         char plaintext[128];
41         unsigned char psize;
42         char digest[MAX_DIGEST_SIZE];
43         unsigned char np;
44         unsigned char tap[MAX_TAP];             
45 };
46
47 struct cipher_testvec {
48         unsigned char fail;
49         unsigned char wk; /* weak key flag */
50         char key[MAX_KEYLEN];
51         unsigned char klen;
52         char iv[MAX_IVLEN];
53         char input[48];
54         unsigned char ilen;
55         char result[48];
56         unsigned char rlen;
57         int np;
58         unsigned char tap[MAX_TAP];     
59 };
60
61 /*
62  * MD4 test vectors from RFC1320
63  */
64 #define MD4_TEST_VECTORS        7
65
66 struct hash_testvec md4_tv_template [] = {
67         {
68                 .plaintext = "",
69                 .digest = { 0x31, 0xd6, 0xcf, 0xe0, 0xd1, 0x6a, 0xe9, 0x31,
70                             0xb7, 0x3c, 0x59, 0xd7, 0xe0, 0xc0, 0x89, 0xc0 },
71         }, {
72                 .plaintext = "a",
73                 .psize  = 1,
74                 .digest = { 0xbd, 0xe5, 0x2c, 0xb3, 0x1d, 0xe3, 0x3e, 0x46,
75                             0x24, 0x5e, 0x05, 0xfb, 0xdb, 0xd6, 0xfb, 0x24 },
76         }, {
77                 .plaintext = "abc",
78                 .psize  = 3,
79                 .digest = { 0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52,
80                             0x5f, 0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d },
81         }, {
82                 .plaintext = "message digest",
83                 .psize  = 14,
84                 .digest = { 0xd9, 0x13, 0x0a, 0x81, 0x64, 0x54, 0x9f, 0xe8,
85                             0x18, 0x87, 0x48, 0x06, 0xe1, 0xc7, 0x01, 0x4b },
86         }, {
87                 .plaintext = "abcdefghijklmnopqrstuvwxyz",
88                 .psize  = 26,
89                 .digest = { 0xd7, 0x9e, 0x1c, 0x30, 0x8a, 0xa5, 0xbb, 0xcd,
90                             0xee, 0xa8, 0xed, 0x63, 0xdf, 0x41, 0x2d, 0xa9 },
91                 .np     = 2,
92                 .tap    = { 13, 13 },
93         }, {
94                 .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
95                 .psize  = 62,
96                 .digest = { 0x04, 0x3f, 0x85, 0x82, 0xf2, 0x41, 0xdb, 0x35,
97                             0x1c, 0xe6, 0x27, 0xe1, 0x53, 0xe7, 0xf0, 0xe4 },
98         }, {
99                 .plaintext = "123456789012345678901234567890123456789012345678901234567890123"
100                              "45678901234567890",
101                 .psize  = 80,
102                 .digest = { 0xe3, 0x3b, 0x4d, 0xdc, 0x9c, 0x38, 0xf2, 0x19,
103                             0x9c, 0x3e, 0x7b, 0x16, 0x4f, 0xcc, 0x05, 0x36 },
104         },
105 };
106
107 /*
108  * MD5 test vectors from RFC1321
109  */
110 #define MD5_TEST_VECTORS        7
111
112 struct hash_testvec md5_tv_template[] = {
113         {
114                 .digest = { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
115                             0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e },
116         }, {
117                 .plaintext = "a",
118                 .psize  = 1,
119                 .digest = { 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8,
120                             0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 },
121         }, {
122                 .plaintext = "abc",
123                 .psize  = 3,
124                 .digest = { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0,
125                             0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 },
126         }, {
127                 .plaintext = "message digest",
128                 .psize  = 14,
129                 .digest = { 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d,
130                             0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 },
131         }, {
132                 .plaintext = "abcdefghijklmnopqrstuvwxyz",
133                 .psize  = 26,
134                 .digest = { 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00,
135                             0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b },
136                 .np     = 2,
137                 .tap    = {13, 13}
138         }, {
139                 .plaintext = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
140                 .psize  = 62,
141                 .digest = { 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5,
142                             0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f },
143         }, {
144                 .plaintext = "12345678901234567890123456789012345678901234567890123456789012"
145                              "345678901234567890",
146                 .psize  = 80,
147                 .digest = { 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55,
148                             0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a },
149         }
150 };
151
152 /*
153  * SHA1 test vectors  from from FIPS PUB 180-1
154  */
155 #define SHA1_TEST_VECTORS       2
156
157 struct hash_testvec sha1_tv_template[] = {
158         { 
159                 .plaintext = "abc",
160                 .psize  = 3,
161                 .digest = { 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e,
162                             0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d },
163         }, {
164                 .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
165                 .psize  = 56,
166                 .digest = { 0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2, 0x6e, 0xba, 0xae,
167                             0x4a, 0xa1, 0xf9, 0x51, 0x29, 0xe5, 0xe5, 0x46, 0x70, 0xf1 },
168                 .np     = 2,
169                 .tap    = { 28, 28 }
170         }
171 };
172
173 /*
174  * SHA256 test vectors from from NIST
175  */
176 #define SHA256_TEST_VECTORS     2
177
178 struct hash_testvec sha256_tv_template[] = {    
179         { 
180                 .plaintext = "abc",
181                 .psize  = 3,
182                 .digest = { 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
183                             0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
184                             0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
185                             0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad },
186         }, {
187                 .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
188                 .psize  = 56,
189                 .digest = { 0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
190                             0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
191                             0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
192                             0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1 },
193                 .np     = 2,
194                 .tap    = { 28, 28 }
195         },
196 };
197
198 /*
199  * SHA384 test vectors from from NIST and kerneli
200  */
201 #define SHA384_TEST_VECTORS     4
202
203 struct hash_testvec sha384_tv_template[] = {
204         { 
205                 .plaintext= "abc",
206                 .psize  = 3,
207                 .digest = { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
208                             0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
209                             0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
210                             0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
211                             0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
212                             0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7 },
213         }, {
214                 .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
215                 .psize  = 56,
216                 .digest = { 0x33, 0x91, 0xfd, 0xdd, 0xfc, 0x8d, 0xc7, 0x39,
217                             0x37, 0x07, 0xa6, 0x5b, 0x1b, 0x47, 0x09, 0x39,
218                             0x7c, 0xf8, 0xb1, 0xd1, 0x62, 0xaf, 0x05, 0xab,
219                             0xfe, 0x8f, 0x45, 0x0d, 0xe5, 0xf3, 0x6b, 0xc6,
220                             0xb0, 0x45, 0x5a, 0x85, 0x20, 0xbc, 0x4e, 0x6f,
221                             0x5f, 0xe9, 0x5b, 0x1f, 0xe3, 0xc8, 0x45, 0x2b},
222         }, {
223                 .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
224                              "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
225                 .psize  = 112,
226                 .digest = { 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
227                             0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
228                             0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
229                             0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
230                             0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
231                             0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39  },
232         }, {
233                 .plaintext = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"
234                              "efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
235                 .psize  = 104,
236                 .digest = { 0x3d, 0x20, 0x89, 0x73, 0xab, 0x35, 0x08, 0xdb,
237                             0xbd, 0x7e, 0x2c, 0x28, 0x62, 0xba, 0x29, 0x0a,
238                             0xd3, 0x01, 0x0e, 0x49, 0x78, 0xc1, 0x98, 0xdc,
239                             0x4d, 0x8f, 0xd0, 0x14, 0xe5, 0x82, 0x82, 0x3a,
240                             0x89, 0xe1, 0x6f, 0x9b, 0x2a, 0x7b, 0xbc, 0x1a,
241                             0xc9, 0x38, 0xe2, 0xd1, 0x99, 0xe8, 0xbe, 0xa4 },
242                 .np     = 4,
243                 .tap    = { 26, 26, 26, 26 }
244         },
245 };
246
247 /*
248  * SHA512 test vectors from from NIST and kerneli
249  */
250 #define SHA512_TEST_VECTORS     4
251
252 struct hash_testvec sha512_tv_template[] = {
253         { 
254                 .plaintext = "abc",
255                 .psize  = 3,
256                 .digest = { 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
257                             0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
258                             0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
259                             0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
260                             0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
261                             0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
262                             0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
263                             0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f },
264         }, {
265                 .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
266                 .psize  = 56,
267                 .digest = { 0x20, 0x4a, 0x8f, 0xc6, 0xdd, 0xa8, 0x2f, 0x0a,
268                             0x0c, 0xed, 0x7b, 0xeb, 0x8e, 0x08, 0xa4, 0x16,
269                             0x57, 0xc1, 0x6e, 0xf4, 0x68, 0xb2, 0x28, 0xa8,
270                             0x27, 0x9b, 0xe3, 0x31, 0xa7, 0x03, 0xc3, 0x35,
271                             0x96, 0xfd, 0x15, 0xc1, 0x3b, 0x1b, 0x07, 0xf9,
272                             0xaa, 0x1d, 0x3b, 0xea, 0x57, 0x78, 0x9c, 0xa0,
273                             0x31, 0xad, 0x85, 0xc7, 0xa7, 0x1d, 0xd7, 0x03,
274                             0x54, 0xec, 0x63, 0x12, 0x38, 0xca, 0x34, 0x45 },
275         }, {
276                 .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
277                              "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
278                 .psize  = 112,
279                 .digest = { 0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
280                             0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
281                             0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
282                             0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
283                             0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
284                             0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
285                             0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
286                             0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09 },
287         }, {
288                 .plaintext = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd"
289                              "efghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
290                 .psize  = 104,
291                 .digest = { 0x93, 0x0d, 0x0c, 0xef, 0xcb, 0x30, 0xff, 0x11,
292                             0x33, 0xb6, 0x89, 0x81, 0x21, 0xf1, 0xcf, 0x3d,
293                             0x27, 0x57, 0x8a, 0xfc, 0xaf, 0xe8, 0x67, 0x7c,
294                             0x52, 0x57, 0xcf, 0x06, 0x99, 0x11, 0xf7, 0x5d,
295                             0x8f, 0x58, 0x31, 0xb5, 0x6e, 0xbf, 0xda, 0x67,
296                             0xb2, 0x78, 0xe6, 0x6d, 0xff, 0x8b, 0x84, 0xfe,
297                             0x2b, 0x28, 0x70, 0xf7, 0x42, 0xa5, 0x80, 0xd8,
298                             0xed, 0xb4, 0x19, 0x87, 0x23, 0x28, 0x50, 0xc9 },
299                 .np     = 4,
300                 .tap    = { 26, 26, 26, 26 }
301         },
302 };
303
304 #ifdef CONFIG_CRYPTO_HMAC
305 /*
306  * HMAC-MD5 test vectors from RFC2202
307  * (These need to be fixed to not use strlen).
308  */
309 #define HMAC_MD5_TEST_VECTORS   7
310
311 struct hmac_testvec hmac_md5_tv_template[] =
312 {       
313         {
314                 .key    = { [0 ... 15] =  0x0b },
315                 .ksize  = 16,
316                 .plaintext = "Hi There",
317                 .psize  = 8,
318                 .digest = { 0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c,
319                             0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d },
320         }, {
321                 .key    = { 'J', 'e', 'f', 'e' },
322                 .ksize  = 4,
323                 .plaintext = "what do ya want for nothing?",
324                 .psize  = 28,
325                 .digest = { 0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03,
326                             0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38 },
327                 .np     = 2,
328                 .tap    = {14, 14}
329         }, {
330                 .key    = { [0 ... 15] = 0xaa },
331                 .ksize  = 16,
332                 .plaintext = { [0 ... 49] =  0xdd },
333                 .psize  = 50,
334                 .digest = { 0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88,
335                             0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 },
336         }, {
337                 .key    = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
338                             0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
339                             0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, },
340                 .ksize  = 25,
341                 .plaintext = { [0 ... 49] =  0xcd },
342                 .psize  = 50,
343                 .digest = { 0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea,
344                             0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79 },
345         }, {
346                 .key    = { [0 ... 15] = 0x0c },
347                 .ksize  = 16,
348                 .plaintext = "Test With Truncation",
349                 .psize  = 20,
350                 .digest = { 0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00,
351                             0xf9, 0xba, 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c },
352         }, {
353                 .key    = { [0 ... 79] =  0xaa },
354                 .ksize  = 80,
355                 .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
356                 .psize  = 54,
357                 .digest = { 0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f,
358                             0x0b, 0x62, 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd },
359         }, {
360                 .key    = { [0 ... 79] =  0xaa },
361                 .ksize  = 80,
362                 .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One "
363                              "Block-Size Data",
364                 .psize  = 73,
365                 .digest = { 0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee,
366                             0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e },
367         },
368 };
369
370 /*
371  * HMAC-SHA1 test vectors from RFC2202
372  */
373 #define HMAC_SHA1_TEST_VECTORS  7
374
375 struct hmac_testvec hmac_sha1_tv_template[] = { 
376         {
377                 .key    = { [0 ... 19] = 0x0b },
378                 .ksize  = 20,
379                 .plaintext = "Hi There",
380                 .psize  = 8,
381                 .digest = { 0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64,
382                             0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, 0xf1,
383                             0x46, 0xbe },
384         }, {
385                 .key    = { 'J', 'e', 'f', 'e' },               
386                 .ksize  = 4,
387                 .plaintext = "what do ya want for nothing?",
388                 .psize  = 28,
389                 .digest = { 0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, 0x2f, 0xa2, 0xd2, 0x74, 
390                             0x16, 0xd5, 0xf1, 0x84, 0xdf, 0x9c, 0x25, 0x9a, 0x7c, 0x79 },
391                 .np     = 2,
392                 .tap    = { 14, 14 }
393         }, {
394                 .key    = { [0 ... 19] = 0xaa },
395                 .ksize  = 20,
396                 .plaintext = { [0 ... 49] = 0xdd },
397                 .psize  = 50,
398                 .digest = { 0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, 0x11, 0xcd, 0x91, 0xa3, 
399                             0x9a, 0xf4, 0x8a, 0xa1, 0x7b, 0x4f, 0x63, 0xf1, 0x75, 0xd3 },
400         }, {
401                 .key    = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
402                             0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 
403                             0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 },
404                 .ksize  = 25,
405                 .plaintext = { [0 ... 49] = 0xcd },
406                 .psize  = 50,
407                 .digest = { 0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62, 0x50, 0xc6, 0xbc, 0x84, 
408                             0x14, 0xf9, 0xbf, 0x50, 0xc8, 0x6c, 0x2d, 0x72, 0x35, 0xda },
409         }, {
410                 .key    = { [0 ... 19] = 0x0c },
411                 .ksize  = 20,
412                 .plaintext = "Test With Truncation",
413                 .psize  = 20,
414                 .digest = { 0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55, 0xe0, 0x7f, 0xe7, 0xf2, 
415                             0x7b, 0xe1, 0xd5, 0x8b, 0xb9, 0x32, 0x4a, 0x9a, 0x5a, 0x04 },
416         }, {
417                 .key    = { [0 ... 79] = 0xaa },
418                 .ksize  = 80,
419                 .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
420                 .psize  = 54,
421                 .digest = { 0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72, 0xd0, 0x0e, 0x95, 0x70, 
422                             0x56, 0x37, 0xce, 0x8a, 0x3b, 0x55, 0xed, 0x40, 0x21, 0x12 },
423         }, {
424                 .key    = { [0 ... 79] = 0xaa },
425                 .ksize  = 80,
426                 .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One "
427                              "Block-Size Data",
428                 .psize  = 73,
429                 .digest = { 0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d, 0x6b, 
430                             0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91 },
431         },
432 };
433
434 /*
435  * HMAC-SHA256 test vectors from
436  * draft-ietf-ipsec-ciph-sha-256-01.txt
437  */
438 #define HMAC_SHA256_TEST_VECTORS        10
439
440 struct hmac_testvec hmac_sha256_tv_template[] = {
441         {
442                 .key    = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
443                             0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
444                             0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
445                             0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20},
446                 .ksize  = 32,
447                 .plaintext = "abc",
448                 .psize  = 3,
449                 .digest = { 0xa2, 0x1b, 0x1f, 0x5d, 0x4c, 0xf4, 0xf7, 0x3a,
450                             0x4d, 0xd9, 0x39, 0x75, 0x0f, 0x7a, 0x06, 0x6a,
451                             0x7f, 0x98, 0xcc, 0x13, 0x1c, 0xb1, 0x6a, 0x66,
452                             0x92, 0x75, 0x90, 0x21, 0xcf, 0xab, 0x81, 0x81 },
453         }, {
454                 .key    = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
455                             0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
456                             0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
457                             0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 },
458                 .ksize  = 32,
459                 .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
460                 .psize  = 56,
461                 .digest = { 0x10, 0x4f, 0xdc, 0x12, 0x57, 0x32, 0x8f, 0x08,
462                             0x18, 0x4b, 0xa7, 0x31, 0x31, 0xc5, 0x3c, 0xae,
463                             0xe6, 0x98, 0xe3, 0x61, 0x19, 0x42, 0x11, 0x49,
464                             0xea, 0x8c, 0x71, 0x24, 0x56, 0x69, 0x7d, 0x30 },
465         }, {
466                 .key    = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
467                             0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
468                             0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
469                             0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 },
470                 .ksize  = 32,
471                 .plaintext = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
472                              "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
473                 .psize  = 112,
474                 .digest = { 0x47, 0x03, 0x05, 0xfc, 0x7e, 0x40, 0xfe, 0x34,
475                             0xd3, 0xee, 0xb3, 0xe7, 0x73, 0xd9, 0x5a, 0xab,
476                             0x73, 0xac, 0xf0, 0xfd, 0x06, 0x04, 0x47, 0xa5,
477                             0xeb, 0x45, 0x95, 0xbf, 0x33, 0xa9, 0xd1, 0xa3 },
478         }, {
479                 .key    = { [0 ... 31] = 0x0b },
480                 .ksize  = 32,
481                 .plaintext = "Hi There",
482                 .psize  = 8,
483                 .digest = { 0x19, 0x8a, 0x60, 0x7e, 0xb4, 0x4b, 0xfb, 0xc6,
484                             0x99, 0x03, 0xa0, 0xf1, 0xcf, 0x2b, 0xbd, 0xc5,
485                             0xba, 0x0a, 0xa3, 0xf3, 0xd9, 0xae, 0x3c, 0x1c,
486                             0x7a, 0x3b, 0x16, 0x96, 0xa0, 0xb6, 0x8c, 0xf7 },
487         }, {
488                 .key    = "Jefe",
489                 .ksize  = 4,
490                 .plaintext = "what do ya want for nothing?",
491                 .psize  = 28,
492                 .digest = { 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e,
493                             0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7,
494                             0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83,
495                             0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43 },
496                 .np     = 2,
497                 .tap    = { 14, 14 }
498         }, {
499                 .key    = { [0 ... 31] = 0xaa },
500                 .ksize  = 32,
501                 .plaintext = { [0 ... 49] = 0xdd },
502                 .psize  = 50,
503                 .digest = { 0xcd, 0xcb, 0x12, 0x20, 0xd1, 0xec, 0xcc, 0xea,
504                             0x91, 0xe5, 0x3a, 0xba, 0x30, 0x92, 0xf9, 0x62,
505                             0xe5, 0x49, 0xfe, 0x6c, 0xe9, 0xed, 0x7f, 0xdc,
506                             0x43, 0x19, 0x1f, 0xbd, 0xe4, 0x5c, 0x30, 0xb0 },
507         }, {
508                 .key    = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
509                             0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
510                             0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
511                             0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
512                             0x21, 0x22, 0x23, 0x24, 0x25 },
513                 .ksize  = 37,
514                 .plaintext = { [0 ... 49] = 0xcd },
515                 .psize  = 50,
516                 .digest = { 0xd4, 0x63, 0x3c, 0x17, 0xf6, 0xfb, 0x8d, 0x74,
517                             0x4c, 0x66, 0xde, 0xe0, 0xf8, 0xf0, 0x74, 0x55,
518                             0x6e, 0xc4, 0xaf, 0x55, 0xef, 0x07, 0x99, 0x85,
519                             0x41, 0x46, 0x8e, 0xb4, 0x9b, 0xd2, 0xe9, 0x17 },
520         }, {
521                 .key    = { [0 ... 31] = 0x0c },
522                 .ksize  = 32,
523                 .plaintext = "Test With Truncation",
524                 .psize  = 20,
525                 .digest = { 0x75, 0x46, 0xaf, 0x01, 0x84, 0x1f, 0xc0, 0x9b,
526                             0x1a, 0xb9, 0xc3, 0x74, 0x9a, 0x5f, 0x1c, 0x17,
527                             0xd4, 0xf5, 0x89, 0x66, 0x8a, 0x58, 0x7b, 0x27,
528                             0x00, 0xa9, 0xc9, 0x7c, 0x11, 0x93, 0xcf, 0x42 },
529         }, {
530                 .key    = { [0 ... 79] = 0xaa },
531                 .ksize  = 80,
532                 .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First",
533                 .psize  = 54,
534                 .digest = { 0x69, 0x53, 0x02, 0x5e, 0xd9, 0x6f, 0x0c, 0x09,
535                             0xf8, 0x0a, 0x96, 0xf7, 0x8e, 0x65, 0x38, 0xdb,
536                             0xe2, 0xe7, 0xb8, 0x20, 0xe3, 0xdd, 0x97, 0x0e,
537                             0x7d, 0xdd, 0x39, 0x09, 0x1b, 0x32, 0x35, 0x2f },
538         }, {
539                 .key    = { [0 ... 79] = 0xaa },
540                 .ksize  = 80,
541                 .plaintext = "Test Using Larger Than Block-Size Key and Larger Than "
542                              "One Block-Size Data",
543                 .psize  = 73,
544                 .digest = { 0x63, 0x55, 0xac, 0x22, 0xe8, 0x90, 0xd0, 0xa3,
545                             0xc8, 0x48, 0x1a, 0x5c, 0xa4, 0x82, 0x5b, 0xc8,
546                             0x84, 0xd3, 0xe7, 0xa1, 0xff, 0x98, 0xa2, 0xfc,
547                             0x2a, 0xc7, 0xd8, 0xe0, 0x64, 0xc3, 0xb2, 0xe6 },
548         },
549 };
550
551 #endif  /* CONFIG_CRYPTO_HMAC */
552
553 /*
554  * DES test vectors.
555  */
556 #define DES_ENC_TEST_VECTORS            10
557 #define DES_DEC_TEST_VECTORS            4
558 #define DES_CBC_ENC_TEST_VECTORS        5
559 #define DES_CBC_DEC_TEST_VECTORS        4
560 #define DES3_EDE_ENC_TEST_VECTORS       3
561 #define DES3_EDE_DEC_TEST_VECTORS       3
562
563 struct cipher_testvec des_enc_tv_template[] = {
564         { /* From Applied Cryptography */
565                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
566                 .klen   = 8,
567                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7 },
568                 .ilen   = 8,
569                 .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d },
570                 .rlen   = 8,
571         }, { /* Same key, different plaintext block */
572                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
573                 .klen   = 8,
574                 .input  = { 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 },
575                 .ilen   = 8,
576                 .result = { 0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b },
577                 .rlen   = 8,
578         }, { /* Sbox test from NBS */
579                 .key    = { 0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57 },
580                 .klen   = 8,
581                 .input  = { 0x01, 0xa1, 0xd6, 0xd0, 0x39, 0x77, 0x67, 0x42 },
582                 .ilen   = 8,
583                 .result = { 0x69, 0x0f, 0x5b, 0x0d, 0x9a, 0x26, 0x93, 0x9b },
584                 .rlen   = 8,
585         }, { /* Three blocks */
586                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
587                 .klen   = 8,
588                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7,
589                             0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
590                             0xca, 0xfe, 0xba, 0xbe, 0xfe, 0xed, 0xbe, 0xef },
591                 .ilen   = 24,
592                 .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d,
593                             0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b,
594                             0xb4, 0x99, 0x26, 0xf7, 0x1f, 0xe1, 0xd4, 0x90 },
595                 .rlen   = 24,
596         }, { /* Weak key */
597                 .fail   = 1,
598                 .wk     = 1,
599                 .key    = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
600                 .klen   = 8,
601                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7 },
602                 .ilen   = 8,
603                 .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d },
604                 .rlen   = 8,
605         }, { /* Two blocks -- for testing encryption across pages */
606                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
607                 .klen   = 8,
608                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7,
609                             0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 },
610                 .ilen   = 16,
611                 .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d,
612                             0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b },
613                 .rlen   = 16,
614                 .np     = 2,
615                 .tap    = { 8, 8 }
616         }, { /* Four blocks -- for testing encryption with chunking */
617                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
618                 .klen   = 8,
619                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7,
620                             0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
621                             0xca, 0xfe, 0xba, 0xbe, 0xfe, 0xed, 0xbe, 0xef,
622                             0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 },
623                 .ilen   = 32,
624                 .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d,
625                             0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b,
626                             0xb4, 0x99, 0x26, 0xf7, 0x1f, 0xe1, 0xd4, 0x90,
627                             0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b },
628                 .rlen   = 32,
629                 .np     = 3,
630                 .tap    = { 14, 10, 8 } 
631         }, {
632                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
633                 .klen   = 8,
634                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7,
635                             0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
636                             0xca, 0xfe, 0xba, 0xbe, 0xfe, 0xed, 0xbe, 0xef },
637                 .ilen   = 24,
638                 .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d,
639                             0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b,
640                             0xb4, 0x99, 0x26, 0xf7, 0x1f, 0xe1, 0xd4, 0x90 },
641                 .rlen   = 24,
642                 .np     = 4,
643                 .tap    = { 2, 1, 3, 18 } 
644         }, {
645                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
646                 .klen   = 8,
647                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7,
648                             0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 },
649                 .ilen   = 16,
650                 .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d,
651                             0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b },
652                 .rlen   = 16,
653                 .np     = 5,
654                 .tap    = { 2, 2, 2, 2, 8 } 
655         }, {
656                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
657                 .klen   = 8,
658                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7 },
659                 .ilen   = 8,
660                 .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d },
661                 .rlen   = 8,
662                 .np     = 8,
663                 .tap    = { 1, 1, 1, 1, 1, 1, 1, 1 } 
664         },
665 };
666
667 struct cipher_testvec des_dec_tv_template[] = {
668         { /* From Applied Cryptography */
669                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
670                 .klen   = 8,
671                 .input  = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d },
672                 .ilen   = 8,
673                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7 },
674                 .rlen   = 8,
675         }, { /* Sbox test from NBS */
676                 .key    = { 0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57 },           
677                 .klen   = 8,
678                 .input  = { 0x69, 0x0f, 0x5b, 0x0d, 0x9a, 0x26, 0x93, 0x9b },
679                 .ilen   = 8,
680                 .result = { 0x01, 0xa1, 0xd6, 0xd0, 0x39, 0x77, 0x67, 0x42 },
681                 .rlen   = 8,
682         }, { /* Two blocks, for chunking test */
683                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
684                 .klen   = 8,
685                 .input  = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d,
686                             0x69, 0x0f, 0x5b, 0x0d, 0x9a, 0x26, 0x93, 0x9b },
687                 .ilen   = 16,
688                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7,
689                             0xa3, 0x99, 0x7b, 0xca, 0xaf, 0x69, 0xa0, 0xf5 },
690                 .rlen   = 16,
691                 .np     = 2,
692                 .tap    = { 8, 8 }
693         }, {
694                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
695                 .klen   = 8,
696                 .input  = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d,
697                             0x69, 0x0f, 0x5b, 0x0d, 0x9a, 0x26, 0x93, 0x9b },
698                 .ilen   = 16,
699                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7,
700                             0xa3, 0x99, 0x7b, 0xca, 0xaf, 0x69, 0xa0, 0xf5 },
701                 .rlen   = 16,
702                 .np     = 3,
703                 .tap    = { 3, 12, 1 }
704         },
705 };
706
707 struct cipher_testvec des_cbc_enc_tv_template[] = {
708         { /* From OpenSSL */
709                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef},
710                 .klen   = 8,
711                 .iv     = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10},            
712                 .input  = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, 
713                             0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, 
714                             0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, 
715                 .ilen   = 24,
716                 .result = { 0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4, 
717                             0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb, 
718                             0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68 }, 
719                 .rlen   = 24,
720         }, { /* FIPS Pub 81 */
721                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
722                 .klen   = 8,
723                 .iv     = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef },           
724                 .input  = { 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74 },
725                 .ilen   = 8,
726                 .result = { 0xe5, 0xc7, 0xcd, 0xde, 0x87, 0x2b, 0xf2, 0x7c },
727                 .rlen   = 8,
728         }, {
729                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
730                 .klen   = 8,
731                 .iv     = { 0xe5, 0xc7, 0xcd, 0xde, 0x87, 0x2b, 0xf2, 0x7c },
732                 .input  = { 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 },
733                 .ilen   = 8,
734                 .result = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f },
735                 .rlen   = 8,
736         }, {    
737                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
738                 .klen   = 8,
739                 .iv     = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f },
740                 .input  = { 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20 },
741                 .ilen   = 8,
742                 .result = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 },
743                 .rlen   = 8,
744         }, { /* Copy of openssl vector for chunk testing */     
745              /* From OpenSSL */
746                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef},
747                 .klen   = 8,
748                 .iv     = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10},            
749                 .input  = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, 
750                             0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, 
751                             0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, 
752                 .ilen   = 24,
753                 .result = { 0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4, 
754                             0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb, 
755                             0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68 }, 
756                 .rlen   = 24,
757                 .np     = 2,
758                 .tap    = { 13, 11 }
759         },
760 };
761
762 struct cipher_testvec des_cbc_dec_tv_template[] = {
763         { /* FIPS Pub 81 */
764                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
765                 .klen   = 8,
766                 .iv     = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef },
767                 .input  = { 0xe5, 0xc7, 0xcd, 0xde, 0x87, 0x2b, 0xf2, 0x7c },
768                 .ilen   = 8,
769                 .result = { 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74 },
770                 .rlen   = 8,
771         }, {
772                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
773                 .klen   = 8,
774                 .iv     = { 0xe5, 0xc7, 0xcd, 0xde, 0x87, 0x2b, 0xf2, 0x7c },           
775                 .input  = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f },
776                 .ilen   = 8,
777                 .result = { 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, 
778                 .rlen   = 8,
779         }, {
780                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
781                 .klen   = 8,
782                 .iv     = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f },
783                 .input  = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 }, 
784                 .ilen   = 8,
785                 .result = { 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20 },
786                 .rlen   = 8,
787         }, { /* Copy of above, for chunk testing */     
788                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
789                 .klen   = 8,
790                 .iv     = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f },
791                 .input  = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 }, 
792                 .ilen   = 8,
793                 .result = { 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20 },
794                 .rlen   = 8,
795                 .np     = 2,
796                 .tap    = { 4, 4 }
797         },
798 };
799
800 /*
801  * We really need some more test vectors, especially for DES3 CBC.
802  */
803 struct cipher_testvec des3_ede_enc_tv_template[] = {
804         { /* These are from openssl */
805                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
806                             0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
807                             0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10},
808                 .klen   = 24,
809                 .input  = { 0x73, 0x6f, 0x6d, 0x65, 0x64, 0x61, 0x74, 0x61 },
810                 .ilen   = 8,
811                 .result = { 0x18, 0xd7, 0x48, 0xe5, 0x63, 0x62, 0x05, 0x72 },
812                 .rlen   = 8,
813         }, {
814                 .key    = { 0x03, 0x52, 0x02, 0x07, 0x67, 0x20, 0x82, 0x17,
815                             0x86, 0x02, 0x87, 0x66, 0x59, 0x08, 0x21, 0x98,
816                             0x64, 0x05, 0x6a, 0xbd, 0xfe, 0xa9, 0x34, 0x57 },
817                 .klen   = 24,
818                 .input  = { 0x73, 0x71, 0x75, 0x69, 0x67, 0x67, 0x6c, 0x65 },
819                 .ilen   = 8,
820                 .result = { 0xc0, 0x7d, 0x2a, 0x0f, 0xa5, 0x66, 0xfa, 0x30 },
821                 .rlen   = 8,
822         }, {
823                 .key    = { 0x10, 0x46, 0x10, 0x34, 0x89, 0x98, 0x80, 0x20,
824                             0x91, 0x07, 0xd0, 0x15, 0x89, 0x19, 0x01, 0x01,
825                             0x19, 0x07, 0x92, 0x10, 0x98, 0x1a, 0x01, 0x01 },
826                 .klen   = 24,
827                 .input  = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
828                 .ilen   = 8,
829                 .result = { 0xe1, 0xef, 0x62, 0xc3, 0x32, 0xfe, 0x82, 0x5b },
830                 .rlen   = 8,
831         },
832 };
833
834 struct cipher_testvec des3_ede_dec_tv_template[] = {
835         { /* These are from openssl */
836                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
837                             0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
838                             0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10},
839                 .klen   = 24,
840                 .input  = { 0x18, 0xd7, 0x48, 0xe5, 0x63, 0x62, 0x05, 0x72 },
841                 .ilen   = 8,
842                 .result = { 0x73, 0x6f, 0x6d, 0x65, 0x64, 0x61, 0x74, 0x61 },
843                 .rlen   = 8,
844         }, {
845                 .key    = { 0x03, 0x52, 0x02, 0x07, 0x67, 0x20, 0x82, 0x17,
846                             0x86, 0x02, 0x87, 0x66, 0x59, 0x08, 0x21, 0x98,
847                             0x64, 0x05, 0x6a, 0xbd, 0xfe, 0xa9, 0x34, 0x57 },
848                 .klen   = 24,
849                 .input  = { 0xc0, 0x7d, 0x2a, 0x0f, 0xa5, 0x66, 0xfa, 0x30 },
850                 .ilen   = 8,
851                 .result = { 0x73, 0x71, 0x75, 0x69, 0x67, 0x67, 0x6c, 0x65 },
852                 .rlen   = 8,
853         }, {
854                 .key    = { 0x10, 0x46, 0x10, 0x34, 0x89, 0x98, 0x80, 0x20,
855                             0x91, 0x07, 0xd0, 0x15, 0x89, 0x19, 0x01, 0x01,
856                             0x19, 0x07, 0x92, 0x10, 0x98, 0x1a, 0x01, 0x01 },
857                 .klen   = 24,
858                 .input  = { 0xe1, 0xef, 0x62, 0xc3, 0x32, 0xfe, 0x82, 0x5b },
859                 .ilen   = 8,
860                 .result = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
861                 .rlen   = 8,
862         },
863 };
864
865 /*
866  * Blowfish test vectors.
867  */
868 #define BF_ENC_TEST_VECTORS     6
869 #define BF_DEC_TEST_VECTORS     6
870 #define BF_CBC_ENC_TEST_VECTORS 1
871 #define BF_CBC_DEC_TEST_VECTORS 1
872
873 struct cipher_testvec bf_enc_tv_template[] = {
874         { /* DES test vectors from OpenSSL */
875                 .key    = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
876                 .klen   = 8,
877                 .input  = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
878                 .ilen   = 8,
879                 .result = { 0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78 },
880                 .rlen   = 8,
881         }, {
882                 .key    = { 0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e },
883                 .klen   = 8,
884                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
885                 .ilen   = 8,
886                 .result = { 0xa7, 0x90, 0x79, 0x51, 0x08, 0xea, 0x3c, 0xae },
887                 .rlen   = 8,
888         }, {
889                 .key    = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 },
890                 .klen   = 8,
891                 .input  = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
892                 .ilen   = 8,
893                 .result = { 0xe8, 0x7a, 0x24, 0x4e, 0x2c, 0xc8, 0x5e, 0x82 },
894                 .rlen   = 8,
895         }, { /* Vary the keylength... */        
896                 .key    = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
897                             0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f },
898                 .klen   = 16,
899                 .input  = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
900                 .ilen   = 8,
901                 .result = { 0x93, 0x14, 0x28, 0x87, 0xee, 0x3b, 0xe1, 0x5c },
902                 .rlen   = 8,
903         }, {
904                 .key    = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
905                             0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f,
906                             0x00, 0x11, 0x22, 0x33, 0x44 },
907                 .klen   = 21,
908                 .input  = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
909                 .ilen   = 8,
910                 .result = { 0xe6, 0xf5, 0x1e, 0xd7, 0x9b, 0x9d, 0xb2, 0x1f },
911                 .rlen   = 8,
912         }, { /* Generated with bf488 */
913                 .key    = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
914                             0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f,
915                             0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
916                             0x04, 0x68, 0x91, 0x04, 0xc2, 0xfd, 0x3b, 0x2f, 
917                             0x58, 0x40, 0x23, 0x64, 0x1a, 0xba, 0x61, 0x76, 
918                             0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e, 
919                             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
920                 .klen   = 56,
921                 .input  = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
922                 .ilen   = 8,
923                 .result = { 0xc0, 0x45, 0x04, 0x01, 0x2e, 0x4e, 0x1f, 0x53 },
924                 .rlen   = 8,
925         },
926 };
927
928 struct cipher_testvec bf_dec_tv_template[] = {
929         { /* DES test vectors from OpenSSL */
930                 .key    = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
931                 .klen   = 8,
932                 .input  = { 0x4e, 0xf9, 0x97, 0x45, 0x61, 0x98, 0xdd, 0x78 },
933                 .ilen   = 8,
934                 .result = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
935                 .rlen   = 8,
936         }, {
937                 .key    = { 0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e },
938                 .klen   = 8,
939                 .input  = { 0xa7, 0x90, 0x79, 0x51, 0x08, 0xea, 0x3c, 0xae },
940                 .ilen   = 8,
941                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
942                 .rlen   = 8,
943         }, {
944                 .key    = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 },
945                 .klen   = 8,
946                 .input  = { 0xe8, 0x7a, 0x24, 0x4e, 0x2c, 0xc8, 0x5e, 0x82 },
947                 .ilen   = 8,
948                 .result = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
949                 .rlen   = 8,
950         }, { /* Vary the keylength... */        
951                 .key    = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
952                             0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f },
953                 .klen   = 16,
954                 .input  = { 0x93, 0x14, 0x28, 0x87, 0xee, 0x3b, 0xe1, 0x5c },
955                 .ilen   = 8,
956                 .result = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
957                 .rlen   = 8,
958         }, {
959                 .key    = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
960                             0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f,
961                             0x00, 0x11, 0x22, 0x33, 0x44 },
962                 .klen   = 21,
963                 .input  = { 0xe6, 0xf5, 0x1e, 0xd7, 0x9b, 0x9d, 0xb2, 0x1f },
964                 .ilen   = 8,
965                 .result = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
966                 .rlen   = 8,
967         }, { /* Generated with bf488, using OpenSSL, Libgcrypt and Nettle */
968                 .key    = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
969                             0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f,
970                             0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
971                             0x04, 0x68, 0x91, 0x04, 0xc2, 0xfd, 0x3b, 0x2f, 
972                             0x58, 0x40, 0x23, 0x64, 0x1a, 0xba, 0x61, 0x76, 
973                             0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e, 
974                             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
975                 .klen   = 56,
976                 .input  = { 0xc0, 0x45, 0x04, 0x01, 0x2e, 0x4e, 0x1f, 0x53 },
977                 .ilen   = 8,
978                 .result = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },
979                 .rlen   = 8,
980         },
981 };
982
983 struct cipher_testvec bf_cbc_enc_tv_template[] = {
984         { /* From OpenSSL */
985                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
986                             0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 },
987                 .klen   = 16,
988                 .iv     = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },           
989                 .input  = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
990                             0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
991                             0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
992                             0x66, 0x6f, 0x72, 0x20, 0x00, 0x00, 0x00, 0x00 },
993                 .ilen   = 32,
994                 .result = { 0x6b, 0x77, 0xb4, 0xd6, 0x30, 0x06, 0xde, 0xe6,
995                             0x05, 0xb1, 0x56, 0xe2, 0x74, 0x03, 0x97, 0x93,
996                             0x58, 0xde, 0xb9, 0xe7, 0x15, 0x46, 0x16, 0xd9,
997                             0x59, 0xf1, 0x65, 0x2b, 0xd5, 0xff, 0x92, 0xcc },
998                 .rlen   = 32,
999         },
1000 };
1001
1002 struct cipher_testvec bf_cbc_dec_tv_template[] = {
1003         { /* From OpenSSL */
1004                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1005                             0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 },
1006                 .klen   = 16,
1007                 .iv     = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 },           
1008                 .input  = { 0x6b, 0x77, 0xb4, 0xd6, 0x30, 0x06, 0xde, 0xe6,
1009                             0x05, 0xb1, 0x56, 0xe2, 0x74, 0x03, 0x97, 0x93,
1010                             0x58, 0xde, 0xb9, 0xe7, 0x15, 0x46, 0x16, 0xd9,
1011                             0x59, 0xf1, 0x65, 0x2b, 0xd5, 0xff, 0x92, 0xcc },
1012                 .ilen   = 32,
1013                 .result = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
1014                             0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
1015                             0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
1016                             0x66, 0x6f, 0x72, 0x20, 0x00, 0x00, 0x00, 0x00 },
1017                 .rlen   = 32,
1018         },
1019 };
1020
1021 /*
1022  * Twofish test vectors.
1023  */
1024 #define TF_ENC_TEST_VECTORS             3
1025 #define TF_DEC_TEST_VECTORS             3
1026 #define TF_CBC_ENC_TEST_VECTORS         4
1027 #define TF_CBC_DEC_TEST_VECTORS         4
1028
1029 struct cipher_testvec tf_enc_tv_template[] = {
1030         {
1031                 .key    = { [0 ... 15] = 0x00 },
1032                 .klen   = 16,
1033                 .input  = { [0 ... 15] = 0x00 },
1034                 .ilen   = 16,
1035                 .result = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32,
1036                             0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a },
1037                 .rlen   = 16,
1038         }, {
1039                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1040                             0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
1041                             0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
1042                 .klen   = 24,
1043                 .input  = { [0 ... 15] = 0x00 },
1044                 .ilen   = 16,
1045                 .result = { 0xcf, 0xd1, 0xd2, 0xe5, 0xa9, 0xbe, 0x9c, 0xdf,
1046                             0x50, 0x1f, 0x13, 0xb8, 0x92, 0xbd, 0x22, 0x48 },
1047                 .rlen   = 16,
1048         }, {
1049                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1050                             0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
1051                             0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
1052                             0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
1053                 .klen   = 32,
1054                 .input  = { [0 ... 15] = 0x00 },
1055                 .ilen   = 16,
1056                 .result = { 0x37, 0x52, 0x7b, 0xe0, 0x05, 0x23, 0x34, 0xb8,
1057                             0x9f, 0x0c, 0xfc, 0xca, 0xe8, 0x7c, 0xfa, 0x20 },
1058                 .rlen   = 16,
1059         },
1060 };
1061
1062 struct cipher_testvec tf_dec_tv_template[] = {
1063         {
1064                 .key    = { [0 ... 15] = 0x00 },
1065                 .klen   = 16,
1066                 .input  = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32,
1067                             0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a },
1068                 .ilen   = 16,
1069                 .result = { [0 ... 15] = 0x00 },
1070                 .rlen   = 16,
1071         }, {
1072                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1073                             0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
1074                             0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 },
1075                 .klen   = 24,
1076                 .input  = { 0xcf, 0xd1, 0xd2, 0xe5, 0xa9, 0xbe, 0x9c, 0xdf,
1077                             0x50, 0x1f, 0x13, 0xb8, 0x92, 0xbd, 0x22, 0x48 },
1078                 .ilen   = 16,
1079                 .result = { [0 ... 15] = 0x00 },
1080                 .rlen   = 16,
1081         }, {
1082                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
1083                             0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
1084                             0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
1085                             0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
1086                 .klen   = 32,
1087                 .input  = { 0x37, 0x52, 0x7b, 0xe0, 0x05, 0x23, 0x34, 0xb8,
1088                             0x9f, 0x0c, 0xfc, 0xca, 0xe8, 0x7c, 0xfa, 0x20 },
1089                 .ilen   = 16,
1090                 .result = { [0 ... 15] = 0x00 },
1091                 .rlen   = 16,
1092         },
1093 };
1094
1095 struct cipher_testvec tf_cbc_enc_tv_template[] = {
1096         { /* Generated with Nettle */
1097                 .key    = { [0 ... 15] = 0x00 },
1098                 .klen   = 16,
1099                 .iv     = { [0 ... 15] = 0x00 },
1100                 .input  = { [0 ... 15] = 0x00 },
1101                 .ilen   = 16,
1102                 .result = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32,
1103                             0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a },
1104                 .rlen   = 16,
1105         }, {
1106                 .key    = { [0 ... 15] = 0x00 },
1107                 .klen   = 16,
1108                 .iv     = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32,
1109                             0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a },           
1110                 .input  = { [0 ... 15] = 0x00 },
1111                 .ilen   = 16,
1112                 .result = { 0xd4, 0x91, 0xdb, 0x16, 0xe7, 0xb1, 0xc3, 0x9e,
1113                             0x86, 0xcb, 0x08, 0x6b, 0x78, 0x9f, 0x54, 0x19 },
1114                 .rlen   = 16,
1115         }, {
1116                 .key    = { [0 ... 15] = 0x00 },
1117                 .klen   = 16,
1118                 .iv     = { 0xd4, 0x91, 0xdb, 0x16, 0xe7, 0xb1, 0xc3, 0x9e,
1119                             0x86, 0xcb, 0x08, 0x6b, 0x78, 0x9f, 0x54, 0x19 },
1120                 .input  = { [0 ... 15] = 0x00 },
1121                 .ilen   = 16,
1122                 .result = { 0x05, 0xef, 0x8c, 0x61, 0xa8, 0x11, 0x58, 0x26,
1123                             0x34, 0xba, 0x5c, 0xb7, 0x10, 0x6a, 0xa6, 0x41 },
1124                 .rlen   = 16,
1125         }, {
1126                 .key    = { [0 ... 15] = 0x00 },
1127                 .klen   = 16,
1128                 .iv     = { [0 ... 15] = 0x00 },
1129                 .input  = { [0 ... 47] = 0x00 },
1130                 .ilen   = 48,
1131                 .result = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32,
1132                             0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a,
1133                             0xd4, 0x91, 0xdb, 0x16, 0xe7, 0xb1, 0xc3, 0x9e,
1134                             0x86, 0xcb, 0x08, 0x6b, 0x78, 0x9f, 0x54, 0x19,
1135                             0x05, 0xef, 0x8c, 0x61, 0xa8, 0x11, 0x58, 0x26,
1136                             0x34, 0xba, 0x5c, 0xb7, 0x10, 0x6a, 0xa6, 0x41 },
1137                 .rlen   = 48,
1138         },
1139 };
1140
1141 struct cipher_testvec tf_cbc_dec_tv_template[] = {
1142         { /* Reverse of the first four above */
1143                 .key    = { [0 ... 15] = 0x00 },
1144                 .klen   = 16,
1145                 .iv     = { [0 ... 15] = 0x00 },
1146                 .input  = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32,
1147                             0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a },             
1148                 .ilen   = 16,
1149                 .result = { [0 ... 15] = 0x00 },
1150                 .rlen   = 16,
1151         }, {
1152                 .key    = { [0 ... 15] = 0x00 },
1153                 .klen   = 16,
1154                 .iv     = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32,
1155                             0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a },
1156                 .input  = { 0xd4, 0x91, 0xdb, 0x16, 0xe7, 0xb1, 0xc3, 0x9e,
1157                             0x86, 0xcb, 0x08, 0x6b, 0x78, 0x9f, 0x54, 0x19 },
1158                 .ilen   = 16,
1159                 .result = { [0 ... 15] = 0x00 },
1160                 .rlen   = 16,
1161         }, {
1162                 .key    = { [0 ... 15] = 0x00 },
1163                 .klen   = 16,
1164                 .iv     = { 0xd4, 0x91, 0xdb, 0x16, 0xe7, 0xb1, 0xc3, 0x9e,
1165                             0x86, 0xcb, 0x08, 0x6b, 0x78, 0x9f, 0x54, 0x19 },
1166                 .input  = { 0x05, 0xef, 0x8c, 0x61, 0xa8, 0x11, 0x58, 0x26,
1167                             0x34, 0xba, 0x5c, 0xb7, 0x10, 0x6a, 0xa6, 0x41 },
1168                 .ilen   = 16,
1169                 .result = { [0 ... 15] = 0x00 },
1170                 .rlen   = 16,
1171         }, {
1172                 .key    = { [0 ... 15] = 0x00 },
1173                 .klen   = 16,
1174                 .iv     = { [0 ... 15] = 0x00 },
1175                 .input  = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32,
1176                             0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a,
1177                             0xd4, 0x91, 0xdb, 0x16, 0xe7, 0xb1, 0xc3, 0x9e,
1178                             0x86, 0xcb, 0x08, 0x6b, 0x78, 0x9f, 0x54, 0x19,
1179                             0x05, 0xef, 0x8c, 0x61, 0xa8, 0x11, 0x58, 0x26,
1180                             0x34, 0xba, 0x5c, 0xb7, 0x10, 0x6a, 0xa6, 0x41 },
1181                 .ilen   = 48,
1182                 .result = { [0 ... 47] = 0x00 },
1183                 .rlen   = 48,
1184         },
1185 };
1186
1187 /*
1188  * Serpent test vectors.  These are backwards because Serpent writes
1189  * octect sequences in right-to-left mode.
1190  */
1191 #define SERPENT_ENC_TEST_VECTORS        4
1192 #define SERPENT_DEC_TEST_VECTORS        4
1193
1194 struct cipher_testvec serpent_enc_tv_template[] = 
1195 {
1196         {
1197                 .input  = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1198                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1199                 .ilen   = 16,
1200                 .result = { 0x12, 0x07, 0xfc, 0xce, 0x9b, 0xd0, 0xd6, 0x47,
1201                             0x6a, 0xe9, 0x8f, 0xbe, 0xd1, 0x43, 0xa0, 0xe2 },
1202                 .rlen   = 16,
1203         }, {
1204                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1205                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1206                 .klen   = 16,
1207                 .input  = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1208                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1209                 .ilen   = 16,
1210                 .result = { 0x4c, 0x7d, 0x8a, 0x32, 0x80, 0x72, 0xa2, 0x2c,
1211                             0x82, 0x3e, 0x4a, 0x1f, 0x3a, 0xcd, 0xa1, 0x6d },
1212                 .rlen   = 16,
1213         }, {
1214                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1215                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1216                             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1217                             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
1218                 .klen   = 32,
1219                 .input  = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1220                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1221                 .ilen   = 16,
1222                 .result = { 0xde, 0x26, 0x9f, 0xf8, 0x33, 0xe4, 0x32, 0xb8,
1223                             0x5b, 0x2e, 0x88, 0xd2, 0x70, 0x1c, 0xe7, 0x5c },
1224                 .rlen   = 16,
1225         }, {
1226                 .key    = { [15] = 0x80 },
1227                 .klen   = 16,
1228                 .input  = { [0 ... 15] = 0x00 },
1229                 .ilen   = 16,
1230                 .result = { 0xdd, 0xd2, 0x6b, 0x98, 0xa5, 0xff, 0xd8, 0x2c,
1231                             0x05, 0x34, 0x5a, 0x9d, 0xad, 0xbf, 0xaf, 0x49},
1232                 .rlen   = 16,
1233         },
1234 };
1235
1236 struct cipher_testvec serpent_dec_tv_template[] = 
1237 {
1238         {
1239                 .input  = { 0x12, 0x07, 0xfc, 0xce, 0x9b, 0xd0, 0xd6, 0x47,
1240                             0x6a, 0xe9, 0x8f, 0xbe, 0xd1, 0x43, 0xa0, 0xe2 },
1241                 .ilen   = 16,
1242                 .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1243                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1244                 .rlen   = 16,
1245         }, {
1246                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1247                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1248                 .klen   = 16,
1249                 .input  = { 0x4c, 0x7d, 0x8a, 0x32, 0x80, 0x72, 0xa2, 0x2c,
1250                             0x82, 0x3e, 0x4a, 0x1f, 0x3a, 0xcd, 0xa1, 0x6d },
1251                 .ilen   = 16,
1252                 .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1253                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1254                 .rlen   = 16,
1255         }, {
1256                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1257                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1258                             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1259                             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
1260                 .klen   = 32,
1261                 .input  = { 0xde, 0x26, 0x9f, 0xf8, 0x33, 0xe4, 0x32, 0xb8,
1262                             0x5b, 0x2e, 0x88, 0xd2, 0x70, 0x1c, 0xe7, 0x5c },
1263                 .ilen   = 16,
1264                 .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1265                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1266                 .rlen   = 16,
1267         }, {
1268                 .key    = { [15] = 0x80 },
1269                 .klen   = 16,
1270                 .input  = { 0xdd, 0xd2, 0x6b, 0x98, 0xa5, 0xff, 0xd8, 0x2c,
1271                             0x05, 0x34, 0x5a, 0x9d, 0xad, 0xbf, 0xaf, 0x49},
1272                 .ilen   = 16,
1273                 .result = { [0 ... 15] = 0x00 },
1274                 .rlen   = 16,
1275         },
1276 };
1277
1278 /* Cast6 test vectors from RFC 2612 */
1279 #define CAST6_ENC_TEST_VECTORS  3
1280 #define CAST6_DEC_TEST_VECTORS  3
1281
1282 struct cipher_testvec cast6_enc_tv_template[] = 
1283 {
1284         {
1285                 .key    = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, 
1286                             0x0a, 0xf7, 0x56, 0x47, 0xf2, 0x9f, 0x61, 0x5d },
1287                 .klen   = 16,
1288                 .input  = { [0 ... 15] = 0x00 },
1289                 .ilen   = 16,
1290                 .result = { 0xc8, 0x42, 0xa0, 0x89, 0x72, 0xb4, 0x3d, 0x20, 
1291                             0x83, 0x6c, 0x91, 0xd1, 0xb7, 0x53, 0x0f, 0x6b },
1292                 .rlen   = 16,
1293         }, {
1294                 .key    = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, 
1295                             0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, 
1296                             0xba, 0xc7, 0x7a, 0x77, 0x17, 0x94, 0x28, 0x63 },
1297                 .klen   = 24,
1298                 .input  = { [0 ... 15] = 0x00 },
1299                 .ilen   = 16,
1300                 .result = { 0x1b, 0x38, 0x6c, 0x02, 0x10, 0xdc, 0xad, 0xcb, 
1301                             0xdd, 0x0e, 0x41, 0xaa, 0x08, 0xa7, 0xa7, 0xe8 },
1302                 .rlen   = 16,
1303         }, {
1304                 .key    = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c,
1305                             0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98,
1306                             0x8d, 0x7c, 0x47, 0xce, 0x26, 0x49, 0x08, 0x46,
1307                             0x1c, 0xc1, 0xb5, 0x13, 0x7a, 0xe6, 0xb6, 0x04 },                             
1308                 .klen   = 32,
1309                 .input  = { [0 ... 15] = 0x00 },
1310                 .ilen   = 16,
1311                 .result = { 0x4f, 0x6a, 0x20, 0x38, 0x28, 0x68, 0x97, 0xb9, 
1312                             0xc9, 0x87, 0x01, 0x36, 0x55, 0x33, 0x17, 0xfa },
1313                 .rlen   = 16,
1314         },
1315 };
1316
1317 struct cipher_testvec cast6_dec_tv_template[] = 
1318 {
1319         {
1320                 .key    = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, 
1321                             0x0a, 0xf7, 0x56, 0x47, 0xf2, 0x9f, 0x61, 0x5d },
1322                 .klen   = 16,
1323                 .input  = { 0xc8, 0x42, 0xa0, 0x89, 0x72, 0xb4, 0x3d, 0x20, 
1324                             0x83, 0x6c, 0x91, 0xd1, 0xb7, 0x53, 0x0f, 0x6b },
1325                 .ilen   = 16,
1326                 .result = { [0 ... 15] = 0x00 },
1327                 .rlen   = 16,
1328         }, {
1329                 .key    = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, 
1330                             0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, 
1331                             0xba, 0xc7, 0x7a, 0x77, 0x17, 0x94, 0x28, 0x63 },
1332                 .klen   = 24,
1333                 .input  = { 0x1b, 0x38, 0x6c, 0x02, 0x10, 0xdc, 0xad, 0xcb, 
1334                             0xdd, 0x0e, 0x41, 0xaa, 0x08, 0xa7, 0xa7, 0xe8 },
1335                 .ilen   = 16,
1336                 .result = { [0 ... 15] = 0x00 },
1337                 .rlen   = 16,
1338         }, {
1339                 .key    = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c,
1340                             0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98,
1341                             0x8d, 0x7c, 0x47, 0xce, 0x26, 0x49, 0x08, 0x46,
1342                             0x1c, 0xc1, 0xb5, 0x13, 0x7a, 0xe6, 0xb6, 0x04 },                             
1343                 .klen   = 32,
1344                 .input  = { 0x4f, 0x6a, 0x20, 0x38, 0x28, 0x68, 0x97, 0xb9, 
1345                             0xc9, 0x87, 0x01, 0x36, 0x55, 0x33, 0x17, 0xfa },
1346                 .ilen   = 16,
1347                 .result = { [0 ... 15] = 0x00 },
1348                 .rlen   = 16,
1349         },
1350 };
1351
1352
1353 /*
1354  * AES test vectors.
1355  */
1356 #define AES_ENC_TEST_VECTORS 3
1357 #define AES_DEC_TEST_VECTORS 3
1358
1359 struct cipher_testvec aes_enc_tv_template[] = { 
1360         { /* From FIPS-197 */
1361                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
1362                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1363                 .klen   = 16,
1364                 .input  = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
1365                             0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
1366                 .ilen   = 16,
1367                 .result = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30,
1368                             0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a },
1369                 .rlen   = 16,
1370         }, {
1371                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1372                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1373                             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
1374                 .klen   = 24,
1375                 .input  = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 
1376                             0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
1377                 .ilen   = 16,
1378                 .result = { 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0,
1379                             0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91 },
1380                 .rlen   = 16,
1381         }, {
1382                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1383                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1384                             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1385                             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
1386                 .klen   = 32,
1387                 .input  = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 
1388                             0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
1389                 .ilen   = 16,
1390                 .result = { 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf,
1391                             0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89 },
1392                 .rlen   = 16,
1393         },
1394 };
1395
1396 struct cipher_testvec aes_dec_tv_template[] = { 
1397         { /* From FIPS-197 */
1398                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
1399                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
1400                 .klen   = 16,
1401                 .input  = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30,
1402                             0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a },
1403                 .ilen   = 16,
1404                 .result = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
1405                             0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
1406                 .rlen   = 16,
1407         }, {
1408                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1409                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1410                             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
1411                 .klen   = 24,
1412                 .input  = { 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0,
1413                             0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91 },
1414                 .ilen   = 16,
1415                 .result = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 
1416                             0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },  
1417                 .rlen   = 16,
1418         }, {
1419                 .key    = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1420                             0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1421                             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1422                             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
1423                 .klen   = 32,
1424                 .input  = { 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf,
1425                             0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89 },
1426                 .ilen   = 16,
1427                 .result = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 
1428                             0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff },
1429                 .rlen   = 16,
1430         },
1431 };
1432
1433 /* Cast5 test vectors from RFC 2144 */
1434 #define CAST5_ENC_TEST_VECTORS  3
1435 #define CAST5_DEC_TEST_VECTORS  3
1436
1437 struct cipher_testvec cast5_enc_tv_template[] =
1438 {
1439         {
1440                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
1441                             0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a },
1442                 .klen   = 16,
1443                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1444                 .ilen   = 8,
1445                 .result = { 0x23, 0x8b, 0x4f, 0xe5, 0x84, 0x7e, 0x44, 0xb2 },
1446                 .rlen   = 8,
1447         }, {
1448                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
1449                             0x23, 0x45 },
1450                 .klen   = 10,
1451                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1452                 .ilen   = 8,
1453                 .result = { 0xeb, 0x6a, 0x71, 0x1a, 0x2c, 0x02, 0x27, 0x1b },
1454                 .rlen   = 8,
1455         }, {
1456                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x12 },
1457                 .klen   = 5,
1458                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1459                 .ilen   = 8,
1460                 .result = { 0x7a, 0xc8, 0x16, 0xd1, 0x6e, 0x9b, 0x30, 0x2e },
1461                 .rlen   = 8,
1462         },
1463 };
1464
1465 struct cipher_testvec cast5_dec_tv_template[] =
1466 {
1467         {
1468                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
1469                             0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a },
1470                 .klen   = 16,
1471                 .input  = { 0x23, 0x8b, 0x4f, 0xe5, 0x84, 0x7e, 0x44, 0xb2 },
1472                 .ilen   = 8,
1473                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1474                 .rlen   = 8,
1475         }, {
1476                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
1477                             0x23, 0x45 },
1478                 .klen   = 10,
1479                 .input  = { 0xeb, 0x6a, 0x71, 0x1a, 0x2c, 0x02, 0x27, 0x1b },
1480                 .ilen   = 8,
1481                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1482                 .rlen   = 8,
1483         }, {
1484                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x12 },
1485                 .klen   = 5,
1486                 .input  = { 0x7a, 0xc8, 0x16, 0xd1, 0x6e, 0x9b, 0x30, 0x2e },
1487                 .ilen   = 8,
1488                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1489                 .rlen   = 8,
1490         },
1491 };
1492
1493 /* 
1494  * ARC4 test vectors from OpenSSL 
1495  */
1496 #define ARC4_ENC_TEST_VECTORS   7
1497 #define ARC4_DEC_TEST_VECTORS   7
1498
1499 struct cipher_testvec arc4_enc_tv_template[] =
1500 {
1501         {
1502                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1503                 .klen   = 8,
1504                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1505                 .ilen   = 8,
1506                 .result = { 0x75, 0xb7, 0x87, 0x80, 0x99, 0xe0, 0xc5, 0x96 },
1507                 .rlen   = 8,
1508         }, {
1509                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1510                 .klen   = 8,
1511                 .input  = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1512                 .ilen   = 8,
1513                 .result = { 0x74, 0x94, 0xc2, 0xe7, 0x10, 0x4b, 0x08, 0x79 },
1514                 .rlen   = 8,
1515         }, {
1516                 .key    = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1517                 .klen   = 8,
1518                 .input  = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1519                 .ilen   = 8,
1520                 .result = { 0xde, 0x18, 0x89, 0x41, 0xa3, 0x37, 0x5d, 0x3a },
1521                 .rlen   = 8,
1522         }, {
1523                 .key    = { 0xef, 0x01, 0x23, 0x45},
1524                 .klen   = 4,
1525                 .input  = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1526                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1527                             0x00, 0x00, 0x00, 0x00 },
1528                 .ilen   = 20,
1529                 .result = { 0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf,
1530                             0xbd, 0x61, 0x5a, 0x11, 0x62, 0xe1, 0xc7, 0xba,
1531                             0x36, 0xb6, 0x78, 0x58 },
1532                 .rlen   = 20,
1533         }, {
1534                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1535                 .klen   = 8,
1536                 .input  = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
1537                             0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
1538                             0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
1539                             0x12, 0x34, 0x56, 0x78 },
1540                 .ilen   = 28,
1541                 .result = { 0x66, 0xa0, 0x94, 0x9f, 0x8a, 0xf7, 0xd6, 0x89,
1542                             0x1f, 0x7f, 0x83, 0x2b, 0xa8, 0x33, 0xc0, 0x0c,
1543                             0x89, 0x2e, 0xbe, 0x30, 0x14, 0x3c, 0xe2, 0x87,
1544                             0x40, 0x01, 0x1e, 0xcf },
1545                 .rlen   = 28,
1546         }, {
1547                 .key    = { 0xef, 0x01, 0x23, 0x45 },
1548                 .klen   = 4,
1549                 .input  = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1550                             0x00, 0x00 },
1551                 .ilen   = 10,
1552                 .result = { 0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf,
1553                             0xbd, 0x61 },
1554                 .rlen   = 10,
1555         }, {
1556                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
1557                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1558                 .klen   = 16,
1559                 .input  = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
1560                 .ilen   = 8,
1561                 .result = { 0x69, 0x72, 0x36, 0x59, 0x1B, 0x52, 0x42, 0xB1 },
1562                 .rlen   = 8,
1563         },
1564 };
1565
1566 struct cipher_testvec arc4_dec_tv_template[] =
1567 {
1568         {
1569                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1570                 .klen   = 8,
1571                 .input  = { 0x75, 0xb7, 0x87, 0x80, 0x99, 0xe0, 0xc5, 0x96 },
1572                 .ilen   = 8,
1573                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1574                 .rlen   = 8,
1575         }, {
1576                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1577                 .klen   = 8,
1578                 .input  = { 0x74, 0x94, 0xc2, 0xe7, 0x10, 0x4b, 0x08, 0x79 },
1579                 .ilen   = 8,
1580                 .result = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1581                 .rlen   = 8,
1582         }, {
1583                 .key    = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1584                 .klen   = 8,
1585                 .input  = { 0xde, 0x18, 0x89, 0x41, 0xa3, 0x37, 0x5d, 0x3a },
1586                 .ilen   = 8,
1587                 .result = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1588                 .rlen   = 8,
1589         }, {
1590                 .key    = { 0xef, 0x01, 0x23, 0x45},
1591                 .klen   = 4,
1592                 .input  = { 0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf,
1593                             0xbd, 0x61, 0x5a, 0x11, 0x62, 0xe1, 0xc7, 0xba,
1594                             0x36, 0xb6, 0x78, 0x58 },
1595                 .ilen   = 20,
1596                 .result = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1597                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1598                             0x00, 0x00, 0x00, 0x00 },
1599                 .rlen   = 20,
1600         }, {
1601                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef },
1602                 .klen   = 8,
1603                 .input  = { 0x66, 0xa0, 0x94, 0x9f, 0x8a, 0xf7, 0xd6, 0x89,
1604                             0x1f, 0x7f, 0x83, 0x2b, 0xa8, 0x33, 0xc0, 0x0c,
1605                             0x89, 0x2e, 0xbe, 0x30, 0x14, 0x3c, 0xe2, 0x87,
1606                             0x40, 0x01, 0x1e, 0xcf },
1607                 .ilen   = 28,
1608                 .result = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
1609                             0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
1610                             0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
1611                             0x12, 0x34, 0x56, 0x78 },
1612                 .rlen   = 28,
1613         }, {
1614                 .key    = { 0xef, 0x01, 0x23, 0x45 },
1615                 .klen   = 4,
1616                 .input  = { 0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf,
1617                             0xbd, 0x61 },
1618                 .ilen   = 10,
1619                 .result = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1620                             0x00, 0x00 },
1621                 .rlen   = 10,
1622         }, {
1623                 .key    = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
1624                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1625                 .klen   = 16,
1626                 .input  = { 0x69, 0x72, 0x36, 0x59, 0x1B, 0x52, 0x42, 0xB1 },
1627                 .ilen   = 8,
1628                 .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
1629                 .rlen   = 8,
1630         },
1631 };
1632
1633
1634 /*
1635  * Compression stuff.
1636  */
1637 #define COMP_BUF_SIZE           512
1638
1639 struct comp_testvec {
1640         int inlen, outlen;
1641         char input[COMP_BUF_SIZE];
1642         char output[COMP_BUF_SIZE];
1643 };
1644
1645 /*
1646  * Deflate test vectors (null-terminated strings).
1647  * Params: winbits=11, Z_DEFAULT_COMPRESSION, MAX_MEM_LEVEL.
1648  */
1649 #define DEFLATE_COMP_TEST_VECTORS 2
1650 #define DEFLATE_DECOMP_TEST_VECTORS 2
1651
1652 struct comp_testvec deflate_comp_tv_template[] = {
1653         {
1654                 .inlen  = 70,
1655                 .outlen = 38,
1656                 .input  = "Join us now and share the software "
1657                           "Join us now and share the software ",
1658                 .output = { 0xf3, 0xca, 0xcf, 0xcc, 0x53, 0x28, 0x2d, 0x56,
1659                             0xc8, 0xcb, 0x2f, 0x57, 0x48, 0xcc, 0x4b, 0x51,
1660                             0x28, 0xce, 0x48, 0x2c, 0x4a, 0x55, 0x28, 0xc9,
1661                             0x48, 0x55, 0x28, 0xce, 0x4f, 0x2b, 0x29, 0x07,
1662                             0x71, 0xbc, 0x08, 0x2b, 0x01, 0x00 },
1663         }, {
1664                 .inlen  = 191,
1665                 .outlen = 122,
1666                 .input  = "This document describes a compression method based on the DEFLATE"
1667                           "compression algorithm.  This document defines the application of "
1668                           "the DEFLATE algorithm to the IP Payload Compression Protocol.",
1669                 .output = { 0x5d, 0x8d, 0x31, 0x0e, 0xc2, 0x30, 0x10, 0x04,
1670                             0xbf, 0xb2, 0x2f, 0xc8, 0x1f, 0x10, 0x04, 0x09,
1671                             0x89, 0xc2, 0x85, 0x3f, 0x70, 0xb1, 0x2f, 0xf8,
1672                             0x24, 0xdb, 0x67, 0xd9, 0x47, 0xc1, 0xef, 0x49,
1673                             0x68, 0x12, 0x51, 0xae, 0x76, 0x67, 0xd6, 0x27,
1674                             0x19, 0x88, 0x1a, 0xde, 0x85, 0xab, 0x21, 0xf2,
1675                             0x08, 0x5d, 0x16, 0x1e, 0x20, 0x04, 0x2d, 0xad,
1676                             0xf3, 0x18, 0xa2, 0x15, 0x85, 0x2d, 0x69, 0xc4,
1677                             0x42, 0x83, 0x23, 0xb6, 0x6c, 0x89, 0x71, 0x9b,
1678                             0xef, 0xcf, 0x8b, 0x9f, 0xcf, 0x33, 0xca, 0x2f,
1679                             0xed, 0x62, 0xa9, 0x4c, 0x80, 0xff, 0x13, 0xaf,
1680                             0x52, 0x37, 0xed, 0x0e, 0x52, 0x6b, 0x59, 0x02,
1681                             0xd9, 0x4e, 0xe8, 0x7a, 0x76, 0x1d, 0x02, 0x98,
1682                             0xfe, 0x8a, 0x87, 0x83, 0xa3, 0x4f, 0x56, 0x8a,
1683                             0xb8, 0x9e, 0x8e, 0x5c, 0x57, 0xd3, 0xa0, 0x79,
1684                             0xfa, 0x02 },
1685         },
1686 };
1687
1688 struct comp_testvec deflate_decomp_tv_template[] = {
1689         {
1690                 .inlen  = 122,
1691                 .outlen = 191,
1692                 .input  = { 0x5d, 0x8d, 0x31, 0x0e, 0xc2, 0x30, 0x10, 0x04,
1693                             0xbf, 0xb2, 0x2f, 0xc8, 0x1f, 0x10, 0x04, 0x09,
1694                             0x89, 0xc2, 0x85, 0x3f, 0x70, 0xb1, 0x2f, 0xf8,
1695                             0x24, 0xdb, 0x67, 0xd9, 0x47, 0xc1, 0xef, 0x49,
1696                             0x68, 0x12, 0x51, 0xae, 0x76, 0x67, 0xd6, 0x27,
1697                             0x19, 0x88, 0x1a, 0xde, 0x85, 0xab, 0x21, 0xf2,
1698                             0x08, 0x5d, 0x16, 0x1e, 0x20, 0x04, 0x2d, 0xad,
1699                             0xf3, 0x18, 0xa2, 0x15, 0x85, 0x2d, 0x69, 0xc4,
1700                             0x42, 0x83, 0x23, 0xb6, 0x6c, 0x89, 0x71, 0x9b,
1701                             0xef, 0xcf, 0x8b, 0x9f, 0xcf, 0x33, 0xca, 0x2f,
1702                             0xed, 0x62, 0xa9, 0x4c, 0x80, 0xff, 0x13, 0xaf,
1703                             0x52, 0x37, 0xed, 0x0e, 0x52, 0x6b, 0x59, 0x02,
1704                             0xd9, 0x4e, 0xe8, 0x7a, 0x76, 0x1d, 0x02, 0x98,
1705                             0xfe, 0x8a, 0x87, 0x83, 0xa3, 0x4f, 0x56, 0x8a,
1706                             0xb8, 0x9e, 0x8e, 0x5c, 0x57, 0xd3, 0xa0, 0x79,
1707                             0xfa, 0x02 },
1708                 .output = "This document describes a compression method based on the DEFLATE"
1709                           "compression algorithm.  This document defines the application of "
1710                           "the DEFLATE algorithm to the IP Payload Compression Protocol.",
1711         }, {
1712                 .inlen  = 38,
1713                 .outlen = 70,
1714                 .input  = { 0xf3, 0xca, 0xcf, 0xcc, 0x53, 0x28, 0x2d, 0x56,
1715                             0xc8, 0xcb, 0x2f, 0x57, 0x48, 0xcc, 0x4b, 0x51,
1716                             0x28, 0xce, 0x48, 0x2c, 0x4a, 0x55, 0x28, 0xc9,
1717                             0x48, 0x55, 0x28, 0xce, 0x4f, 0x2b, 0x29, 0x07,
1718                             0x71, 0xbc, 0x08, 0x2b, 0x01, 0x00 },
1719                 .output = "Join us now and share the software "
1720                           "Join us now and share the software ",
1721         },
1722 };
1723
1724 /*
1725  * Michael MIC test vectors from IEEE 802.11i
1726  */
1727 #define MICHAEL_MIC_TEST_VECTORS 6
1728
1729 struct hash_testvec michael_mic_tv_template[] =
1730 {
1731         {
1732                 .key = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1733                 .ksize = 8,
1734                 .plaintext = { },
1735                 .psize = 0,
1736                 .digest = { 0x82, 0x92, 0x5c, 0x1c, 0xa1, 0xd1, 0x30, 0xb8 }
1737         },
1738         {
1739                 .key = { 0x82, 0x92, 0x5c, 0x1c, 0xa1, 0xd1, 0x30, 0xb8 },
1740                 .ksize = 8,
1741                 .plaintext = { 'M' },
1742                 .psize = 1,
1743                 .digest = { 0x43, 0x47, 0x21, 0xca, 0x40, 0x63, 0x9b, 0x3f }
1744         },
1745         {
1746                 .key = { 0x43, 0x47, 0x21, 0xca, 0x40, 0x63, 0x9b, 0x3f },
1747                 .ksize = 8,
1748                 .plaintext = { 'M', 'i' },
1749                 .psize = 2,
1750                 .digest = { 0xe8, 0xf9, 0xbe, 0xca, 0xe9, 0x7e, 0x5d, 0x29 }
1751         },
1752         {
1753                 .key = { 0xe8, 0xf9, 0xbe, 0xca, 0xe9, 0x7e, 0x5d, 0x29 },
1754                 .ksize = 8,
1755                 .plaintext = { 'M', 'i', 'c' },
1756                 .psize = 3,
1757                 .digest = { 0x90, 0x03, 0x8f, 0xc6, 0xcf, 0x13, 0xc1, 0xdb }
1758         },
1759         {
1760                 .key = { 0x90, 0x03, 0x8f, 0xc6, 0xcf, 0x13, 0xc1, 0xdb },
1761                 .ksize = 8,
1762                 .plaintext = { 'M', 'i', 'c', 'h' },
1763                 .psize = 4,
1764                 .digest = { 0xd5, 0x5e, 0x10, 0x05, 0x10, 0x12, 0x89, 0x86 }
1765         },
1766         {
1767                 .key = { 0xd5, 0x5e, 0x10, 0x05, 0x10, 0x12, 0x89, 0x86 },
1768                 .ksize = 8,
1769                 .plaintext = { 'M', 'i', 'c', 'h', 'a', 'e', 'l' },
1770                 .psize = 7,
1771                 .digest = { 0x0a, 0x94, 0x2b, 0x12, 0x4e, 0xca, 0xa5, 0x46 },
1772         }
1773 };
1774 #endif  /* _CRYPTO_TCRYPT_H */