]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - crypto/testmgr.c
crypto: drbg - Add DRBG test code to testmgr
[mirror_ubuntu-bionic-kernel.git] / crypto / testmgr.c
CommitLineData
da7f033d
HX
1/*
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 *
69435b94
AH
9 * 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 *
da7f033d
HX
16 * 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>
7647d6ce 29#include <crypto/rng.h>
64d1cdfb 30#include <crypto/drbg.h>
da7f033d
HX
31
32#include "internal.h"
0b767f96 33
326a6346 34#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
0b767f96
AS
35
36/* a perfect nop */
37int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
38{
39 return 0;
40}
41
42#else
43
da7f033d
HX
44#include "testmgr.h"
45
46/*
47 * Need slab memory for testing (size in number of pages).
48 */
49#define XBUFSIZE 8
50
51/*
52 * Indexes into the xbuf to simulate cross-page access.
53 */
54#define IDX1 32
55#define IDX2 32400
56#define IDX3 1
57#define IDX4 8193
58#define IDX5 22222
59#define IDX6 17101
60#define IDX7 27333
61#define IDX8 3000
62
63/*
64* Used by test_cipher()
65*/
66#define ENCRYPT 1
67#define DECRYPT 0
68
69struct tcrypt_result {
70 struct completion completion;
71 int err;
72};
73
74struct aead_test_suite {
75 struct {
76 struct aead_testvec *vecs;
77 unsigned int count;
78 } enc, dec;
79};
80
81struct cipher_test_suite {
82 struct {
83 struct cipher_testvec *vecs;
84 unsigned int count;
85 } enc, dec;
86};
87
88struct comp_test_suite {
89 struct {
90 struct comp_testvec *vecs;
91 unsigned int count;
92 } comp, decomp;
93};
94
8064efb8
GU
95struct pcomp_test_suite {
96 struct {
97 struct pcomp_testvec *vecs;
98 unsigned int count;
99 } comp, decomp;
100};
101
da7f033d
HX
102struct hash_test_suite {
103 struct hash_testvec *vecs;
104 unsigned int count;
105};
106
7647d6ce
JW
107struct cprng_test_suite {
108 struct cprng_testvec *vecs;
109 unsigned int count;
110};
111
64d1cdfb
SM
112struct drbg_test_suite {
113 struct drbg_testvec *vecs;
114 unsigned int count;
115};
116
da7f033d
HX
117struct alg_test_desc {
118 const char *alg;
119 int (*test)(const struct alg_test_desc *desc, const char *driver,
120 u32 type, u32 mask);
a1915d51 121 int fips_allowed; /* set if alg is allowed in fips mode */
da7f033d
HX
122
123 union {
124 struct aead_test_suite aead;
125 struct cipher_test_suite cipher;
126 struct comp_test_suite comp;
8064efb8 127 struct pcomp_test_suite pcomp;
da7f033d 128 struct hash_test_suite hash;
7647d6ce 129 struct cprng_test_suite cprng;
64d1cdfb 130 struct drbg_test_suite drbg;
da7f033d
HX
131 } suite;
132};
133
134static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
135
da7f033d
HX
136static void hexdump(unsigned char *buf, unsigned int len)
137{
138 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
139 16, 1,
140 buf, len, false);
141}
142
143static void tcrypt_complete(struct crypto_async_request *req, int err)
144{
145 struct tcrypt_result *res = req->data;
146
147 if (err == -EINPROGRESS)
148 return;
149
150 res->err = err;
151 complete(&res->completion);
152}
153
f8b0d4d0
HX
154static int testmgr_alloc_buf(char *buf[XBUFSIZE])
155{
156 int i;
157
158 for (i = 0; i < XBUFSIZE; i++) {
159 buf[i] = (void *)__get_free_page(GFP_KERNEL);
160 if (!buf[i])
161 goto err_free_buf;
162 }
163
164 return 0;
165
166err_free_buf:
167 while (i-- > 0)
168 free_page((unsigned long)buf[i]);
169
170 return -ENOMEM;
171}
172
173static void testmgr_free_buf(char *buf[XBUFSIZE])
174{
175 int i;
176
177 for (i = 0; i < XBUFSIZE; i++)
178 free_page((unsigned long)buf[i]);
179}
180
a8f1a052
DM
181static int do_one_async_hash_op(struct ahash_request *req,
182 struct tcrypt_result *tr,
183 int ret)
184{
185 if (ret == -EINPROGRESS || ret == -EBUSY) {
186 ret = wait_for_completion_interruptible(&tr->completion);
187 if (!ret)
188 ret = tr->err;
16735d02 189 reinit_completion(&tr->completion);
a8f1a052
DM
190 }
191 return ret;
192}
193
da5ffe11
JK
194static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
195 unsigned int tcount, bool use_digest,
196 const int align_offset)
da7f033d
HX
197{
198 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
199 unsigned int i, j, k, temp;
200 struct scatterlist sg[8];
201 char result[64];
202 struct ahash_request *req;
203 struct tcrypt_result tresult;
da7f033d 204 void *hash_buff;
f8b0d4d0
HX
205 char *xbuf[XBUFSIZE];
206 int ret = -ENOMEM;
207
208 if (testmgr_alloc_buf(xbuf))
209 goto out_nobuf;
da7f033d
HX
210
211 init_completion(&tresult.completion);
212
213 req = ahash_request_alloc(tfm, GFP_KERNEL);
214 if (!req) {
215 printk(KERN_ERR "alg: hash: Failed to allocate request for "
216 "%s\n", algo);
da7f033d
HX
217 goto out_noreq;
218 }
219 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
220 tcrypt_complete, &tresult);
221
a0cfae59 222 j = 0;
da7f033d 223 for (i = 0; i < tcount; i++) {
a0cfae59
HX
224 if (template[i].np)
225 continue;
226
da5ffe11
JK
227 ret = -EINVAL;
228 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
229 goto out;
230
a0cfae59 231 j++;
da7f033d
HX
232 memset(result, 0, 64);
233
234 hash_buff = xbuf[0];
da5ffe11 235 hash_buff += align_offset;
da7f033d
HX
236
237 memcpy(hash_buff, template[i].plaintext, template[i].psize);
238 sg_init_one(&sg[0], hash_buff, template[i].psize);
239
240 if (template[i].ksize) {
241 crypto_ahash_clear_flags(tfm, ~0);
242 ret = crypto_ahash_setkey(tfm, template[i].key,
243 template[i].ksize);
244 if (ret) {
245 printk(KERN_ERR "alg: hash: setkey failed on "
a0cfae59 246 "test %d for %s: ret=%d\n", j, algo,
da7f033d
HX
247 -ret);
248 goto out;
249 }
250 }
251
252 ahash_request_set_crypt(req, sg, result, template[i].psize);
a8f1a052
DM
253 if (use_digest) {
254 ret = do_one_async_hash_op(req, &tresult,
255 crypto_ahash_digest(req));
256 if (ret) {
257 pr_err("alg: hash: digest failed on test %d "
258 "for %s: ret=%d\n", j, algo, -ret);
259 goto out;
260 }
261 } else {
262 ret = do_one_async_hash_op(req, &tresult,
263 crypto_ahash_init(req));
264 if (ret) {
265 pr_err("alt: hash: init failed on test %d "
266 "for %s: ret=%d\n", j, algo, -ret);
267 goto out;
268 }
269 ret = do_one_async_hash_op(req, &tresult,
270 crypto_ahash_update(req));
271 if (ret) {
272 pr_err("alt: hash: update failed on test %d "
273 "for %s: ret=%d\n", j, algo, -ret);
274 goto out;
275 }
276 ret = do_one_async_hash_op(req, &tresult,
277 crypto_ahash_final(req));
278 if (ret) {
279 pr_err("alt: hash: final failed on test %d "
280 "for %s: ret=%d\n", j, algo, -ret);
281 goto out;
da7f033d 282 }
da7f033d
HX
283 }
284
285 if (memcmp(result, template[i].digest,
286 crypto_ahash_digestsize(tfm))) {
287 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
a0cfae59 288 j, algo);
da7f033d
HX
289 hexdump(result, crypto_ahash_digestsize(tfm));
290 ret = -EINVAL;
291 goto out;
292 }
293 }
294
295 j = 0;
296 for (i = 0; i < tcount; i++) {
da5ffe11
JK
297 /* alignment tests are only done with continuous buffers */
298 if (align_offset != 0)
299 break;
300
da7f033d
HX
301 if (template[i].np) {
302 j++;
303 memset(result, 0, 64);
304
305 temp = 0;
306 sg_init_table(sg, template[i].np);
fd57f22a 307 ret = -EINVAL;
da7f033d 308 for (k = 0; k < template[i].np; k++) {
fd57f22a
HX
309 if (WARN_ON(offset_in_page(IDX[k]) +
310 template[i].tap[k] > PAGE_SIZE))
311 goto out;
da7f033d
HX
312 sg_set_buf(&sg[k],
313 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
314 offset_in_page(IDX[k]),
315 template[i].plaintext + temp,
316 template[i].tap[k]),
317 template[i].tap[k]);
318 temp += template[i].tap[k];
319 }
320
321 if (template[i].ksize) {
322 crypto_ahash_clear_flags(tfm, ~0);
323 ret = crypto_ahash_setkey(tfm, template[i].key,
324 template[i].ksize);
325
326 if (ret) {
327 printk(KERN_ERR "alg: hash: setkey "
328 "failed on chunking test %d "
329 "for %s: ret=%d\n", j, algo,
330 -ret);
331 goto out;
332 }
333 }
334
335 ahash_request_set_crypt(req, sg, result,
336 template[i].psize);
337 ret = crypto_ahash_digest(req);
338 switch (ret) {
339 case 0:
340 break;
341 case -EINPROGRESS:
342 case -EBUSY:
343 ret = wait_for_completion_interruptible(
344 &tresult.completion);
345 if (!ret && !(ret = tresult.err)) {
16735d02 346 reinit_completion(&tresult.completion);
da7f033d
HX
347 break;
348 }
349 /* fall through */
350 default:
351 printk(KERN_ERR "alg: hash: digest failed "
352 "on chunking test %d for %s: "
353 "ret=%d\n", j, algo, -ret);
354 goto out;
355 }
356
357 if (memcmp(result, template[i].digest,
358 crypto_ahash_digestsize(tfm))) {
359 printk(KERN_ERR "alg: hash: Chunking test %d "
360 "failed for %s\n", j, algo);
361 hexdump(result, crypto_ahash_digestsize(tfm));
362 ret = -EINVAL;
363 goto out;
364 }
365 }
366 }
367
368 ret = 0;
369
370out:
371 ahash_request_free(req);
372out_noreq:
f8b0d4d0
HX
373 testmgr_free_buf(xbuf);
374out_nobuf:
da7f033d
HX
375 return ret;
376}
377
da5ffe11
JK
378static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
379 unsigned int tcount, bool use_digest)
380{
381 unsigned int alignmask;
382 int ret;
383
384 ret = __test_hash(tfm, template, tcount, use_digest, 0);
385 if (ret)
386 return ret;
387
388 /* test unaligned buffers, check with one byte offset */
389 ret = __test_hash(tfm, template, tcount, use_digest, 1);
390 if (ret)
391 return ret;
392
393 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
394 if (alignmask) {
395 /* Check if alignment mask for tfm is correctly set. */
396 ret = __test_hash(tfm, template, tcount, use_digest,
397 alignmask + 1);
398 if (ret)
399 return ret;
400 }
401
402 return 0;
403}
404
d8a32ac2
JK
405static int __test_aead(struct crypto_aead *tfm, int enc,
406 struct aead_testvec *template, unsigned int tcount,
58dcf548 407 const bool diff_dst, const int align_offset)
da7f033d
HX
408{
409 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
410 unsigned int i, j, k, n, temp;
f8b0d4d0 411 int ret = -ENOMEM;
da7f033d
HX
412 char *q;
413 char *key;
414 struct aead_request *req;
d8a32ac2
JK
415 struct scatterlist *sg;
416 struct scatterlist *asg;
417 struct scatterlist *sgout;
418 const char *e, *d;
da7f033d
HX
419 struct tcrypt_result result;
420 unsigned int authsize;
421 void *input;
d8a32ac2 422 void *output;
da7f033d 423 void *assoc;
9bac019d 424 char *iv;
f8b0d4d0 425 char *xbuf[XBUFSIZE];
d8a32ac2 426 char *xoutbuf[XBUFSIZE];
f8b0d4d0
HX
427 char *axbuf[XBUFSIZE];
428
9bac019d
TS
429 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
430 if (!iv)
431 return ret;
f8b0d4d0
HX
432 if (testmgr_alloc_buf(xbuf))
433 goto out_noxbuf;
434 if (testmgr_alloc_buf(axbuf))
435 goto out_noaxbuf;
d8a32ac2
JK
436 if (diff_dst && testmgr_alloc_buf(xoutbuf))
437 goto out_nooutbuf;
438
439 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
440 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
441 if (!sg)
442 goto out_nosg;
443 asg = &sg[8];
444 sgout = &asg[8];
445
446 if (diff_dst)
447 d = "-ddst";
448 else
449 d = "";
450
da7f033d
HX
451 if (enc == ENCRYPT)
452 e = "encryption";
453 else
454 e = "decryption";
455
456 init_completion(&result.completion);
457
458 req = aead_request_alloc(tfm, GFP_KERNEL);
459 if (!req) {
d8a32ac2
JK
460 pr_err("alg: aead%s: Failed to allocate request for %s\n",
461 d, algo);
da7f033d
HX
462 goto out;
463 }
464
465 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
466 tcrypt_complete, &result);
467
468 for (i = 0, j = 0; i < tcount; i++) {
469 if (!template[i].np) {
470 j++;
471
58dcf548 472 /* some templates have no input data but they will
da7f033d
HX
473 * touch input
474 */
475 input = xbuf[0];
58dcf548 476 input += align_offset;
da7f033d
HX
477 assoc = axbuf[0];
478
fd57f22a 479 ret = -EINVAL;
58dcf548
JK
480 if (WARN_ON(align_offset + template[i].ilen >
481 PAGE_SIZE || template[i].alen > PAGE_SIZE))
fd57f22a
HX
482 goto out;
483
da7f033d
HX
484 memcpy(input, template[i].input, template[i].ilen);
485 memcpy(assoc, template[i].assoc, template[i].alen);
486 if (template[i].iv)
487 memcpy(iv, template[i].iv, MAX_IVLEN);
488 else
489 memset(iv, 0, MAX_IVLEN);
490
491 crypto_aead_clear_flags(tfm, ~0);
492 if (template[i].wk)
493 crypto_aead_set_flags(
494 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
495
496 key = template[i].key;
497
498 ret = crypto_aead_setkey(tfm, key,
499 template[i].klen);
500 if (!ret == template[i].fail) {
d8a32ac2
JK
501 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
502 d, j, algo, crypto_aead_get_flags(tfm));
da7f033d
HX
503 goto out;
504 } else if (ret)
505 continue;
506
507 authsize = abs(template[i].rlen - template[i].ilen);
508 ret = crypto_aead_setauthsize(tfm, authsize);
509 if (ret) {
d8a32ac2
JK
510 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
511 d, authsize, j, algo);
da7f033d
HX
512 goto out;
513 }
514
d8a32ac2
JK
515 if (diff_dst) {
516 output = xoutbuf[0];
58dcf548 517 output += align_offset;
8ec25c51 518 sg_init_one(&sg[0], input, template[i].ilen);
d8a32ac2 519 sg_init_one(&sgout[0], output,
8ec25c51
HG
520 template[i].rlen);
521 } else {
522 sg_init_one(&sg[0], input,
d8a32ac2
JK
523 template[i].ilen +
524 (enc ? authsize : 0));
d8a32ac2
JK
525 output = input;
526 }
527
da7f033d
HX
528 sg_init_one(&asg[0], assoc, template[i].alen);
529
d8a32ac2 530 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
da7f033d
HX
531 template[i].ilen, iv);
532
533 aead_request_set_assoc(req, asg, template[i].alen);
534
535 ret = enc ?
536 crypto_aead_encrypt(req) :
537 crypto_aead_decrypt(req);
538
539 switch (ret) {
540 case 0:
e44a1b44
JW
541 if (template[i].novrfy) {
542 /* verification was supposed to fail */
d8a32ac2
JK
543 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
544 d, e, j, algo);
e44a1b44
JW
545 /* so really, we got a bad message */
546 ret = -EBADMSG;
547 goto out;
548 }
da7f033d
HX
549 break;
550 case -EINPROGRESS:
551 case -EBUSY:
552 ret = wait_for_completion_interruptible(
553 &result.completion);
554 if (!ret && !(ret = result.err)) {
16735d02 555 reinit_completion(&result.completion);
da7f033d
HX
556 break;
557 }
e44a1b44
JW
558 case -EBADMSG:
559 if (template[i].novrfy)
560 /* verification failure was expected */
561 continue;
da7f033d
HX
562 /* fall through */
563 default:
d8a32ac2
JK
564 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
565 d, e, j, algo, -ret);
da7f033d
HX
566 goto out;
567 }
568
d8a32ac2 569 q = output;
da7f033d 570 if (memcmp(q, template[i].result, template[i].rlen)) {
d8a32ac2
JK
571 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
572 d, j, e, algo);
da7f033d
HX
573 hexdump(q, template[i].rlen);
574 ret = -EINVAL;
575 goto out;
576 }
577 }
578 }
579
580 for (i = 0, j = 0; i < tcount; i++) {
58dcf548
JK
581 /* alignment tests are only done with continuous buffers */
582 if (align_offset != 0)
583 break;
584
da7f033d
HX
585 if (template[i].np) {
586 j++;
587
588 if (template[i].iv)
589 memcpy(iv, template[i].iv, MAX_IVLEN);
590 else
591 memset(iv, 0, MAX_IVLEN);
592
593 crypto_aead_clear_flags(tfm, ~0);
594 if (template[i].wk)
595 crypto_aead_set_flags(
596 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
597 key = template[i].key;
598
599 ret = crypto_aead_setkey(tfm, key, template[i].klen);
600 if (!ret == template[i].fail) {
d8a32ac2
JK
601 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
602 d, j, algo, crypto_aead_get_flags(tfm));
da7f033d
HX
603 goto out;
604 } else if (ret)
605 continue;
606
607 authsize = abs(template[i].rlen - template[i].ilen);
608
609 ret = -EINVAL;
610 sg_init_table(sg, template[i].np);
d8a32ac2
JK
611 if (diff_dst)
612 sg_init_table(sgout, template[i].np);
da7f033d
HX
613 for (k = 0, temp = 0; k < template[i].np; k++) {
614 if (WARN_ON(offset_in_page(IDX[k]) +
615 template[i].tap[k] > PAGE_SIZE))
616 goto out;
617
618 q = xbuf[IDX[k] >> PAGE_SHIFT] +
619 offset_in_page(IDX[k]);
620
621 memcpy(q, template[i].input + temp,
622 template[i].tap[k]);
623
da7f033d 624 sg_set_buf(&sg[k], q, template[i].tap[k]);
d8a32ac2
JK
625
626 if (diff_dst) {
627 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
628 offset_in_page(IDX[k]);
629
630 memset(q, 0, template[i].tap[k]);
d8a32ac2
JK
631
632 sg_set_buf(&sgout[k], q,
633 template[i].tap[k]);
634 }
635
8ec25c51
HG
636 n = template[i].tap[k];
637 if (k == template[i].np - 1 && enc)
638 n += authsize;
639 if (offset_in_page(q) + n < PAGE_SIZE)
640 q[n] = 0;
641
da7f033d
HX
642 temp += template[i].tap[k];
643 }
644
645 ret = crypto_aead_setauthsize(tfm, authsize);
646 if (ret) {
d8a32ac2
JK
647 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
648 d, authsize, j, algo);
da7f033d
HX
649 goto out;
650 }
651
652 if (enc) {
653 if (WARN_ON(sg[k - 1].offset +
654 sg[k - 1].length + authsize >
655 PAGE_SIZE)) {
656 ret = -EINVAL;
657 goto out;
658 }
659
d8a32ac2
JK
660 if (diff_dst)
661 sgout[k - 1].length += authsize;
8ec25c51
HG
662 else
663 sg[k - 1].length += authsize;
da7f033d
HX
664 }
665
666 sg_init_table(asg, template[i].anp);
fd57f22a 667 ret = -EINVAL;
da7f033d 668 for (k = 0, temp = 0; k < template[i].anp; k++) {
fd57f22a
HX
669 if (WARN_ON(offset_in_page(IDX[k]) +
670 template[i].atap[k] > PAGE_SIZE))
671 goto out;
da7f033d
HX
672 sg_set_buf(&asg[k],
673 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
674 offset_in_page(IDX[k]),
675 template[i].assoc + temp,
676 template[i].atap[k]),
677 template[i].atap[k]);
678 temp += template[i].atap[k];
679 }
680
d8a32ac2 681 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
da7f033d
HX
682 template[i].ilen,
683 iv);
684
685 aead_request_set_assoc(req, asg, template[i].alen);
686
687 ret = enc ?
688 crypto_aead_encrypt(req) :
689 crypto_aead_decrypt(req);
690
691 switch (ret) {
692 case 0:
e44a1b44
JW
693 if (template[i].novrfy) {
694 /* verification was supposed to fail */
d8a32ac2
JK
695 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
696 d, e, j, algo);
e44a1b44
JW
697 /* so really, we got a bad message */
698 ret = -EBADMSG;
699 goto out;
700 }
da7f033d
HX
701 break;
702 case -EINPROGRESS:
703 case -EBUSY:
704 ret = wait_for_completion_interruptible(
705 &result.completion);
706 if (!ret && !(ret = result.err)) {
16735d02 707 reinit_completion(&result.completion);
da7f033d
HX
708 break;
709 }
e44a1b44
JW
710 case -EBADMSG:
711 if (template[i].novrfy)
712 /* verification failure was expected */
713 continue;
da7f033d
HX
714 /* fall through */
715 default:
d8a32ac2
JK
716 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
717 d, e, j, algo, -ret);
da7f033d
HX
718 goto out;
719 }
720
721 ret = -EINVAL;
722 for (k = 0, temp = 0; k < template[i].np; k++) {
d8a32ac2
JK
723 if (diff_dst)
724 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
725 offset_in_page(IDX[k]);
726 else
727 q = xbuf[IDX[k] >> PAGE_SHIFT] +
728 offset_in_page(IDX[k]);
da7f033d
HX
729
730 n = template[i].tap[k];
731 if (k == template[i].np - 1)
732 n += enc ? authsize : -authsize;
733
734 if (memcmp(q, template[i].result + temp, n)) {
d8a32ac2
JK
735 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
736 d, j, e, k, algo);
da7f033d
HX
737 hexdump(q, n);
738 goto out;
739 }
740
741 q += n;
742 if (k == template[i].np - 1 && !enc) {
d8a32ac2
JK
743 if (!diff_dst &&
744 memcmp(q, template[i].input +
da7f033d
HX
745 temp + n, authsize))
746 n = authsize;
747 else
748 n = 0;
749 } else {
750 for (n = 0; offset_in_page(q + n) &&
751 q[n]; n++)
752 ;
753 }
754 if (n) {
d8a32ac2
JK
755 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
756 d, j, e, k, algo, n);
da7f033d
HX
757 hexdump(q, n);
758 goto out;
759 }
760
761 temp += template[i].tap[k];
762 }
763 }
764 }
765
766 ret = 0;
767
768out:
769 aead_request_free(req);
d8a32ac2
JK
770 kfree(sg);
771out_nosg:
772 if (diff_dst)
773 testmgr_free_buf(xoutbuf);
774out_nooutbuf:
f8b0d4d0
HX
775 testmgr_free_buf(axbuf);
776out_noaxbuf:
777 testmgr_free_buf(xbuf);
778out_noxbuf:
9bac019d 779 kfree(iv);
da7f033d
HX
780 return ret;
781}
782
d8a32ac2
JK
783static int test_aead(struct crypto_aead *tfm, int enc,
784 struct aead_testvec *template, unsigned int tcount)
785{
58dcf548 786 unsigned int alignmask;
d8a32ac2
JK
787 int ret;
788
789 /* test 'dst == src' case */
58dcf548 790 ret = __test_aead(tfm, enc, template, tcount, false, 0);
d8a32ac2
JK
791 if (ret)
792 return ret;
793
794 /* test 'dst != src' case */
58dcf548
JK
795 ret = __test_aead(tfm, enc, template, tcount, true, 0);
796 if (ret)
797 return ret;
798
799 /* test unaligned buffers, check with one byte offset */
800 ret = __test_aead(tfm, enc, template, tcount, true, 1);
801 if (ret)
802 return ret;
803
804 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
805 if (alignmask) {
806 /* Check if alignment mask for tfm is correctly set. */
807 ret = __test_aead(tfm, enc, template, tcount, true,
808 alignmask + 1);
809 if (ret)
810 return ret;
811 }
812
813 return 0;
d8a32ac2
JK
814}
815
1aa4ecd9 816static int test_cipher(struct crypto_cipher *tfm, int enc,
da7f033d 817 struct cipher_testvec *template, unsigned int tcount)
1aa4ecd9
HX
818{
819 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
820 unsigned int i, j, k;
1aa4ecd9
HX
821 char *q;
822 const char *e;
823 void *data;
f8b0d4d0
HX
824 char *xbuf[XBUFSIZE];
825 int ret = -ENOMEM;
826
827 if (testmgr_alloc_buf(xbuf))
828 goto out_nobuf;
1aa4ecd9
HX
829
830 if (enc == ENCRYPT)
831 e = "encryption";
832 else
833 e = "decryption";
834
835 j = 0;
836 for (i = 0; i < tcount; i++) {
837 if (template[i].np)
838 continue;
839
840 j++;
841
fd57f22a
HX
842 ret = -EINVAL;
843 if (WARN_ON(template[i].ilen > PAGE_SIZE))
844 goto out;
845
1aa4ecd9
HX
846 data = xbuf[0];
847 memcpy(data, template[i].input, template[i].ilen);
848
849 crypto_cipher_clear_flags(tfm, ~0);
850 if (template[i].wk)
851 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
852
853 ret = crypto_cipher_setkey(tfm, template[i].key,
854 template[i].klen);
855 if (!ret == template[i].fail) {
856 printk(KERN_ERR "alg: cipher: setkey failed "
857 "on test %d for %s: flags=%x\n", j,
858 algo, crypto_cipher_get_flags(tfm));
859 goto out;
860 } else if (ret)
861 continue;
862
863 for (k = 0; k < template[i].ilen;
864 k += crypto_cipher_blocksize(tfm)) {
865 if (enc)
866 crypto_cipher_encrypt_one(tfm, data + k,
867 data + k);
868 else
869 crypto_cipher_decrypt_one(tfm, data + k,
870 data + k);
871 }
872
873 q = data;
874 if (memcmp(q, template[i].result, template[i].rlen)) {
875 printk(KERN_ERR "alg: cipher: Test %d failed "
876 "on %s for %s\n", j, e, algo);
877 hexdump(q, template[i].rlen);
878 ret = -EINVAL;
879 goto out;
880 }
881 }
882
883 ret = 0;
884
885out:
f8b0d4d0
HX
886 testmgr_free_buf(xbuf);
887out_nobuf:
1aa4ecd9
HX
888 return ret;
889}
890
08d6af8c
JK
891static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
892 struct cipher_testvec *template, unsigned int tcount,
3a338f20 893 const bool diff_dst, const int align_offset)
da7f033d
HX
894{
895 const char *algo =
896 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
897 unsigned int i, j, k, n, temp;
da7f033d
HX
898 char *q;
899 struct ablkcipher_request *req;
900 struct scatterlist sg[8];
08d6af8c
JK
901 struct scatterlist sgout[8];
902 const char *e, *d;
da7f033d
HX
903 struct tcrypt_result result;
904 void *data;
905 char iv[MAX_IVLEN];
f8b0d4d0 906 char *xbuf[XBUFSIZE];
08d6af8c 907 char *xoutbuf[XBUFSIZE];
f8b0d4d0
HX
908 int ret = -ENOMEM;
909
910 if (testmgr_alloc_buf(xbuf))
911 goto out_nobuf;
da7f033d 912
08d6af8c
JK
913 if (diff_dst && testmgr_alloc_buf(xoutbuf))
914 goto out_nooutbuf;
915
916 if (diff_dst)
917 d = "-ddst";
918 else
919 d = "";
920
da7f033d
HX
921 if (enc == ENCRYPT)
922 e = "encryption";
923 else
924 e = "decryption";
925
926 init_completion(&result.completion);
927
928 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
929 if (!req) {
08d6af8c
JK
930 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
931 d, algo);
da7f033d
HX
932 goto out;
933 }
934
935 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
936 tcrypt_complete, &result);
937
938 j = 0;
939 for (i = 0; i < tcount; i++) {
940 if (template[i].iv)
941 memcpy(iv, template[i].iv, MAX_IVLEN);
942 else
943 memset(iv, 0, MAX_IVLEN);
944
f44d83d1 945 if (!(template[i].np) || (template[i].also_non_np)) {
da7f033d
HX
946 j++;
947
fd57f22a 948 ret = -EINVAL;
3a338f20
JK
949 if (WARN_ON(align_offset + template[i].ilen >
950 PAGE_SIZE))
fd57f22a
HX
951 goto out;
952
da7f033d 953 data = xbuf[0];
3a338f20 954 data += align_offset;
da7f033d
HX
955 memcpy(data, template[i].input, template[i].ilen);
956
957 crypto_ablkcipher_clear_flags(tfm, ~0);
958 if (template[i].wk)
959 crypto_ablkcipher_set_flags(
960 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
961
962 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
963 template[i].klen);
964 if (!ret == template[i].fail) {
08d6af8c
JK
965 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
966 d, j, algo,
967 crypto_ablkcipher_get_flags(tfm));
da7f033d
HX
968 goto out;
969 } else if (ret)
970 continue;
971
972 sg_init_one(&sg[0], data, template[i].ilen);
08d6af8c
JK
973 if (diff_dst) {
974 data = xoutbuf[0];
3a338f20 975 data += align_offset;
08d6af8c
JK
976 sg_init_one(&sgout[0], data, template[i].ilen);
977 }
da7f033d 978
08d6af8c
JK
979 ablkcipher_request_set_crypt(req, sg,
980 (diff_dst) ? sgout : sg,
da7f033d
HX
981 template[i].ilen, iv);
982 ret = enc ?
983 crypto_ablkcipher_encrypt(req) :
984 crypto_ablkcipher_decrypt(req);
985
986 switch (ret) {
987 case 0:
988 break;
989 case -EINPROGRESS:
990 case -EBUSY:
991 ret = wait_for_completion_interruptible(
992 &result.completion);
993 if (!ret && !((ret = result.err))) {
16735d02 994 reinit_completion(&result.completion);
da7f033d
HX
995 break;
996 }
997 /* fall through */
998 default:
08d6af8c
JK
999 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1000 d, e, j, algo, -ret);
da7f033d
HX
1001 goto out;
1002 }
1003
1004 q = data;
1005 if (memcmp(q, template[i].result, template[i].rlen)) {
08d6af8c
JK
1006 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1007 d, j, e, algo);
da7f033d
HX
1008 hexdump(q, template[i].rlen);
1009 ret = -EINVAL;
1010 goto out;
1011 }
1012 }
1013 }
1014
1015 j = 0;
1016 for (i = 0; i < tcount; i++) {
3a338f20
JK
1017 /* alignment tests are only done with continuous buffers */
1018 if (align_offset != 0)
1019 break;
da7f033d
HX
1020
1021 if (template[i].iv)
1022 memcpy(iv, template[i].iv, MAX_IVLEN);
1023 else
1024 memset(iv, 0, MAX_IVLEN);
1025
1026 if (template[i].np) {
1027 j++;
1028
1029 crypto_ablkcipher_clear_flags(tfm, ~0);
1030 if (template[i].wk)
1031 crypto_ablkcipher_set_flags(
1032 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1033
1034 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1035 template[i].klen);
1036 if (!ret == template[i].fail) {
08d6af8c
JK
1037 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1038 d, j, algo,
da7f033d
HX
1039 crypto_ablkcipher_get_flags(tfm));
1040 goto out;
1041 } else if (ret)
1042 continue;
1043
1044 temp = 0;
1045 ret = -EINVAL;
1046 sg_init_table(sg, template[i].np);
08d6af8c
JK
1047 if (diff_dst)
1048 sg_init_table(sgout, template[i].np);
da7f033d
HX
1049 for (k = 0; k < template[i].np; k++) {
1050 if (WARN_ON(offset_in_page(IDX[k]) +
1051 template[i].tap[k] > PAGE_SIZE))
1052 goto out;
1053
1054 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1055 offset_in_page(IDX[k]);
1056
1057 memcpy(q, template[i].input + temp,
1058 template[i].tap[k]);
1059
1060 if (offset_in_page(q) + template[i].tap[k] <
1061 PAGE_SIZE)
1062 q[template[i].tap[k]] = 0;
1063
1064 sg_set_buf(&sg[k], q, template[i].tap[k]);
08d6af8c
JK
1065 if (diff_dst) {
1066 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1067 offset_in_page(IDX[k]);
1068
1069 sg_set_buf(&sgout[k], q,
1070 template[i].tap[k]);
1071
1072 memset(q, 0, template[i].tap[k]);
1073 if (offset_in_page(q) +
1074 template[i].tap[k] < PAGE_SIZE)
1075 q[template[i].tap[k]] = 0;
1076 }
da7f033d
HX
1077
1078 temp += template[i].tap[k];
1079 }
1080
08d6af8c
JK
1081 ablkcipher_request_set_crypt(req, sg,
1082 (diff_dst) ? sgout : sg,
da7f033d
HX
1083 template[i].ilen, iv);
1084
1085 ret = enc ?
1086 crypto_ablkcipher_encrypt(req) :
1087 crypto_ablkcipher_decrypt(req);
1088
1089 switch (ret) {
1090 case 0:
1091 break;
1092 case -EINPROGRESS:
1093 case -EBUSY:
1094 ret = wait_for_completion_interruptible(
1095 &result.completion);
1096 if (!ret && !((ret = result.err))) {
16735d02 1097 reinit_completion(&result.completion);
da7f033d
HX
1098 break;
1099 }
1100 /* fall through */
1101 default:
08d6af8c
JK
1102 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1103 d, e, j, algo, -ret);
da7f033d
HX
1104 goto out;
1105 }
1106
1107 temp = 0;
1108 ret = -EINVAL;
1109 for (k = 0; k < template[i].np; k++) {
08d6af8c
JK
1110 if (diff_dst)
1111 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1112 offset_in_page(IDX[k]);
1113 else
1114 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1115 offset_in_page(IDX[k]);
da7f033d
HX
1116
1117 if (memcmp(q, template[i].result + temp,
1118 template[i].tap[k])) {
08d6af8c
JK
1119 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1120 d, j, e, k, algo);
da7f033d
HX
1121 hexdump(q, template[i].tap[k]);
1122 goto out;
1123 }
1124
1125 q += template[i].tap[k];
1126 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1127 ;
1128 if (n) {
08d6af8c
JK
1129 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1130 d, j, e, k, algo, n);
da7f033d
HX
1131 hexdump(q, n);
1132 goto out;
1133 }
1134 temp += template[i].tap[k];
1135 }
1136 }
1137 }
1138
1139 ret = 0;
1140
1141out:
1142 ablkcipher_request_free(req);
08d6af8c
JK
1143 if (diff_dst)
1144 testmgr_free_buf(xoutbuf);
1145out_nooutbuf:
f8b0d4d0
HX
1146 testmgr_free_buf(xbuf);
1147out_nobuf:
da7f033d
HX
1148 return ret;
1149}
1150
08d6af8c
JK
1151static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1152 struct cipher_testvec *template, unsigned int tcount)
1153{
3a338f20 1154 unsigned int alignmask;
08d6af8c
JK
1155 int ret;
1156
1157 /* test 'dst == src' case */
3a338f20 1158 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
08d6af8c
JK
1159 if (ret)
1160 return ret;
1161
1162 /* test 'dst != src' case */
3a338f20
JK
1163 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1164 if (ret)
1165 return ret;
1166
1167 /* test unaligned buffers, check with one byte offset */
1168 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1169 if (ret)
1170 return ret;
1171
1172 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1173 if (alignmask) {
1174 /* Check if alignment mask for tfm is correctly set. */
1175 ret = __test_skcipher(tfm, enc, template, tcount, true,
1176 alignmask + 1);
1177 if (ret)
1178 return ret;
1179 }
1180
1181 return 0;
08d6af8c
JK
1182}
1183
da7f033d
HX
1184static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1185 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1186{
1187 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1188 unsigned int i;
1189 char result[COMP_BUF_SIZE];
1190 int ret;
1191
1192 for (i = 0; i < ctcount; i++) {
c79cf910
GU
1193 int ilen;
1194 unsigned int dlen = COMP_BUF_SIZE;
da7f033d
HX
1195
1196 memset(result, 0, sizeof (result));
1197
1198 ilen = ctemplate[i].inlen;
1199 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1200 ilen, result, &dlen);
1201 if (ret) {
1202 printk(KERN_ERR "alg: comp: compression failed "
1203 "on test %d for %s: ret=%d\n", i + 1, algo,
1204 -ret);
1205 goto out;
1206 }
1207
b812eb00
GU
1208 if (dlen != ctemplate[i].outlen) {
1209 printk(KERN_ERR "alg: comp: Compression test %d "
1210 "failed for %s: output len = %d\n", i + 1, algo,
1211 dlen);
1212 ret = -EINVAL;
1213 goto out;
1214 }
1215
da7f033d
HX
1216 if (memcmp(result, ctemplate[i].output, dlen)) {
1217 printk(KERN_ERR "alg: comp: Compression test %d "
1218 "failed for %s\n", i + 1, algo);
1219 hexdump(result, dlen);
1220 ret = -EINVAL;
1221 goto out;
1222 }
1223 }
1224
1225 for (i = 0; i < dtcount; i++) {
c79cf910
GU
1226 int ilen;
1227 unsigned int dlen = COMP_BUF_SIZE;
da7f033d
HX
1228
1229 memset(result, 0, sizeof (result));
1230
1231 ilen = dtemplate[i].inlen;
1232 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1233 ilen, result, &dlen);
1234 if (ret) {
1235 printk(KERN_ERR "alg: comp: decompression failed "
1236 "on test %d for %s: ret=%d\n", i + 1, algo,
1237 -ret);
1238 goto out;
1239 }
1240
b812eb00
GU
1241 if (dlen != dtemplate[i].outlen) {
1242 printk(KERN_ERR "alg: comp: Decompression test %d "
1243 "failed for %s: output len = %d\n", i + 1, algo,
1244 dlen);
1245 ret = -EINVAL;
1246 goto out;
1247 }
1248
da7f033d
HX
1249 if (memcmp(result, dtemplate[i].output, dlen)) {
1250 printk(KERN_ERR "alg: comp: Decompression test %d "
1251 "failed for %s\n", i + 1, algo);
1252 hexdump(result, dlen);
1253 ret = -EINVAL;
1254 goto out;
1255 }
1256 }
1257
1258 ret = 0;
1259
1260out:
1261 return ret;
1262}
1263
8064efb8
GU
1264static int test_pcomp(struct crypto_pcomp *tfm,
1265 struct pcomp_testvec *ctemplate,
1266 struct pcomp_testvec *dtemplate, int ctcount,
1267 int dtcount)
1268{
1269 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1270 unsigned int i;
1271 char result[COMP_BUF_SIZE];
3ce858cb 1272 int res;
8064efb8
GU
1273
1274 for (i = 0; i < ctcount; i++) {
1275 struct comp_request req;
3ce858cb 1276 unsigned int produced = 0;
8064efb8 1277
3ce858cb
GU
1278 res = crypto_compress_setup(tfm, ctemplate[i].params,
1279 ctemplate[i].paramsize);
1280 if (res) {
8064efb8 1281 pr_err("alg: pcomp: compression setup failed on test "
3ce858cb
GU
1282 "%d for %s: error=%d\n", i + 1, algo, res);
1283 return res;
8064efb8
GU
1284 }
1285
3ce858cb
GU
1286 res = crypto_compress_init(tfm);
1287 if (res) {
8064efb8 1288 pr_err("alg: pcomp: compression init failed on test "
3ce858cb
GU
1289 "%d for %s: error=%d\n", i + 1, algo, res);
1290 return res;
8064efb8
GU
1291 }
1292
1293 memset(result, 0, sizeof(result));
1294
1295 req.next_in = ctemplate[i].input;
1296 req.avail_in = ctemplate[i].inlen / 2;
1297 req.next_out = result;
1298 req.avail_out = ctemplate[i].outlen / 2;
1299
3ce858cb
GU
1300 res = crypto_compress_update(tfm, &req);
1301 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
8064efb8 1302 pr_err("alg: pcomp: compression update failed on test "
3ce858cb
GU
1303 "%d for %s: error=%d\n", i + 1, algo, res);
1304 return res;
8064efb8 1305 }
3ce858cb
GU
1306 if (res > 0)
1307 produced += res;
8064efb8
GU
1308
1309 /* Add remaining input data */
1310 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1311
3ce858cb
GU
1312 res = crypto_compress_update(tfm, &req);
1313 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
8064efb8 1314 pr_err("alg: pcomp: compression update failed on test "
3ce858cb
GU
1315 "%d for %s: error=%d\n", i + 1, algo, res);
1316 return res;
8064efb8 1317 }
3ce858cb
GU
1318 if (res > 0)
1319 produced += res;
8064efb8
GU
1320
1321 /* Provide remaining output space */
1322 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1323
3ce858cb
GU
1324 res = crypto_compress_final(tfm, &req);
1325 if (res < 0) {
8064efb8 1326 pr_err("alg: pcomp: compression final failed on test "
3ce858cb
GU
1327 "%d for %s: error=%d\n", i + 1, algo, res);
1328 return res;
8064efb8 1329 }
3ce858cb 1330 produced += res;
8064efb8
GU
1331
1332 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1333 pr_err("alg: comp: Compression test %d failed for %s: "
1334 "output len = %d (expected %d)\n", i + 1, algo,
1335 COMP_BUF_SIZE - req.avail_out,
1336 ctemplate[i].outlen);
1337 return -EINVAL;
1338 }
1339
3ce858cb
GU
1340 if (produced != ctemplate[i].outlen) {
1341 pr_err("alg: comp: Compression test %d failed for %s: "
1342 "returned len = %u (expected %d)\n", i + 1,
1343 algo, produced, ctemplate[i].outlen);
1344 return -EINVAL;
1345 }
1346
8064efb8
GU
1347 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1348 pr_err("alg: pcomp: Compression test %d failed for "
1349 "%s\n", i + 1, algo);
1350 hexdump(result, ctemplate[i].outlen);
1351 return -EINVAL;
1352 }
1353 }
1354
1355 for (i = 0; i < dtcount; i++) {
1356 struct comp_request req;
3ce858cb 1357 unsigned int produced = 0;
8064efb8 1358
3ce858cb
GU
1359 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1360 dtemplate[i].paramsize);
1361 if (res) {
8064efb8 1362 pr_err("alg: pcomp: decompression setup failed on "
3ce858cb
GU
1363 "test %d for %s: error=%d\n", i + 1, algo, res);
1364 return res;
8064efb8
GU
1365 }
1366
3ce858cb
GU
1367 res = crypto_decompress_init(tfm);
1368 if (res) {
8064efb8 1369 pr_err("alg: pcomp: decompression init failed on test "
3ce858cb
GU
1370 "%d for %s: error=%d\n", i + 1, algo, res);
1371 return res;
8064efb8
GU
1372 }
1373
1374 memset(result, 0, sizeof(result));
1375
1376 req.next_in = dtemplate[i].input;
1377 req.avail_in = dtemplate[i].inlen / 2;
1378 req.next_out = result;
1379 req.avail_out = dtemplate[i].outlen / 2;
1380
3ce858cb
GU
1381 res = crypto_decompress_update(tfm, &req);
1382 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
8064efb8 1383 pr_err("alg: pcomp: decompression update failed on "
3ce858cb
GU
1384 "test %d for %s: error=%d\n", i + 1, algo, res);
1385 return res;
8064efb8 1386 }
3ce858cb
GU
1387 if (res > 0)
1388 produced += res;
8064efb8
GU
1389
1390 /* Add remaining input data */
1391 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1392
3ce858cb
GU
1393 res = crypto_decompress_update(tfm, &req);
1394 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
8064efb8 1395 pr_err("alg: pcomp: decompression update failed on "
3ce858cb
GU
1396 "test %d for %s: error=%d\n", i + 1, algo, res);
1397 return res;
8064efb8 1398 }
3ce858cb
GU
1399 if (res > 0)
1400 produced += res;
8064efb8
GU
1401
1402 /* Provide remaining output space */
1403 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1404
3ce858cb
GU
1405 res = crypto_decompress_final(tfm, &req);
1406 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
8064efb8 1407 pr_err("alg: pcomp: decompression final failed on "
3ce858cb
GU
1408 "test %d for %s: error=%d\n", i + 1, algo, res);
1409 return res;
8064efb8 1410 }
3ce858cb
GU
1411 if (res > 0)
1412 produced += res;
8064efb8
GU
1413
1414 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1415 pr_err("alg: comp: Decompression test %d failed for "
1416 "%s: output len = %d (expected %d)\n", i + 1,
1417 algo, COMP_BUF_SIZE - req.avail_out,
1418 dtemplate[i].outlen);
1419 return -EINVAL;
1420 }
1421
3ce858cb
GU
1422 if (produced != dtemplate[i].outlen) {
1423 pr_err("alg: comp: Decompression test %d failed for "
1424 "%s: returned len = %u (expected %d)\n", i + 1,
1425 algo, produced, dtemplate[i].outlen);
1426 return -EINVAL;
1427 }
1428
8064efb8
GU
1429 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1430 pr_err("alg: pcomp: Decompression test %d failed for "
1431 "%s\n", i + 1, algo);
1432 hexdump(result, dtemplate[i].outlen);
1433 return -EINVAL;
1434 }
1435 }
1436
1437 return 0;
1438}
1439
7647d6ce
JW
1440
1441static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1442 unsigned int tcount)
1443{
1444 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
fa4ef8a6 1445 int err = 0, i, j, seedsize;
7647d6ce
JW
1446 u8 *seed;
1447 char result[32];
1448
1449 seedsize = crypto_rng_seedsize(tfm);
1450
1451 seed = kmalloc(seedsize, GFP_KERNEL);
1452 if (!seed) {
1453 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1454 "for %s\n", algo);
1455 return -ENOMEM;
1456 }
1457
1458 for (i = 0; i < tcount; i++) {
1459 memset(result, 0, 32);
1460
1461 memcpy(seed, template[i].v, template[i].vlen);
1462 memcpy(seed + template[i].vlen, template[i].key,
1463 template[i].klen);
1464 memcpy(seed + template[i].vlen + template[i].klen,
1465 template[i].dt, template[i].dtlen);
1466
1467 err = crypto_rng_reset(tfm, seed, seedsize);
1468 if (err) {
1469 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1470 "for %s\n", algo);
1471 goto out;
1472 }
1473
1474 for (j = 0; j < template[i].loops; j++) {
1475 err = crypto_rng_get_bytes(tfm, result,
1476 template[i].rlen);
1477 if (err != template[i].rlen) {
1478 printk(KERN_ERR "alg: cprng: Failed to obtain "
1479 "the correct amount of random data for "
1480 "%s (requested %d, got %d)\n", algo,
1481 template[i].rlen, err);
1482 goto out;
1483 }
1484 }
1485
1486 err = memcmp(result, template[i].result,
1487 template[i].rlen);
1488 if (err) {
1489 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1490 i, algo);
1491 hexdump(result, template[i].rlen);
1492 err = -EINVAL;
1493 goto out;
1494 }
1495 }
1496
1497out:
1498 kfree(seed);
1499 return err;
1500}
1501
da7f033d
HX
1502static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1503 u32 type, u32 mask)
1504{
1505 struct crypto_aead *tfm;
1506 int err = 0;
1507
1508 tfm = crypto_alloc_aead(driver, type, mask);
1509 if (IS_ERR(tfm)) {
1510 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1511 "%ld\n", driver, PTR_ERR(tfm));
1512 return PTR_ERR(tfm);
1513 }
1514
1515 if (desc->suite.aead.enc.vecs) {
1516 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1517 desc->suite.aead.enc.count);
1518 if (err)
1519 goto out;
1520 }
1521
1522 if (!err && desc->suite.aead.dec.vecs)
1523 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1524 desc->suite.aead.dec.count);
1525
1526out:
1527 crypto_free_aead(tfm);
1528 return err;
1529}
1530
1531static int alg_test_cipher(const struct alg_test_desc *desc,
1532 const char *driver, u32 type, u32 mask)
1533{
1aa4ecd9 1534 struct crypto_cipher *tfm;
da7f033d
HX
1535 int err = 0;
1536
1aa4ecd9 1537 tfm = crypto_alloc_cipher(driver, type, mask);
da7f033d
HX
1538 if (IS_ERR(tfm)) {
1539 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1540 "%s: %ld\n", driver, PTR_ERR(tfm));
1541 return PTR_ERR(tfm);
1542 }
1543
1544 if (desc->suite.cipher.enc.vecs) {
1545 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1546 desc->suite.cipher.enc.count);
1547 if (err)
1548 goto out;
1549 }
1550
1551 if (desc->suite.cipher.dec.vecs)
1552 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1553 desc->suite.cipher.dec.count);
1554
1aa4ecd9
HX
1555out:
1556 crypto_free_cipher(tfm);
1557 return err;
1558}
1559
1560static int alg_test_skcipher(const struct alg_test_desc *desc,
1561 const char *driver, u32 type, u32 mask)
1562{
1563 struct crypto_ablkcipher *tfm;
1564 int err = 0;
1565
1566 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1567 if (IS_ERR(tfm)) {
1568 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1569 "%s: %ld\n", driver, PTR_ERR(tfm));
1570 return PTR_ERR(tfm);
1571 }
1572
1573 if (desc->suite.cipher.enc.vecs) {
1574 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1575 desc->suite.cipher.enc.count);
1576 if (err)
1577 goto out;
1578 }
1579
1580 if (desc->suite.cipher.dec.vecs)
1581 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1582 desc->suite.cipher.dec.count);
1583
da7f033d
HX
1584out:
1585 crypto_free_ablkcipher(tfm);
1586 return err;
1587}
1588
1589static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1590 u32 type, u32 mask)
1591{
1592 struct crypto_comp *tfm;
1593 int err;
1594
1595 tfm = crypto_alloc_comp(driver, type, mask);
1596 if (IS_ERR(tfm)) {
1597 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1598 "%ld\n", driver, PTR_ERR(tfm));
1599 return PTR_ERR(tfm);
1600 }
1601
1602 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1603 desc->suite.comp.decomp.vecs,
1604 desc->suite.comp.comp.count,
1605 desc->suite.comp.decomp.count);
1606
1607 crypto_free_comp(tfm);
1608 return err;
1609}
1610
8064efb8
GU
1611static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1612 u32 type, u32 mask)
1613{
1614 struct crypto_pcomp *tfm;
1615 int err;
1616
1617 tfm = crypto_alloc_pcomp(driver, type, mask);
1618 if (IS_ERR(tfm)) {
1619 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1620 driver, PTR_ERR(tfm));
1621 return PTR_ERR(tfm);
1622 }
1623
1624 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1625 desc->suite.pcomp.decomp.vecs,
1626 desc->suite.pcomp.comp.count,
1627 desc->suite.pcomp.decomp.count);
1628
1629 crypto_free_pcomp(tfm);
1630 return err;
1631}
1632
da7f033d
HX
1633static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1634 u32 type, u32 mask)
1635{
1636 struct crypto_ahash *tfm;
1637 int err;
1638
1639 tfm = crypto_alloc_ahash(driver, type, mask);
1640 if (IS_ERR(tfm)) {
1641 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1642 "%ld\n", driver, PTR_ERR(tfm));
1643 return PTR_ERR(tfm);
1644 }
1645
a8f1a052
DM
1646 err = test_hash(tfm, desc->suite.hash.vecs,
1647 desc->suite.hash.count, true);
1648 if (!err)
1649 err = test_hash(tfm, desc->suite.hash.vecs,
1650 desc->suite.hash.count, false);
da7f033d
HX
1651
1652 crypto_free_ahash(tfm);
1653 return err;
1654}
1655
8e3ee85e
HX
1656static int alg_test_crc32c(const struct alg_test_desc *desc,
1657 const char *driver, u32 type, u32 mask)
1658{
1659 struct crypto_shash *tfm;
1660 u32 val;
1661 int err;
1662
1663 err = alg_test_hash(desc, driver, type, mask);
1664 if (err)
1665 goto out;
1666
1667 tfm = crypto_alloc_shash(driver, type, mask);
1668 if (IS_ERR(tfm)) {
1669 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1670 "%ld\n", driver, PTR_ERR(tfm));
1671 err = PTR_ERR(tfm);
1672 goto out;
1673 }
1674
1675 do {
1676 struct {
1677 struct shash_desc shash;
1678 char ctx[crypto_shash_descsize(tfm)];
1679 } sdesc;
1680
1681 sdesc.shash.tfm = tfm;
1682 sdesc.shash.flags = 0;
1683
1684 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1685 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1686 if (err) {
1687 printk(KERN_ERR "alg: crc32c: Operation failed for "
1688 "%s: %d\n", driver, err);
1689 break;
1690 }
1691
1692 if (val != ~420553207) {
1693 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1694 "%d\n", driver, val);
1695 err = -EINVAL;
1696 }
1697 } while (0);
1698
1699 crypto_free_shash(tfm);
1700
1701out:
1702 return err;
1703}
1704
7647d6ce
JW
1705static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1706 u32 type, u32 mask)
1707{
1708 struct crypto_rng *rng;
1709 int err;
1710
1711 rng = crypto_alloc_rng(driver, type, mask);
1712 if (IS_ERR(rng)) {
1713 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1714 "%ld\n", driver, PTR_ERR(rng));
1715 return PTR_ERR(rng);
1716 }
1717
1718 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1719
1720 crypto_free_rng(rng);
1721
1722 return err;
1723}
1724
64d1cdfb
SM
1725
1726static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1727 const char *driver, u32 type, u32 mask)
1728{
1729 int ret = -EAGAIN;
1730 struct crypto_rng *drng;
1731 struct drbg_test_data test_data;
1732 struct drbg_string addtl, pers, testentropy;
1733 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1734
1735 if (!buf)
1736 return -ENOMEM;
1737
1738 drng = crypto_alloc_rng(driver, type, mask);
1739 if (IS_ERR(drng)) {
1740 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for"
1741 "%s\n", driver);
1742 kzfree(buf);
1743 return -ENOMEM;
1744 }
1745
1746 test_data.testentropy = &testentropy;
1747 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1748 drbg_string_fill(&pers, test->pers, test->perslen);
1749 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1750 if (ret) {
1751 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1752 goto outbuf;
1753 }
1754
1755 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1756 if (pr) {
1757 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1758 ret = crypto_drbg_get_bytes_addtl_test(drng,
1759 buf, test->expectedlen, &addtl, &test_data);
1760 } else {
1761 ret = crypto_drbg_get_bytes_addtl(drng,
1762 buf, test->expectedlen, &addtl);
1763 }
1764 if (ret <= 0) {
1765 printk(KERN_ERR "alg: drbg: could not obtain random data for"
1766 "driver %s\n", driver);
1767 goto outbuf;
1768 }
1769
1770 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1771 if (pr) {
1772 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1773 ret = crypto_drbg_get_bytes_addtl_test(drng,
1774 buf, test->expectedlen, &addtl, &test_data);
1775 } else {
1776 ret = crypto_drbg_get_bytes_addtl(drng,
1777 buf, test->expectedlen, &addtl);
1778 }
1779 if (ret <= 0) {
1780 printk(KERN_ERR "alg: drbg: could not obtain random data for"
1781 "driver %s\n", driver);
1782 goto outbuf;
1783 }
1784
1785 ret = memcmp(test->expected, buf, test->expectedlen);
1786
1787outbuf:
1788 crypto_free_rng(drng);
1789 kzfree(buf);
1790 return ret;
1791}
1792
1793
1794static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1795 u32 type, u32 mask)
1796{
1797 int err = 0;
1798 int pr = 0;
1799 int i = 0;
1800 struct drbg_testvec *template = desc->suite.drbg.vecs;
1801 unsigned int tcount = desc->suite.drbg.count;
1802
1803 if (0 == memcmp(driver, "drbg_pr_", 8))
1804 pr = 1;
1805
1806 for (i = 0; i < tcount; i++) {
1807 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1808 if (err) {
1809 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1810 i, driver);
1811 err = -EINVAL;
1812 break;
1813 }
1814 }
1815 return err;
1816
1817}
1818
863b557a
YS
1819static int alg_test_null(const struct alg_test_desc *desc,
1820 const char *driver, u32 type, u32 mask)
1821{
1822 return 0;
1823}
1824
da7f033d
HX
1825/* Please keep this list sorted by algorithm name. */
1826static const struct alg_test_desc alg_test_descs[] = {
1827 {
4d6d6a2c
JG
1828 .alg = "__cbc-cast5-avx",
1829 .test = alg_test_null,
4ea1277d
JG
1830 }, {
1831 .alg = "__cbc-cast6-avx",
1832 .test = alg_test_null,
4d6d6a2c 1833 }, {
7efe4076
JG
1834 .alg = "__cbc-serpent-avx",
1835 .test = alg_test_null,
56d76c96
JK
1836 }, {
1837 .alg = "__cbc-serpent-avx2",
1838 .test = alg_test_null,
7efe4076 1839 }, {
937c30d7
JK
1840 .alg = "__cbc-serpent-sse2",
1841 .test = alg_test_null,
107778b5
JG
1842 }, {
1843 .alg = "__cbc-twofish-avx",
1844 .test = alg_test_null,
937c30d7 1845 }, {
863b557a
YS
1846 .alg = "__driver-cbc-aes-aesni",
1847 .test = alg_test_null,
6c79294f 1848 .fips_allowed = 1,
d9b1d2e7
JK
1849 }, {
1850 .alg = "__driver-cbc-camellia-aesni",
1851 .test = alg_test_null,
f3f935a7
JK
1852 }, {
1853 .alg = "__driver-cbc-camellia-aesni-avx2",
1854 .test = alg_test_null,
4d6d6a2c
JG
1855 }, {
1856 .alg = "__driver-cbc-cast5-avx",
1857 .test = alg_test_null,
4ea1277d
JG
1858 }, {
1859 .alg = "__driver-cbc-cast6-avx",
1860 .test = alg_test_null,
7efe4076
JG
1861 }, {
1862 .alg = "__driver-cbc-serpent-avx",
1863 .test = alg_test_null,
56d76c96
JK
1864 }, {
1865 .alg = "__driver-cbc-serpent-avx2",
1866 .test = alg_test_null,
937c30d7
JK
1867 }, {
1868 .alg = "__driver-cbc-serpent-sse2",
1869 .test = alg_test_null,
107778b5
JG
1870 }, {
1871 .alg = "__driver-cbc-twofish-avx",
1872 .test = alg_test_null,
863b557a
YS
1873 }, {
1874 .alg = "__driver-ecb-aes-aesni",
1875 .test = alg_test_null,
6c79294f 1876 .fips_allowed = 1,
d9b1d2e7
JK
1877 }, {
1878 .alg = "__driver-ecb-camellia-aesni",
1879 .test = alg_test_null,
f3f935a7
JK
1880 }, {
1881 .alg = "__driver-ecb-camellia-aesni-avx2",
1882 .test = alg_test_null,
4d6d6a2c
JG
1883 }, {
1884 .alg = "__driver-ecb-cast5-avx",
1885 .test = alg_test_null,
4ea1277d
JG
1886 }, {
1887 .alg = "__driver-ecb-cast6-avx",
1888 .test = alg_test_null,
7efe4076
JG
1889 }, {
1890 .alg = "__driver-ecb-serpent-avx",
1891 .test = alg_test_null,
56d76c96
JK
1892 }, {
1893 .alg = "__driver-ecb-serpent-avx2",
1894 .test = alg_test_null,
937c30d7
JK
1895 }, {
1896 .alg = "__driver-ecb-serpent-sse2",
1897 .test = alg_test_null,
107778b5
JG
1898 }, {
1899 .alg = "__driver-ecb-twofish-avx",
1900 .test = alg_test_null,
863b557a
YS
1901 }, {
1902 .alg = "__ghash-pclmulqdqni",
1903 .test = alg_test_null,
6c79294f 1904 .fips_allowed = 1,
863b557a 1905 }, {
e08ca2da
JW
1906 .alg = "ansi_cprng",
1907 .test = alg_test_cprng,
a1915d51 1908 .fips_allowed = 1,
e08ca2da
JW
1909 .suite = {
1910 .cprng = {
1911 .vecs = ansi_cprng_aes_tv_template,
1912 .count = ANSI_CPRNG_AES_TEST_VECTORS
1913 }
1914 }
bca4feb0
HG
1915 }, {
1916 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1917 .test = alg_test_aead,
1918 .fips_allowed = 1,
1919 .suite = {
1920 .aead = {
1921 .enc = {
1922 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1923 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1924 },
1925 .dec = {
1926 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1927 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1928 }
1929 }
1930 }
e46e9a46
HG
1931 }, {
1932 .alg = "authenc(hmac(sha1),cbc(aes))",
1933 .test = alg_test_aead,
1934 .fips_allowed = 1,
1935 .suite = {
1936 .aead = {
1937 .enc = {
5208ed2c
NL
1938 .vecs =
1939 hmac_sha1_aes_cbc_enc_tv_temp,
1940 .count =
1941 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1942 }
1943 }
1944 }
1945 }, {
1946 .alg = "authenc(hmac(sha1),cbc(des))",
1947 .test = alg_test_aead,
1948 .fips_allowed = 1,
1949 .suite = {
1950 .aead = {
1951 .enc = {
1952 .vecs =
1953 hmac_sha1_des_cbc_enc_tv_temp,
1954 .count =
1955 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1956 }
1957 }
1958 }
1959 }, {
1960 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1961 .test = alg_test_aead,
1962 .fips_allowed = 1,
1963 .suite = {
1964 .aead = {
1965 .enc = {
1966 .vecs =
1967 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1968 .count =
1969 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
e46e9a46
HG
1970 }
1971 }
1972 }
bca4feb0
HG
1973 }, {
1974 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1975 .test = alg_test_aead,
1976 .fips_allowed = 1,
1977 .suite = {
1978 .aead = {
1979 .enc = {
5208ed2c
NL
1980 .vecs =
1981 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1982 .count =
1983 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
bca4feb0
HG
1984 },
1985 .dec = {
5208ed2c
NL
1986 .vecs =
1987 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1988 .count =
1989 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1990 }
1991 }
1992 }
1993 }, {
1994 .alg = "authenc(hmac(sha224),cbc(des))",
1995 .test = alg_test_aead,
1996 .fips_allowed = 1,
1997 .suite = {
1998 .aead = {
1999 .enc = {
2000 .vecs =
2001 hmac_sha224_des_cbc_enc_tv_temp,
2002 .count =
2003 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2004 }
2005 }
2006 }
2007 }, {
2008 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2009 .test = alg_test_aead,
2010 .fips_allowed = 1,
2011 .suite = {
2012 .aead = {
2013 .enc = {
2014 .vecs =
2015 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2016 .count =
2017 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
bca4feb0
HG
2018 }
2019 }
2020 }
e46e9a46
HG
2021 }, {
2022 .alg = "authenc(hmac(sha256),cbc(aes))",
2023 .test = alg_test_aead,
2024 .fips_allowed = 1,
2025 .suite = {
2026 .aead = {
2027 .enc = {
5208ed2c
NL
2028 .vecs =
2029 hmac_sha256_aes_cbc_enc_tv_temp,
2030 .count =
2031 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2032 }
2033 }
2034 }
2035 }, {
2036 .alg = "authenc(hmac(sha256),cbc(des))",
2037 .test = alg_test_aead,
2038 .fips_allowed = 1,
2039 .suite = {
2040 .aead = {
2041 .enc = {
2042 .vecs =
2043 hmac_sha256_des_cbc_enc_tv_temp,
2044 .count =
2045 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2046 }
2047 }
2048 }
2049 }, {
2050 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2051 .test = alg_test_aead,
2052 .fips_allowed = 1,
2053 .suite = {
2054 .aead = {
2055 .enc = {
2056 .vecs =
2057 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2058 .count =
2059 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2060 }
2061 }
2062 }
2063 }, {
2064 .alg = "authenc(hmac(sha384),cbc(des))",
2065 .test = alg_test_aead,
2066 .fips_allowed = 1,
2067 .suite = {
2068 .aead = {
2069 .enc = {
2070 .vecs =
2071 hmac_sha384_des_cbc_enc_tv_temp,
2072 .count =
2073 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2074 }
2075 }
2076 }
2077 }, {
2078 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2079 .test = alg_test_aead,
2080 .fips_allowed = 1,
2081 .suite = {
2082 .aead = {
2083 .enc = {
2084 .vecs =
2085 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2086 .count =
2087 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
e46e9a46
HG
2088 }
2089 }
2090 }
2091 }, {
2092 .alg = "authenc(hmac(sha512),cbc(aes))",
2093 .test = alg_test_aead,
2094 .fips_allowed = 1,
2095 .suite = {
2096 .aead = {
2097 .enc = {
5208ed2c
NL
2098 .vecs =
2099 hmac_sha512_aes_cbc_enc_tv_temp,
2100 .count =
2101 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2102 }
2103 }
2104 }
2105 }, {
2106 .alg = "authenc(hmac(sha512),cbc(des))",
2107 .test = alg_test_aead,
2108 .fips_allowed = 1,
2109 .suite = {
2110 .aead = {
2111 .enc = {
2112 .vecs =
2113 hmac_sha512_des_cbc_enc_tv_temp,
2114 .count =
2115 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2116 }
2117 }
2118 }
2119 }, {
2120 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2121 .test = alg_test_aead,
2122 .fips_allowed = 1,
2123 .suite = {
2124 .aead = {
2125 .enc = {
2126 .vecs =
2127 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2128 .count =
2129 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
e46e9a46
HG
2130 }
2131 }
2132 }
e08ca2da 2133 }, {
da7f033d 2134 .alg = "cbc(aes)",
1aa4ecd9 2135 .test = alg_test_skcipher,
a1915d51 2136 .fips_allowed = 1,
da7f033d
HX
2137 .suite = {
2138 .cipher = {
2139 .enc = {
2140 .vecs = aes_cbc_enc_tv_template,
2141 .count = AES_CBC_ENC_TEST_VECTORS
2142 },
2143 .dec = {
2144 .vecs = aes_cbc_dec_tv_template,
2145 .count = AES_CBC_DEC_TEST_VECTORS
2146 }
2147 }
2148 }
2149 }, {
2150 .alg = "cbc(anubis)",
1aa4ecd9 2151 .test = alg_test_skcipher,
da7f033d
HX
2152 .suite = {
2153 .cipher = {
2154 .enc = {
2155 .vecs = anubis_cbc_enc_tv_template,
2156 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2157 },
2158 .dec = {
2159 .vecs = anubis_cbc_dec_tv_template,
2160 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2161 }
2162 }
2163 }
2164 }, {
2165 .alg = "cbc(blowfish)",
1aa4ecd9 2166 .test = alg_test_skcipher,
da7f033d
HX
2167 .suite = {
2168 .cipher = {
2169 .enc = {
2170 .vecs = bf_cbc_enc_tv_template,
2171 .count = BF_CBC_ENC_TEST_VECTORS
2172 },
2173 .dec = {
2174 .vecs = bf_cbc_dec_tv_template,
2175 .count = BF_CBC_DEC_TEST_VECTORS
2176 }
2177 }
2178 }
2179 }, {
2180 .alg = "cbc(camellia)",
1aa4ecd9 2181 .test = alg_test_skcipher,
da7f033d
HX
2182 .suite = {
2183 .cipher = {
2184 .enc = {
2185 .vecs = camellia_cbc_enc_tv_template,
2186 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2187 },
2188 .dec = {
2189 .vecs = camellia_cbc_dec_tv_template,
2190 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2191 }
2192 }
2193 }
a2c58260
JG
2194 }, {
2195 .alg = "cbc(cast5)",
2196 .test = alg_test_skcipher,
2197 .suite = {
2198 .cipher = {
2199 .enc = {
2200 .vecs = cast5_cbc_enc_tv_template,
2201 .count = CAST5_CBC_ENC_TEST_VECTORS
2202 },
2203 .dec = {
2204 .vecs = cast5_cbc_dec_tv_template,
2205 .count = CAST5_CBC_DEC_TEST_VECTORS
2206 }
2207 }
2208 }
9b8b0405
JG
2209 }, {
2210 .alg = "cbc(cast6)",
2211 .test = alg_test_skcipher,
2212 .suite = {
2213 .cipher = {
2214 .enc = {
2215 .vecs = cast6_cbc_enc_tv_template,
2216 .count = CAST6_CBC_ENC_TEST_VECTORS
2217 },
2218 .dec = {
2219 .vecs = cast6_cbc_dec_tv_template,
2220 .count = CAST6_CBC_DEC_TEST_VECTORS
2221 }
2222 }
2223 }
da7f033d
HX
2224 }, {
2225 .alg = "cbc(des)",
1aa4ecd9 2226 .test = alg_test_skcipher,
da7f033d
HX
2227 .suite = {
2228 .cipher = {
2229 .enc = {
2230 .vecs = des_cbc_enc_tv_template,
2231 .count = DES_CBC_ENC_TEST_VECTORS
2232 },
2233 .dec = {
2234 .vecs = des_cbc_dec_tv_template,
2235 .count = DES_CBC_DEC_TEST_VECTORS
2236 }
2237 }
2238 }
2239 }, {
2240 .alg = "cbc(des3_ede)",
1aa4ecd9 2241 .test = alg_test_skcipher,
a1915d51 2242 .fips_allowed = 1,
da7f033d
HX
2243 .suite = {
2244 .cipher = {
2245 .enc = {
2246 .vecs = des3_ede_cbc_enc_tv_template,
2247 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2248 },
2249 .dec = {
2250 .vecs = des3_ede_cbc_dec_tv_template,
2251 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2252 }
2253 }
2254 }
9d25917d
JK
2255 }, {
2256 .alg = "cbc(serpent)",
2257 .test = alg_test_skcipher,
2258 .suite = {
2259 .cipher = {
2260 .enc = {
2261 .vecs = serpent_cbc_enc_tv_template,
2262 .count = SERPENT_CBC_ENC_TEST_VECTORS
2263 },
2264 .dec = {
2265 .vecs = serpent_cbc_dec_tv_template,
2266 .count = SERPENT_CBC_DEC_TEST_VECTORS
2267 }
2268 }
2269 }
da7f033d
HX
2270 }, {
2271 .alg = "cbc(twofish)",
1aa4ecd9 2272 .test = alg_test_skcipher,
da7f033d
HX
2273 .suite = {
2274 .cipher = {
2275 .enc = {
2276 .vecs = tf_cbc_enc_tv_template,
2277 .count = TF_CBC_ENC_TEST_VECTORS
2278 },
2279 .dec = {
2280 .vecs = tf_cbc_dec_tv_template,
2281 .count = TF_CBC_DEC_TEST_VECTORS
2282 }
2283 }
2284 }
2285 }, {
2286 .alg = "ccm(aes)",
2287 .test = alg_test_aead,
a1915d51 2288 .fips_allowed = 1,
da7f033d
HX
2289 .suite = {
2290 .aead = {
2291 .enc = {
2292 .vecs = aes_ccm_enc_tv_template,
2293 .count = AES_CCM_ENC_TEST_VECTORS
2294 },
2295 .dec = {
2296 .vecs = aes_ccm_dec_tv_template,
2297 .count = AES_CCM_DEC_TEST_VECTORS
2298 }
2299 }
2300 }
93b5e86a
JK
2301 }, {
2302 .alg = "cmac(aes)",
2303 .test = alg_test_hash,
2304 .suite = {
2305 .hash = {
2306 .vecs = aes_cmac128_tv_template,
2307 .count = CMAC_AES_TEST_VECTORS
2308 }
2309 }
2310 }, {
2311 .alg = "cmac(des3_ede)",
2312 .test = alg_test_hash,
2313 .suite = {
2314 .hash = {
2315 .vecs = des3_ede_cmac64_tv_template,
2316 .count = CMAC_DES3_EDE_TEST_VECTORS
2317 }
2318 }
e448370d
JK
2319 }, {
2320 .alg = "compress_null",
2321 .test = alg_test_null,
da7f033d
HX
2322 }, {
2323 .alg = "crc32c",
8e3ee85e 2324 .test = alg_test_crc32c,
a1915d51 2325 .fips_allowed = 1,
da7f033d
HX
2326 .suite = {
2327 .hash = {
2328 .vecs = crc32c_tv_template,
2329 .count = CRC32C_TEST_VECTORS
2330 }
2331 }
68411521
HX
2332 }, {
2333 .alg = "crct10dif",
2334 .test = alg_test_hash,
2335 .fips_allowed = 1,
2336 .suite = {
2337 .hash = {
2338 .vecs = crct10dif_tv_template,
2339 .count = CRCT10DIF_TEST_VECTORS
2340 }
2341 }
6c79294f
MB
2342 }, {
2343 .alg = "cryptd(__driver-cbc-aes-aesni)",
2344 .test = alg_test_null,
2345 .fips_allowed = 1,
d9b1d2e7
JK
2346 }, {
2347 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2348 .test = alg_test_null,
f3f935a7
JK
2349 }, {
2350 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2351 .test = alg_test_null,
56d76c96
JK
2352 }, {
2353 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2354 .test = alg_test_null,
863b557a
YS
2355 }, {
2356 .alg = "cryptd(__driver-ecb-aes-aesni)",
2357 .test = alg_test_null,
6c79294f 2358 .fips_allowed = 1,
d9b1d2e7
JK
2359 }, {
2360 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2361 .test = alg_test_null,
f3f935a7
JK
2362 }, {
2363 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2364 .test = alg_test_null,
4d6d6a2c
JG
2365 }, {
2366 .alg = "cryptd(__driver-ecb-cast5-avx)",
2367 .test = alg_test_null,
4ea1277d
JG
2368 }, {
2369 .alg = "cryptd(__driver-ecb-cast6-avx)",
2370 .test = alg_test_null,
7efe4076
JG
2371 }, {
2372 .alg = "cryptd(__driver-ecb-serpent-avx)",
2373 .test = alg_test_null,
56d76c96
JK
2374 }, {
2375 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2376 .test = alg_test_null,
937c30d7
JK
2377 }, {
2378 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2379 .test = alg_test_null,
107778b5
JG
2380 }, {
2381 .alg = "cryptd(__driver-ecb-twofish-avx)",
2382 .test = alg_test_null,
6c79294f
MB
2383 }, {
2384 .alg = "cryptd(__driver-gcm-aes-aesni)",
2385 .test = alg_test_null,
2386 .fips_allowed = 1,
863b557a
YS
2387 }, {
2388 .alg = "cryptd(__ghash-pclmulqdqni)",
2389 .test = alg_test_null,
6c79294f 2390 .fips_allowed = 1,
f7cb80f2
JW
2391 }, {
2392 .alg = "ctr(aes)",
2393 .test = alg_test_skcipher,
a1915d51 2394 .fips_allowed = 1,
f7cb80f2
JW
2395 .suite = {
2396 .cipher = {
2397 .enc = {
2398 .vecs = aes_ctr_enc_tv_template,
2399 .count = AES_CTR_ENC_TEST_VECTORS
2400 },
2401 .dec = {
2402 .vecs = aes_ctr_dec_tv_template,
2403 .count = AES_CTR_DEC_TEST_VECTORS
2404 }
2405 }
2406 }
85b63e34
JK
2407 }, {
2408 .alg = "ctr(blowfish)",
2409 .test = alg_test_skcipher,
2410 .suite = {
2411 .cipher = {
2412 .enc = {
2413 .vecs = bf_ctr_enc_tv_template,
2414 .count = BF_CTR_ENC_TEST_VECTORS
2415 },
2416 .dec = {
2417 .vecs = bf_ctr_dec_tv_template,
2418 .count = BF_CTR_DEC_TEST_VECTORS
2419 }
2420 }
2421 }
0840605e
JK
2422 }, {
2423 .alg = "ctr(camellia)",
2424 .test = alg_test_skcipher,
2425 .suite = {
2426 .cipher = {
2427 .enc = {
2428 .vecs = camellia_ctr_enc_tv_template,
2429 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2430 },
2431 .dec = {
2432 .vecs = camellia_ctr_dec_tv_template,
2433 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2434 }
2435 }
2436 }
a2c58260
JG
2437 }, {
2438 .alg = "ctr(cast5)",
2439 .test = alg_test_skcipher,
2440 .suite = {
2441 .cipher = {
2442 .enc = {
2443 .vecs = cast5_ctr_enc_tv_template,
2444 .count = CAST5_CTR_ENC_TEST_VECTORS
2445 },
2446 .dec = {
2447 .vecs = cast5_ctr_dec_tv_template,
2448 .count = CAST5_CTR_DEC_TEST_VECTORS
2449 }
2450 }
2451 }
9b8b0405
JG
2452 }, {
2453 .alg = "ctr(cast6)",
2454 .test = alg_test_skcipher,
2455 .suite = {
2456 .cipher = {
2457 .enc = {
2458 .vecs = cast6_ctr_enc_tv_template,
2459 .count = CAST6_CTR_ENC_TEST_VECTORS
2460 },
2461 .dec = {
2462 .vecs = cast6_ctr_dec_tv_template,
2463 .count = CAST6_CTR_DEC_TEST_VECTORS
2464 }
2465 }
2466 }
8163fc30
JK
2467 }, {
2468 .alg = "ctr(des)",
2469 .test = alg_test_skcipher,
2470 .suite = {
2471 .cipher = {
2472 .enc = {
2473 .vecs = des_ctr_enc_tv_template,
2474 .count = DES_CTR_ENC_TEST_VECTORS
2475 },
2476 .dec = {
2477 .vecs = des_ctr_dec_tv_template,
2478 .count = DES_CTR_DEC_TEST_VECTORS
2479 }
2480 }
2481 }
e080b17a
JK
2482 }, {
2483 .alg = "ctr(des3_ede)",
2484 .test = alg_test_skcipher,
2485 .suite = {
2486 .cipher = {
2487 .enc = {
2488 .vecs = des3_ede_ctr_enc_tv_template,
2489 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2490 },
2491 .dec = {
2492 .vecs = des3_ede_ctr_dec_tv_template,
2493 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2494 }
2495 }
2496 }
9d25917d
JK
2497 }, {
2498 .alg = "ctr(serpent)",
2499 .test = alg_test_skcipher,
2500 .suite = {
2501 .cipher = {
2502 .enc = {
2503 .vecs = serpent_ctr_enc_tv_template,
2504 .count = SERPENT_CTR_ENC_TEST_VECTORS
2505 },
2506 .dec = {
2507 .vecs = serpent_ctr_dec_tv_template,
2508 .count = SERPENT_CTR_DEC_TEST_VECTORS
2509 }
2510 }
2511 }
573da620
JK
2512 }, {
2513 .alg = "ctr(twofish)",
2514 .test = alg_test_skcipher,
2515 .suite = {
2516 .cipher = {
2517 .enc = {
2518 .vecs = tf_ctr_enc_tv_template,
2519 .count = TF_CTR_ENC_TEST_VECTORS
2520 },
2521 .dec = {
2522 .vecs = tf_ctr_dec_tv_template,
2523 .count = TF_CTR_DEC_TEST_VECTORS
2524 }
2525 }
2526 }
da7f033d
HX
2527 }, {
2528 .alg = "cts(cbc(aes))",
1aa4ecd9 2529 .test = alg_test_skcipher,
da7f033d
HX
2530 .suite = {
2531 .cipher = {
2532 .enc = {
2533 .vecs = cts_mode_enc_tv_template,
2534 .count = CTS_MODE_ENC_TEST_VECTORS
2535 },
2536 .dec = {
2537 .vecs = cts_mode_dec_tv_template,
2538 .count = CTS_MODE_DEC_TEST_VECTORS
2539 }
2540 }
2541 }
2542 }, {
2543 .alg = "deflate",
2544 .test = alg_test_comp,
0818904d 2545 .fips_allowed = 1,
da7f033d
HX
2546 .suite = {
2547 .comp = {
2548 .comp = {
2549 .vecs = deflate_comp_tv_template,
2550 .count = DEFLATE_COMP_TEST_VECTORS
2551 },
2552 .decomp = {
2553 .vecs = deflate_decomp_tv_template,
2554 .count = DEFLATE_DECOMP_TEST_VECTORS
2555 }
2556 }
2557 }
e448370d
JK
2558 }, {
2559 .alg = "digest_null",
2560 .test = alg_test_null,
64d1cdfb
SM
2561 }, {
2562 .alg = "drbg_nopr_ctr_aes128",
2563 .test = alg_test_drbg,
2564 .fips_allowed = 1,
2565 .suite = {
2566 .drbg = {
2567 .vecs = drbg_nopr_ctr_aes128_tv_template,
2568 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2569 }
2570 }
2571 }, {
2572 .alg = "drbg_nopr_ctr_aes192",
2573 .test = alg_test_drbg,
2574 .fips_allowed = 1,
2575 .suite = {
2576 .drbg = {
2577 .vecs = drbg_nopr_ctr_aes192_tv_template,
2578 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2579 }
2580 }
2581 }, {
2582 .alg = "drbg_nopr_ctr_aes256",
2583 .test = alg_test_drbg,
2584 .fips_allowed = 1,
2585 .suite = {
2586 .drbg = {
2587 .vecs = drbg_nopr_ctr_aes256_tv_template,
2588 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2589 }
2590 }
2591 }, {
2592 /*
2593 * There is no need to specifically test the DRBG with every
2594 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2595 */
2596 .alg = "drbg_nopr_hmac_sha1",
2597 .fips_allowed = 1,
2598 .test = alg_test_null,
2599 }, {
2600 .alg = "drbg_nopr_hmac_sha256",
2601 .test = alg_test_drbg,
2602 .fips_allowed = 1,
2603 .suite = {
2604 .drbg = {
2605 .vecs = drbg_nopr_hmac_sha256_tv_template,
2606 .count =
2607 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2608 }
2609 }
2610 }, {
2611 /* covered by drbg_nopr_hmac_sha256 test */
2612 .alg = "drbg_nopr_hmac_sha384",
2613 .fips_allowed = 1,
2614 .test = alg_test_null,
2615 }, {
2616 .alg = "drbg_nopr_hmac_sha512",
2617 .test = alg_test_null,
2618 .fips_allowed = 1,
2619 }, {
2620 .alg = "drbg_nopr_sha1",
2621 .fips_allowed = 1,
2622 .test = alg_test_null,
2623 }, {
2624 .alg = "drbg_nopr_sha256",
2625 .test = alg_test_drbg,
2626 .fips_allowed = 1,
2627 .suite = {
2628 .drbg = {
2629 .vecs = drbg_nopr_sha256_tv_template,
2630 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2631 }
2632 }
2633 }, {
2634 /* covered by drbg_nopr_sha256 test */
2635 .alg = "drbg_nopr_sha384",
2636 .fips_allowed = 1,
2637 .test = alg_test_null,
2638 }, {
2639 .alg = "drbg_nopr_sha512",
2640 .fips_allowed = 1,
2641 .test = alg_test_null,
2642 }, {
2643 .alg = "drbg_pr_ctr_aes128",
2644 .test = alg_test_drbg,
2645 .fips_allowed = 1,
2646 .suite = {
2647 .drbg = {
2648 .vecs = drbg_pr_ctr_aes128_tv_template,
2649 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2650 }
2651 }
2652 }, {
2653 /* covered by drbg_pr_ctr_aes128 test */
2654 .alg = "drbg_pr_ctr_aes192",
2655 .fips_allowed = 1,
2656 .test = alg_test_null,
2657 }, {
2658 .alg = "drbg_pr_ctr_aes256",
2659 .fips_allowed = 1,
2660 .test = alg_test_null,
2661 }, {
2662 .alg = "drbg_pr_hmac_sha1",
2663 .fips_allowed = 1,
2664 .test = alg_test_null,
2665 }, {
2666 .alg = "drbg_pr_hmac_sha256",
2667 .test = alg_test_drbg,
2668 .fips_allowed = 1,
2669 .suite = {
2670 .drbg = {
2671 .vecs = drbg_pr_hmac_sha256_tv_template,
2672 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2673 }
2674 }
2675 }, {
2676 /* covered by drbg_pr_hmac_sha256 test */
2677 .alg = "drbg_pr_hmac_sha384",
2678 .fips_allowed = 1,
2679 .test = alg_test_null,
2680 }, {
2681 .alg = "drbg_pr_hmac_sha512",
2682 .test = alg_test_null,
2683 .fips_allowed = 1,
2684 }, {
2685 .alg = "drbg_pr_sha1",
2686 .fips_allowed = 1,
2687 .test = alg_test_null,
2688 }, {
2689 .alg = "drbg_pr_sha256",
2690 .test = alg_test_drbg,
2691 .fips_allowed = 1,
2692 .suite = {
2693 .drbg = {
2694 .vecs = drbg_pr_sha256_tv_template,
2695 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2696 }
2697 }
2698 }, {
2699 /* covered by drbg_pr_sha256 test */
2700 .alg = "drbg_pr_sha384",
2701 .fips_allowed = 1,
2702 .test = alg_test_null,
2703 }, {
2704 .alg = "drbg_pr_sha512",
2705 .fips_allowed = 1,
2706 .test = alg_test_null,
863b557a
YS
2707 }, {
2708 .alg = "ecb(__aes-aesni)",
2709 .test = alg_test_null,
6c79294f 2710 .fips_allowed = 1,
da7f033d
HX
2711 }, {
2712 .alg = "ecb(aes)",
1aa4ecd9 2713 .test = alg_test_skcipher,
a1915d51 2714 .fips_allowed = 1,
da7f033d
HX
2715 .suite = {
2716 .cipher = {
2717 .enc = {
2718 .vecs = aes_enc_tv_template,
2719 .count = AES_ENC_TEST_VECTORS
2720 },
2721 .dec = {
2722 .vecs = aes_dec_tv_template,
2723 .count = AES_DEC_TEST_VECTORS
2724 }
2725 }
2726 }
2727 }, {
2728 .alg = "ecb(anubis)",
1aa4ecd9 2729 .test = alg_test_skcipher,
da7f033d
HX
2730 .suite = {
2731 .cipher = {
2732 .enc = {
2733 .vecs = anubis_enc_tv_template,
2734 .count = ANUBIS_ENC_TEST_VECTORS
2735 },
2736 .dec = {
2737 .vecs = anubis_dec_tv_template,
2738 .count = ANUBIS_DEC_TEST_VECTORS
2739 }
2740 }
2741 }
2742 }, {
2743 .alg = "ecb(arc4)",
1aa4ecd9 2744 .test = alg_test_skcipher,
da7f033d
HX
2745 .suite = {
2746 .cipher = {
2747 .enc = {
2748 .vecs = arc4_enc_tv_template,
2749 .count = ARC4_ENC_TEST_VECTORS
2750 },
2751 .dec = {
2752 .vecs = arc4_dec_tv_template,
2753 .count = ARC4_DEC_TEST_VECTORS
2754 }
2755 }
2756 }
2757 }, {
2758 .alg = "ecb(blowfish)",
1aa4ecd9 2759 .test = alg_test_skcipher,
da7f033d
HX
2760 .suite = {
2761 .cipher = {
2762 .enc = {
2763 .vecs = bf_enc_tv_template,
2764 .count = BF_ENC_TEST_VECTORS
2765 },
2766 .dec = {
2767 .vecs = bf_dec_tv_template,
2768 .count = BF_DEC_TEST_VECTORS
2769 }
2770 }
2771 }
2772 }, {
2773 .alg = "ecb(camellia)",
1aa4ecd9 2774 .test = alg_test_skcipher,
da7f033d
HX
2775 .suite = {
2776 .cipher = {
2777 .enc = {
2778 .vecs = camellia_enc_tv_template,
2779 .count = CAMELLIA_ENC_TEST_VECTORS
2780 },
2781 .dec = {
2782 .vecs = camellia_dec_tv_template,
2783 .count = CAMELLIA_DEC_TEST_VECTORS
2784 }
2785 }
2786 }
2787 }, {
2788 .alg = "ecb(cast5)",
1aa4ecd9 2789 .test = alg_test_skcipher,
da7f033d
HX
2790 .suite = {
2791 .cipher = {
2792 .enc = {
2793 .vecs = cast5_enc_tv_template,
2794 .count = CAST5_ENC_TEST_VECTORS
2795 },
2796 .dec = {
2797 .vecs = cast5_dec_tv_template,
2798 .count = CAST5_DEC_TEST_VECTORS
2799 }
2800 }
2801 }
2802 }, {
2803 .alg = "ecb(cast6)",
1aa4ecd9 2804 .test = alg_test_skcipher,
da7f033d
HX
2805 .suite = {
2806 .cipher = {
2807 .enc = {
2808 .vecs = cast6_enc_tv_template,
2809 .count = CAST6_ENC_TEST_VECTORS
2810 },
2811 .dec = {
2812 .vecs = cast6_dec_tv_template,
2813 .count = CAST6_DEC_TEST_VECTORS
2814 }
2815 }
2816 }
e448370d
JK
2817 }, {
2818 .alg = "ecb(cipher_null)",
2819 .test = alg_test_null,
da7f033d
HX
2820 }, {
2821 .alg = "ecb(des)",
1aa4ecd9 2822 .test = alg_test_skcipher,
a1915d51 2823 .fips_allowed = 1,
da7f033d
HX
2824 .suite = {
2825 .cipher = {
2826 .enc = {
2827 .vecs = des_enc_tv_template,
2828 .count = DES_ENC_TEST_VECTORS
2829 },
2830 .dec = {
2831 .vecs = des_dec_tv_template,
2832 .count = DES_DEC_TEST_VECTORS
2833 }
2834 }
2835 }
2836 }, {
2837 .alg = "ecb(des3_ede)",
1aa4ecd9 2838 .test = alg_test_skcipher,
a1915d51 2839 .fips_allowed = 1,
da7f033d
HX
2840 .suite = {
2841 .cipher = {
2842 .enc = {
2843 .vecs = des3_ede_enc_tv_template,
2844 .count = DES3_EDE_ENC_TEST_VECTORS
2845 },
2846 .dec = {
2847 .vecs = des3_ede_dec_tv_template,
2848 .count = DES3_EDE_DEC_TEST_VECTORS
2849 }
2850 }
2851 }
66e5bd00
JK
2852 }, {
2853 .alg = "ecb(fcrypt)",
2854 .test = alg_test_skcipher,
2855 .suite = {
2856 .cipher = {
2857 .enc = {
2858 .vecs = fcrypt_pcbc_enc_tv_template,
2859 .count = 1
2860 },
2861 .dec = {
2862 .vecs = fcrypt_pcbc_dec_tv_template,
2863 .count = 1
2864 }
2865 }
2866 }
da7f033d
HX
2867 }, {
2868 .alg = "ecb(khazad)",
1aa4ecd9 2869 .test = alg_test_skcipher,
da7f033d
HX
2870 .suite = {
2871 .cipher = {
2872 .enc = {
2873 .vecs = khazad_enc_tv_template,
2874 .count = KHAZAD_ENC_TEST_VECTORS
2875 },
2876 .dec = {
2877 .vecs = khazad_dec_tv_template,
2878 .count = KHAZAD_DEC_TEST_VECTORS
2879 }
2880 }
2881 }
2882 }, {
2883 .alg = "ecb(seed)",
1aa4ecd9 2884 .test = alg_test_skcipher,
da7f033d
HX
2885 .suite = {
2886 .cipher = {
2887 .enc = {
2888 .vecs = seed_enc_tv_template,
2889 .count = SEED_ENC_TEST_VECTORS
2890 },
2891 .dec = {
2892 .vecs = seed_dec_tv_template,
2893 .count = SEED_DEC_TEST_VECTORS
2894 }
2895 }
2896 }
2897 }, {
2898 .alg = "ecb(serpent)",
1aa4ecd9 2899 .test = alg_test_skcipher,
da7f033d
HX
2900 .suite = {
2901 .cipher = {
2902 .enc = {
2903 .vecs = serpent_enc_tv_template,
2904 .count = SERPENT_ENC_TEST_VECTORS
2905 },
2906 .dec = {
2907 .vecs = serpent_dec_tv_template,
2908 .count = SERPENT_DEC_TEST_VECTORS
2909 }
2910 }
2911 }
2912 }, {
2913 .alg = "ecb(tea)",
1aa4ecd9 2914 .test = alg_test_skcipher,
da7f033d
HX
2915 .suite = {
2916 .cipher = {
2917 .enc = {
2918 .vecs = tea_enc_tv_template,
2919 .count = TEA_ENC_TEST_VECTORS
2920 },
2921 .dec = {
2922 .vecs = tea_dec_tv_template,
2923 .count = TEA_DEC_TEST_VECTORS
2924 }
2925 }
2926 }
2927 }, {
2928 .alg = "ecb(tnepres)",
1aa4ecd9 2929 .test = alg_test_skcipher,
da7f033d
HX
2930 .suite = {
2931 .cipher = {
2932 .enc = {
2933 .vecs = tnepres_enc_tv_template,
2934 .count = TNEPRES_ENC_TEST_VECTORS
2935 },
2936 .dec = {
2937 .vecs = tnepres_dec_tv_template,
2938 .count = TNEPRES_DEC_TEST_VECTORS
2939 }
2940 }
2941 }
2942 }, {
2943 .alg = "ecb(twofish)",
1aa4ecd9 2944 .test = alg_test_skcipher,
da7f033d
HX
2945 .suite = {
2946 .cipher = {
2947 .enc = {
2948 .vecs = tf_enc_tv_template,
2949 .count = TF_ENC_TEST_VECTORS
2950 },
2951 .dec = {
2952 .vecs = tf_dec_tv_template,
2953 .count = TF_DEC_TEST_VECTORS
2954 }
2955 }
2956 }
2957 }, {
2958 .alg = "ecb(xeta)",
1aa4ecd9 2959 .test = alg_test_skcipher,
da7f033d
HX
2960 .suite = {
2961 .cipher = {
2962 .enc = {
2963 .vecs = xeta_enc_tv_template,
2964 .count = XETA_ENC_TEST_VECTORS
2965 },
2966 .dec = {
2967 .vecs = xeta_dec_tv_template,
2968 .count = XETA_DEC_TEST_VECTORS
2969 }
2970 }
2971 }
2972 }, {
2973 .alg = "ecb(xtea)",
1aa4ecd9 2974 .test = alg_test_skcipher,
da7f033d
HX
2975 .suite = {
2976 .cipher = {
2977 .enc = {
2978 .vecs = xtea_enc_tv_template,
2979 .count = XTEA_ENC_TEST_VECTORS
2980 },
2981 .dec = {
2982 .vecs = xtea_dec_tv_template,
2983 .count = XTEA_DEC_TEST_VECTORS
2984 }
2985 }
2986 }
2987 }, {
2988 .alg = "gcm(aes)",
2989 .test = alg_test_aead,
a1915d51 2990 .fips_allowed = 1,
da7f033d
HX
2991 .suite = {
2992 .aead = {
2993 .enc = {
2994 .vecs = aes_gcm_enc_tv_template,
2995 .count = AES_GCM_ENC_TEST_VECTORS
2996 },
2997 .dec = {
2998 .vecs = aes_gcm_dec_tv_template,
2999 .count = AES_GCM_DEC_TEST_VECTORS
3000 }
3001 }
3002 }
507069c9
YS
3003 }, {
3004 .alg = "ghash",
3005 .test = alg_test_hash,
18c0ebd2 3006 .fips_allowed = 1,
507069c9
YS
3007 .suite = {
3008 .hash = {
3009 .vecs = ghash_tv_template,
3010 .count = GHASH_TEST_VECTORS
3011 }
3012 }
a482b081
SZ
3013 }, {
3014 .alg = "hmac(crc32)",
3015 .test = alg_test_hash,
3016 .suite = {
3017 .hash = {
3018 .vecs = bfin_crc_tv_template,
3019 .count = BFIN_CRC_TEST_VECTORS
3020 }
3021 }
da7f033d
HX
3022 }, {
3023 .alg = "hmac(md5)",
3024 .test = alg_test_hash,
3025 .suite = {
3026 .hash = {
3027 .vecs = hmac_md5_tv_template,
3028 .count = HMAC_MD5_TEST_VECTORS
3029 }
3030 }
3031 }, {
3032 .alg = "hmac(rmd128)",
3033 .test = alg_test_hash,
3034 .suite = {
3035 .hash = {
3036 .vecs = hmac_rmd128_tv_template,
3037 .count = HMAC_RMD128_TEST_VECTORS
3038 }
3039 }
3040 }, {
3041 .alg = "hmac(rmd160)",
3042 .test = alg_test_hash,
3043 .suite = {
3044 .hash = {
3045 .vecs = hmac_rmd160_tv_template,
3046 .count = HMAC_RMD160_TEST_VECTORS
3047 }
3048 }
3049 }, {
3050 .alg = "hmac(sha1)",
3051 .test = alg_test_hash,
a1915d51 3052 .fips_allowed = 1,
da7f033d
HX
3053 .suite = {
3054 .hash = {
3055 .vecs = hmac_sha1_tv_template,
3056 .count = HMAC_SHA1_TEST_VECTORS
3057 }
3058 }
3059 }, {
3060 .alg = "hmac(sha224)",
3061 .test = alg_test_hash,
a1915d51 3062 .fips_allowed = 1,
da7f033d
HX
3063 .suite = {
3064 .hash = {
3065 .vecs = hmac_sha224_tv_template,
3066 .count = HMAC_SHA224_TEST_VECTORS
3067 }
3068 }
3069 }, {
3070 .alg = "hmac(sha256)",
3071 .test = alg_test_hash,
a1915d51 3072 .fips_allowed = 1,
da7f033d
HX
3073 .suite = {
3074 .hash = {
3075 .vecs = hmac_sha256_tv_template,
3076 .count = HMAC_SHA256_TEST_VECTORS
3077 }
3078 }
3079 }, {
3080 .alg = "hmac(sha384)",
3081 .test = alg_test_hash,
a1915d51 3082 .fips_allowed = 1,
da7f033d
HX
3083 .suite = {
3084 .hash = {
3085 .vecs = hmac_sha384_tv_template,
3086 .count = HMAC_SHA384_TEST_VECTORS
3087 }
3088 }
3089 }, {
3090 .alg = "hmac(sha512)",
3091 .test = alg_test_hash,
a1915d51 3092 .fips_allowed = 1,
da7f033d
HX
3093 .suite = {
3094 .hash = {
3095 .vecs = hmac_sha512_tv_template,
3096 .count = HMAC_SHA512_TEST_VECTORS
3097 }
3098 }
3099 }, {
3100 .alg = "lrw(aes)",
1aa4ecd9 3101 .test = alg_test_skcipher,
da7f033d
HX
3102 .suite = {
3103 .cipher = {
3104 .enc = {
3105 .vecs = aes_lrw_enc_tv_template,
3106 .count = AES_LRW_ENC_TEST_VECTORS
3107 },
3108 .dec = {
3109 .vecs = aes_lrw_dec_tv_template,
3110 .count = AES_LRW_DEC_TEST_VECTORS
3111 }
3112 }
3113 }
0840605e
JK
3114 }, {
3115 .alg = "lrw(camellia)",
3116 .test = alg_test_skcipher,
3117 .suite = {
3118 .cipher = {
3119 .enc = {
3120 .vecs = camellia_lrw_enc_tv_template,
3121 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3122 },
3123 .dec = {
3124 .vecs = camellia_lrw_dec_tv_template,
3125 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3126 }
3127 }
3128 }
9b8b0405
JG
3129 }, {
3130 .alg = "lrw(cast6)",
3131 .test = alg_test_skcipher,
3132 .suite = {
3133 .cipher = {
3134 .enc = {
3135 .vecs = cast6_lrw_enc_tv_template,
3136 .count = CAST6_LRW_ENC_TEST_VECTORS
3137 },
3138 .dec = {
3139 .vecs = cast6_lrw_dec_tv_template,
3140 .count = CAST6_LRW_DEC_TEST_VECTORS
3141 }
3142 }
3143 }
d7bfc0fa
JK
3144 }, {
3145 .alg = "lrw(serpent)",
3146 .test = alg_test_skcipher,
3147 .suite = {
3148 .cipher = {
3149 .enc = {
3150 .vecs = serpent_lrw_enc_tv_template,
3151 .count = SERPENT_LRW_ENC_TEST_VECTORS
3152 },
3153 .dec = {
3154 .vecs = serpent_lrw_dec_tv_template,
3155 .count = SERPENT_LRW_DEC_TEST_VECTORS
3156 }
3157 }
3158 }
0b2a1551
JK
3159 }, {
3160 .alg = "lrw(twofish)",
3161 .test = alg_test_skcipher,
3162 .suite = {
3163 .cipher = {
3164 .enc = {
3165 .vecs = tf_lrw_enc_tv_template,
3166 .count = TF_LRW_ENC_TEST_VECTORS
3167 },
3168 .dec = {
3169 .vecs = tf_lrw_dec_tv_template,
3170 .count = TF_LRW_DEC_TEST_VECTORS
3171 }
3172 }
3173 }
da7f033d
HX
3174 }, {
3175 .alg = "lzo",
3176 .test = alg_test_comp,
0818904d 3177 .fips_allowed = 1,
da7f033d
HX
3178 .suite = {
3179 .comp = {
3180 .comp = {
3181 .vecs = lzo_comp_tv_template,
3182 .count = LZO_COMP_TEST_VECTORS
3183 },
3184 .decomp = {
3185 .vecs = lzo_decomp_tv_template,
3186 .count = LZO_DECOMP_TEST_VECTORS
3187 }
3188 }
3189 }
3190 }, {
3191 .alg = "md4",
3192 .test = alg_test_hash,
3193 .suite = {
3194 .hash = {
3195 .vecs = md4_tv_template,
3196 .count = MD4_TEST_VECTORS
3197 }
3198 }
3199 }, {
3200 .alg = "md5",
3201 .test = alg_test_hash,
3202 .suite = {
3203 .hash = {
3204 .vecs = md5_tv_template,
3205 .count = MD5_TEST_VECTORS
3206 }
3207 }
3208 }, {
3209 .alg = "michael_mic",
3210 .test = alg_test_hash,
3211 .suite = {
3212 .hash = {
3213 .vecs = michael_mic_tv_template,
3214 .count = MICHAEL_MIC_TEST_VECTORS
3215 }
3216 }
ba0e14ac
PS
3217 }, {
3218 .alg = "ofb(aes)",
3219 .test = alg_test_skcipher,
3220 .fips_allowed = 1,
3221 .suite = {
3222 .cipher = {
3223 .enc = {
3224 .vecs = aes_ofb_enc_tv_template,
3225 .count = AES_OFB_ENC_TEST_VECTORS
3226 },
3227 .dec = {
3228 .vecs = aes_ofb_dec_tv_template,
3229 .count = AES_OFB_DEC_TEST_VECTORS
3230 }
3231 }
3232 }
da7f033d
HX
3233 }, {
3234 .alg = "pcbc(fcrypt)",
1aa4ecd9 3235 .test = alg_test_skcipher,
da7f033d
HX
3236 .suite = {
3237 .cipher = {
3238 .enc = {
3239 .vecs = fcrypt_pcbc_enc_tv_template,
3240 .count = FCRYPT_ENC_TEST_VECTORS
3241 },
3242 .dec = {
3243 .vecs = fcrypt_pcbc_dec_tv_template,
3244 .count = FCRYPT_DEC_TEST_VECTORS
3245 }
3246 }
3247 }
3248 }, {
3249 .alg = "rfc3686(ctr(aes))",
1aa4ecd9 3250 .test = alg_test_skcipher,
a1915d51 3251 .fips_allowed = 1,
da7f033d
HX
3252 .suite = {
3253 .cipher = {
3254 .enc = {
f7cb80f2
JW
3255 .vecs = aes_ctr_rfc3686_enc_tv_template,
3256 .count = AES_CTR_3686_ENC_TEST_VECTORS
da7f033d
HX
3257 },
3258 .dec = {
f7cb80f2
JW
3259 .vecs = aes_ctr_rfc3686_dec_tv_template,
3260 .count = AES_CTR_3686_DEC_TEST_VECTORS
da7f033d
HX
3261 }
3262 }
3263 }
5d667322 3264 }, {
69435b94
AH
3265 .alg = "rfc4106(gcm(aes))",
3266 .test = alg_test_aead,
3267 .suite = {
3268 .aead = {
3269 .enc = {
3270 .vecs = aes_gcm_rfc4106_enc_tv_template,
3271 .count = AES_GCM_4106_ENC_TEST_VECTORS
3272 },
3273 .dec = {
3274 .vecs = aes_gcm_rfc4106_dec_tv_template,
3275 .count = AES_GCM_4106_DEC_TEST_VECTORS
3276 }
3277 }
3278 }
3279 }, {
5d667322
JW
3280 .alg = "rfc4309(ccm(aes))",
3281 .test = alg_test_aead,
a1915d51 3282 .fips_allowed = 1,
5d667322
JW
3283 .suite = {
3284 .aead = {
3285 .enc = {
3286 .vecs = aes_ccm_rfc4309_enc_tv_template,
3287 .count = AES_CCM_4309_ENC_TEST_VECTORS
3288 },
3289 .dec = {
3290 .vecs = aes_ccm_rfc4309_dec_tv_template,
3291 .count = AES_CCM_4309_DEC_TEST_VECTORS
3292 }
3293 }
3294 }
e9b7441a
JK
3295 }, {
3296 .alg = "rfc4543(gcm(aes))",
3297 .test = alg_test_aead,
3298 .suite = {
3299 .aead = {
3300 .enc = {
3301 .vecs = aes_gcm_rfc4543_enc_tv_template,
3302 .count = AES_GCM_4543_ENC_TEST_VECTORS
3303 },
3304 .dec = {
3305 .vecs = aes_gcm_rfc4543_dec_tv_template,
3306 .count = AES_GCM_4543_DEC_TEST_VECTORS
3307 },
3308 }
3309 }
da7f033d
HX
3310 }, {
3311 .alg = "rmd128",
3312 .test = alg_test_hash,
3313 .suite = {
3314 .hash = {
3315 .vecs = rmd128_tv_template,
3316 .count = RMD128_TEST_VECTORS
3317 }
3318 }
3319 }, {
3320 .alg = "rmd160",
3321 .test = alg_test_hash,
3322 .suite = {
3323 .hash = {
3324 .vecs = rmd160_tv_template,
3325 .count = RMD160_TEST_VECTORS
3326 }
3327 }
3328 }, {
3329 .alg = "rmd256",
3330 .test = alg_test_hash,
3331 .suite = {
3332 .hash = {
3333 .vecs = rmd256_tv_template,
3334 .count = RMD256_TEST_VECTORS
3335 }
3336 }
3337 }, {
3338 .alg = "rmd320",
3339 .test = alg_test_hash,
3340 .suite = {
3341 .hash = {
3342 .vecs = rmd320_tv_template,
3343 .count = RMD320_TEST_VECTORS
3344 }
3345 }
3346 }, {
3347 .alg = "salsa20",
1aa4ecd9 3348 .test = alg_test_skcipher,
da7f033d
HX
3349 .suite = {
3350 .cipher = {
3351 .enc = {
3352 .vecs = salsa20_stream_enc_tv_template,
3353 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3354 }
3355 }
3356 }
3357 }, {
3358 .alg = "sha1",
3359 .test = alg_test_hash,
a1915d51 3360 .fips_allowed = 1,
da7f033d
HX
3361 .suite = {
3362 .hash = {
3363 .vecs = sha1_tv_template,
3364 .count = SHA1_TEST_VECTORS
3365 }
3366 }
3367 }, {
3368 .alg = "sha224",
3369 .test = alg_test_hash,
a1915d51 3370 .fips_allowed = 1,
da7f033d
HX
3371 .suite = {
3372 .hash = {
3373 .vecs = sha224_tv_template,
3374 .count = SHA224_TEST_VECTORS
3375 }
3376 }
3377 }, {
3378 .alg = "sha256",
3379 .test = alg_test_hash,
a1915d51 3380 .fips_allowed = 1,
da7f033d
HX
3381 .suite = {
3382 .hash = {
3383 .vecs = sha256_tv_template,
3384 .count = SHA256_TEST_VECTORS
3385 }
3386 }
3387 }, {
3388 .alg = "sha384",
3389 .test = alg_test_hash,
a1915d51 3390 .fips_allowed = 1,
da7f033d
HX
3391 .suite = {
3392 .hash = {
3393 .vecs = sha384_tv_template,
3394 .count = SHA384_TEST_VECTORS
3395 }
3396 }
3397 }, {
3398 .alg = "sha512",
3399 .test = alg_test_hash,
a1915d51 3400 .fips_allowed = 1,
da7f033d
HX
3401 .suite = {
3402 .hash = {
3403 .vecs = sha512_tv_template,
3404 .count = SHA512_TEST_VECTORS
3405 }
3406 }
3407 }, {
3408 .alg = "tgr128",
3409 .test = alg_test_hash,
3410 .suite = {
3411 .hash = {
3412 .vecs = tgr128_tv_template,
3413 .count = TGR128_TEST_VECTORS
3414 }
3415 }
3416 }, {
3417 .alg = "tgr160",
3418 .test = alg_test_hash,
3419 .suite = {
3420 .hash = {
3421 .vecs = tgr160_tv_template,
3422 .count = TGR160_TEST_VECTORS
3423 }
3424 }
3425 }, {
3426 .alg = "tgr192",
3427 .test = alg_test_hash,
3428 .suite = {
3429 .hash = {
3430 .vecs = tgr192_tv_template,
3431 .count = TGR192_TEST_VECTORS
3432 }
3433 }
f1939f7c
SW
3434 }, {
3435 .alg = "vmac(aes)",
3436 .test = alg_test_hash,
3437 .suite = {
3438 .hash = {
3439 .vecs = aes_vmac128_tv_template,
3440 .count = VMAC_AES_TEST_VECTORS
3441 }
3442 }
da7f033d
HX
3443 }, {
3444 .alg = "wp256",
3445 .test = alg_test_hash,
3446 .suite = {
3447 .hash = {
3448 .vecs = wp256_tv_template,
3449 .count = WP256_TEST_VECTORS
3450 }
3451 }
3452 }, {
3453 .alg = "wp384",
3454 .test = alg_test_hash,
3455 .suite = {
3456 .hash = {
3457 .vecs = wp384_tv_template,
3458 .count = WP384_TEST_VECTORS
3459 }
3460 }
3461 }, {
3462 .alg = "wp512",
3463 .test = alg_test_hash,
3464 .suite = {
3465 .hash = {
3466 .vecs = wp512_tv_template,
3467 .count = WP512_TEST_VECTORS
3468 }
3469 }
3470 }, {
3471 .alg = "xcbc(aes)",
3472 .test = alg_test_hash,
3473 .suite = {
3474 .hash = {
3475 .vecs = aes_xcbc128_tv_template,
3476 .count = XCBC_AES_TEST_VECTORS
3477 }
3478 }
3479 }, {
3480 .alg = "xts(aes)",
1aa4ecd9 3481 .test = alg_test_skcipher,
2918aa8d 3482 .fips_allowed = 1,
da7f033d
HX
3483 .suite = {
3484 .cipher = {
3485 .enc = {
3486 .vecs = aes_xts_enc_tv_template,
3487 .count = AES_XTS_ENC_TEST_VECTORS
3488 },
3489 .dec = {
3490 .vecs = aes_xts_dec_tv_template,
3491 .count = AES_XTS_DEC_TEST_VECTORS
3492 }
3493 }
3494 }
0840605e
JK
3495 }, {
3496 .alg = "xts(camellia)",
3497 .test = alg_test_skcipher,
3498 .suite = {
3499 .cipher = {
3500 .enc = {
3501 .vecs = camellia_xts_enc_tv_template,
3502 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3503 },
3504 .dec = {
3505 .vecs = camellia_xts_dec_tv_template,
3506 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3507 }
3508 }
3509 }
9b8b0405
JG
3510 }, {
3511 .alg = "xts(cast6)",
3512 .test = alg_test_skcipher,
3513 .suite = {
3514 .cipher = {
3515 .enc = {
3516 .vecs = cast6_xts_enc_tv_template,
3517 .count = CAST6_XTS_ENC_TEST_VECTORS
3518 },
3519 .dec = {
3520 .vecs = cast6_xts_dec_tv_template,
3521 .count = CAST6_XTS_DEC_TEST_VECTORS
3522 }
3523 }
3524 }
18be20b9
JK
3525 }, {
3526 .alg = "xts(serpent)",
3527 .test = alg_test_skcipher,
3528 .suite = {
3529 .cipher = {
3530 .enc = {
3531 .vecs = serpent_xts_enc_tv_template,
3532 .count = SERPENT_XTS_ENC_TEST_VECTORS
3533 },
3534 .dec = {
3535 .vecs = serpent_xts_dec_tv_template,
3536 .count = SERPENT_XTS_DEC_TEST_VECTORS
3537 }
3538 }
3539 }
aed265b9
JK
3540 }, {
3541 .alg = "xts(twofish)",
3542 .test = alg_test_skcipher,
3543 .suite = {
3544 .cipher = {
3545 .enc = {
3546 .vecs = tf_xts_enc_tv_template,
3547 .count = TF_XTS_ENC_TEST_VECTORS
3548 },
3549 .dec = {
3550 .vecs = tf_xts_dec_tv_template,
3551 .count = TF_XTS_DEC_TEST_VECTORS
3552 }
3553 }
3554 }
0c01aed5
GU
3555 }, {
3556 .alg = "zlib",
3557 .test = alg_test_pcomp,
0818904d 3558 .fips_allowed = 1,
0c01aed5
GU
3559 .suite = {
3560 .pcomp = {
3561 .comp = {
3562 .vecs = zlib_comp_tv_template,
3563 .count = ZLIB_COMP_TEST_VECTORS
3564 },
3565 .decomp = {
3566 .vecs = zlib_decomp_tv_template,
3567 .count = ZLIB_DECOMP_TEST_VECTORS
3568 }
3569 }
3570 }
da7f033d
HX
3571 }
3572};
3573
5714758b
JK
3574static bool alg_test_descs_checked;
3575
3576static void alg_test_descs_check_order(void)
3577{
3578 int i;
3579
3580 /* only check once */
3581 if (alg_test_descs_checked)
3582 return;
3583
3584 alg_test_descs_checked = true;
3585
3586 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3587 int diff = strcmp(alg_test_descs[i - 1].alg,
3588 alg_test_descs[i].alg);
3589
3590 if (WARN_ON(diff > 0)) {
3591 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3592 alg_test_descs[i - 1].alg,
3593 alg_test_descs[i].alg);
3594 }
3595
3596 if (WARN_ON(diff == 0)) {
3597 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3598 alg_test_descs[i].alg);
3599 }
3600 }
3601}
3602
1aa4ecd9 3603static int alg_find_test(const char *alg)
da7f033d
HX
3604{
3605 int start = 0;
3606 int end = ARRAY_SIZE(alg_test_descs);
3607
3608 while (start < end) {
3609 int i = (start + end) / 2;
3610 int diff = strcmp(alg_test_descs[i].alg, alg);
3611
3612 if (diff > 0) {
3613 end = i;
3614 continue;
3615 }
3616
3617 if (diff < 0) {
3618 start = i + 1;
3619 continue;
3620 }
3621
1aa4ecd9
HX
3622 return i;
3623 }
3624
3625 return -1;
3626}
3627
3628int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3629{
3630 int i;
a68f6610 3631 int j;
d12d6b6d 3632 int rc;
1aa4ecd9 3633
5714758b
JK
3634 alg_test_descs_check_order();
3635
1aa4ecd9
HX
3636 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3637 char nalg[CRYPTO_MAX_ALG_NAME];
3638
3639 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3640 sizeof(nalg))
3641 return -ENAMETOOLONG;
3642
3643 i = alg_find_test(nalg);
3644 if (i < 0)
3645 goto notest;
3646
a3bef3a3
JW
3647 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3648 goto non_fips_alg;
3649
941fb328
JW
3650 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3651 goto test_done;
da7f033d
HX
3652 }
3653
1aa4ecd9 3654 i = alg_find_test(alg);
a68f6610
HX
3655 j = alg_find_test(driver);
3656 if (i < 0 && j < 0)
1aa4ecd9
HX
3657 goto notest;
3658
a68f6610
HX
3659 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3660 (j >= 0 && !alg_test_descs[j].fips_allowed)))
a3bef3a3
JW
3661 goto non_fips_alg;
3662
a68f6610
HX
3663 rc = 0;
3664 if (i >= 0)
3665 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3666 type, mask);
032c8cac 3667 if (j >= 0 && j != i)
a68f6610
HX
3668 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3669 type, mask);
3670
941fb328 3671test_done:
d12d6b6d
NH
3672 if (fips_enabled && rc)
3673 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3674
29ecd4ab 3675 if (fips_enabled && !rc)
5208ed2c
NL
3676 pr_info(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3677 driver, alg);
29ecd4ab 3678
d12d6b6d 3679 return rc;
1aa4ecd9
HX
3680
3681notest:
da7f033d
HX
3682 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3683 return 0;
a3bef3a3
JW
3684non_fips_alg:
3685 return -EINVAL;
da7f033d 3686}
0b767f96 3687
326a6346 3688#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
0b767f96 3689
da7f033d 3690EXPORT_SYMBOL_GPL(alg_test);