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