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