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