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