blob: 941d75cd1f7cd918ef2ef1b436854cd9ec7abb03 [file] [log] [blame]
Herbert Xuda7f0332008-07-31 17:08:25 +08001/*
2 * Algorithm testing framework and tests.
3 *
4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
6 * Copyright (c) 2007 Nokia Siemens Networks
7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
8 *
Adrian Hoban69435b92010-11-04 15:02:04 -04009 * Updated RFC4106 AES-GCM testing.
10 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
11 * Adrian Hoban <adrian.hoban@intel.com>
12 * Gabriele Paoloni <gabriele.paoloni@intel.com>
13 * Tadeusz Struk (tadeusz.struk@intel.com)
14 * Copyright (c) 2010, Intel Corporation.
15 *
Herbert Xuda7f0332008-07-31 17:08:25 +080016 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the Free
18 * Software Foundation; either version 2 of the License, or (at your option)
19 * any later version.
20 *
21 */
22
23#include <crypto/hash.h>
24#include <linux/err.h>
25#include <linux/module.h>
26#include <linux/scatterlist.h>
27#include <linux/slab.h>
28#include <linux/string.h>
Jarod Wilson7647d6c2009-05-04 19:44:50 +080029#include <crypto/rng.h>
Herbert Xuda7f0332008-07-31 17:08:25 +080030
31#include "internal.h"
Alexander Shishkin0b767f92010-06-03 20:53:43 +100032
Herbert Xu326a6342010-08-06 09:40:28 +080033#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
Alexander Shishkin0b767f92010-06-03 20:53:43 +100034
35/* a perfect nop */
36int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
37{
38 return 0;
39}
40
41#else
42
Herbert Xuda7f0332008-07-31 17:08:25 +080043#include "testmgr.h"
44
45/*
46 * Need slab memory for testing (size in number of pages).
47 */
48#define XBUFSIZE 8
49
50/*
51 * Indexes into the xbuf to simulate cross-page access.
52 */
53#define IDX1 32
54#define IDX2 32400
55#define IDX3 1
56#define IDX4 8193
57#define IDX5 22222
58#define IDX6 17101
59#define IDX7 27333
60#define IDX8 3000
61
62/*
63* Used by test_cipher()
64*/
65#define ENCRYPT 1
66#define DECRYPT 0
67
68struct tcrypt_result {
69 struct completion completion;
70 int err;
71};
72
73struct aead_test_suite {
74 struct {
75 struct aead_testvec *vecs;
76 unsigned int count;
77 } enc, dec;
78};
79
80struct cipher_test_suite {
81 struct {
82 struct cipher_testvec *vecs;
83 unsigned int count;
84 } enc, dec;
85};
86
87struct comp_test_suite {
88 struct {
89 struct comp_testvec *vecs;
90 unsigned int count;
91 } comp, decomp;
92};
93
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +080094struct pcomp_test_suite {
95 struct {
96 struct pcomp_testvec *vecs;
97 unsigned int count;
98 } comp, decomp;
99};
100
Herbert Xuda7f0332008-07-31 17:08:25 +0800101struct hash_test_suite {
102 struct hash_testvec *vecs;
103 unsigned int count;
104};
105
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800106struct cprng_test_suite {
107 struct cprng_testvec *vecs;
108 unsigned int count;
109};
110
Herbert Xuda7f0332008-07-31 17:08:25 +0800111struct alg_test_desc {
112 const char *alg;
113 int (*test)(const struct alg_test_desc *desc, const char *driver,
114 u32 type, u32 mask);
Jarod Wilsona1915d52009-05-15 15:16:03 +1000115 int fips_allowed; /* set if alg is allowed in fips mode */
Herbert Xuda7f0332008-07-31 17:08:25 +0800116
117 union {
118 struct aead_test_suite aead;
119 struct cipher_test_suite cipher;
120 struct comp_test_suite comp;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +0800121 struct pcomp_test_suite pcomp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800122 struct hash_test_suite hash;
Jarod Wilson7647d6c2009-05-04 19:44:50 +0800123 struct cprng_test_suite cprng;
Herbert Xuda7f0332008-07-31 17:08:25 +0800124 } suite;
125};
126
127static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
128
Herbert Xuda7f0332008-07-31 17:08:25 +0800129static void hexdump(unsigned char *buf, unsigned int len)
130{
131 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
132 16, 1,
133 buf, len, false);
134}
135
136static void tcrypt_complete(struct crypto_async_request *req, int err)
137{
138 struct tcrypt_result *res = req->data;
139
140 if (err == -EINPROGRESS)
141 return;
142
143 res->err = err;
144 complete(&res->completion);
145}
146
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800147static int testmgr_alloc_buf(char *buf[XBUFSIZE])
148{
149 int i;
150
151 for (i = 0; i < XBUFSIZE; i++) {
152 buf[i] = (void *)__get_free_page(GFP_KERNEL);
153 if (!buf[i])
154 goto err_free_buf;
155 }
156
157 return 0;
158
159err_free_buf:
160 while (i-- > 0)
161 free_page((unsigned long)buf[i]);
162
163 return -ENOMEM;
164}
165
166static void testmgr_free_buf(char *buf[XBUFSIZE])
167{
168 int i;
169
170 for (i = 0; i < XBUFSIZE; i++)
171 free_page((unsigned long)buf[i]);
172}
173
David S. Millera8f1a052010-05-19 14:12:03 +1000174static int do_one_async_hash_op(struct ahash_request *req,
175 struct tcrypt_result *tr,
176 int ret)
177{
178 if (ret == -EINPROGRESS || ret == -EBUSY) {
179 ret = wait_for_completion_interruptible(&tr->completion);
180 if (!ret)
181 ret = tr->err;
182 INIT_COMPLETION(tr->completion);
183 }
184 return ret;
185}
186
Herbert Xuda7f0332008-07-31 17:08:25 +0800187static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
David S. Millera8f1a052010-05-19 14:12:03 +1000188 unsigned int tcount, bool use_digest)
Herbert Xuda7f0332008-07-31 17:08:25 +0800189{
190 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
191 unsigned int i, j, k, temp;
192 struct scatterlist sg[8];
193 char result[64];
194 struct ahash_request *req;
195 struct tcrypt_result tresult;
Herbert Xuda7f0332008-07-31 17:08:25 +0800196 void *hash_buff;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800197 char *xbuf[XBUFSIZE];
198 int ret = -ENOMEM;
199
200 if (testmgr_alloc_buf(xbuf))
201 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800202
203 init_completion(&tresult.completion);
204
205 req = ahash_request_alloc(tfm, GFP_KERNEL);
206 if (!req) {
207 printk(KERN_ERR "alg: hash: Failed to allocate request for "
208 "%s\n", algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800209 goto out_noreq;
210 }
211 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
212 tcrypt_complete, &tresult);
213
Herbert Xua0cfae52009-05-29 16:23:12 +1000214 j = 0;
Herbert Xuda7f0332008-07-31 17:08:25 +0800215 for (i = 0; i < tcount; i++) {
Herbert Xua0cfae52009-05-29 16:23:12 +1000216 if (template[i].np)
217 continue;
218
219 j++;
Herbert Xuda7f0332008-07-31 17:08:25 +0800220 memset(result, 0, 64);
221
222 hash_buff = xbuf[0];
223
224 memcpy(hash_buff, template[i].plaintext, template[i].psize);
225 sg_init_one(&sg[0], hash_buff, template[i].psize);
226
227 if (template[i].ksize) {
228 crypto_ahash_clear_flags(tfm, ~0);
229 ret = crypto_ahash_setkey(tfm, template[i].key,
230 template[i].ksize);
231 if (ret) {
232 printk(KERN_ERR "alg: hash: setkey failed on "
Herbert Xua0cfae52009-05-29 16:23:12 +1000233 "test %d for %s: ret=%d\n", j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800234 -ret);
235 goto out;
236 }
237 }
238
239 ahash_request_set_crypt(req, sg, result, template[i].psize);
David S. Millera8f1a052010-05-19 14:12:03 +1000240 if (use_digest) {
241 ret = do_one_async_hash_op(req, &tresult,
242 crypto_ahash_digest(req));
243 if (ret) {
244 pr_err("alg: hash: digest failed on test %d "
245 "for %s: ret=%d\n", j, algo, -ret);
246 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800247 }
David S. Millera8f1a052010-05-19 14:12:03 +1000248 } else {
249 ret = do_one_async_hash_op(req, &tresult,
250 crypto_ahash_init(req));
251 if (ret) {
252 pr_err("alt: hash: init failed on test %d "
253 "for %s: ret=%d\n", j, algo, -ret);
254 goto out;
255 }
256 ret = do_one_async_hash_op(req, &tresult,
257 crypto_ahash_update(req));
258 if (ret) {
259 pr_err("alt: hash: update failed on test %d "
260 "for %s: ret=%d\n", j, algo, -ret);
261 goto out;
262 }
263 ret = do_one_async_hash_op(req, &tresult,
264 crypto_ahash_final(req));
265 if (ret) {
266 pr_err("alt: hash: final failed on test %d "
267 "for %s: ret=%d\n", j, algo, -ret);
268 goto out;
269 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800270 }
271
272 if (memcmp(result, template[i].digest,
273 crypto_ahash_digestsize(tfm))) {
274 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
Herbert Xua0cfae52009-05-29 16:23:12 +1000275 j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800276 hexdump(result, crypto_ahash_digestsize(tfm));
277 ret = -EINVAL;
278 goto out;
279 }
280 }
281
282 j = 0;
283 for (i = 0; i < tcount; i++) {
284 if (template[i].np) {
285 j++;
286 memset(result, 0, 64);
287
288 temp = 0;
289 sg_init_table(sg, template[i].np);
Herbert Xufd57f222009-05-29 16:05:42 +1000290 ret = -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +0800291 for (k = 0; k < template[i].np; k++) {
Herbert Xufd57f222009-05-29 16:05:42 +1000292 if (WARN_ON(offset_in_page(IDX[k]) +
293 template[i].tap[k] > PAGE_SIZE))
294 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800295 sg_set_buf(&sg[k],
296 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
297 offset_in_page(IDX[k]),
298 template[i].plaintext + temp,
299 template[i].tap[k]),
300 template[i].tap[k]);
301 temp += template[i].tap[k];
302 }
303
304 if (template[i].ksize) {
305 crypto_ahash_clear_flags(tfm, ~0);
306 ret = crypto_ahash_setkey(tfm, template[i].key,
307 template[i].ksize);
308
309 if (ret) {
310 printk(KERN_ERR "alg: hash: setkey "
311 "failed on chunking test %d "
312 "for %s: ret=%d\n", j, algo,
313 -ret);
314 goto out;
315 }
316 }
317
318 ahash_request_set_crypt(req, sg, result,
319 template[i].psize);
320 ret = crypto_ahash_digest(req);
321 switch (ret) {
322 case 0:
323 break;
324 case -EINPROGRESS:
325 case -EBUSY:
326 ret = wait_for_completion_interruptible(
327 &tresult.completion);
328 if (!ret && !(ret = tresult.err)) {
329 INIT_COMPLETION(tresult.completion);
330 break;
331 }
332 /* fall through */
333 default:
334 printk(KERN_ERR "alg: hash: digest failed "
335 "on chunking test %d for %s: "
336 "ret=%d\n", j, algo, -ret);
337 goto out;
338 }
339
340 if (memcmp(result, template[i].digest,
341 crypto_ahash_digestsize(tfm))) {
342 printk(KERN_ERR "alg: hash: Chunking test %d "
343 "failed for %s\n", j, algo);
344 hexdump(result, crypto_ahash_digestsize(tfm));
345 ret = -EINVAL;
346 goto out;
347 }
348 }
349 }
350
351 ret = 0;
352
353out:
354 ahash_request_free(req);
355out_noreq:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800356 testmgr_free_buf(xbuf);
357out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +0800358 return ret;
359}
360
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300361static int __test_aead(struct crypto_aead *tfm, int enc,
362 struct aead_testvec *template, unsigned int tcount,
363 const bool diff_dst)
Herbert Xuda7f0332008-07-31 17:08:25 +0800364{
365 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
366 unsigned int i, j, k, n, temp;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800367 int ret = -ENOMEM;
Herbert Xuda7f0332008-07-31 17:08:25 +0800368 char *q;
369 char *key;
370 struct aead_request *req;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300371 struct scatterlist *sg;
372 struct scatterlist *asg;
373 struct scatterlist *sgout;
374 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800375 struct tcrypt_result result;
376 unsigned int authsize;
377 void *input;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300378 void *output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800379 void *assoc;
380 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800381 char *xbuf[XBUFSIZE];
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300382 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800383 char *axbuf[XBUFSIZE];
384
385 if (testmgr_alloc_buf(xbuf))
386 goto out_noxbuf;
387 if (testmgr_alloc_buf(axbuf))
388 goto out_noaxbuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800389
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300390 if (diff_dst && testmgr_alloc_buf(xoutbuf))
391 goto out_nooutbuf;
392
393 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
394 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
395 if (!sg)
396 goto out_nosg;
397 asg = &sg[8];
398 sgout = &asg[8];
399
400 if (diff_dst)
401 d = "-ddst";
402 else
403 d = "";
404
Herbert Xuda7f0332008-07-31 17:08:25 +0800405 if (enc == ENCRYPT)
406 e = "encryption";
407 else
408 e = "decryption";
409
410 init_completion(&result.completion);
411
412 req = aead_request_alloc(tfm, GFP_KERNEL);
413 if (!req) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300414 pr_err("alg: aead%s: Failed to allocate request for %s\n",
415 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800416 goto out;
417 }
418
419 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
420 tcrypt_complete, &result);
421
422 for (i = 0, j = 0; i < tcount; i++) {
423 if (!template[i].np) {
424 j++;
425
426 /* some tepmplates have no input data but they will
427 * touch input
428 */
429 input = xbuf[0];
430 assoc = axbuf[0];
431
Herbert Xufd57f222009-05-29 16:05:42 +1000432 ret = -EINVAL;
433 if (WARN_ON(template[i].ilen > PAGE_SIZE ||
434 template[i].alen > PAGE_SIZE))
435 goto out;
436
Herbert Xuda7f0332008-07-31 17:08:25 +0800437 memcpy(input, template[i].input, template[i].ilen);
438 memcpy(assoc, template[i].assoc, template[i].alen);
439 if (template[i].iv)
440 memcpy(iv, template[i].iv, MAX_IVLEN);
441 else
442 memset(iv, 0, MAX_IVLEN);
443
444 crypto_aead_clear_flags(tfm, ~0);
445 if (template[i].wk)
446 crypto_aead_set_flags(
447 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
448
449 key = template[i].key;
450
451 ret = crypto_aead_setkey(tfm, key,
452 template[i].klen);
453 if (!ret == template[i].fail) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300454 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
455 d, j, algo, crypto_aead_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800456 goto out;
457 } else if (ret)
458 continue;
459
460 authsize = abs(template[i].rlen - template[i].ilen);
461 ret = crypto_aead_setauthsize(tfm, authsize);
462 if (ret) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300463 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
464 d, authsize, j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800465 goto out;
466 }
467
468 sg_init_one(&sg[0], input,
469 template[i].ilen + (enc ? authsize : 0));
470
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300471 if (diff_dst) {
472 output = xoutbuf[0];
473 sg_init_one(&sgout[0], output,
474 template[i].ilen +
475 (enc ? authsize : 0));
476 } else {
477 output = input;
478 }
479
Herbert Xuda7f0332008-07-31 17:08:25 +0800480 sg_init_one(&asg[0], assoc, template[i].alen);
481
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300482 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800483 template[i].ilen, iv);
484
485 aead_request_set_assoc(req, asg, template[i].alen);
486
487 ret = enc ?
488 crypto_aead_encrypt(req) :
489 crypto_aead_decrypt(req);
490
491 switch (ret) {
492 case 0:
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800493 if (template[i].novrfy) {
494 /* verification was supposed to fail */
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300495 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
496 d, e, j, algo);
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800497 /* so really, we got a bad message */
498 ret = -EBADMSG;
499 goto out;
500 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800501 break;
502 case -EINPROGRESS:
503 case -EBUSY:
504 ret = wait_for_completion_interruptible(
505 &result.completion);
506 if (!ret && !(ret = result.err)) {
507 INIT_COMPLETION(result.completion);
508 break;
509 }
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800510 case -EBADMSG:
511 if (template[i].novrfy)
512 /* verification failure was expected */
513 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800514 /* fall through */
515 default:
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300516 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
517 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800518 goto out;
519 }
520
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300521 q = output;
Herbert Xuda7f0332008-07-31 17:08:25 +0800522 if (memcmp(q, template[i].result, template[i].rlen)) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300523 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
524 d, j, e, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800525 hexdump(q, template[i].rlen);
526 ret = -EINVAL;
527 goto out;
528 }
529 }
530 }
531
532 for (i = 0, j = 0; i < tcount; i++) {
533 if (template[i].np) {
534 j++;
535
536 if (template[i].iv)
537 memcpy(iv, template[i].iv, MAX_IVLEN);
538 else
539 memset(iv, 0, MAX_IVLEN);
540
541 crypto_aead_clear_flags(tfm, ~0);
542 if (template[i].wk)
543 crypto_aead_set_flags(
544 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
545 key = template[i].key;
546
547 ret = crypto_aead_setkey(tfm, key, template[i].klen);
548 if (!ret == template[i].fail) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300549 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
550 d, j, algo, crypto_aead_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800551 goto out;
552 } else if (ret)
553 continue;
554
555 authsize = abs(template[i].rlen - template[i].ilen);
556
557 ret = -EINVAL;
558 sg_init_table(sg, template[i].np);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300559 if (diff_dst)
560 sg_init_table(sgout, template[i].np);
Herbert Xuda7f0332008-07-31 17:08:25 +0800561 for (k = 0, temp = 0; k < template[i].np; k++) {
562 if (WARN_ON(offset_in_page(IDX[k]) +
563 template[i].tap[k] > PAGE_SIZE))
564 goto out;
565
566 q = xbuf[IDX[k] >> PAGE_SHIFT] +
567 offset_in_page(IDX[k]);
568
569 memcpy(q, template[i].input + temp,
570 template[i].tap[k]);
571
572 n = template[i].tap[k];
573 if (k == template[i].np - 1 && enc)
574 n += authsize;
575 if (offset_in_page(q) + n < PAGE_SIZE)
576 q[n] = 0;
577
578 sg_set_buf(&sg[k], q, template[i].tap[k]);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300579
580 if (diff_dst) {
581 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
582 offset_in_page(IDX[k]);
583
584 memset(q, 0, template[i].tap[k]);
585 if (offset_in_page(q) + n < PAGE_SIZE)
586 q[n] = 0;
587
588 sg_set_buf(&sgout[k], q,
589 template[i].tap[k]);
590 }
591
Herbert Xuda7f0332008-07-31 17:08:25 +0800592 temp += template[i].tap[k];
593 }
594
595 ret = crypto_aead_setauthsize(tfm, authsize);
596 if (ret) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300597 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
598 d, authsize, j, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800599 goto out;
600 }
601
602 if (enc) {
603 if (WARN_ON(sg[k - 1].offset +
604 sg[k - 1].length + authsize >
605 PAGE_SIZE)) {
606 ret = -EINVAL;
607 goto out;
608 }
609
610 sg[k - 1].length += authsize;
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300611
612 if (diff_dst)
613 sgout[k - 1].length += authsize;
Herbert Xuda7f0332008-07-31 17:08:25 +0800614 }
615
616 sg_init_table(asg, template[i].anp);
Herbert Xufd57f222009-05-29 16:05:42 +1000617 ret = -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +0800618 for (k = 0, temp = 0; k < template[i].anp; k++) {
Herbert Xufd57f222009-05-29 16:05:42 +1000619 if (WARN_ON(offset_in_page(IDX[k]) +
620 template[i].atap[k] > PAGE_SIZE))
621 goto out;
Herbert Xuda7f0332008-07-31 17:08:25 +0800622 sg_set_buf(&asg[k],
623 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
624 offset_in_page(IDX[k]),
625 template[i].assoc + temp,
626 template[i].atap[k]),
627 template[i].atap[k]);
628 temp += template[i].atap[k];
629 }
630
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300631 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800632 template[i].ilen,
633 iv);
634
635 aead_request_set_assoc(req, asg, template[i].alen);
636
637 ret = enc ?
638 crypto_aead_encrypt(req) :
639 crypto_aead_decrypt(req);
640
641 switch (ret) {
642 case 0:
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800643 if (template[i].novrfy) {
644 /* verification was supposed to fail */
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300645 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
646 d, e, j, algo);
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800647 /* so really, we got a bad message */
648 ret = -EBADMSG;
649 goto out;
650 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800651 break;
652 case -EINPROGRESS:
653 case -EBUSY:
654 ret = wait_for_completion_interruptible(
655 &result.completion);
656 if (!ret && !(ret = result.err)) {
657 INIT_COMPLETION(result.completion);
658 break;
659 }
Jarod Wilsone44a1b42009-05-04 19:22:11 +0800660 case -EBADMSG:
661 if (template[i].novrfy)
662 /* verification failure was expected */
663 continue;
Herbert Xuda7f0332008-07-31 17:08:25 +0800664 /* fall through */
665 default:
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300666 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
667 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800668 goto out;
669 }
670
671 ret = -EINVAL;
672 for (k = 0, temp = 0; k < template[i].np; k++) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300673 if (diff_dst)
674 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
675 offset_in_page(IDX[k]);
676 else
677 q = xbuf[IDX[k] >> PAGE_SHIFT] +
678 offset_in_page(IDX[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +0800679
680 n = template[i].tap[k];
681 if (k == template[i].np - 1)
682 n += enc ? authsize : -authsize;
683
684 if (memcmp(q, template[i].result + temp, n)) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300685 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
686 d, j, e, k, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800687 hexdump(q, n);
688 goto out;
689 }
690
691 q += n;
692 if (k == template[i].np - 1 && !enc) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300693 if (!diff_dst &&
694 memcmp(q, template[i].input +
Herbert Xuda7f0332008-07-31 17:08:25 +0800695 temp + n, authsize))
696 n = authsize;
697 else
698 n = 0;
699 } else {
700 for (n = 0; offset_in_page(q + n) &&
701 q[n]; n++)
702 ;
703 }
704 if (n) {
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300705 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
706 d, j, e, k, algo, n);
Herbert Xuda7f0332008-07-31 17:08:25 +0800707 hexdump(q, n);
708 goto out;
709 }
710
711 temp += template[i].tap[k];
712 }
713 }
714 }
715
716 ret = 0;
717
718out:
719 aead_request_free(req);
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300720 kfree(sg);
721out_nosg:
722 if (diff_dst)
723 testmgr_free_buf(xoutbuf);
724out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800725 testmgr_free_buf(axbuf);
726out_noaxbuf:
727 testmgr_free_buf(xbuf);
728out_noxbuf:
Herbert Xuda7f0332008-07-31 17:08:25 +0800729 return ret;
730}
731
Jussi Kivilinnad8a32ac2012-09-21 10:26:52 +0300732static int test_aead(struct crypto_aead *tfm, int enc,
733 struct aead_testvec *template, unsigned int tcount)
734{
735 int ret;
736
737 /* test 'dst == src' case */
738 ret = __test_aead(tfm, enc, template, tcount, false);
739 if (ret)
740 return ret;
741
742 /* test 'dst != src' case */
743 return __test_aead(tfm, enc, template, tcount, true);
744}
745
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000746static int test_cipher(struct crypto_cipher *tfm, int enc,
Herbert Xuda7f0332008-07-31 17:08:25 +0800747 struct cipher_testvec *template, unsigned int tcount)
748{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000749 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
750 unsigned int i, j, k;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000751 char *q;
752 const char *e;
753 void *data;
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800754 char *xbuf[XBUFSIZE];
755 int ret = -ENOMEM;
756
757 if (testmgr_alloc_buf(xbuf))
758 goto out_nobuf;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000759
760 if (enc == ENCRYPT)
761 e = "encryption";
762 else
763 e = "decryption";
764
765 j = 0;
766 for (i = 0; i < tcount; i++) {
767 if (template[i].np)
768 continue;
769
770 j++;
771
Herbert Xufd57f222009-05-29 16:05:42 +1000772 ret = -EINVAL;
773 if (WARN_ON(template[i].ilen > PAGE_SIZE))
774 goto out;
775
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000776 data = xbuf[0];
777 memcpy(data, template[i].input, template[i].ilen);
778
779 crypto_cipher_clear_flags(tfm, ~0);
780 if (template[i].wk)
781 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
782
783 ret = crypto_cipher_setkey(tfm, template[i].key,
784 template[i].klen);
785 if (!ret == template[i].fail) {
786 printk(KERN_ERR "alg: cipher: setkey failed "
787 "on test %d for %s: flags=%x\n", j,
788 algo, crypto_cipher_get_flags(tfm));
789 goto out;
790 } else if (ret)
791 continue;
792
793 for (k = 0; k < template[i].ilen;
794 k += crypto_cipher_blocksize(tfm)) {
795 if (enc)
796 crypto_cipher_encrypt_one(tfm, data + k,
797 data + k);
798 else
799 crypto_cipher_decrypt_one(tfm, data + k,
800 data + k);
801 }
802
803 q = data;
804 if (memcmp(q, template[i].result, template[i].rlen)) {
805 printk(KERN_ERR "alg: cipher: Test %d failed "
806 "on %s for %s\n", j, e, algo);
807 hexdump(q, template[i].rlen);
808 ret = -EINVAL;
809 goto out;
810 }
811 }
812
813 ret = 0;
814
815out:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800816 testmgr_free_buf(xbuf);
817out_nobuf:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000818 return ret;
819}
820
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300821static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
822 struct cipher_testvec *template, unsigned int tcount,
823 const bool diff_dst)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +1000824{
Herbert Xuda7f0332008-07-31 17:08:25 +0800825 const char *algo =
826 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
827 unsigned int i, j, k, n, temp;
Herbert Xuda7f0332008-07-31 17:08:25 +0800828 char *q;
829 struct ablkcipher_request *req;
830 struct scatterlist sg[8];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300831 struct scatterlist sgout[8];
832 const char *e, *d;
Herbert Xuda7f0332008-07-31 17:08:25 +0800833 struct tcrypt_result result;
834 void *data;
835 char iv[MAX_IVLEN];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800836 char *xbuf[XBUFSIZE];
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300837 char *xoutbuf[XBUFSIZE];
Herbert Xuf8b0d4d2009-05-06 14:15:47 +0800838 int ret = -ENOMEM;
839
840 if (testmgr_alloc_buf(xbuf))
841 goto out_nobuf;
Herbert Xuda7f0332008-07-31 17:08:25 +0800842
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300843 if (diff_dst && testmgr_alloc_buf(xoutbuf))
844 goto out_nooutbuf;
845
846 if (diff_dst)
847 d = "-ddst";
848 else
849 d = "";
850
Herbert Xuda7f0332008-07-31 17:08:25 +0800851 if (enc == ENCRYPT)
852 e = "encryption";
853 else
854 e = "decryption";
855
856 init_completion(&result.completion);
857
858 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
859 if (!req) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300860 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
861 d, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800862 goto out;
863 }
864
865 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
866 tcrypt_complete, &result);
867
868 j = 0;
869 for (i = 0; i < tcount; i++) {
870 if (template[i].iv)
871 memcpy(iv, template[i].iv, MAX_IVLEN);
872 else
873 memset(iv, 0, MAX_IVLEN);
874
Jussi Kivilinnaf44d83d2012-09-19 09:42:49 +0300875 if (!(template[i].np) || (template[i].also_non_np)) {
Herbert Xuda7f0332008-07-31 17:08:25 +0800876 j++;
877
Herbert Xufd57f222009-05-29 16:05:42 +1000878 ret = -EINVAL;
879 if (WARN_ON(template[i].ilen > PAGE_SIZE))
880 goto out;
881
Herbert Xuda7f0332008-07-31 17:08:25 +0800882 data = xbuf[0];
883 memcpy(data, template[i].input, template[i].ilen);
884
885 crypto_ablkcipher_clear_flags(tfm, ~0);
886 if (template[i].wk)
887 crypto_ablkcipher_set_flags(
888 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
889
890 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
891 template[i].klen);
892 if (!ret == template[i].fail) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300893 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
894 d, j, algo,
895 crypto_ablkcipher_get_flags(tfm));
Herbert Xuda7f0332008-07-31 17:08:25 +0800896 goto out;
897 } else if (ret)
898 continue;
899
900 sg_init_one(&sg[0], data, template[i].ilen);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300901 if (diff_dst) {
902 data = xoutbuf[0];
903 sg_init_one(&sgout[0], data, template[i].ilen);
904 }
Herbert Xuda7f0332008-07-31 17:08:25 +0800905
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300906 ablkcipher_request_set_crypt(req, sg,
907 (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +0800908 template[i].ilen, iv);
909 ret = enc ?
910 crypto_ablkcipher_encrypt(req) :
911 crypto_ablkcipher_decrypt(req);
912
913 switch (ret) {
914 case 0:
915 break;
916 case -EINPROGRESS:
917 case -EBUSY:
918 ret = wait_for_completion_interruptible(
919 &result.completion);
920 if (!ret && !((ret = result.err))) {
921 INIT_COMPLETION(result.completion);
922 break;
923 }
924 /* fall through */
925 default:
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300926 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
927 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +0800928 goto out;
929 }
930
931 q = data;
932 if (memcmp(q, template[i].result, template[i].rlen)) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300933 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
934 d, j, e, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +0800935 hexdump(q, template[i].rlen);
936 ret = -EINVAL;
937 goto out;
938 }
939 }
940 }
941
942 j = 0;
943 for (i = 0; i < tcount; i++) {
944
945 if (template[i].iv)
946 memcpy(iv, template[i].iv, MAX_IVLEN);
947 else
948 memset(iv, 0, MAX_IVLEN);
949
950 if (template[i].np) {
951 j++;
952
953 crypto_ablkcipher_clear_flags(tfm, ~0);
954 if (template[i].wk)
955 crypto_ablkcipher_set_flags(
956 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
957
958 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
959 template[i].klen);
960 if (!ret == template[i].fail) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300961 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
962 d, j, algo,
Herbert Xuda7f0332008-07-31 17:08:25 +0800963 crypto_ablkcipher_get_flags(tfm));
964 goto out;
965 } else if (ret)
966 continue;
967
968 temp = 0;
969 ret = -EINVAL;
970 sg_init_table(sg, template[i].np);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300971 if (diff_dst)
972 sg_init_table(sgout, template[i].np);
Herbert Xuda7f0332008-07-31 17:08:25 +0800973 for (k = 0; k < template[i].np; k++) {
974 if (WARN_ON(offset_in_page(IDX[k]) +
975 template[i].tap[k] > PAGE_SIZE))
976 goto out;
977
978 q = xbuf[IDX[k] >> PAGE_SHIFT] +
979 offset_in_page(IDX[k]);
980
981 memcpy(q, template[i].input + temp,
982 template[i].tap[k]);
983
984 if (offset_in_page(q) + template[i].tap[k] <
985 PAGE_SIZE)
986 q[template[i].tap[k]] = 0;
987
988 sg_set_buf(&sg[k], q, template[i].tap[k]);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +0300989 if (diff_dst) {
990 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
991 offset_in_page(IDX[k]);
992
993 sg_set_buf(&sgout[k], q,
994 template[i].tap[k]);
995
996 memset(q, 0, template[i].tap[k]);
997 if (offset_in_page(q) +
998 template[i].tap[k] < PAGE_SIZE)
999 q[template[i].tap[k]] = 0;
1000 }
Herbert Xuda7f0332008-07-31 17:08:25 +08001001
1002 temp += template[i].tap[k];
1003 }
1004
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001005 ablkcipher_request_set_crypt(req, sg,
1006 (diff_dst) ? sgout : sg,
Herbert Xuda7f0332008-07-31 17:08:25 +08001007 template[i].ilen, iv);
1008
1009 ret = enc ?
1010 crypto_ablkcipher_encrypt(req) :
1011 crypto_ablkcipher_decrypt(req);
1012
1013 switch (ret) {
1014 case 0:
1015 break;
1016 case -EINPROGRESS:
1017 case -EBUSY:
1018 ret = wait_for_completion_interruptible(
1019 &result.completion);
1020 if (!ret && !((ret = result.err))) {
1021 INIT_COMPLETION(result.completion);
1022 break;
1023 }
1024 /* fall through */
1025 default:
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001026 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1027 d, e, j, algo, -ret);
Herbert Xuda7f0332008-07-31 17:08:25 +08001028 goto out;
1029 }
1030
1031 temp = 0;
1032 ret = -EINVAL;
1033 for (k = 0; k < template[i].np; k++) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001034 if (diff_dst)
1035 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1036 offset_in_page(IDX[k]);
1037 else
1038 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1039 offset_in_page(IDX[k]);
Herbert Xuda7f0332008-07-31 17:08:25 +08001040
1041 if (memcmp(q, template[i].result + temp,
1042 template[i].tap[k])) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001043 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1044 d, j, e, k, algo);
Herbert Xuda7f0332008-07-31 17:08:25 +08001045 hexdump(q, template[i].tap[k]);
1046 goto out;
1047 }
1048
1049 q += template[i].tap[k];
1050 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1051 ;
1052 if (n) {
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001053 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1054 d, j, e, k, algo, n);
Herbert Xuda7f0332008-07-31 17:08:25 +08001055 hexdump(q, n);
1056 goto out;
1057 }
1058 temp += template[i].tap[k];
1059 }
1060 }
1061 }
1062
1063 ret = 0;
1064
1065out:
1066 ablkcipher_request_free(req);
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001067 if (diff_dst)
1068 testmgr_free_buf(xoutbuf);
1069out_nooutbuf:
Herbert Xuf8b0d4d2009-05-06 14:15:47 +08001070 testmgr_free_buf(xbuf);
1071out_nobuf:
Herbert Xuda7f0332008-07-31 17:08:25 +08001072 return ret;
1073}
1074
Jussi Kivilinna08d6af82012-09-21 10:26:47 +03001075static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1076 struct cipher_testvec *template, unsigned int tcount)
1077{
1078 int ret;
1079
1080 /* test 'dst == src' case */
1081 ret = __test_skcipher(tfm, enc, template, tcount, false);
1082 if (ret)
1083 return ret;
1084
1085 /* test 'dst != src' case */
1086 return __test_skcipher(tfm, enc, template, tcount, true);
1087}
1088
Herbert Xuda7f0332008-07-31 17:08:25 +08001089static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1090 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1091{
1092 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1093 unsigned int i;
1094 char result[COMP_BUF_SIZE];
1095 int ret;
1096
1097 for (i = 0; i < ctcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001098 int ilen;
1099 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001100
1101 memset(result, 0, sizeof (result));
1102
1103 ilen = ctemplate[i].inlen;
1104 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1105 ilen, result, &dlen);
1106 if (ret) {
1107 printk(KERN_ERR "alg: comp: compression failed "
1108 "on test %d for %s: ret=%d\n", i + 1, algo,
1109 -ret);
1110 goto out;
1111 }
1112
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001113 if (dlen != ctemplate[i].outlen) {
1114 printk(KERN_ERR "alg: comp: Compression test %d "
1115 "failed for %s: output len = %d\n", i + 1, algo,
1116 dlen);
1117 ret = -EINVAL;
1118 goto out;
1119 }
1120
Herbert Xuda7f0332008-07-31 17:08:25 +08001121 if (memcmp(result, ctemplate[i].output, dlen)) {
1122 printk(KERN_ERR "alg: comp: Compression test %d "
1123 "failed for %s\n", i + 1, algo);
1124 hexdump(result, dlen);
1125 ret = -EINVAL;
1126 goto out;
1127 }
1128 }
1129
1130 for (i = 0; i < dtcount; i++) {
Geert Uytterhoevenc79cf912009-03-29 15:44:19 +08001131 int ilen;
1132 unsigned int dlen = COMP_BUF_SIZE;
Herbert Xuda7f0332008-07-31 17:08:25 +08001133
1134 memset(result, 0, sizeof (result));
1135
1136 ilen = dtemplate[i].inlen;
1137 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1138 ilen, result, &dlen);
1139 if (ret) {
1140 printk(KERN_ERR "alg: comp: decompression failed "
1141 "on test %d for %s: ret=%d\n", i + 1, algo,
1142 -ret);
1143 goto out;
1144 }
1145
Geert Uytterhoevenb812eb02008-11-28 20:51:28 +08001146 if (dlen != dtemplate[i].outlen) {
1147 printk(KERN_ERR "alg: comp: Decompression test %d "
1148 "failed for %s: output len = %d\n", i + 1, algo,
1149 dlen);
1150 ret = -EINVAL;
1151 goto out;
1152 }
1153
Herbert Xuda7f0332008-07-31 17:08:25 +08001154 if (memcmp(result, dtemplate[i].output, dlen)) {
1155 printk(KERN_ERR "alg: comp: Decompression test %d "
1156 "failed for %s\n", i + 1, algo);
1157 hexdump(result, dlen);
1158 ret = -EINVAL;
1159 goto out;
1160 }
1161 }
1162
1163 ret = 0;
1164
1165out:
1166 return ret;
1167}
1168
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001169static int test_pcomp(struct crypto_pcomp *tfm,
1170 struct pcomp_testvec *ctemplate,
1171 struct pcomp_testvec *dtemplate, int ctcount,
1172 int dtcount)
1173{
1174 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1175 unsigned int i;
1176 char result[COMP_BUF_SIZE];
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001177 int res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001178
1179 for (i = 0; i < ctcount; i++) {
1180 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001181 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001182
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001183 res = crypto_compress_setup(tfm, ctemplate[i].params,
1184 ctemplate[i].paramsize);
1185 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001186 pr_err("alg: pcomp: compression setup failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001187 "%d for %s: error=%d\n", i + 1, algo, res);
1188 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001189 }
1190
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001191 res = crypto_compress_init(tfm);
1192 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001193 pr_err("alg: pcomp: compression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001194 "%d for %s: error=%d\n", i + 1, algo, res);
1195 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001196 }
1197
1198 memset(result, 0, sizeof(result));
1199
1200 req.next_in = ctemplate[i].input;
1201 req.avail_in = ctemplate[i].inlen / 2;
1202 req.next_out = result;
1203 req.avail_out = ctemplate[i].outlen / 2;
1204
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001205 res = crypto_compress_update(tfm, &req);
1206 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001207 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001208 "%d for %s: error=%d\n", i + 1, algo, res);
1209 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001210 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001211 if (res > 0)
1212 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001213
1214 /* Add remaining input data */
1215 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1216
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001217 res = crypto_compress_update(tfm, &req);
1218 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001219 pr_err("alg: pcomp: compression update failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001220 "%d for %s: error=%d\n", i + 1, algo, res);
1221 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001222 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001223 if (res > 0)
1224 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001225
1226 /* Provide remaining output space */
1227 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1228
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001229 res = crypto_compress_final(tfm, &req);
1230 if (res < 0) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001231 pr_err("alg: pcomp: compression final failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001232 "%d for %s: error=%d\n", i + 1, algo, res);
1233 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001234 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001235 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001236
1237 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1238 pr_err("alg: comp: Compression test %d failed for %s: "
1239 "output len = %d (expected %d)\n", i + 1, algo,
1240 COMP_BUF_SIZE - req.avail_out,
1241 ctemplate[i].outlen);
1242 return -EINVAL;
1243 }
1244
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001245 if (produced != ctemplate[i].outlen) {
1246 pr_err("alg: comp: Compression test %d failed for %s: "
1247 "returned len = %u (expected %d)\n", i + 1,
1248 algo, produced, ctemplate[i].outlen);
1249 return -EINVAL;
1250 }
1251
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001252 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1253 pr_err("alg: pcomp: Compression test %d failed for "
1254 "%s\n", i + 1, algo);
1255 hexdump(result, ctemplate[i].outlen);
1256 return -EINVAL;
1257 }
1258 }
1259
1260 for (i = 0; i < dtcount; i++) {
1261 struct comp_request req;
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001262 unsigned int produced = 0;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001263
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001264 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1265 dtemplate[i].paramsize);
1266 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001267 pr_err("alg: pcomp: decompression setup failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001268 "test %d for %s: error=%d\n", i + 1, algo, res);
1269 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001270 }
1271
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001272 res = crypto_decompress_init(tfm);
1273 if (res) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001274 pr_err("alg: pcomp: decompression init failed on test "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001275 "%d for %s: error=%d\n", i + 1, algo, res);
1276 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001277 }
1278
1279 memset(result, 0, sizeof(result));
1280
1281 req.next_in = dtemplate[i].input;
1282 req.avail_in = dtemplate[i].inlen / 2;
1283 req.next_out = result;
1284 req.avail_out = dtemplate[i].outlen / 2;
1285
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001286 res = crypto_decompress_update(tfm, &req);
1287 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001288 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001289 "test %d for %s: error=%d\n", i + 1, algo, res);
1290 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001291 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001292 if (res > 0)
1293 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001294
1295 /* Add remaining input data */
1296 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1297
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001298 res = crypto_decompress_update(tfm, &req);
1299 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001300 pr_err("alg: pcomp: decompression update failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001301 "test %d for %s: error=%d\n", i + 1, algo, res);
1302 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001303 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001304 if (res > 0)
1305 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001306
1307 /* Provide remaining output space */
1308 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1309
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001310 res = crypto_decompress_final(tfm, &req);
1311 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001312 pr_err("alg: pcomp: decompression final failed on "
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001313 "test %d for %s: error=%d\n", i + 1, algo, res);
1314 return res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001315 }
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001316 if (res > 0)
1317 produced += res;
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001318
1319 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1320 pr_err("alg: comp: Decompression test %d failed for "
1321 "%s: output len = %d (expected %d)\n", i + 1,
1322 algo, COMP_BUF_SIZE - req.avail_out,
1323 dtemplate[i].outlen);
1324 return -EINVAL;
1325 }
1326
Geert Uytterhoeven3ce858c2009-05-27 15:05:02 +10001327 if (produced != dtemplate[i].outlen) {
1328 pr_err("alg: comp: Decompression test %d failed for "
1329 "%s: returned len = %u (expected %d)\n", i + 1,
1330 algo, produced, dtemplate[i].outlen);
1331 return -EINVAL;
1332 }
1333
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001334 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1335 pr_err("alg: pcomp: Decompression test %d failed for "
1336 "%s\n", i + 1, algo);
1337 hexdump(result, dtemplate[i].outlen);
1338 return -EINVAL;
1339 }
1340 }
1341
1342 return 0;
1343}
1344
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001345
1346static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1347 unsigned int tcount)
1348{
1349 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Felipe Contrerasfa4ef8a2009-10-27 19:04:42 +08001350 int err = 0, i, j, seedsize;
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001351 u8 *seed;
1352 char result[32];
1353
1354 seedsize = crypto_rng_seedsize(tfm);
1355
1356 seed = kmalloc(seedsize, GFP_KERNEL);
1357 if (!seed) {
1358 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1359 "for %s\n", algo);
1360 return -ENOMEM;
1361 }
1362
1363 for (i = 0; i < tcount; i++) {
1364 memset(result, 0, 32);
1365
1366 memcpy(seed, template[i].v, template[i].vlen);
1367 memcpy(seed + template[i].vlen, template[i].key,
1368 template[i].klen);
1369 memcpy(seed + template[i].vlen + template[i].klen,
1370 template[i].dt, template[i].dtlen);
1371
1372 err = crypto_rng_reset(tfm, seed, seedsize);
1373 if (err) {
1374 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1375 "for %s\n", algo);
1376 goto out;
1377 }
1378
1379 for (j = 0; j < template[i].loops; j++) {
1380 err = crypto_rng_get_bytes(tfm, result,
1381 template[i].rlen);
1382 if (err != template[i].rlen) {
1383 printk(KERN_ERR "alg: cprng: Failed to obtain "
1384 "the correct amount of random data for "
1385 "%s (requested %d, got %d)\n", algo,
1386 template[i].rlen, err);
1387 goto out;
1388 }
1389 }
1390
1391 err = memcmp(result, template[i].result,
1392 template[i].rlen);
1393 if (err) {
1394 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1395 i, algo);
1396 hexdump(result, template[i].rlen);
1397 err = -EINVAL;
1398 goto out;
1399 }
1400 }
1401
1402out:
1403 kfree(seed);
1404 return err;
1405}
1406
Herbert Xuda7f0332008-07-31 17:08:25 +08001407static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1408 u32 type, u32 mask)
1409{
1410 struct crypto_aead *tfm;
1411 int err = 0;
1412
1413 tfm = crypto_alloc_aead(driver, type, mask);
1414 if (IS_ERR(tfm)) {
1415 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1416 "%ld\n", driver, PTR_ERR(tfm));
1417 return PTR_ERR(tfm);
1418 }
1419
1420 if (desc->suite.aead.enc.vecs) {
1421 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1422 desc->suite.aead.enc.count);
1423 if (err)
1424 goto out;
1425 }
1426
1427 if (!err && desc->suite.aead.dec.vecs)
1428 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1429 desc->suite.aead.dec.count);
1430
1431out:
1432 crypto_free_aead(tfm);
1433 return err;
1434}
1435
1436static int alg_test_cipher(const struct alg_test_desc *desc,
1437 const char *driver, u32 type, u32 mask)
1438{
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001439 struct crypto_cipher *tfm;
Herbert Xuda7f0332008-07-31 17:08:25 +08001440 int err = 0;
1441
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001442 tfm = crypto_alloc_cipher(driver, type, mask);
Herbert Xuda7f0332008-07-31 17:08:25 +08001443 if (IS_ERR(tfm)) {
1444 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1445 "%s: %ld\n", driver, PTR_ERR(tfm));
1446 return PTR_ERR(tfm);
1447 }
1448
1449 if (desc->suite.cipher.enc.vecs) {
1450 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1451 desc->suite.cipher.enc.count);
1452 if (err)
1453 goto out;
1454 }
1455
1456 if (desc->suite.cipher.dec.vecs)
1457 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1458 desc->suite.cipher.dec.count);
1459
1460out:
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001461 crypto_free_cipher(tfm);
1462 return err;
1463}
1464
1465static int alg_test_skcipher(const struct alg_test_desc *desc,
1466 const char *driver, u32 type, u32 mask)
1467{
1468 struct crypto_ablkcipher *tfm;
1469 int err = 0;
1470
1471 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1472 if (IS_ERR(tfm)) {
1473 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1474 "%s: %ld\n", driver, PTR_ERR(tfm));
1475 return PTR_ERR(tfm);
1476 }
1477
1478 if (desc->suite.cipher.enc.vecs) {
1479 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1480 desc->suite.cipher.enc.count);
1481 if (err)
1482 goto out;
1483 }
1484
1485 if (desc->suite.cipher.dec.vecs)
1486 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1487 desc->suite.cipher.dec.count);
1488
1489out:
Herbert Xuda7f0332008-07-31 17:08:25 +08001490 crypto_free_ablkcipher(tfm);
1491 return err;
1492}
1493
1494static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1495 u32 type, u32 mask)
1496{
1497 struct crypto_comp *tfm;
1498 int err;
1499
1500 tfm = crypto_alloc_comp(driver, type, mask);
1501 if (IS_ERR(tfm)) {
1502 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1503 "%ld\n", driver, PTR_ERR(tfm));
1504 return PTR_ERR(tfm);
1505 }
1506
1507 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1508 desc->suite.comp.decomp.vecs,
1509 desc->suite.comp.comp.count,
1510 desc->suite.comp.decomp.count);
1511
1512 crypto_free_comp(tfm);
1513 return err;
1514}
1515
Geert Uytterhoeven8064efb2009-03-04 15:08:03 +08001516static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1517 u32 type, u32 mask)
1518{
1519 struct crypto_pcomp *tfm;
1520 int err;
1521
1522 tfm = crypto_alloc_pcomp(driver, type, mask);
1523 if (IS_ERR(tfm)) {
1524 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1525 driver, PTR_ERR(tfm));
1526 return PTR_ERR(tfm);
1527 }
1528
1529 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1530 desc->suite.pcomp.decomp.vecs,
1531 desc->suite.pcomp.comp.count,
1532 desc->suite.pcomp.decomp.count);
1533
1534 crypto_free_pcomp(tfm);
1535 return err;
1536}
1537
Herbert Xuda7f0332008-07-31 17:08:25 +08001538static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1539 u32 type, u32 mask)
1540{
1541 struct crypto_ahash *tfm;
1542 int err;
1543
1544 tfm = crypto_alloc_ahash(driver, type, mask);
1545 if (IS_ERR(tfm)) {
1546 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1547 "%ld\n", driver, PTR_ERR(tfm));
1548 return PTR_ERR(tfm);
1549 }
1550
David S. Millera8f1a052010-05-19 14:12:03 +10001551 err = test_hash(tfm, desc->suite.hash.vecs,
1552 desc->suite.hash.count, true);
1553 if (!err)
1554 err = test_hash(tfm, desc->suite.hash.vecs,
1555 desc->suite.hash.count, false);
Herbert Xuda7f0332008-07-31 17:08:25 +08001556
1557 crypto_free_ahash(tfm);
1558 return err;
1559}
1560
Herbert Xu8e3ee852008-11-07 14:58:52 +08001561static int alg_test_crc32c(const struct alg_test_desc *desc,
1562 const char *driver, u32 type, u32 mask)
1563{
1564 struct crypto_shash *tfm;
1565 u32 val;
1566 int err;
1567
1568 err = alg_test_hash(desc, driver, type, mask);
1569 if (err)
1570 goto out;
1571
1572 tfm = crypto_alloc_shash(driver, type, mask);
1573 if (IS_ERR(tfm)) {
1574 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1575 "%ld\n", driver, PTR_ERR(tfm));
1576 err = PTR_ERR(tfm);
1577 goto out;
1578 }
1579
1580 do {
1581 struct {
1582 struct shash_desc shash;
1583 char ctx[crypto_shash_descsize(tfm)];
1584 } sdesc;
1585
1586 sdesc.shash.tfm = tfm;
1587 sdesc.shash.flags = 0;
1588
1589 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1590 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1591 if (err) {
1592 printk(KERN_ERR "alg: crc32c: Operation failed for "
1593 "%s: %d\n", driver, err);
1594 break;
1595 }
1596
1597 if (val != ~420553207) {
1598 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1599 "%d\n", driver, val);
1600 err = -EINVAL;
1601 }
1602 } while (0);
1603
1604 crypto_free_shash(tfm);
1605
1606out:
1607 return err;
1608}
1609
Jarod Wilson7647d6c2009-05-04 19:44:50 +08001610static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1611 u32 type, u32 mask)
1612{
1613 struct crypto_rng *rng;
1614 int err;
1615
1616 rng = crypto_alloc_rng(driver, type, mask);
1617 if (IS_ERR(rng)) {
1618 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1619 "%ld\n", driver, PTR_ERR(rng));
1620 return PTR_ERR(rng);
1621 }
1622
1623 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1624
1625 crypto_free_rng(rng);
1626
1627 return err;
1628}
1629
Youquan, Song863b5572009-12-23 19:45:20 +08001630static int alg_test_null(const struct alg_test_desc *desc,
1631 const char *driver, u32 type, u32 mask)
1632{
1633 return 0;
1634}
1635
Herbert Xuda7f0332008-07-31 17:08:25 +08001636/* Please keep this list sorted by algorithm name. */
1637static const struct alg_test_desc alg_test_descs[] = {
1638 {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001639 .alg = "__cbc-cast5-avx",
1640 .test = alg_test_null,
1641 .suite = {
1642 .cipher = {
1643 .enc = {
1644 .vecs = NULL,
1645 .count = 0
1646 },
1647 .dec = {
1648 .vecs = NULL,
1649 .count = 0
1650 }
1651 }
1652 }
1653 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001654 .alg = "__cbc-cast6-avx",
1655 .test = alg_test_null,
1656 .suite = {
1657 .cipher = {
1658 .enc = {
1659 .vecs = NULL,
1660 .count = 0
1661 },
1662 .dec = {
1663 .vecs = NULL,
1664 .count = 0
1665 }
1666 }
1667 }
1668 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001669 .alg = "__cbc-serpent-avx",
1670 .test = alg_test_null,
1671 .suite = {
1672 .cipher = {
1673 .enc = {
1674 .vecs = NULL,
1675 .count = 0
1676 },
1677 .dec = {
1678 .vecs = NULL,
1679 .count = 0
1680 }
1681 }
1682 }
1683 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001684 .alg = "__cbc-serpent-sse2",
1685 .test = alg_test_null,
1686 .suite = {
1687 .cipher = {
1688 .enc = {
1689 .vecs = NULL,
1690 .count = 0
1691 },
1692 .dec = {
1693 .vecs = NULL,
1694 .count = 0
1695 }
1696 }
1697 }
1698 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001699 .alg = "__cbc-twofish-avx",
1700 .test = alg_test_null,
1701 .suite = {
1702 .cipher = {
1703 .enc = {
1704 .vecs = NULL,
1705 .count = 0
1706 },
1707 .dec = {
1708 .vecs = NULL,
1709 .count = 0
1710 }
1711 }
1712 }
1713 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001714 .alg = "__driver-cbc-aes-aesni",
1715 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001716 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001717 .suite = {
1718 .cipher = {
1719 .enc = {
1720 .vecs = NULL,
1721 .count = 0
1722 },
1723 .dec = {
1724 .vecs = NULL,
1725 .count = 0
1726 }
1727 }
1728 }
1729 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001730 .alg = "__driver-cbc-cast5-avx",
1731 .test = alg_test_null,
1732 .suite = {
1733 .cipher = {
1734 .enc = {
1735 .vecs = NULL,
1736 .count = 0
1737 },
1738 .dec = {
1739 .vecs = NULL,
1740 .count = 0
1741 }
1742 }
1743 }
1744 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001745 .alg = "__driver-cbc-cast6-avx",
1746 .test = alg_test_null,
1747 .suite = {
1748 .cipher = {
1749 .enc = {
1750 .vecs = NULL,
1751 .count = 0
1752 },
1753 .dec = {
1754 .vecs = NULL,
1755 .count = 0
1756 }
1757 }
1758 }
1759 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001760 .alg = "__driver-cbc-serpent-avx",
1761 .test = alg_test_null,
1762 .suite = {
1763 .cipher = {
1764 .enc = {
1765 .vecs = NULL,
1766 .count = 0
1767 },
1768 .dec = {
1769 .vecs = NULL,
1770 .count = 0
1771 }
1772 }
1773 }
1774 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001775 .alg = "__driver-cbc-serpent-sse2",
1776 .test = alg_test_null,
1777 .suite = {
1778 .cipher = {
1779 .enc = {
1780 .vecs = NULL,
1781 .count = 0
1782 },
1783 .dec = {
1784 .vecs = NULL,
1785 .count = 0
1786 }
1787 }
1788 }
1789 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001790 .alg = "__driver-cbc-twofish-avx",
1791 .test = alg_test_null,
1792 .suite = {
1793 .cipher = {
1794 .enc = {
1795 .vecs = NULL,
1796 .count = 0
1797 },
1798 .dec = {
1799 .vecs = NULL,
1800 .count = 0
1801 }
1802 }
1803 }
1804 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001805 .alg = "__driver-ecb-aes-aesni",
1806 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001807 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001808 .suite = {
1809 .cipher = {
1810 .enc = {
1811 .vecs = NULL,
1812 .count = 0
1813 },
1814 .dec = {
1815 .vecs = NULL,
1816 .count = 0
1817 }
1818 }
1819 }
1820 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02001821 .alg = "__driver-ecb-cast5-avx",
1822 .test = alg_test_null,
1823 .suite = {
1824 .cipher = {
1825 .enc = {
1826 .vecs = NULL,
1827 .count = 0
1828 },
1829 .dec = {
1830 .vecs = NULL,
1831 .count = 0
1832 }
1833 }
1834 }
1835 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02001836 .alg = "__driver-ecb-cast6-avx",
1837 .test = alg_test_null,
1838 .suite = {
1839 .cipher = {
1840 .enc = {
1841 .vecs = NULL,
1842 .count = 0
1843 },
1844 .dec = {
1845 .vecs = NULL,
1846 .count = 0
1847 }
1848 }
1849 }
1850 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08001851 .alg = "__driver-ecb-serpent-avx",
1852 .test = alg_test_null,
1853 .suite = {
1854 .cipher = {
1855 .enc = {
1856 .vecs = NULL,
1857 .count = 0
1858 },
1859 .dec = {
1860 .vecs = NULL,
1861 .count = 0
1862 }
1863 }
1864 }
1865 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02001866 .alg = "__driver-ecb-serpent-sse2",
1867 .test = alg_test_null,
1868 .suite = {
1869 .cipher = {
1870 .enc = {
1871 .vecs = NULL,
1872 .count = 0
1873 },
1874 .dec = {
1875 .vecs = NULL,
1876 .count = 0
1877 }
1878 }
1879 }
1880 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001881 .alg = "__driver-ecb-twofish-avx",
1882 .test = alg_test_null,
1883 .suite = {
1884 .cipher = {
1885 .enc = {
1886 .vecs = NULL,
1887 .count = 0
1888 },
1889 .dec = {
1890 .vecs = NULL,
1891 .count = 0
1892 }
1893 }
1894 }
1895 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08001896 .alg = "__ghash-pclmulqdqni",
1897 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02001898 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08001899 .suite = {
1900 .hash = {
1901 .vecs = NULL,
1902 .count = 0
1903 }
1904 }
1905 }, {
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001906 .alg = "ansi_cprng",
1907 .test = alg_test_cprng,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001908 .fips_allowed = 1,
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001909 .suite = {
1910 .cprng = {
1911 .vecs = ansi_cprng_aes_tv_template,
1912 .count = ANSI_CPRNG_AES_TEST_VECTORS
1913 }
1914 }
1915 }, {
Horia Geantae46e9a42012-07-03 19:16:54 +03001916 .alg = "authenc(hmac(sha1),cbc(aes))",
1917 .test = alg_test_aead,
1918 .fips_allowed = 1,
1919 .suite = {
1920 .aead = {
1921 .enc = {
1922 .vecs = hmac_sha1_aes_cbc_enc_tv_template,
1923 .count = HMAC_SHA1_AES_CBC_ENC_TEST_VECTORS
1924 }
1925 }
1926 }
1927 }, {
1928 .alg = "authenc(hmac(sha256),cbc(aes))",
1929 .test = alg_test_aead,
1930 .fips_allowed = 1,
1931 .suite = {
1932 .aead = {
1933 .enc = {
1934 .vecs = hmac_sha256_aes_cbc_enc_tv_template,
1935 .count = HMAC_SHA256_AES_CBC_ENC_TEST_VECTORS
1936 }
1937 }
1938 }
1939 }, {
1940 .alg = "authenc(hmac(sha512),cbc(aes))",
1941 .test = alg_test_aead,
1942 .fips_allowed = 1,
1943 .suite = {
1944 .aead = {
1945 .enc = {
1946 .vecs = hmac_sha512_aes_cbc_enc_tv_template,
1947 .count = HMAC_SHA512_AES_CBC_ENC_TEST_VECTORS
1948 }
1949 }
1950 }
1951 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08001952 .alg = "cbc(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001953 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10001954 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08001955 .suite = {
1956 .cipher = {
1957 .enc = {
1958 .vecs = aes_cbc_enc_tv_template,
1959 .count = AES_CBC_ENC_TEST_VECTORS
1960 },
1961 .dec = {
1962 .vecs = aes_cbc_dec_tv_template,
1963 .count = AES_CBC_DEC_TEST_VECTORS
1964 }
1965 }
1966 }
1967 }, {
1968 .alg = "cbc(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001969 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001970 .suite = {
1971 .cipher = {
1972 .enc = {
1973 .vecs = anubis_cbc_enc_tv_template,
1974 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1975 },
1976 .dec = {
1977 .vecs = anubis_cbc_dec_tv_template,
1978 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1979 }
1980 }
1981 }
1982 }, {
1983 .alg = "cbc(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001984 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08001985 .suite = {
1986 .cipher = {
1987 .enc = {
1988 .vecs = bf_cbc_enc_tv_template,
1989 .count = BF_CBC_ENC_TEST_VECTORS
1990 },
1991 .dec = {
1992 .vecs = bf_cbc_dec_tv_template,
1993 .count = BF_CBC_DEC_TEST_VECTORS
1994 }
1995 }
1996 }
1997 }, {
1998 .alg = "cbc(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10001999 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002000 .suite = {
2001 .cipher = {
2002 .enc = {
2003 .vecs = camellia_cbc_enc_tv_template,
2004 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2005 },
2006 .dec = {
2007 .vecs = camellia_cbc_dec_tv_template,
2008 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2009 }
2010 }
2011 }
2012 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002013 .alg = "cbc(cast5)",
2014 .test = alg_test_skcipher,
2015 .suite = {
2016 .cipher = {
2017 .enc = {
2018 .vecs = cast5_cbc_enc_tv_template,
2019 .count = CAST5_CBC_ENC_TEST_VECTORS
2020 },
2021 .dec = {
2022 .vecs = cast5_cbc_dec_tv_template,
2023 .count = CAST5_CBC_DEC_TEST_VECTORS
2024 }
2025 }
2026 }
2027 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002028 .alg = "cbc(cast6)",
2029 .test = alg_test_skcipher,
2030 .suite = {
2031 .cipher = {
2032 .enc = {
2033 .vecs = cast6_cbc_enc_tv_template,
2034 .count = CAST6_CBC_ENC_TEST_VECTORS
2035 },
2036 .dec = {
2037 .vecs = cast6_cbc_dec_tv_template,
2038 .count = CAST6_CBC_DEC_TEST_VECTORS
2039 }
2040 }
2041 }
2042 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002043 .alg = "cbc(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002044 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002045 .suite = {
2046 .cipher = {
2047 .enc = {
2048 .vecs = des_cbc_enc_tv_template,
2049 .count = DES_CBC_ENC_TEST_VECTORS
2050 },
2051 .dec = {
2052 .vecs = des_cbc_dec_tv_template,
2053 .count = DES_CBC_DEC_TEST_VECTORS
2054 }
2055 }
2056 }
2057 }, {
2058 .alg = "cbc(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002059 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002060 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002061 .suite = {
2062 .cipher = {
2063 .enc = {
2064 .vecs = des3_ede_cbc_enc_tv_template,
2065 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2066 },
2067 .dec = {
2068 .vecs = des3_ede_cbc_dec_tv_template,
2069 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2070 }
2071 }
2072 }
2073 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002074 .alg = "cbc(serpent)",
2075 .test = alg_test_skcipher,
2076 .suite = {
2077 .cipher = {
2078 .enc = {
2079 .vecs = serpent_cbc_enc_tv_template,
2080 .count = SERPENT_CBC_ENC_TEST_VECTORS
2081 },
2082 .dec = {
2083 .vecs = serpent_cbc_dec_tv_template,
2084 .count = SERPENT_CBC_DEC_TEST_VECTORS
2085 }
2086 }
2087 }
2088 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002089 .alg = "cbc(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002090 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002091 .suite = {
2092 .cipher = {
2093 .enc = {
2094 .vecs = tf_cbc_enc_tv_template,
2095 .count = TF_CBC_ENC_TEST_VECTORS
2096 },
2097 .dec = {
2098 .vecs = tf_cbc_dec_tv_template,
2099 .count = TF_CBC_DEC_TEST_VECTORS
2100 }
2101 }
2102 }
2103 }, {
2104 .alg = "ccm(aes)",
2105 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002106 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002107 .suite = {
2108 .aead = {
2109 .enc = {
2110 .vecs = aes_ccm_enc_tv_template,
2111 .count = AES_CCM_ENC_TEST_VECTORS
2112 },
2113 .dec = {
2114 .vecs = aes_ccm_dec_tv_template,
2115 .count = AES_CCM_DEC_TEST_VECTORS
2116 }
2117 }
2118 }
2119 }, {
2120 .alg = "crc32c",
Herbert Xu8e3ee852008-11-07 14:58:52 +08002121 .test = alg_test_crc32c,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002122 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002123 .suite = {
2124 .hash = {
2125 .vecs = crc32c_tv_template,
2126 .count = CRC32C_TEST_VECTORS
2127 }
2128 }
2129 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002130 .alg = "cryptd(__driver-cbc-aes-aesni)",
2131 .test = alg_test_null,
2132 .fips_allowed = 1,
2133 .suite = {
2134 .cipher = {
2135 .enc = {
2136 .vecs = NULL,
2137 .count = 0
2138 },
2139 .dec = {
2140 .vecs = NULL,
2141 .count = 0
2142 }
2143 }
2144 }
2145 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002146 .alg = "cryptd(__driver-ecb-aes-aesni)",
2147 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002148 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002149 .suite = {
2150 .cipher = {
2151 .enc = {
2152 .vecs = NULL,
2153 .count = 0
2154 },
2155 .dec = {
2156 .vecs = NULL,
2157 .count = 0
2158 }
2159 }
2160 }
2161 }, {
Johannes Goetzfried4d6d6a22012-07-11 19:37:37 +02002162 .alg = "cryptd(__driver-ecb-cast5-avx)",
2163 .test = alg_test_null,
2164 .suite = {
2165 .cipher = {
2166 .enc = {
2167 .vecs = NULL,
2168 .count = 0
2169 },
2170 .dec = {
2171 .vecs = NULL,
2172 .count = 0
2173 }
2174 }
2175 }
2176 }, {
Johannes Goetzfried4ea12772012-07-11 19:38:57 +02002177 .alg = "cryptd(__driver-ecb-cast6-avx)",
2178 .test = alg_test_null,
2179 .suite = {
2180 .cipher = {
2181 .enc = {
2182 .vecs = NULL,
2183 .count = 0
2184 },
2185 .dec = {
2186 .vecs = NULL,
2187 .count = 0
2188 }
2189 }
2190 }
2191 }, {
Johannes Goetzfried7efe4072012-06-12 16:47:43 +08002192 .alg = "cryptd(__driver-ecb-serpent-avx)",
2193 .test = alg_test_null,
2194 .suite = {
2195 .cipher = {
2196 .enc = {
2197 .vecs = NULL,
2198 .count = 0
2199 },
2200 .dec = {
2201 .vecs = NULL,
2202 .count = 0
2203 }
2204 }
2205 }
2206 }, {
Jussi Kivilinna937c30d2011-11-09 16:26:25 +02002207 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2208 .test = alg_test_null,
2209 .suite = {
2210 .cipher = {
2211 .enc = {
2212 .vecs = NULL,
2213 .count = 0
2214 },
2215 .dec = {
2216 .vecs = NULL,
2217 .count = 0
2218 }
2219 }
2220 }
2221 }, {
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002222 .alg = "cryptd(__driver-ecb-twofish-avx)",
2223 .test = alg_test_null,
2224 .suite = {
2225 .cipher = {
2226 .enc = {
2227 .vecs = NULL,
2228 .count = 0
2229 },
2230 .dec = {
2231 .vecs = NULL,
2232 .count = 0
2233 }
2234 }
2235 }
2236 }, {
Milan Broz6c792942012-06-29 22:08:09 +02002237 .alg = "cryptd(__driver-gcm-aes-aesni)",
2238 .test = alg_test_null,
2239 .fips_allowed = 1,
2240 .suite = {
2241 .cipher = {
2242 .enc = {
2243 .vecs = NULL,
2244 .count = 0
2245 },
2246 .dec = {
2247 .vecs = NULL,
2248 .count = 0
2249 }
2250 }
2251 }
2252 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002253 .alg = "cryptd(__ghash-pclmulqdqni)",
2254 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002255 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002256 .suite = {
2257 .hash = {
2258 .vecs = NULL,
2259 .count = 0
2260 }
2261 }
2262 }, {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002263 .alg = "ctr(aes)",
2264 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002265 .fips_allowed = 1,
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002266 .suite = {
2267 .cipher = {
2268 .enc = {
2269 .vecs = aes_ctr_enc_tv_template,
2270 .count = AES_CTR_ENC_TEST_VECTORS
2271 },
2272 .dec = {
2273 .vecs = aes_ctr_dec_tv_template,
2274 .count = AES_CTR_DEC_TEST_VECTORS
2275 }
2276 }
2277 }
2278 }, {
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03002279 .alg = "ctr(blowfish)",
2280 .test = alg_test_skcipher,
2281 .suite = {
2282 .cipher = {
2283 .enc = {
2284 .vecs = bf_ctr_enc_tv_template,
2285 .count = BF_CTR_ENC_TEST_VECTORS
2286 },
2287 .dec = {
2288 .vecs = bf_ctr_dec_tv_template,
2289 .count = BF_CTR_DEC_TEST_VECTORS
2290 }
2291 }
2292 }
2293 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002294 .alg = "ctr(camellia)",
2295 .test = alg_test_skcipher,
2296 .suite = {
2297 .cipher = {
2298 .enc = {
2299 .vecs = camellia_ctr_enc_tv_template,
2300 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2301 },
2302 .dec = {
2303 .vecs = camellia_ctr_dec_tv_template,
2304 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2305 }
2306 }
2307 }
2308 }, {
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002309 .alg = "ctr(cast5)",
2310 .test = alg_test_skcipher,
2311 .suite = {
2312 .cipher = {
2313 .enc = {
2314 .vecs = cast5_ctr_enc_tv_template,
2315 .count = CAST5_CTR_ENC_TEST_VECTORS
2316 },
2317 .dec = {
2318 .vecs = cast5_ctr_dec_tv_template,
2319 .count = CAST5_CTR_DEC_TEST_VECTORS
2320 }
2321 }
2322 }
2323 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002324 .alg = "ctr(cast6)",
2325 .test = alg_test_skcipher,
2326 .suite = {
2327 .cipher = {
2328 .enc = {
2329 .vecs = cast6_ctr_enc_tv_template,
2330 .count = CAST6_CTR_ENC_TEST_VECTORS
2331 },
2332 .dec = {
2333 .vecs = cast6_ctr_dec_tv_template,
2334 .count = CAST6_CTR_DEC_TEST_VECTORS
2335 }
2336 }
2337 }
2338 }, {
Jussi Kivilinna9d259172011-10-18 00:02:53 +03002339 .alg = "ctr(serpent)",
2340 .test = alg_test_skcipher,
2341 .suite = {
2342 .cipher = {
2343 .enc = {
2344 .vecs = serpent_ctr_enc_tv_template,
2345 .count = SERPENT_CTR_ENC_TEST_VECTORS
2346 },
2347 .dec = {
2348 .vecs = serpent_ctr_dec_tv_template,
2349 .count = SERPENT_CTR_DEC_TEST_VECTORS
2350 }
2351 }
2352 }
2353 }, {
Jussi Kivilinna573da622011-10-10 23:03:12 +03002354 .alg = "ctr(twofish)",
2355 .test = alg_test_skcipher,
2356 .suite = {
2357 .cipher = {
2358 .enc = {
2359 .vecs = tf_ctr_enc_tv_template,
2360 .count = TF_CTR_ENC_TEST_VECTORS
2361 },
2362 .dec = {
2363 .vecs = tf_ctr_dec_tv_template,
2364 .count = TF_CTR_DEC_TEST_VECTORS
2365 }
2366 }
2367 }
2368 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002369 .alg = "cts(cbc(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002370 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002371 .suite = {
2372 .cipher = {
2373 .enc = {
2374 .vecs = cts_mode_enc_tv_template,
2375 .count = CTS_MODE_ENC_TEST_VECTORS
2376 },
2377 .dec = {
2378 .vecs = cts_mode_dec_tv_template,
2379 .count = CTS_MODE_DEC_TEST_VECTORS
2380 }
2381 }
2382 }
2383 }, {
2384 .alg = "deflate",
2385 .test = alg_test_comp,
2386 .suite = {
2387 .comp = {
2388 .comp = {
2389 .vecs = deflate_comp_tv_template,
2390 .count = DEFLATE_COMP_TEST_VECTORS
2391 },
2392 .decomp = {
2393 .vecs = deflate_decomp_tv_template,
2394 .count = DEFLATE_DECOMP_TEST_VECTORS
2395 }
2396 }
2397 }
2398 }, {
Youquan, Song863b5572009-12-23 19:45:20 +08002399 .alg = "ecb(__aes-aesni)",
2400 .test = alg_test_null,
Milan Broz6c792942012-06-29 22:08:09 +02002401 .fips_allowed = 1,
Youquan, Song863b5572009-12-23 19:45:20 +08002402 .suite = {
2403 .cipher = {
2404 .enc = {
2405 .vecs = NULL,
2406 .count = 0
2407 },
2408 .dec = {
2409 .vecs = NULL,
2410 .count = 0
2411 }
2412 }
2413 }
2414 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002415 .alg = "ecb(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002416 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002417 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002418 .suite = {
2419 .cipher = {
2420 .enc = {
2421 .vecs = aes_enc_tv_template,
2422 .count = AES_ENC_TEST_VECTORS
2423 },
2424 .dec = {
2425 .vecs = aes_dec_tv_template,
2426 .count = AES_DEC_TEST_VECTORS
2427 }
2428 }
2429 }
2430 }, {
2431 .alg = "ecb(anubis)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002432 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002433 .suite = {
2434 .cipher = {
2435 .enc = {
2436 .vecs = anubis_enc_tv_template,
2437 .count = ANUBIS_ENC_TEST_VECTORS
2438 },
2439 .dec = {
2440 .vecs = anubis_dec_tv_template,
2441 .count = ANUBIS_DEC_TEST_VECTORS
2442 }
2443 }
2444 }
2445 }, {
2446 .alg = "ecb(arc4)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002447 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002448 .suite = {
2449 .cipher = {
2450 .enc = {
2451 .vecs = arc4_enc_tv_template,
2452 .count = ARC4_ENC_TEST_VECTORS
2453 },
2454 .dec = {
2455 .vecs = arc4_dec_tv_template,
2456 .count = ARC4_DEC_TEST_VECTORS
2457 }
2458 }
2459 }
2460 }, {
2461 .alg = "ecb(blowfish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002462 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002463 .suite = {
2464 .cipher = {
2465 .enc = {
2466 .vecs = bf_enc_tv_template,
2467 .count = BF_ENC_TEST_VECTORS
2468 },
2469 .dec = {
2470 .vecs = bf_dec_tv_template,
2471 .count = BF_DEC_TEST_VECTORS
2472 }
2473 }
2474 }
2475 }, {
2476 .alg = "ecb(camellia)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002477 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002478 .suite = {
2479 .cipher = {
2480 .enc = {
2481 .vecs = camellia_enc_tv_template,
2482 .count = CAMELLIA_ENC_TEST_VECTORS
2483 },
2484 .dec = {
2485 .vecs = camellia_dec_tv_template,
2486 .count = CAMELLIA_DEC_TEST_VECTORS
2487 }
2488 }
2489 }
2490 }, {
2491 .alg = "ecb(cast5)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002492 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002493 .suite = {
2494 .cipher = {
2495 .enc = {
2496 .vecs = cast5_enc_tv_template,
2497 .count = CAST5_ENC_TEST_VECTORS
2498 },
2499 .dec = {
2500 .vecs = cast5_dec_tv_template,
2501 .count = CAST5_DEC_TEST_VECTORS
2502 }
2503 }
2504 }
2505 }, {
2506 .alg = "ecb(cast6)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002507 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002508 .suite = {
2509 .cipher = {
2510 .enc = {
2511 .vecs = cast6_enc_tv_template,
2512 .count = CAST6_ENC_TEST_VECTORS
2513 },
2514 .dec = {
2515 .vecs = cast6_dec_tv_template,
2516 .count = CAST6_DEC_TEST_VECTORS
2517 }
2518 }
2519 }
2520 }, {
2521 .alg = "ecb(des)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002522 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002523 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002524 .suite = {
2525 .cipher = {
2526 .enc = {
2527 .vecs = des_enc_tv_template,
2528 .count = DES_ENC_TEST_VECTORS
2529 },
2530 .dec = {
2531 .vecs = des_dec_tv_template,
2532 .count = DES_DEC_TEST_VECTORS
2533 }
2534 }
2535 }
2536 }, {
2537 .alg = "ecb(des3_ede)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002538 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002539 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002540 .suite = {
2541 .cipher = {
2542 .enc = {
2543 .vecs = des3_ede_enc_tv_template,
2544 .count = DES3_EDE_ENC_TEST_VECTORS
2545 },
2546 .dec = {
2547 .vecs = des3_ede_dec_tv_template,
2548 .count = DES3_EDE_DEC_TEST_VECTORS
2549 }
2550 }
2551 }
2552 }, {
2553 .alg = "ecb(khazad)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002554 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002555 .suite = {
2556 .cipher = {
2557 .enc = {
2558 .vecs = khazad_enc_tv_template,
2559 .count = KHAZAD_ENC_TEST_VECTORS
2560 },
2561 .dec = {
2562 .vecs = khazad_dec_tv_template,
2563 .count = KHAZAD_DEC_TEST_VECTORS
2564 }
2565 }
2566 }
2567 }, {
2568 .alg = "ecb(seed)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002569 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002570 .suite = {
2571 .cipher = {
2572 .enc = {
2573 .vecs = seed_enc_tv_template,
2574 .count = SEED_ENC_TEST_VECTORS
2575 },
2576 .dec = {
2577 .vecs = seed_dec_tv_template,
2578 .count = SEED_DEC_TEST_VECTORS
2579 }
2580 }
2581 }
2582 }, {
2583 .alg = "ecb(serpent)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002584 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002585 .suite = {
2586 .cipher = {
2587 .enc = {
2588 .vecs = serpent_enc_tv_template,
2589 .count = SERPENT_ENC_TEST_VECTORS
2590 },
2591 .dec = {
2592 .vecs = serpent_dec_tv_template,
2593 .count = SERPENT_DEC_TEST_VECTORS
2594 }
2595 }
2596 }
2597 }, {
2598 .alg = "ecb(tea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002599 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002600 .suite = {
2601 .cipher = {
2602 .enc = {
2603 .vecs = tea_enc_tv_template,
2604 .count = TEA_ENC_TEST_VECTORS
2605 },
2606 .dec = {
2607 .vecs = tea_dec_tv_template,
2608 .count = TEA_DEC_TEST_VECTORS
2609 }
2610 }
2611 }
2612 }, {
2613 .alg = "ecb(tnepres)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002614 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002615 .suite = {
2616 .cipher = {
2617 .enc = {
2618 .vecs = tnepres_enc_tv_template,
2619 .count = TNEPRES_ENC_TEST_VECTORS
2620 },
2621 .dec = {
2622 .vecs = tnepres_dec_tv_template,
2623 .count = TNEPRES_DEC_TEST_VECTORS
2624 }
2625 }
2626 }
2627 }, {
2628 .alg = "ecb(twofish)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002629 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002630 .suite = {
2631 .cipher = {
2632 .enc = {
2633 .vecs = tf_enc_tv_template,
2634 .count = TF_ENC_TEST_VECTORS
2635 },
2636 .dec = {
2637 .vecs = tf_dec_tv_template,
2638 .count = TF_DEC_TEST_VECTORS
2639 }
2640 }
2641 }
2642 }, {
2643 .alg = "ecb(xeta)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002644 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002645 .suite = {
2646 .cipher = {
2647 .enc = {
2648 .vecs = xeta_enc_tv_template,
2649 .count = XETA_ENC_TEST_VECTORS
2650 },
2651 .dec = {
2652 .vecs = xeta_dec_tv_template,
2653 .count = XETA_DEC_TEST_VECTORS
2654 }
2655 }
2656 }
2657 }, {
2658 .alg = "ecb(xtea)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002659 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002660 .suite = {
2661 .cipher = {
2662 .enc = {
2663 .vecs = xtea_enc_tv_template,
2664 .count = XTEA_ENC_TEST_VECTORS
2665 },
2666 .dec = {
2667 .vecs = xtea_dec_tv_template,
2668 .count = XTEA_DEC_TEST_VECTORS
2669 }
2670 }
2671 }
2672 }, {
2673 .alg = "gcm(aes)",
2674 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002675 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002676 .suite = {
2677 .aead = {
2678 .enc = {
2679 .vecs = aes_gcm_enc_tv_template,
2680 .count = AES_GCM_ENC_TEST_VECTORS
2681 },
2682 .dec = {
2683 .vecs = aes_gcm_dec_tv_template,
2684 .count = AES_GCM_DEC_TEST_VECTORS
2685 }
2686 }
2687 }
2688 }, {
Youquan, Song507069c2009-11-23 20:23:04 +08002689 .alg = "ghash",
2690 .test = alg_test_hash,
Jarod Wilson18c0ebd2011-01-29 15:14:35 +11002691 .fips_allowed = 1,
Youquan, Song507069c2009-11-23 20:23:04 +08002692 .suite = {
2693 .hash = {
2694 .vecs = ghash_tv_template,
2695 .count = GHASH_TEST_VECTORS
2696 }
2697 }
2698 }, {
Sonic Zhanga482b082012-05-25 17:54:13 +08002699 .alg = "hmac(crc32)",
2700 .test = alg_test_hash,
2701 .suite = {
2702 .hash = {
2703 .vecs = bfin_crc_tv_template,
2704 .count = BFIN_CRC_TEST_VECTORS
2705 }
2706 }
2707 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002708 .alg = "hmac(md5)",
2709 .test = alg_test_hash,
2710 .suite = {
2711 .hash = {
2712 .vecs = hmac_md5_tv_template,
2713 .count = HMAC_MD5_TEST_VECTORS
2714 }
2715 }
2716 }, {
2717 .alg = "hmac(rmd128)",
2718 .test = alg_test_hash,
2719 .suite = {
2720 .hash = {
2721 .vecs = hmac_rmd128_tv_template,
2722 .count = HMAC_RMD128_TEST_VECTORS
2723 }
2724 }
2725 }, {
2726 .alg = "hmac(rmd160)",
2727 .test = alg_test_hash,
2728 .suite = {
2729 .hash = {
2730 .vecs = hmac_rmd160_tv_template,
2731 .count = HMAC_RMD160_TEST_VECTORS
2732 }
2733 }
2734 }, {
2735 .alg = "hmac(sha1)",
2736 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002737 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002738 .suite = {
2739 .hash = {
2740 .vecs = hmac_sha1_tv_template,
2741 .count = HMAC_SHA1_TEST_VECTORS
2742 }
2743 }
2744 }, {
2745 .alg = "hmac(sha224)",
2746 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002747 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002748 .suite = {
2749 .hash = {
2750 .vecs = hmac_sha224_tv_template,
2751 .count = HMAC_SHA224_TEST_VECTORS
2752 }
2753 }
2754 }, {
2755 .alg = "hmac(sha256)",
2756 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002757 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002758 .suite = {
2759 .hash = {
2760 .vecs = hmac_sha256_tv_template,
2761 .count = HMAC_SHA256_TEST_VECTORS
2762 }
2763 }
2764 }, {
2765 .alg = "hmac(sha384)",
2766 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002767 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002768 .suite = {
2769 .hash = {
2770 .vecs = hmac_sha384_tv_template,
2771 .count = HMAC_SHA384_TEST_VECTORS
2772 }
2773 }
2774 }, {
2775 .alg = "hmac(sha512)",
2776 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002777 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002778 .suite = {
2779 .hash = {
2780 .vecs = hmac_sha512_tv_template,
2781 .count = HMAC_SHA512_TEST_VECTORS
2782 }
2783 }
2784 }, {
2785 .alg = "lrw(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002786 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002787 .suite = {
2788 .cipher = {
2789 .enc = {
2790 .vecs = aes_lrw_enc_tv_template,
2791 .count = AES_LRW_ENC_TEST_VECTORS
2792 },
2793 .dec = {
2794 .vecs = aes_lrw_dec_tv_template,
2795 .count = AES_LRW_DEC_TEST_VECTORS
2796 }
2797 }
2798 }
2799 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02002800 .alg = "lrw(camellia)",
2801 .test = alg_test_skcipher,
2802 .suite = {
2803 .cipher = {
2804 .enc = {
2805 .vecs = camellia_lrw_enc_tv_template,
2806 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
2807 },
2808 .dec = {
2809 .vecs = camellia_lrw_dec_tv_template,
2810 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
2811 }
2812 }
2813 }
2814 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002815 .alg = "lrw(cast6)",
2816 .test = alg_test_skcipher,
2817 .suite = {
2818 .cipher = {
2819 .enc = {
2820 .vecs = cast6_lrw_enc_tv_template,
2821 .count = CAST6_LRW_ENC_TEST_VECTORS
2822 },
2823 .dec = {
2824 .vecs = cast6_lrw_dec_tv_template,
2825 .count = CAST6_LRW_DEC_TEST_VECTORS
2826 }
2827 }
2828 }
2829 }, {
Jussi Kivilinnad7bfc0f2011-10-18 13:32:34 +03002830 .alg = "lrw(serpent)",
2831 .test = alg_test_skcipher,
2832 .suite = {
2833 .cipher = {
2834 .enc = {
2835 .vecs = serpent_lrw_enc_tv_template,
2836 .count = SERPENT_LRW_ENC_TEST_VECTORS
2837 },
2838 .dec = {
2839 .vecs = serpent_lrw_dec_tv_template,
2840 .count = SERPENT_LRW_DEC_TEST_VECTORS
2841 }
2842 }
2843 }
2844 }, {
Jussi Kivilinna0b2a1552011-10-18 13:32:50 +03002845 .alg = "lrw(twofish)",
2846 .test = alg_test_skcipher,
2847 .suite = {
2848 .cipher = {
2849 .enc = {
2850 .vecs = tf_lrw_enc_tv_template,
2851 .count = TF_LRW_ENC_TEST_VECTORS
2852 },
2853 .dec = {
2854 .vecs = tf_lrw_dec_tv_template,
2855 .count = TF_LRW_DEC_TEST_VECTORS
2856 }
2857 }
2858 }
2859 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002860 .alg = "lzo",
2861 .test = alg_test_comp,
2862 .suite = {
2863 .comp = {
2864 .comp = {
2865 .vecs = lzo_comp_tv_template,
2866 .count = LZO_COMP_TEST_VECTORS
2867 },
2868 .decomp = {
2869 .vecs = lzo_decomp_tv_template,
2870 .count = LZO_DECOMP_TEST_VECTORS
2871 }
2872 }
2873 }
2874 }, {
2875 .alg = "md4",
2876 .test = alg_test_hash,
2877 .suite = {
2878 .hash = {
2879 .vecs = md4_tv_template,
2880 .count = MD4_TEST_VECTORS
2881 }
2882 }
2883 }, {
2884 .alg = "md5",
2885 .test = alg_test_hash,
2886 .suite = {
2887 .hash = {
2888 .vecs = md5_tv_template,
2889 .count = MD5_TEST_VECTORS
2890 }
2891 }
2892 }, {
2893 .alg = "michael_mic",
2894 .test = alg_test_hash,
2895 .suite = {
2896 .hash = {
2897 .vecs = michael_mic_tv_template,
2898 .count = MICHAEL_MIC_TEST_VECTORS
2899 }
2900 }
2901 }, {
Puneet Saxenaba0e14a2011-05-04 15:04:10 +10002902 .alg = "ofb(aes)",
2903 .test = alg_test_skcipher,
2904 .fips_allowed = 1,
2905 .suite = {
2906 .cipher = {
2907 .enc = {
2908 .vecs = aes_ofb_enc_tv_template,
2909 .count = AES_OFB_ENC_TEST_VECTORS
2910 },
2911 .dec = {
2912 .vecs = aes_ofb_dec_tv_template,
2913 .count = AES_OFB_DEC_TEST_VECTORS
2914 }
2915 }
2916 }
2917 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002918 .alg = "pcbc(fcrypt)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002919 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08002920 .suite = {
2921 .cipher = {
2922 .enc = {
2923 .vecs = fcrypt_pcbc_enc_tv_template,
2924 .count = FCRYPT_ENC_TEST_VECTORS
2925 },
2926 .dec = {
2927 .vecs = fcrypt_pcbc_dec_tv_template,
2928 .count = FCRYPT_DEC_TEST_VECTORS
2929 }
2930 }
2931 }
2932 }, {
2933 .alg = "rfc3686(ctr(aes))",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10002934 .test = alg_test_skcipher,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002935 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08002936 .suite = {
2937 .cipher = {
2938 .enc = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002939 .vecs = aes_ctr_rfc3686_enc_tv_template,
2940 .count = AES_CTR_3686_ENC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08002941 },
2942 .dec = {
Jarod Wilsonf7cb80f2009-05-06 17:29:17 +08002943 .vecs = aes_ctr_rfc3686_dec_tv_template,
2944 .count = AES_CTR_3686_DEC_TEST_VECTORS
Herbert Xuda7f0332008-07-31 17:08:25 +08002945 }
2946 }
2947 }
2948 }, {
Adrian Hoban69435b92010-11-04 15:02:04 -04002949 .alg = "rfc4106(gcm(aes))",
2950 .test = alg_test_aead,
2951 .suite = {
2952 .aead = {
2953 .enc = {
2954 .vecs = aes_gcm_rfc4106_enc_tv_template,
2955 .count = AES_GCM_4106_ENC_TEST_VECTORS
2956 },
2957 .dec = {
2958 .vecs = aes_gcm_rfc4106_dec_tv_template,
2959 .count = AES_GCM_4106_DEC_TEST_VECTORS
2960 }
2961 }
2962 }
2963 }, {
2964
2965
Jarod Wilson5d667322009-05-04 19:23:40 +08002966 .alg = "rfc4309(ccm(aes))",
2967 .test = alg_test_aead,
Jarod Wilsona1915d52009-05-15 15:16:03 +10002968 .fips_allowed = 1,
Jarod Wilson5d667322009-05-04 19:23:40 +08002969 .suite = {
2970 .aead = {
2971 .enc = {
2972 .vecs = aes_ccm_rfc4309_enc_tv_template,
2973 .count = AES_CCM_4309_ENC_TEST_VECTORS
2974 },
2975 .dec = {
2976 .vecs = aes_ccm_rfc4309_dec_tv_template,
2977 .count = AES_CCM_4309_DEC_TEST_VECTORS
2978 }
2979 }
2980 }
2981 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08002982 .alg = "rmd128",
2983 .test = alg_test_hash,
2984 .suite = {
2985 .hash = {
2986 .vecs = rmd128_tv_template,
2987 .count = RMD128_TEST_VECTORS
2988 }
2989 }
2990 }, {
2991 .alg = "rmd160",
2992 .test = alg_test_hash,
2993 .suite = {
2994 .hash = {
2995 .vecs = rmd160_tv_template,
2996 .count = RMD160_TEST_VECTORS
2997 }
2998 }
2999 }, {
3000 .alg = "rmd256",
3001 .test = alg_test_hash,
3002 .suite = {
3003 .hash = {
3004 .vecs = rmd256_tv_template,
3005 .count = RMD256_TEST_VECTORS
3006 }
3007 }
3008 }, {
3009 .alg = "rmd320",
3010 .test = alg_test_hash,
3011 .suite = {
3012 .hash = {
3013 .vecs = rmd320_tv_template,
3014 .count = RMD320_TEST_VECTORS
3015 }
3016 }
3017 }, {
3018 .alg = "salsa20",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003019 .test = alg_test_skcipher,
Herbert Xuda7f0332008-07-31 17:08:25 +08003020 .suite = {
3021 .cipher = {
3022 .enc = {
3023 .vecs = salsa20_stream_enc_tv_template,
3024 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3025 }
3026 }
3027 }
3028 }, {
3029 .alg = "sha1",
3030 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003031 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003032 .suite = {
3033 .hash = {
3034 .vecs = sha1_tv_template,
3035 .count = SHA1_TEST_VECTORS
3036 }
3037 }
3038 }, {
3039 .alg = "sha224",
3040 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003041 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003042 .suite = {
3043 .hash = {
3044 .vecs = sha224_tv_template,
3045 .count = SHA224_TEST_VECTORS
3046 }
3047 }
3048 }, {
3049 .alg = "sha256",
3050 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003051 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003052 .suite = {
3053 .hash = {
3054 .vecs = sha256_tv_template,
3055 .count = SHA256_TEST_VECTORS
3056 }
3057 }
3058 }, {
3059 .alg = "sha384",
3060 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003061 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003062 .suite = {
3063 .hash = {
3064 .vecs = sha384_tv_template,
3065 .count = SHA384_TEST_VECTORS
3066 }
3067 }
3068 }, {
3069 .alg = "sha512",
3070 .test = alg_test_hash,
Jarod Wilsona1915d52009-05-15 15:16:03 +10003071 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003072 .suite = {
3073 .hash = {
3074 .vecs = sha512_tv_template,
3075 .count = SHA512_TEST_VECTORS
3076 }
3077 }
3078 }, {
3079 .alg = "tgr128",
3080 .test = alg_test_hash,
3081 .suite = {
3082 .hash = {
3083 .vecs = tgr128_tv_template,
3084 .count = TGR128_TEST_VECTORS
3085 }
3086 }
3087 }, {
3088 .alg = "tgr160",
3089 .test = alg_test_hash,
3090 .suite = {
3091 .hash = {
3092 .vecs = tgr160_tv_template,
3093 .count = TGR160_TEST_VECTORS
3094 }
3095 }
3096 }, {
3097 .alg = "tgr192",
3098 .test = alg_test_hash,
3099 .suite = {
3100 .hash = {
3101 .vecs = tgr192_tv_template,
3102 .count = TGR192_TEST_VECTORS
3103 }
3104 }
3105 }, {
Shane Wangf1939f72009-09-02 20:05:22 +10003106 .alg = "vmac(aes)",
3107 .test = alg_test_hash,
3108 .suite = {
3109 .hash = {
3110 .vecs = aes_vmac128_tv_template,
3111 .count = VMAC_AES_TEST_VECTORS
3112 }
3113 }
3114 }, {
Herbert Xuda7f0332008-07-31 17:08:25 +08003115 .alg = "wp256",
3116 .test = alg_test_hash,
3117 .suite = {
3118 .hash = {
3119 .vecs = wp256_tv_template,
3120 .count = WP256_TEST_VECTORS
3121 }
3122 }
3123 }, {
3124 .alg = "wp384",
3125 .test = alg_test_hash,
3126 .suite = {
3127 .hash = {
3128 .vecs = wp384_tv_template,
3129 .count = WP384_TEST_VECTORS
3130 }
3131 }
3132 }, {
3133 .alg = "wp512",
3134 .test = alg_test_hash,
3135 .suite = {
3136 .hash = {
3137 .vecs = wp512_tv_template,
3138 .count = WP512_TEST_VECTORS
3139 }
3140 }
3141 }, {
3142 .alg = "xcbc(aes)",
3143 .test = alg_test_hash,
3144 .suite = {
3145 .hash = {
3146 .vecs = aes_xcbc128_tv_template,
3147 .count = XCBC_AES_TEST_VECTORS
3148 }
3149 }
3150 }, {
3151 .alg = "xts(aes)",
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003152 .test = alg_test_skcipher,
Jarod Wilson2918aa82011-01-29 15:14:01 +11003153 .fips_allowed = 1,
Herbert Xuda7f0332008-07-31 17:08:25 +08003154 .suite = {
3155 .cipher = {
3156 .enc = {
3157 .vecs = aes_xts_enc_tv_template,
3158 .count = AES_XTS_ENC_TEST_VECTORS
3159 },
3160 .dec = {
3161 .vecs = aes_xts_dec_tv_template,
3162 .count = AES_XTS_DEC_TEST_VECTORS
3163 }
3164 }
3165 }
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003166 }, {
Jussi Kivilinna08406052012-03-05 20:26:21 +02003167 .alg = "xts(camellia)",
3168 .test = alg_test_skcipher,
3169 .suite = {
3170 .cipher = {
3171 .enc = {
3172 .vecs = camellia_xts_enc_tv_template,
3173 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3174 },
3175 .dec = {
3176 .vecs = camellia_xts_dec_tv_template,
3177 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3178 }
3179 }
3180 }
3181 }, {
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02003182 .alg = "xts(cast6)",
3183 .test = alg_test_skcipher,
3184 .suite = {
3185 .cipher = {
3186 .enc = {
3187 .vecs = cast6_xts_enc_tv_template,
3188 .count = CAST6_XTS_ENC_TEST_VECTORS
3189 },
3190 .dec = {
3191 .vecs = cast6_xts_dec_tv_template,
3192 .count = CAST6_XTS_DEC_TEST_VECTORS
3193 }
3194 }
3195 }
3196 }, {
Jussi Kivilinna18be20b2011-10-18 13:33:17 +03003197 .alg = "xts(serpent)",
3198 .test = alg_test_skcipher,
3199 .suite = {
3200 .cipher = {
3201 .enc = {
3202 .vecs = serpent_xts_enc_tv_template,
3203 .count = SERPENT_XTS_ENC_TEST_VECTORS
3204 },
3205 .dec = {
3206 .vecs = serpent_xts_dec_tv_template,
3207 .count = SERPENT_XTS_DEC_TEST_VECTORS
3208 }
3209 }
3210 }
3211 }, {
Jussi Kivilinnaaed265b2011-10-18 13:33:33 +03003212 .alg = "xts(twofish)",
3213 .test = alg_test_skcipher,
3214 .suite = {
3215 .cipher = {
3216 .enc = {
3217 .vecs = tf_xts_enc_tv_template,
3218 .count = TF_XTS_ENC_TEST_VECTORS
3219 },
3220 .dec = {
3221 .vecs = tf_xts_dec_tv_template,
3222 .count = TF_XTS_DEC_TEST_VECTORS
3223 }
3224 }
3225 }
3226 }, {
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08003227 .alg = "zlib",
3228 .test = alg_test_pcomp,
3229 .suite = {
3230 .pcomp = {
3231 .comp = {
3232 .vecs = zlib_comp_tv_template,
3233 .count = ZLIB_COMP_TEST_VECTORS
3234 },
3235 .decomp = {
3236 .vecs = zlib_decomp_tv_template,
3237 .count = ZLIB_DECOMP_TEST_VECTORS
3238 }
3239 }
3240 }
Herbert Xuda7f0332008-07-31 17:08:25 +08003241 }
3242};
3243
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003244static int alg_find_test(const char *alg)
Herbert Xuda7f0332008-07-31 17:08:25 +08003245{
3246 int start = 0;
3247 int end = ARRAY_SIZE(alg_test_descs);
3248
3249 while (start < end) {
3250 int i = (start + end) / 2;
3251 int diff = strcmp(alg_test_descs[i].alg, alg);
3252
3253 if (diff > 0) {
3254 end = i;
3255 continue;
3256 }
3257
3258 if (diff < 0) {
3259 start = i + 1;
3260 continue;
3261 }
3262
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003263 return i;
Herbert Xuda7f0332008-07-31 17:08:25 +08003264 }
3265
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003266 return -1;
3267}
3268
3269int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3270{
3271 int i;
Herbert Xua68f6612009-07-02 16:32:12 +08003272 int j;
Neil Hormand12d6b62008-10-12 20:36:51 +08003273 int rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003274
3275 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3276 char nalg[CRYPTO_MAX_ALG_NAME];
3277
3278 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3279 sizeof(nalg))
3280 return -ENAMETOOLONG;
3281
3282 i = alg_find_test(nalg);
3283 if (i < 0)
3284 goto notest;
3285
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003286 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3287 goto non_fips_alg;
3288
Jarod Wilson941fb322009-05-04 19:49:23 +08003289 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3290 goto test_done;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003291 }
3292
3293 i = alg_find_test(alg);
Herbert Xua68f6612009-07-02 16:32:12 +08003294 j = alg_find_test(driver);
3295 if (i < 0 && j < 0)
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003296 goto notest;
3297
Herbert Xua68f6612009-07-02 16:32:12 +08003298 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3299 (j >= 0 && !alg_test_descs[j].fips_allowed)))
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003300 goto non_fips_alg;
3301
Herbert Xua68f6612009-07-02 16:32:12 +08003302 rc = 0;
3303 if (i >= 0)
3304 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3305 type, mask);
3306 if (j >= 0)
3307 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3308 type, mask);
3309
Jarod Wilson941fb322009-05-04 19:49:23 +08003310test_done:
Neil Hormand12d6b62008-10-12 20:36:51 +08003311 if (fips_enabled && rc)
3312 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3313
Jarod Wilson29ecd4a2009-05-04 19:51:17 +08003314 if (fips_enabled && !rc)
3315 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3316 driver, alg);
3317
Neil Hormand12d6b62008-10-12 20:36:51 +08003318 return rc;
Herbert Xu1aa4ecd2008-08-17 17:01:56 +10003319
3320notest:
Herbert Xuda7f0332008-07-31 17:08:25 +08003321 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3322 return 0;
Jarod Wilsona3bef3a2009-05-15 15:17:05 +10003323non_fips_alg:
3324 return -EINVAL;
Herbert Xuda7f0332008-07-31 17:08:25 +08003325}
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003326
Herbert Xu326a6342010-08-06 09:40:28 +08003327#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
Alexander Shishkin0b767f92010-06-03 20:53:43 +10003328
Herbert Xuda7f0332008-07-31 17:08:25 +08003329EXPORT_SYMBOL_GPL(alg_test);