Root/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 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 */
15
16#include <crypto/hash.h>
17#include <linux/err.h>
18#include <linux/module.h>
19#include <linux/scatterlist.h>
20#include <linux/slab.h>
21#include <linux/string.h>
22#include <crypto/rng.h>
23
24#include "internal.h"
25#include "testmgr.h"
26
27/*
28 * Need slab memory for testing (size in number of pages).
29 */
30#define XBUFSIZE 8
31
32/*
33 * Indexes into the xbuf to simulate cross-page access.
34 */
35#define IDX1 32
36#define IDX2 32400
37#define IDX3 1
38#define IDX4 8193
39#define IDX5 22222
40#define IDX6 17101
41#define IDX7 27333
42#define IDX8 3000
43
44/*
45* Used by test_cipher()
46*/
47#define ENCRYPT 1
48#define DECRYPT 0
49
50#ifndef CONFIG_CRYPTO_MANAGER_NO_TESTS
51
52struct tcrypt_result {
53    struct completion completion;
54    int err;
55};
56
57struct aead_test_suite {
58    struct {
59        struct aead_testvec *vecs;
60        unsigned int count;
61    } enc, dec;
62};
63
64struct cipher_test_suite {
65    struct {
66        struct cipher_testvec *vecs;
67        unsigned int count;
68    } enc, dec;
69};
70
71struct comp_test_suite {
72    struct {
73        struct comp_testvec *vecs;
74        unsigned int count;
75    } comp, decomp;
76};
77
78struct pcomp_test_suite {
79    struct {
80        struct pcomp_testvec *vecs;
81        unsigned int count;
82    } comp, decomp;
83};
84
85struct hash_test_suite {
86    struct hash_testvec *vecs;
87    unsigned int count;
88};
89
90struct cprng_test_suite {
91    struct cprng_testvec *vecs;
92    unsigned int count;
93};
94
95struct alg_test_desc {
96    const char *alg;
97    int (*test)(const struct alg_test_desc *desc, const char *driver,
98            u32 type, u32 mask);
99    int fips_allowed; /* set if alg is allowed in fips mode */
100
101    union {
102        struct aead_test_suite aead;
103        struct cipher_test_suite cipher;
104        struct comp_test_suite comp;
105        struct pcomp_test_suite pcomp;
106        struct hash_test_suite hash;
107        struct cprng_test_suite cprng;
108    } suite;
109};
110
111static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
112
113static void hexdump(unsigned char *buf, unsigned int len)
114{
115    print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
116            16, 1,
117            buf, len, false);
118}
119
120static void tcrypt_complete(struct crypto_async_request *req, int err)
121{
122    struct tcrypt_result *res = req->data;
123
124    if (err == -EINPROGRESS)
125        return;
126
127    res->err = err;
128    complete(&res->completion);
129}
130
131static int testmgr_alloc_buf(char *buf[XBUFSIZE])
132{
133    int i;
134
135    for (i = 0; i < XBUFSIZE; i++) {
136        buf[i] = (void *)__get_free_page(GFP_KERNEL);
137        if (!buf[i])
138            goto err_free_buf;
139    }
140
141    return 0;
142
143err_free_buf:
144    while (i-- > 0)
145        free_page((unsigned long)buf[i]);
146
147    return -ENOMEM;
148}
149
150static void testmgr_free_buf(char *buf[XBUFSIZE])
151{
152    int i;
153
154    for (i = 0; i < XBUFSIZE; i++)
155        free_page((unsigned long)buf[i]);
156}
157
158static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
159             unsigned int tcount)
160{
161    const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
162    unsigned int i, j, k, temp;
163    struct scatterlist sg[8];
164    char result[64];
165    struct ahash_request *req;
166    struct tcrypt_result tresult;
167    void *hash_buff;
168    char *xbuf[XBUFSIZE];
169    int ret = -ENOMEM;
170
171    if (testmgr_alloc_buf(xbuf))
172        goto out_nobuf;
173
174    init_completion(&tresult.completion);
175
176    req = ahash_request_alloc(tfm, GFP_KERNEL);
177    if (!req) {
178        printk(KERN_ERR "alg: hash: Failed to allocate request for "
179               "%s\n", algo);
180        goto out_noreq;
181    }
182    ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
183                   tcrypt_complete, &tresult);
184
185    j = 0;
186    for (i = 0; i < tcount; i++) {
187        if (template[i].np)
188            continue;
189
190        j++;
191        memset(result, 0, 64);
192
193        hash_buff = xbuf[0];
194
195        memcpy(hash_buff, template[i].plaintext, template[i].psize);
196        sg_init_one(&sg[0], hash_buff, template[i].psize);
197
198        if (template[i].ksize) {
199            crypto_ahash_clear_flags(tfm, ~0);
200            ret = crypto_ahash_setkey(tfm, template[i].key,
201                          template[i].ksize);
202            if (ret) {
203                printk(KERN_ERR "alg: hash: setkey failed on "
204                       "test %d for %s: ret=%d\n", j, algo,
205                       -ret);
206                goto out;
207            }
208        }
209
210        ahash_request_set_crypt(req, sg, result, template[i].psize);
211        ret = crypto_ahash_digest(req);
212        switch (ret) {
213        case 0:
214            break;
215        case -EINPROGRESS:
216        case -EBUSY:
217            ret = wait_for_completion_interruptible(
218                &tresult.completion);
219            if (!ret && !(ret = tresult.err)) {
220                INIT_COMPLETION(tresult.completion);
221                break;
222            }
223            /* fall through */
224        default:
225            printk(KERN_ERR "alg: hash: digest failed on test %d "
226                   "for %s: ret=%d\n", j, algo, -ret);
227            goto out;
228        }
229
230        if (memcmp(result, template[i].digest,
231               crypto_ahash_digestsize(tfm))) {
232            printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
233                   j, algo);
234            hexdump(result, crypto_ahash_digestsize(tfm));
235            ret = -EINVAL;
236            goto out;
237        }
238    }
239
240    j = 0;
241    for (i = 0; i < tcount; i++) {
242        if (template[i].np) {
243            j++;
244            memset(result, 0, 64);
245
246            temp = 0;
247            sg_init_table(sg, template[i].np);
248            ret = -EINVAL;
249            for (k = 0; k < template[i].np; k++) {
250                if (WARN_ON(offset_in_page(IDX[k]) +
251                        template[i].tap[k] > PAGE_SIZE))
252                    goto out;
253                sg_set_buf(&sg[k],
254                       memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
255                          offset_in_page(IDX[k]),
256                          template[i].plaintext + temp,
257                          template[i].tap[k]),
258                       template[i].tap[k]);
259                temp += template[i].tap[k];
260            }
261
262            if (template[i].ksize) {
263                crypto_ahash_clear_flags(tfm, ~0);
264                ret = crypto_ahash_setkey(tfm, template[i].key,
265                              template[i].ksize);
266
267                if (ret) {
268                    printk(KERN_ERR "alg: hash: setkey "
269                           "failed on chunking test %d "
270                           "for %s: ret=%d\n", j, algo,
271                           -ret);
272                    goto out;
273                }
274            }
275
276            ahash_request_set_crypt(req, sg, result,
277                        template[i].psize);
278            ret = crypto_ahash_digest(req);
279            switch (ret) {
280            case 0:
281                break;
282            case -EINPROGRESS:
283            case -EBUSY:
284                ret = wait_for_completion_interruptible(
285                    &tresult.completion);
286                if (!ret && !(ret = tresult.err)) {
287                    INIT_COMPLETION(tresult.completion);
288                    break;
289                }
290                /* fall through */
291            default:
292                printk(KERN_ERR "alg: hash: digest failed "
293                       "on chunking test %d for %s: "
294                       "ret=%d\n", j, algo, -ret);
295                goto out;
296            }
297
298            if (memcmp(result, template[i].digest,
299                   crypto_ahash_digestsize(tfm))) {
300                printk(KERN_ERR "alg: hash: Chunking test %d "
301                       "failed for %s\n", j, algo);
302                hexdump(result, crypto_ahash_digestsize(tfm));
303                ret = -EINVAL;
304                goto out;
305            }
306        }
307    }
308
309    ret = 0;
310
311out:
312    ahash_request_free(req);
313out_noreq:
314    testmgr_free_buf(xbuf);
315out_nobuf:
316    return ret;
317}
318
319static int test_aead(struct crypto_aead *tfm, int enc,
320             struct aead_testvec *template, unsigned int tcount)
321{
322    const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
323    unsigned int i, j, k, n, temp;
324    int ret = -ENOMEM;
325    char *q;
326    char *key;
327    struct aead_request *req;
328    struct scatterlist sg[8];
329    struct scatterlist asg[8];
330    const char *e;
331    struct tcrypt_result result;
332    unsigned int authsize;
333    void *input;
334    void *assoc;
335    char iv[MAX_IVLEN];
336    char *xbuf[XBUFSIZE];
337    char *axbuf[XBUFSIZE];
338
339    if (testmgr_alloc_buf(xbuf))
340        goto out_noxbuf;
341    if (testmgr_alloc_buf(axbuf))
342        goto out_noaxbuf;
343
344    if (enc == ENCRYPT)
345        e = "encryption";
346    else
347        e = "decryption";
348
349    init_completion(&result.completion);
350
351    req = aead_request_alloc(tfm, GFP_KERNEL);
352    if (!req) {
353        printk(KERN_ERR "alg: aead: Failed to allocate request for "
354               "%s\n", algo);
355        goto out;
356    }
357
358    aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
359                  tcrypt_complete, &result);
360
361    for (i = 0, j = 0; i < tcount; i++) {
362        if (!template[i].np) {
363            j++;
364
365            /* some tepmplates have no input data but they will
366             * touch input
367             */
368            input = xbuf[0];
369            assoc = axbuf[0];
370
371            ret = -EINVAL;
372            if (WARN_ON(template[i].ilen > PAGE_SIZE ||
373                    template[i].alen > PAGE_SIZE))
374                goto out;
375
376            memcpy(input, template[i].input, template[i].ilen);
377            memcpy(assoc, template[i].assoc, template[i].alen);
378            if (template[i].iv)
379                memcpy(iv, template[i].iv, MAX_IVLEN);
380            else
381                memset(iv, 0, MAX_IVLEN);
382
383            crypto_aead_clear_flags(tfm, ~0);
384            if (template[i].wk)
385                crypto_aead_set_flags(
386                    tfm, CRYPTO_TFM_REQ_WEAK_KEY);
387
388            key = template[i].key;
389
390            ret = crypto_aead_setkey(tfm, key,
391                         template[i].klen);
392            if (!ret == template[i].fail) {
393                printk(KERN_ERR "alg: aead: setkey failed on "
394                       "test %d for %s: flags=%x\n", j, algo,
395                       crypto_aead_get_flags(tfm));
396                goto out;
397            } else if (ret)
398                continue;
399
400            authsize = abs(template[i].rlen - template[i].ilen);
401            ret = crypto_aead_setauthsize(tfm, authsize);
402            if (ret) {
403                printk(KERN_ERR "alg: aead: Failed to set "
404                       "authsize to %u on test %d for %s\n",
405                       authsize, j, algo);
406                goto out;
407            }
408
409            sg_init_one(&sg[0], input,
410                    template[i].ilen + (enc ? authsize : 0));
411
412            sg_init_one(&asg[0], assoc, template[i].alen);
413
414            aead_request_set_crypt(req, sg, sg,
415                           template[i].ilen, iv);
416
417            aead_request_set_assoc(req, asg, template[i].alen);
418
419            ret = enc ?
420                crypto_aead_encrypt(req) :
421                crypto_aead_decrypt(req);
422
423            switch (ret) {
424            case 0:
425                if (template[i].novrfy) {
426                    /* verification was supposed to fail */
427                    printk(KERN_ERR "alg: aead: %s failed "
428                           "on test %d for %s: ret was 0, "
429                           "expected -EBADMSG\n",
430                           e, j, algo);
431                    /* so really, we got a bad message */
432                    ret = -EBADMSG;
433                    goto out;
434                }
435                break;
436            case -EINPROGRESS:
437            case -EBUSY:
438                ret = wait_for_completion_interruptible(
439                    &result.completion);
440                if (!ret && !(ret = result.err)) {
441                    INIT_COMPLETION(result.completion);
442                    break;
443                }
444            case -EBADMSG:
445                if (template[i].novrfy)
446                    /* verification failure was expected */
447                    continue;
448                /* fall through */
449            default:
450                printk(KERN_ERR "alg: aead: %s failed on test "
451                       "%d for %s: ret=%d\n", e, j, algo, -ret);
452                goto out;
453            }
454
455            q = input;
456            if (memcmp(q, template[i].result, template[i].rlen)) {
457                printk(KERN_ERR "alg: aead: Test %d failed on "
458                       "%s for %s\n", j, e, algo);
459                hexdump(q, template[i].rlen);
460                ret = -EINVAL;
461                goto out;
462            }
463        }
464    }
465
466    for (i = 0, j = 0; i < tcount; i++) {
467        if (template[i].np) {
468            j++;
469
470            if (template[i].iv)
471                memcpy(iv, template[i].iv, MAX_IVLEN);
472            else
473                memset(iv, 0, MAX_IVLEN);
474
475            crypto_aead_clear_flags(tfm, ~0);
476            if (template[i].wk)
477                crypto_aead_set_flags(
478                    tfm, CRYPTO_TFM_REQ_WEAK_KEY);
479            key = template[i].key;
480
481            ret = crypto_aead_setkey(tfm, key, template[i].klen);
482            if (!ret == template[i].fail) {
483                printk(KERN_ERR "alg: aead: setkey failed on "
484                       "chunk test %d for %s: flags=%x\n", j,
485                       algo, crypto_aead_get_flags(tfm));
486                goto out;
487            } else if (ret)
488                continue;
489
490            authsize = abs(template[i].rlen - template[i].ilen);
491
492            ret = -EINVAL;
493            sg_init_table(sg, template[i].np);
494            for (k = 0, temp = 0; k < template[i].np; k++) {
495                if (WARN_ON(offset_in_page(IDX[k]) +
496                        template[i].tap[k] > PAGE_SIZE))
497                    goto out;
498
499                q = xbuf[IDX[k] >> PAGE_SHIFT] +
500                    offset_in_page(IDX[k]);
501
502                memcpy(q, template[i].input + temp,
503                       template[i].tap[k]);
504
505                n = template[i].tap[k];
506                if (k == template[i].np - 1 && enc)
507                    n += authsize;
508                if (offset_in_page(q) + n < PAGE_SIZE)
509                    q[n] = 0;
510
511                sg_set_buf(&sg[k], q, template[i].tap[k]);
512                temp += template[i].tap[k];
513            }
514
515            ret = crypto_aead_setauthsize(tfm, authsize);
516            if (ret) {
517                printk(KERN_ERR "alg: aead: Failed to set "
518                       "authsize to %u on chunk test %d for "
519                       "%s\n", authsize, j, algo);
520                goto out;
521            }
522
523            if (enc) {
524                if (WARN_ON(sg[k - 1].offset +
525                        sg[k - 1].length + authsize >
526                        PAGE_SIZE)) {
527                    ret = -EINVAL;
528                    goto out;
529                }
530
531                sg[k - 1].length += authsize;
532            }
533
534            sg_init_table(asg, template[i].anp);
535            ret = -EINVAL;
536            for (k = 0, temp = 0; k < template[i].anp; k++) {
537                if (WARN_ON(offset_in_page(IDX[k]) +
538                        template[i].atap[k] > PAGE_SIZE))
539                    goto out;
540                sg_set_buf(&asg[k],
541                       memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
542                          offset_in_page(IDX[k]),
543                          template[i].assoc + temp,
544                          template[i].atap[k]),
545                       template[i].atap[k]);
546                temp += template[i].atap[k];
547            }
548
549            aead_request_set_crypt(req, sg, sg,
550                           template[i].ilen,
551                           iv);
552
553            aead_request_set_assoc(req, asg, template[i].alen);
554
555            ret = enc ?
556                crypto_aead_encrypt(req) :
557                crypto_aead_decrypt(req);
558
559            switch (ret) {
560            case 0:
561                if (template[i].novrfy) {
562                    /* verification was supposed to fail */
563                    printk(KERN_ERR "alg: aead: %s failed "
564                           "on chunk test %d for %s: ret "
565                           "was 0, expected -EBADMSG\n",
566                           e, j, algo);
567                    /* so really, we got a bad message */
568                    ret = -EBADMSG;
569                    goto out;
570                }
571                break;
572            case -EINPROGRESS:
573            case -EBUSY:
574                ret = wait_for_completion_interruptible(
575                    &result.completion);
576                if (!ret && !(ret = result.err)) {
577                    INIT_COMPLETION(result.completion);
578                    break;
579                }
580            case -EBADMSG:
581                if (template[i].novrfy)
582                    /* verification failure was expected */
583                    continue;
584                /* fall through */
585            default:
586                printk(KERN_ERR "alg: aead: %s failed on "
587                       "chunk test %d for %s: ret=%d\n", e, j,
588                       algo, -ret);
589                goto out;
590            }
591
592            ret = -EINVAL;
593            for (k = 0, temp = 0; k < template[i].np; k++) {
594                q = xbuf[IDX[k] >> PAGE_SHIFT] +
595                    offset_in_page(IDX[k]);
596
597                n = template[i].tap[k];
598                if (k == template[i].np - 1)
599                    n += enc ? authsize : -authsize;
600
601                if (memcmp(q, template[i].result + temp, n)) {
602                    printk(KERN_ERR "alg: aead: Chunk "
603                           "test %d failed on %s at page "
604                           "%u for %s\n", j, e, k, algo);
605                    hexdump(q, n);
606                    goto out;
607                }
608
609                q += n;
610                if (k == template[i].np - 1 && !enc) {
611                    if (memcmp(q, template[i].input +
612                              temp + n, authsize))
613                        n = authsize;
614                    else
615                        n = 0;
616                } else {
617                    for (n = 0; offset_in_page(q + n) &&
618                            q[n]; n++)
619                        ;
620                }
621                if (n) {
622                    printk(KERN_ERR "alg: aead: Result "
623                           "buffer corruption in chunk "
624                           "test %d on %s at page %u for "
625                           "%s: %u bytes:\n", j, e, k,
626                           algo, n);
627                    hexdump(q, n);
628                    goto out;
629                }
630
631                temp += template[i].tap[k];
632            }
633        }
634    }
635
636    ret = 0;
637
638out:
639    aead_request_free(req);
640    testmgr_free_buf(axbuf);
641out_noaxbuf:
642    testmgr_free_buf(xbuf);
643out_noxbuf:
644    return ret;
645}
646
647static int test_cipher(struct crypto_cipher *tfm, int enc,
648               struct cipher_testvec *template, unsigned int tcount)
649{
650    const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
651    unsigned int i, j, k;
652    char *q;
653    const char *e;
654    void *data;
655    char *xbuf[XBUFSIZE];
656    int ret = -ENOMEM;
657
658    if (testmgr_alloc_buf(xbuf))
659        goto out_nobuf;
660
661    if (enc == ENCRYPT)
662            e = "encryption";
663    else
664        e = "decryption";
665
666    j = 0;
667    for (i = 0; i < tcount; i++) {
668        if (template[i].np)
669            continue;
670
671        j++;
672
673        ret = -EINVAL;
674        if (WARN_ON(template[i].ilen > PAGE_SIZE))
675            goto out;
676
677        data = xbuf[0];
678        memcpy(data, template[i].input, template[i].ilen);
679
680        crypto_cipher_clear_flags(tfm, ~0);
681        if (template[i].wk)
682            crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
683
684        ret = crypto_cipher_setkey(tfm, template[i].key,
685                       template[i].klen);
686        if (!ret == template[i].fail) {
687            printk(KERN_ERR "alg: cipher: setkey failed "
688                   "on test %d for %s: flags=%x\n", j,
689                   algo, crypto_cipher_get_flags(tfm));
690            goto out;
691        } else if (ret)
692            continue;
693
694        for (k = 0; k < template[i].ilen;
695             k += crypto_cipher_blocksize(tfm)) {
696            if (enc)
697                crypto_cipher_encrypt_one(tfm, data + k,
698                              data + k);
699            else
700                crypto_cipher_decrypt_one(tfm, data + k,
701                              data + k);
702        }
703
704        q = data;
705        if (memcmp(q, template[i].result, template[i].rlen)) {
706            printk(KERN_ERR "alg: cipher: Test %d failed "
707                   "on %s for %s\n", j, e, algo);
708            hexdump(q, template[i].rlen);
709            ret = -EINVAL;
710            goto out;
711        }
712    }
713
714    ret = 0;
715
716out:
717    testmgr_free_buf(xbuf);
718out_nobuf:
719    return ret;
720}
721
722static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
723             struct cipher_testvec *template, unsigned int tcount)
724{
725    const char *algo =
726        crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
727    unsigned int i, j, k, n, temp;
728    char *q;
729    struct ablkcipher_request *req;
730    struct scatterlist sg[8];
731    const char *e;
732    struct tcrypt_result result;
733    void *data;
734    char iv[MAX_IVLEN];
735    char *xbuf[XBUFSIZE];
736    int ret = -ENOMEM;
737
738    if (testmgr_alloc_buf(xbuf))
739        goto out_nobuf;
740
741    if (enc == ENCRYPT)
742            e = "encryption";
743    else
744        e = "decryption";
745
746    init_completion(&result.completion);
747
748    req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
749    if (!req) {
750        printk(KERN_ERR "alg: skcipher: Failed to allocate request "
751               "for %s\n", algo);
752        goto out;
753    }
754
755    ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
756                    tcrypt_complete, &result);
757
758    j = 0;
759    for (i = 0; i < tcount; i++) {
760        if (template[i].iv)
761            memcpy(iv, template[i].iv, MAX_IVLEN);
762        else
763            memset(iv, 0, MAX_IVLEN);
764
765        if (!(template[i].np)) {
766            j++;
767
768            ret = -EINVAL;
769            if (WARN_ON(template[i].ilen > PAGE_SIZE))
770                goto out;
771
772            data = xbuf[0];
773            memcpy(data, template[i].input, template[i].ilen);
774
775            crypto_ablkcipher_clear_flags(tfm, ~0);
776            if (template[i].wk)
777                crypto_ablkcipher_set_flags(
778                    tfm, CRYPTO_TFM_REQ_WEAK_KEY);
779
780            ret = crypto_ablkcipher_setkey(tfm, template[i].key,
781                               template[i].klen);
782            if (!ret == template[i].fail) {
783                printk(KERN_ERR "alg: skcipher: setkey failed "
784                       "on test %d for %s: flags=%x\n", j,
785                       algo, crypto_ablkcipher_get_flags(tfm));
786                goto out;
787            } else if (ret)
788                continue;
789
790            sg_init_one(&sg[0], data, template[i].ilen);
791
792            ablkcipher_request_set_crypt(req, sg, sg,
793                             template[i].ilen, iv);
794            ret = enc ?
795                crypto_ablkcipher_encrypt(req) :
796                crypto_ablkcipher_decrypt(req);
797
798            switch (ret) {
799            case 0:
800                break;
801            case -EINPROGRESS:
802            case -EBUSY:
803                ret = wait_for_completion_interruptible(
804                    &result.completion);
805                if (!ret && !((ret = result.err))) {
806                    INIT_COMPLETION(result.completion);
807                    break;
808                }
809                /* fall through */
810            default:
811                printk(KERN_ERR "alg: skcipher: %s failed on "
812                       "test %d for %s: ret=%d\n", e, j, algo,
813                       -ret);
814                goto out;
815            }
816
817            q = data;
818            if (memcmp(q, template[i].result, template[i].rlen)) {
819                printk(KERN_ERR "alg: skcipher: Test %d "
820                       "failed on %s for %s\n", j, e, algo);
821                hexdump(q, template[i].rlen);
822                ret = -EINVAL;
823                goto out;
824            }
825        }
826    }
827
828    j = 0;
829    for (i = 0; i < tcount; i++) {
830
831        if (template[i].iv)
832            memcpy(iv, template[i].iv, MAX_IVLEN);
833        else
834            memset(iv, 0, MAX_IVLEN);
835
836        if (template[i].np) {
837            j++;
838
839            crypto_ablkcipher_clear_flags(tfm, ~0);
840            if (template[i].wk)
841                crypto_ablkcipher_set_flags(
842                    tfm, CRYPTO_TFM_REQ_WEAK_KEY);
843
844            ret = crypto_ablkcipher_setkey(tfm, template[i].key,
845                               template[i].klen);
846            if (!ret == template[i].fail) {
847                printk(KERN_ERR "alg: skcipher: setkey failed "
848                       "on chunk test %d for %s: flags=%x\n",
849                       j, algo,
850                       crypto_ablkcipher_get_flags(tfm));
851                goto out;
852            } else if (ret)
853                continue;
854
855            temp = 0;
856            ret = -EINVAL;
857            sg_init_table(sg, template[i].np);
858            for (k = 0; k < template[i].np; k++) {
859                if (WARN_ON(offset_in_page(IDX[k]) +
860                        template[i].tap[k] > PAGE_SIZE))
861                    goto out;
862
863                q = xbuf[IDX[k] >> PAGE_SHIFT] +
864                    offset_in_page(IDX[k]);
865
866                memcpy(q, template[i].input + temp,
867                       template[i].tap[k]);
868
869                if (offset_in_page(q) + template[i].tap[k] <
870                    PAGE_SIZE)
871                    q[template[i].tap[k]] = 0;
872
873                sg_set_buf(&sg[k], q, template[i].tap[k]);
874
875                temp += template[i].tap[k];
876            }
877
878            ablkcipher_request_set_crypt(req, sg, sg,
879                    template[i].ilen, iv);
880
881            ret = enc ?
882                crypto_ablkcipher_encrypt(req) :
883                crypto_ablkcipher_decrypt(req);
884
885            switch (ret) {
886            case 0:
887                break;
888            case -EINPROGRESS:
889            case -EBUSY:
890                ret = wait_for_completion_interruptible(
891                    &result.completion);
892                if (!ret && !((ret = result.err))) {
893                    INIT_COMPLETION(result.completion);
894                    break;
895                }
896                /* fall through */
897            default:
898                printk(KERN_ERR "alg: skcipher: %s failed on "
899                       "chunk test %d for %s: ret=%d\n", e, j,
900                       algo, -ret);
901                goto out;
902            }
903
904            temp = 0;
905            ret = -EINVAL;
906            for (k = 0; k < template[i].np; k++) {
907                q = xbuf[IDX[k] >> PAGE_SHIFT] +
908                    offset_in_page(IDX[k]);
909
910                if (memcmp(q, template[i].result + temp,
911                       template[i].tap[k])) {
912                    printk(KERN_ERR "alg: skcipher: Chunk "
913                           "test %d failed on %s at page "
914                           "%u for %s\n", j, e, k, algo);
915                    hexdump(q, template[i].tap[k]);
916                    goto out;
917                }
918
919                q += template[i].tap[k];
920                for (n = 0; offset_in_page(q + n) && q[n]; n++)
921                    ;
922                if (n) {
923                    printk(KERN_ERR "alg: skcipher: "
924                           "Result buffer corruption in "
925                           "chunk test %d on %s at page "
926                           "%u for %s: %u bytes:\n", j, e,
927                           k, algo, n);
928                    hexdump(q, n);
929                    goto out;
930                }
931                temp += template[i].tap[k];
932            }
933        }
934    }
935
936    ret = 0;
937
938out:
939    ablkcipher_request_free(req);
940    testmgr_free_buf(xbuf);
941out_nobuf:
942    return ret;
943}
944
945static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
946             struct comp_testvec *dtemplate, int ctcount, int dtcount)
947{
948    const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
949    unsigned int i;
950    char result[COMP_BUF_SIZE];
951    int ret;
952
953    for (i = 0; i < ctcount; i++) {
954        int ilen;
955        unsigned int dlen = COMP_BUF_SIZE;
956
957        memset(result, 0, sizeof (result));
958
959        ilen = ctemplate[i].inlen;
960        ret = crypto_comp_compress(tfm, ctemplate[i].input,
961                                   ilen, result, &dlen);
962        if (ret) {
963            printk(KERN_ERR "alg: comp: compression failed "
964                   "on test %d for %s: ret=%d\n", i + 1, algo,
965                   -ret);
966            goto out;
967        }
968
969        if (dlen != ctemplate[i].outlen) {
970            printk(KERN_ERR "alg: comp: Compression test %d "
971                   "failed for %s: output len = %d\n", i + 1, algo,
972                   dlen);
973            ret = -EINVAL;
974            goto out;
975        }
976
977        if (memcmp(result, ctemplate[i].output, dlen)) {
978            printk(KERN_ERR "alg: comp: Compression test %d "
979                   "failed for %s\n", i + 1, algo);
980            hexdump(result, dlen);
981            ret = -EINVAL;
982            goto out;
983        }
984    }
985
986    for (i = 0; i < dtcount; i++) {
987        int ilen;
988        unsigned int dlen = COMP_BUF_SIZE;
989
990        memset(result, 0, sizeof (result));
991
992        ilen = dtemplate[i].inlen;
993        ret = crypto_comp_decompress(tfm, dtemplate[i].input,
994                                     ilen, result, &dlen);
995        if (ret) {
996            printk(KERN_ERR "alg: comp: decompression failed "
997                   "on test %d for %s: ret=%d\n", i + 1, algo,
998                   -ret);
999            goto out;
1000        }
1001
1002        if (dlen != dtemplate[i].outlen) {
1003            printk(KERN_ERR "alg: comp: Decompression test %d "
1004                   "failed for %s: output len = %d\n", i + 1, algo,
1005                   dlen);
1006            ret = -EINVAL;
1007            goto out;
1008        }
1009
1010        if (memcmp(result, dtemplate[i].output, dlen)) {
1011            printk(KERN_ERR "alg: comp: Decompression test %d "
1012                   "failed for %s\n", i + 1, algo);
1013            hexdump(result, dlen);
1014            ret = -EINVAL;
1015            goto out;
1016        }
1017    }
1018
1019    ret = 0;
1020
1021out:
1022    return ret;
1023}
1024
1025static int test_pcomp(struct crypto_pcomp *tfm,
1026              struct pcomp_testvec *ctemplate,
1027              struct pcomp_testvec *dtemplate, int ctcount,
1028              int dtcount)
1029{
1030    const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1031    unsigned int i;
1032    char result[COMP_BUF_SIZE];
1033    int res;
1034
1035    for (i = 0; i < ctcount; i++) {
1036        struct comp_request req;
1037        unsigned int produced = 0;
1038
1039        res = crypto_compress_setup(tfm, ctemplate[i].params,
1040                        ctemplate[i].paramsize);
1041        if (res) {
1042            pr_err("alg: pcomp: compression setup failed on test "
1043                   "%d for %s: error=%d\n", i + 1, algo, res);
1044            return res;
1045        }
1046
1047        res = crypto_compress_init(tfm);
1048        if (res) {
1049            pr_err("alg: pcomp: compression init failed on test "
1050                   "%d for %s: error=%d\n", i + 1, algo, res);
1051            return res;
1052        }
1053
1054        memset(result, 0, sizeof(result));
1055
1056        req.next_in = ctemplate[i].input;
1057        req.avail_in = ctemplate[i].inlen / 2;
1058        req.next_out = result;
1059        req.avail_out = ctemplate[i].outlen / 2;
1060
1061        res = crypto_compress_update(tfm, &req);
1062        if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1063            pr_err("alg: pcomp: compression update failed on test "
1064                   "%d for %s: error=%d\n", i + 1, algo, res);
1065            return res;
1066        }
1067        if (res > 0)
1068            produced += res;
1069
1070        /* Add remaining input data */
1071        req.avail_in += (ctemplate[i].inlen + 1) / 2;
1072
1073        res = crypto_compress_update(tfm, &req);
1074        if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1075            pr_err("alg: pcomp: compression update failed on test "
1076                   "%d for %s: error=%d\n", i + 1, algo, res);
1077            return res;
1078        }
1079        if (res > 0)
1080            produced += res;
1081
1082        /* Provide remaining output space */
1083        req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1084
1085        res = crypto_compress_final(tfm, &req);
1086        if (res < 0) {
1087            pr_err("alg: pcomp: compression final failed on test "
1088                   "%d for %s: error=%d\n", i + 1, algo, res);
1089            return res;
1090        }
1091        produced += res;
1092
1093        if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1094            pr_err("alg: comp: Compression test %d failed for %s: "
1095                   "output len = %d (expected %d)\n", i + 1, algo,
1096                   COMP_BUF_SIZE - req.avail_out,
1097                   ctemplate[i].outlen);
1098            return -EINVAL;
1099        }
1100
1101        if (produced != ctemplate[i].outlen) {
1102            pr_err("alg: comp: Compression test %d failed for %s: "
1103                   "returned len = %u (expected %d)\n", i + 1,
1104                   algo, produced, ctemplate[i].outlen);
1105            return -EINVAL;
1106        }
1107
1108        if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1109            pr_err("alg: pcomp: Compression test %d failed for "
1110                   "%s\n", i + 1, algo);
1111            hexdump(result, ctemplate[i].outlen);
1112            return -EINVAL;
1113        }
1114    }
1115
1116    for (i = 0; i < dtcount; i++) {
1117        struct comp_request req;
1118        unsigned int produced = 0;
1119
1120        res = crypto_decompress_setup(tfm, dtemplate[i].params,
1121                          dtemplate[i].paramsize);
1122        if (res) {
1123            pr_err("alg: pcomp: decompression setup failed on "
1124                   "test %d for %s: error=%d\n", i + 1, algo, res);
1125            return res;
1126        }
1127
1128        res = crypto_decompress_init(tfm);
1129        if (res) {
1130            pr_err("alg: pcomp: decompression init failed on test "
1131                   "%d for %s: error=%d\n", i + 1, algo, res);
1132            return res;
1133        }
1134
1135        memset(result, 0, sizeof(result));
1136
1137        req.next_in = dtemplate[i].input;
1138        req.avail_in = dtemplate[i].inlen / 2;
1139        req.next_out = result;
1140        req.avail_out = dtemplate[i].outlen / 2;
1141
1142        res = crypto_decompress_update(tfm, &req);
1143        if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1144            pr_err("alg: pcomp: decompression update failed on "
1145                   "test %d for %s: error=%d\n", i + 1, algo, res);
1146            return res;
1147        }
1148        if (res > 0)
1149            produced += res;
1150
1151        /* Add remaining input data */
1152        req.avail_in += (dtemplate[i].inlen + 1) / 2;
1153
1154        res = crypto_decompress_update(tfm, &req);
1155        if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1156            pr_err("alg: pcomp: decompression update failed on "
1157                   "test %d for %s: error=%d\n", i + 1, algo, res);
1158            return res;
1159        }
1160        if (res > 0)
1161            produced += res;
1162
1163        /* Provide remaining output space */
1164        req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1165
1166        res = crypto_decompress_final(tfm, &req);
1167        if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1168            pr_err("alg: pcomp: decompression final failed on "
1169                   "test %d for %s: error=%d\n", i + 1, algo, res);
1170            return res;
1171        }
1172        if (res > 0)
1173            produced += res;
1174
1175        if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1176            pr_err("alg: comp: Decompression test %d failed for "
1177                   "%s: output len = %d (expected %d)\n", i + 1,
1178                   algo, COMP_BUF_SIZE - req.avail_out,
1179                   dtemplate[i].outlen);
1180            return -EINVAL;
1181        }
1182
1183        if (produced != dtemplate[i].outlen) {
1184            pr_err("alg: comp: Decompression test %d failed for "
1185                   "%s: returned len = %u (expected %d)\n", i + 1,
1186                   algo, produced, dtemplate[i].outlen);
1187            return -EINVAL;
1188        }
1189
1190        if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1191            pr_err("alg: pcomp: Decompression test %d failed for "
1192                   "%s\n", i + 1, algo);
1193            hexdump(result, dtemplate[i].outlen);
1194            return -EINVAL;
1195        }
1196    }
1197
1198    return 0;
1199}
1200
1201
1202static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1203              unsigned int tcount)
1204{
1205    const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1206    int err, i, j, seedsize;
1207    u8 *seed;
1208    char result[32];
1209
1210    seedsize = crypto_rng_seedsize(tfm);
1211
1212    seed = kmalloc(seedsize, GFP_KERNEL);
1213    if (!seed) {
1214        printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1215               "for %s\n", algo);
1216        return -ENOMEM;
1217    }
1218
1219    for (i = 0; i < tcount; i++) {
1220        memset(result, 0, 32);
1221
1222        memcpy(seed, template[i].v, template[i].vlen);
1223        memcpy(seed + template[i].vlen, template[i].key,
1224               template[i].klen);
1225        memcpy(seed + template[i].vlen + template[i].klen,
1226               template[i].dt, template[i].dtlen);
1227
1228        err = crypto_rng_reset(tfm, seed, seedsize);
1229        if (err) {
1230            printk(KERN_ERR "alg: cprng: Failed to reset rng "
1231                   "for %s\n", algo);
1232            goto out;
1233        }
1234
1235        for (j = 0; j < template[i].loops; j++) {
1236            err = crypto_rng_get_bytes(tfm, result,
1237                           template[i].rlen);
1238            if (err != template[i].rlen) {
1239                printk(KERN_ERR "alg: cprng: Failed to obtain "
1240                       "the correct amount of random data for "
1241                       "%s (requested %d, got %d)\n", algo,
1242                       template[i].rlen, err);
1243                goto out;
1244            }
1245        }
1246
1247        err = memcmp(result, template[i].result,
1248                 template[i].rlen);
1249        if (err) {
1250            printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1251                   i, algo);
1252            hexdump(result, template[i].rlen);
1253            err = -EINVAL;
1254            goto out;
1255        }
1256    }
1257
1258out:
1259    kfree(seed);
1260    return err;
1261}
1262
1263static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1264             u32 type, u32 mask)
1265{
1266    struct crypto_aead *tfm;
1267    int err = 0;
1268
1269    tfm = crypto_alloc_aead(driver, type, mask);
1270    if (IS_ERR(tfm)) {
1271        printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1272               "%ld\n", driver, PTR_ERR(tfm));
1273        return PTR_ERR(tfm);
1274    }
1275
1276    if (desc->suite.aead.enc.vecs) {
1277        err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1278                desc->suite.aead.enc.count);
1279        if (err)
1280            goto out;
1281    }
1282
1283    if (!err && desc->suite.aead.dec.vecs)
1284        err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1285                desc->suite.aead.dec.count);
1286
1287out:
1288    crypto_free_aead(tfm);
1289    return err;
1290}
1291
1292static int alg_test_cipher(const struct alg_test_desc *desc,
1293               const char *driver, u32 type, u32 mask)
1294{
1295    struct crypto_cipher *tfm;
1296    int err = 0;
1297
1298    tfm = crypto_alloc_cipher(driver, type, mask);
1299    if (IS_ERR(tfm)) {
1300        printk(KERN_ERR "alg: cipher: Failed to load transform for "
1301               "%s: %ld\n", driver, PTR_ERR(tfm));
1302        return PTR_ERR(tfm);
1303    }
1304
1305    if (desc->suite.cipher.enc.vecs) {
1306        err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1307                  desc->suite.cipher.enc.count);
1308        if (err)
1309            goto out;
1310    }
1311
1312    if (desc->suite.cipher.dec.vecs)
1313        err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1314                  desc->suite.cipher.dec.count);
1315
1316out:
1317    crypto_free_cipher(tfm);
1318    return err;
1319}
1320
1321static int alg_test_skcipher(const struct alg_test_desc *desc,
1322                 const char *driver, u32 type, u32 mask)
1323{
1324    struct crypto_ablkcipher *tfm;
1325    int err = 0;
1326
1327    tfm = crypto_alloc_ablkcipher(driver, type, mask);
1328    if (IS_ERR(tfm)) {
1329        printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1330               "%s: %ld\n", driver, PTR_ERR(tfm));
1331        return PTR_ERR(tfm);
1332    }
1333
1334    if (desc->suite.cipher.enc.vecs) {
1335        err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1336                    desc->suite.cipher.enc.count);
1337        if (err)
1338            goto out;
1339    }
1340
1341    if (desc->suite.cipher.dec.vecs)
1342        err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1343                    desc->suite.cipher.dec.count);
1344
1345out:
1346    crypto_free_ablkcipher(tfm);
1347    return err;
1348}
1349
1350static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1351             u32 type, u32 mask)
1352{
1353    struct crypto_comp *tfm;
1354    int err;
1355
1356    tfm = crypto_alloc_comp(driver, type, mask);
1357    if (IS_ERR(tfm)) {
1358        printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1359               "%ld\n", driver, PTR_ERR(tfm));
1360        return PTR_ERR(tfm);
1361    }
1362
1363    err = test_comp(tfm, desc->suite.comp.comp.vecs,
1364            desc->suite.comp.decomp.vecs,
1365            desc->suite.comp.comp.count,
1366            desc->suite.comp.decomp.count);
1367
1368    crypto_free_comp(tfm);
1369    return err;
1370}
1371
1372static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1373              u32 type, u32 mask)
1374{
1375    struct crypto_pcomp *tfm;
1376    int err;
1377
1378    tfm = crypto_alloc_pcomp(driver, type, mask);
1379    if (IS_ERR(tfm)) {
1380        pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1381               driver, PTR_ERR(tfm));
1382        return PTR_ERR(tfm);
1383    }
1384
1385    err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1386             desc->suite.pcomp.decomp.vecs,
1387             desc->suite.pcomp.comp.count,
1388             desc->suite.pcomp.decomp.count);
1389
1390    crypto_free_pcomp(tfm);
1391    return err;
1392}
1393
1394static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1395             u32 type, u32 mask)
1396{
1397    struct crypto_ahash *tfm;
1398    int err;
1399
1400    tfm = crypto_alloc_ahash(driver, type, mask);
1401    if (IS_ERR(tfm)) {
1402        printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1403               "%ld\n", driver, PTR_ERR(tfm));
1404        return PTR_ERR(tfm);
1405    }
1406
1407    err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
1408
1409    crypto_free_ahash(tfm);
1410    return err;
1411}
1412
1413static int alg_test_crc32c(const struct alg_test_desc *desc,
1414               const char *driver, u32 type, u32 mask)
1415{
1416    struct crypto_shash *tfm;
1417    u32 val;
1418    int err;
1419
1420    err = alg_test_hash(desc, driver, type, mask);
1421    if (err)
1422        goto out;
1423
1424    tfm = crypto_alloc_shash(driver, type, mask);
1425    if (IS_ERR(tfm)) {
1426        printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1427               "%ld\n", driver, PTR_ERR(tfm));
1428        err = PTR_ERR(tfm);
1429        goto out;
1430    }
1431
1432    do {
1433        struct {
1434            struct shash_desc shash;
1435            char ctx[crypto_shash_descsize(tfm)];
1436        } sdesc;
1437
1438        sdesc.shash.tfm = tfm;
1439        sdesc.shash.flags = 0;
1440
1441        *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1442        err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1443        if (err) {
1444            printk(KERN_ERR "alg: crc32c: Operation failed for "
1445                   "%s: %d\n", driver, err);
1446            break;
1447        }
1448
1449        if (val != ~420553207) {
1450            printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1451                   "%d\n", driver, val);
1452            err = -EINVAL;
1453        }
1454    } while (0);
1455
1456    crypto_free_shash(tfm);
1457
1458out:
1459    return err;
1460}
1461
1462static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1463              u32 type, u32 mask)
1464{
1465    struct crypto_rng *rng;
1466    int err;
1467
1468    rng = crypto_alloc_rng(driver, type, mask);
1469    if (IS_ERR(rng)) {
1470        printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1471               "%ld\n", driver, PTR_ERR(rng));
1472        return PTR_ERR(rng);
1473    }
1474
1475    err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1476
1477    crypto_free_rng(rng);
1478
1479    return err;
1480}
1481
1482/* Please keep this list sorted by algorithm name. */
1483static const struct alg_test_desc alg_test_descs[] = {
1484    {
1485        .alg = "ansi_cprng",
1486        .test = alg_test_cprng,
1487        .fips_allowed = 1,
1488        .suite = {
1489            .cprng = {
1490                .vecs = ansi_cprng_aes_tv_template,
1491                .count = ANSI_CPRNG_AES_TEST_VECTORS
1492            }
1493        }
1494    }, {
1495        .alg = "cbc(aes)",
1496        .test = alg_test_skcipher,
1497        .fips_allowed = 1,
1498        .suite = {
1499            .cipher = {
1500                .enc = {
1501                    .vecs = aes_cbc_enc_tv_template,
1502                    .count = AES_CBC_ENC_TEST_VECTORS
1503                },
1504                .dec = {
1505                    .vecs = aes_cbc_dec_tv_template,
1506                    .count = AES_CBC_DEC_TEST_VECTORS
1507                }
1508            }
1509        }
1510    }, {
1511        .alg = "cbc(anubis)",
1512        .test = alg_test_skcipher,
1513        .suite = {
1514            .cipher = {
1515                .enc = {
1516                    .vecs = anubis_cbc_enc_tv_template,
1517                    .count = ANUBIS_CBC_ENC_TEST_VECTORS
1518                },
1519                .dec = {
1520                    .vecs = anubis_cbc_dec_tv_template,
1521                    .count = ANUBIS_CBC_DEC_TEST_VECTORS
1522                }
1523            }
1524        }
1525    }, {
1526        .alg = "cbc(blowfish)",
1527        .test = alg_test_skcipher,
1528        .suite = {
1529            .cipher = {
1530                .enc = {
1531                    .vecs = bf_cbc_enc_tv_template,
1532                    .count = BF_CBC_ENC_TEST_VECTORS
1533                },
1534                .dec = {
1535                    .vecs = bf_cbc_dec_tv_template,
1536                    .count = BF_CBC_DEC_TEST_VECTORS
1537                }
1538            }
1539        }
1540    }, {
1541        .alg = "cbc(camellia)",
1542        .test = alg_test_skcipher,
1543        .suite = {
1544            .cipher = {
1545                .enc = {
1546                    .vecs = camellia_cbc_enc_tv_template,
1547                    .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1548                },
1549                .dec = {
1550                    .vecs = camellia_cbc_dec_tv_template,
1551                    .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1552                }
1553            }
1554        }
1555    }, {
1556        .alg = "cbc(des)",
1557        .test = alg_test_skcipher,
1558        .suite = {
1559            .cipher = {
1560                .enc = {
1561                    .vecs = des_cbc_enc_tv_template,
1562                    .count = DES_CBC_ENC_TEST_VECTORS
1563                },
1564                .dec = {
1565                    .vecs = des_cbc_dec_tv_template,
1566                    .count = DES_CBC_DEC_TEST_VECTORS
1567                }
1568            }
1569        }
1570    }, {
1571        .alg = "cbc(des3_ede)",
1572        .test = alg_test_skcipher,
1573        .fips_allowed = 1,
1574        .suite = {
1575            .cipher = {
1576                .enc = {
1577                    .vecs = des3_ede_cbc_enc_tv_template,
1578                    .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1579                },
1580                .dec = {
1581                    .vecs = des3_ede_cbc_dec_tv_template,
1582                    .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1583                }
1584            }
1585        }
1586    }, {
1587        .alg = "cbc(twofish)",
1588        .test = alg_test_skcipher,
1589        .suite = {
1590            .cipher = {
1591                .enc = {
1592                    .vecs = tf_cbc_enc_tv_template,
1593                    .count = TF_CBC_ENC_TEST_VECTORS
1594                },
1595                .dec = {
1596                    .vecs = tf_cbc_dec_tv_template,
1597                    .count = TF_CBC_DEC_TEST_VECTORS
1598                }
1599            }
1600        }
1601    }, {
1602        .alg = "ccm(aes)",
1603        .test = alg_test_aead,
1604        .fips_allowed = 1,
1605        .suite = {
1606            .aead = {
1607                .enc = {
1608                    .vecs = aes_ccm_enc_tv_template,
1609                    .count = AES_CCM_ENC_TEST_VECTORS
1610                },
1611                .dec = {
1612                    .vecs = aes_ccm_dec_tv_template,
1613                    .count = AES_CCM_DEC_TEST_VECTORS
1614                }
1615            }
1616        }
1617    }, {
1618        .alg = "crc32c",
1619        .test = alg_test_crc32c,
1620        .fips_allowed = 1,
1621        .suite = {
1622            .hash = {
1623                .vecs = crc32c_tv_template,
1624                .count = CRC32C_TEST_VECTORS
1625            }
1626        }
1627    }, {
1628        .alg = "ctr(aes)",
1629        .test = alg_test_skcipher,
1630        .fips_allowed = 1,
1631        .suite = {
1632            .cipher = {
1633                .enc = {
1634                    .vecs = aes_ctr_enc_tv_template,
1635                    .count = AES_CTR_ENC_TEST_VECTORS
1636                },
1637                .dec = {
1638                    .vecs = aes_ctr_dec_tv_template,
1639                    .count = AES_CTR_DEC_TEST_VECTORS
1640                }
1641            }
1642        }
1643    }, {
1644        .alg = "cts(cbc(aes))",
1645        .test = alg_test_skcipher,
1646        .suite = {
1647            .cipher = {
1648                .enc = {
1649                    .vecs = cts_mode_enc_tv_template,
1650                    .count = CTS_MODE_ENC_TEST_VECTORS
1651                },
1652                .dec = {
1653                    .vecs = cts_mode_dec_tv_template,
1654                    .count = CTS_MODE_DEC_TEST_VECTORS
1655                }
1656            }
1657        }
1658    }, {
1659        .alg = "deflate",
1660        .test = alg_test_comp,
1661        .suite = {
1662            .comp = {
1663                .comp = {
1664                    .vecs = deflate_comp_tv_template,
1665                    .count = DEFLATE_COMP_TEST_VECTORS
1666                },
1667                .decomp = {
1668                    .vecs = deflate_decomp_tv_template,
1669                    .count = DEFLATE_DECOMP_TEST_VECTORS
1670                }
1671            }
1672        }
1673    }, {
1674        .alg = "ecb(aes)",
1675        .test = alg_test_skcipher,
1676        .fips_allowed = 1,
1677        .suite = {
1678            .cipher = {
1679                .enc = {
1680                    .vecs = aes_enc_tv_template,
1681                    .count = AES_ENC_TEST_VECTORS
1682                },
1683                .dec = {
1684                    .vecs = aes_dec_tv_template,
1685                    .count = AES_DEC_TEST_VECTORS
1686                }
1687            }
1688        }
1689    }, {
1690        .alg = "ecb(anubis)",
1691        .test = alg_test_skcipher,
1692        .suite = {
1693            .cipher = {
1694                .enc = {
1695                    .vecs = anubis_enc_tv_template,
1696                    .count = ANUBIS_ENC_TEST_VECTORS
1697                },
1698                .dec = {
1699                    .vecs = anubis_dec_tv_template,
1700                    .count = ANUBIS_DEC_TEST_VECTORS
1701                }
1702            }
1703        }
1704    }, {
1705        .alg = "ecb(arc4)",
1706        .test = alg_test_skcipher,
1707        .suite = {
1708            .cipher = {
1709                .enc = {
1710                    .vecs = arc4_enc_tv_template,
1711                    .count = ARC4_ENC_TEST_VECTORS
1712                },
1713                .dec = {
1714                    .vecs = arc4_dec_tv_template,
1715                    .count = ARC4_DEC_TEST_VECTORS
1716                }
1717            }
1718        }
1719    }, {
1720        .alg = "ecb(blowfish)",
1721        .test = alg_test_skcipher,
1722        .suite = {
1723            .cipher = {
1724                .enc = {
1725                    .vecs = bf_enc_tv_template,
1726                    .count = BF_ENC_TEST_VECTORS
1727                },
1728                .dec = {
1729                    .vecs = bf_dec_tv_template,
1730                    .count = BF_DEC_TEST_VECTORS
1731                }
1732            }
1733        }
1734    }, {
1735        .alg = "ecb(camellia)",
1736        .test = alg_test_skcipher,
1737        .suite = {
1738            .cipher = {
1739                .enc = {
1740                    .vecs = camellia_enc_tv_template,
1741                    .count = CAMELLIA_ENC_TEST_VECTORS
1742                },
1743                .dec = {
1744                    .vecs = camellia_dec_tv_template,
1745                    .count = CAMELLIA_DEC_TEST_VECTORS
1746                }
1747            }
1748        }
1749    }, {
1750        .alg = "ecb(cast5)",
1751        .test = alg_test_skcipher,
1752        .suite = {
1753            .cipher = {
1754                .enc = {
1755                    .vecs = cast5_enc_tv_template,
1756                    .count = CAST5_ENC_TEST_VECTORS
1757                },
1758                .dec = {
1759                    .vecs = cast5_dec_tv_template,
1760                    .count = CAST5_DEC_TEST_VECTORS
1761                }
1762            }
1763        }
1764    }, {
1765        .alg = "ecb(cast6)",
1766        .test = alg_test_skcipher,
1767        .suite = {
1768            .cipher = {
1769                .enc = {
1770                    .vecs = cast6_enc_tv_template,
1771                    .count = CAST6_ENC_TEST_VECTORS
1772                },
1773                .dec = {
1774                    .vecs = cast6_dec_tv_template,
1775                    .count = CAST6_DEC_TEST_VECTORS
1776                }
1777            }
1778        }
1779    }, {
1780        .alg = "ecb(des)",
1781        .test = alg_test_skcipher,
1782        .fips_allowed = 1,
1783        .suite = {
1784            .cipher = {
1785                .enc = {
1786                    .vecs = des_enc_tv_template,
1787                    .count = DES_ENC_TEST_VECTORS
1788                },
1789                .dec = {
1790                    .vecs = des_dec_tv_template,
1791                    .count = DES_DEC_TEST_VECTORS
1792                }
1793            }
1794        }
1795    }, {
1796        .alg = "ecb(des3_ede)",
1797        .test = alg_test_skcipher,
1798        .fips_allowed = 1,
1799        .suite = {
1800            .cipher = {
1801                .enc = {
1802                    .vecs = des3_ede_enc_tv_template,
1803                    .count = DES3_EDE_ENC_TEST_VECTORS
1804                },
1805                .dec = {
1806                    .vecs = des3_ede_dec_tv_template,
1807                    .count = DES3_EDE_DEC_TEST_VECTORS
1808                }
1809            }
1810        }
1811    }, {
1812        .alg = "ecb(khazad)",
1813        .test = alg_test_skcipher,
1814        .suite = {
1815            .cipher = {
1816                .enc = {
1817                    .vecs = khazad_enc_tv_template,
1818                    .count = KHAZAD_ENC_TEST_VECTORS
1819                },
1820                .dec = {
1821                    .vecs = khazad_dec_tv_template,
1822                    .count = KHAZAD_DEC_TEST_VECTORS
1823                }
1824            }
1825        }
1826    }, {
1827        .alg = "ecb(seed)",
1828        .test = alg_test_skcipher,
1829        .suite = {
1830            .cipher = {
1831                .enc = {
1832                    .vecs = seed_enc_tv_template,
1833                    .count = SEED_ENC_TEST_VECTORS
1834                },
1835                .dec = {
1836                    .vecs = seed_dec_tv_template,
1837                    .count = SEED_DEC_TEST_VECTORS
1838                }
1839            }
1840        }
1841    }, {
1842        .alg = "ecb(serpent)",
1843        .test = alg_test_skcipher,
1844        .suite = {
1845            .cipher = {
1846                .enc = {
1847                    .vecs = serpent_enc_tv_template,
1848                    .count = SERPENT_ENC_TEST_VECTORS
1849                },
1850                .dec = {
1851                    .vecs = serpent_dec_tv_template,
1852                    .count = SERPENT_DEC_TEST_VECTORS
1853                }
1854            }
1855        }
1856    }, {
1857        .alg = "ecb(tea)",
1858        .test = alg_test_skcipher,
1859        .suite = {
1860            .cipher = {
1861                .enc = {
1862                    .vecs = tea_enc_tv_template,
1863                    .count = TEA_ENC_TEST_VECTORS
1864                },
1865                .dec = {
1866                    .vecs = tea_dec_tv_template,
1867                    .count = TEA_DEC_TEST_VECTORS
1868                }
1869            }
1870        }
1871    }, {
1872        .alg = "ecb(tnepres)",
1873        .test = alg_test_skcipher,
1874        .suite = {
1875            .cipher = {
1876                .enc = {
1877                    .vecs = tnepres_enc_tv_template,
1878                    .count = TNEPRES_ENC_TEST_VECTORS
1879                },
1880                .dec = {
1881                    .vecs = tnepres_dec_tv_template,
1882                    .count = TNEPRES_DEC_TEST_VECTORS
1883                }
1884            }
1885        }
1886    }, {
1887        .alg = "ecb(twofish)",
1888        .test = alg_test_skcipher,
1889        .suite = {
1890            .cipher = {
1891                .enc = {
1892                    .vecs = tf_enc_tv_template,
1893                    .count = TF_ENC_TEST_VECTORS
1894                },
1895                .dec = {
1896                    .vecs = tf_dec_tv_template,
1897                    .count = TF_DEC_TEST_VECTORS
1898                }
1899            }
1900        }
1901    }, {
1902        .alg = "ecb(xeta)",
1903        .test = alg_test_skcipher,
1904        .suite = {
1905            .cipher = {
1906                .enc = {
1907                    .vecs = xeta_enc_tv_template,
1908                    .count = XETA_ENC_TEST_VECTORS
1909                },
1910                .dec = {
1911                    .vecs = xeta_dec_tv_template,
1912                    .count = XETA_DEC_TEST_VECTORS
1913                }
1914            }
1915        }
1916    }, {
1917        .alg = "ecb(xtea)",
1918        .test = alg_test_skcipher,
1919        .suite = {
1920            .cipher = {
1921                .enc = {
1922                    .vecs = xtea_enc_tv_template,
1923                    .count = XTEA_ENC_TEST_VECTORS
1924                },
1925                .dec = {
1926                    .vecs = xtea_dec_tv_template,
1927                    .count = XTEA_DEC_TEST_VECTORS
1928                }
1929            }
1930        }
1931    }, {
1932        .alg = "gcm(aes)",
1933        .test = alg_test_aead,
1934        .fips_allowed = 1,
1935        .suite = {
1936            .aead = {
1937                .enc = {
1938                    .vecs = aes_gcm_enc_tv_template,
1939                    .count = AES_GCM_ENC_TEST_VECTORS
1940                },
1941                .dec = {
1942                    .vecs = aes_gcm_dec_tv_template,
1943                    .count = AES_GCM_DEC_TEST_VECTORS
1944                }
1945            }
1946        }
1947    }, {
1948        .alg = "hmac(md5)",
1949        .test = alg_test_hash,
1950        .suite = {
1951            .hash = {
1952                .vecs = hmac_md5_tv_template,
1953                .count = HMAC_MD5_TEST_VECTORS
1954            }
1955        }
1956    }, {
1957        .alg = "hmac(rmd128)",
1958        .test = alg_test_hash,
1959        .suite = {
1960            .hash = {
1961                .vecs = hmac_rmd128_tv_template,
1962                .count = HMAC_RMD128_TEST_VECTORS
1963            }
1964        }
1965    }, {
1966        .alg = "hmac(rmd160)",
1967        .test = alg_test_hash,
1968        .suite = {
1969            .hash = {
1970                .vecs = hmac_rmd160_tv_template,
1971                .count = HMAC_RMD160_TEST_VECTORS
1972            }
1973        }
1974    }, {
1975        .alg = "hmac(sha1)",
1976        .test = alg_test_hash,
1977        .fips_allowed = 1,
1978        .suite = {
1979            .hash = {
1980                .vecs = hmac_sha1_tv_template,
1981                .count = HMAC_SHA1_TEST_VECTORS
1982            }
1983        }
1984    }, {
1985        .alg = "hmac(sha224)",
1986        .test = alg_test_hash,
1987        .fips_allowed = 1,
1988        .suite = {
1989            .hash = {
1990                .vecs = hmac_sha224_tv_template,
1991                .count = HMAC_SHA224_TEST_VECTORS
1992            }
1993        }
1994    }, {
1995        .alg = "hmac(sha256)",
1996        .test = alg_test_hash,
1997        .fips_allowed = 1,
1998        .suite = {
1999            .hash = {
2000                .vecs = hmac_sha256_tv_template,
2001                .count = HMAC_SHA256_TEST_VECTORS
2002            }
2003        }
2004    }, {
2005        .alg = "hmac(sha384)",
2006        .test = alg_test_hash,
2007        .fips_allowed = 1,
2008        .suite = {
2009            .hash = {
2010                .vecs = hmac_sha384_tv_template,
2011                .count = HMAC_SHA384_TEST_VECTORS
2012            }
2013        }
2014    }, {
2015        .alg = "hmac(sha512)",
2016        .test = alg_test_hash,
2017        .fips_allowed = 1,
2018        .suite = {
2019            .hash = {
2020                .vecs = hmac_sha512_tv_template,
2021                .count = HMAC_SHA512_TEST_VECTORS
2022            }
2023        }
2024    }, {
2025        .alg = "lrw(aes)",
2026        .test = alg_test_skcipher,
2027        .suite = {
2028            .cipher = {
2029                .enc = {
2030                    .vecs = aes_lrw_enc_tv_template,
2031                    .count = AES_LRW_ENC_TEST_VECTORS
2032                },
2033                .dec = {
2034                    .vecs = aes_lrw_dec_tv_template,
2035                    .count = AES_LRW_DEC_TEST_VECTORS
2036                }
2037            }
2038        }
2039    }, {
2040        .alg = "lzo",
2041        .test = alg_test_comp,
2042        .suite = {
2043            .comp = {
2044                .comp = {
2045                    .vecs = lzo_comp_tv_template,
2046                    .count = LZO_COMP_TEST_VECTORS
2047                },
2048                .decomp = {
2049                    .vecs = lzo_decomp_tv_template,
2050                    .count = LZO_DECOMP_TEST_VECTORS
2051                }
2052            }
2053        }
2054    }, {
2055        .alg = "md4",
2056        .test = alg_test_hash,
2057        .suite = {
2058            .hash = {
2059                .vecs = md4_tv_template,
2060                .count = MD4_TEST_VECTORS
2061            }
2062        }
2063    }, {
2064        .alg = "md5",
2065        .test = alg_test_hash,
2066        .suite = {
2067            .hash = {
2068                .vecs = md5_tv_template,
2069                .count = MD5_TEST_VECTORS
2070            }
2071        }
2072    }, {
2073        .alg = "michael_mic",
2074        .test = alg_test_hash,
2075        .suite = {
2076            .hash = {
2077                .vecs = michael_mic_tv_template,
2078                .count = MICHAEL_MIC_TEST_VECTORS
2079            }
2080        }
2081    }, {
2082        .alg = "pcbc(fcrypt)",
2083        .test = alg_test_skcipher,
2084        .suite = {
2085            .cipher = {
2086                .enc = {
2087                    .vecs = fcrypt_pcbc_enc_tv_template,
2088                    .count = FCRYPT_ENC_TEST_VECTORS
2089                },
2090                .dec = {
2091                    .vecs = fcrypt_pcbc_dec_tv_template,
2092                    .count = FCRYPT_DEC_TEST_VECTORS
2093                }
2094            }
2095        }
2096    }, {
2097        .alg = "rfc3686(ctr(aes))",
2098        .test = alg_test_skcipher,
2099        .fips_allowed = 1,
2100        .suite = {
2101            .cipher = {
2102                .enc = {
2103                    .vecs = aes_ctr_rfc3686_enc_tv_template,
2104                    .count = AES_CTR_3686_ENC_TEST_VECTORS
2105                },
2106                .dec = {
2107                    .vecs = aes_ctr_rfc3686_dec_tv_template,
2108                    .count = AES_CTR_3686_DEC_TEST_VECTORS
2109                }
2110            }
2111        }
2112    }, {
2113        .alg = "rfc4309(ccm(aes))",
2114        .test = alg_test_aead,
2115        .fips_allowed = 1,
2116        .suite = {
2117            .aead = {
2118                .enc = {
2119                    .vecs = aes_ccm_rfc4309_enc_tv_template,
2120                    .count = AES_CCM_4309_ENC_TEST_VECTORS
2121                },
2122                .dec = {
2123                    .vecs = aes_ccm_rfc4309_dec_tv_template,
2124                    .count = AES_CCM_4309_DEC_TEST_VECTORS
2125                }
2126            }
2127        }
2128    }, {
2129        .alg = "rmd128",
2130        .test = alg_test_hash,
2131        .suite = {
2132            .hash = {
2133                .vecs = rmd128_tv_template,
2134                .count = RMD128_TEST_VECTORS
2135            }
2136        }
2137    }, {
2138        .alg = "rmd160",
2139        .test = alg_test_hash,
2140        .suite = {
2141            .hash = {
2142                .vecs = rmd160_tv_template,
2143                .count = RMD160_TEST_VECTORS
2144            }
2145        }
2146    }, {
2147        .alg = "rmd256",
2148        .test = alg_test_hash,
2149        .suite = {
2150            .hash = {
2151                .vecs = rmd256_tv_template,
2152                .count = RMD256_TEST_VECTORS
2153            }
2154        }
2155    }, {
2156        .alg = "rmd320",
2157        .test = alg_test_hash,
2158        .suite = {
2159            .hash = {
2160                .vecs = rmd320_tv_template,
2161                .count = RMD320_TEST_VECTORS
2162            }
2163        }
2164    }, {
2165        .alg = "salsa20",
2166        .test = alg_test_skcipher,
2167        .suite = {
2168            .cipher = {
2169                .enc = {
2170                    .vecs = salsa20_stream_enc_tv_template,
2171                    .count = SALSA20_STREAM_ENC_TEST_VECTORS
2172                }
2173            }
2174        }
2175    }, {
2176        .alg = "sha1",
2177        .test = alg_test_hash,
2178        .fips_allowed = 1,
2179        .suite = {
2180            .hash = {
2181                .vecs = sha1_tv_template,
2182                .count = SHA1_TEST_VECTORS
2183            }
2184        }
2185    }, {
2186        .alg = "sha224",
2187        .test = alg_test_hash,
2188        .fips_allowed = 1,
2189        .suite = {
2190            .hash = {
2191                .vecs = sha224_tv_template,
2192                .count = SHA224_TEST_VECTORS
2193            }
2194        }
2195    }, {
2196        .alg = "sha256",
2197        .test = alg_test_hash,
2198        .fips_allowed = 1,
2199        .suite = {
2200            .hash = {
2201                .vecs = sha256_tv_template,
2202                .count = SHA256_TEST_VECTORS
2203            }
2204        }
2205    }, {
2206        .alg = "sha384",
2207        .test = alg_test_hash,
2208        .fips_allowed = 1,
2209        .suite = {
2210            .hash = {
2211                .vecs = sha384_tv_template,
2212                .count = SHA384_TEST_VECTORS
2213            }
2214        }
2215    }, {
2216        .alg = "sha512",
2217        .test = alg_test_hash,
2218        .fips_allowed = 1,
2219        .suite = {
2220            .hash = {
2221                .vecs = sha512_tv_template,
2222                .count = SHA512_TEST_VECTORS
2223            }
2224        }
2225    }, {
2226        .alg = "tgr128",
2227        .test = alg_test_hash,
2228        .suite = {
2229            .hash = {
2230                .vecs = tgr128_tv_template,
2231                .count = TGR128_TEST_VECTORS
2232            }
2233        }
2234    }, {
2235        .alg = "tgr160",
2236        .test = alg_test_hash,
2237        .suite = {
2238            .hash = {
2239                .vecs = tgr160_tv_template,
2240                .count = TGR160_TEST_VECTORS
2241            }
2242        }
2243    }, {
2244        .alg = "tgr192",
2245        .test = alg_test_hash,
2246        .suite = {
2247            .hash = {
2248                .vecs = tgr192_tv_template,
2249                .count = TGR192_TEST_VECTORS
2250            }
2251        }
2252    }, {
2253        .alg = "vmac(aes)",
2254        .test = alg_test_hash,
2255        .suite = {
2256            .hash = {
2257                .vecs = aes_vmac128_tv_template,
2258                .count = VMAC_AES_TEST_VECTORS
2259            }
2260        }
2261    }, {
2262        .alg = "wp256",
2263        .test = alg_test_hash,
2264        .suite = {
2265            .hash = {
2266                .vecs = wp256_tv_template,
2267                .count = WP256_TEST_VECTORS
2268            }
2269        }
2270    }, {
2271        .alg = "wp384",
2272        .test = alg_test_hash,
2273        .suite = {
2274            .hash = {
2275                .vecs = wp384_tv_template,
2276                .count = WP384_TEST_VECTORS
2277            }
2278        }
2279    }, {
2280        .alg = "wp512",
2281        .test = alg_test_hash,
2282        .suite = {
2283            .hash = {
2284                .vecs = wp512_tv_template,
2285                .count = WP512_TEST_VECTORS
2286            }
2287        }
2288    }, {
2289        .alg = "xcbc(aes)",
2290        .test = alg_test_hash,
2291        .suite = {
2292            .hash = {
2293                .vecs = aes_xcbc128_tv_template,
2294                .count = XCBC_AES_TEST_VECTORS
2295            }
2296        }
2297    }, {
2298        .alg = "xts(aes)",
2299        .test = alg_test_skcipher,
2300        .suite = {
2301            .cipher = {
2302                .enc = {
2303                    .vecs = aes_xts_enc_tv_template,
2304                    .count = AES_XTS_ENC_TEST_VECTORS
2305                },
2306                .dec = {
2307                    .vecs = aes_xts_dec_tv_template,
2308                    .count = AES_XTS_DEC_TEST_VECTORS
2309                }
2310            }
2311        }
2312    }, {
2313        .alg = "zlib",
2314        .test = alg_test_pcomp,
2315        .suite = {
2316            .pcomp = {
2317                .comp = {
2318                    .vecs = zlib_comp_tv_template,
2319                    .count = ZLIB_COMP_TEST_VECTORS
2320                },
2321                .decomp = {
2322                    .vecs = zlib_decomp_tv_template,
2323                    .count = ZLIB_DECOMP_TEST_VECTORS
2324                }
2325            }
2326        }
2327    }
2328};
2329
2330static int alg_find_test(const char *alg)
2331{
2332    int start = 0;
2333    int end = ARRAY_SIZE(alg_test_descs);
2334
2335    while (start < end) {
2336        int i = (start + end) / 2;
2337        int diff = strcmp(alg_test_descs[i].alg, alg);
2338
2339        if (diff > 0) {
2340            end = i;
2341            continue;
2342        }
2343
2344        if (diff < 0) {
2345            start = i + 1;
2346            continue;
2347        }
2348
2349        return i;
2350    }
2351
2352    return -1;
2353}
2354
2355#endif /* CONFIG_CRYPTO_MANAGER_NO_TESTS */
2356
2357int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
2358{
2359#ifndef CONFIG_CRYPTO_MANAGER_NO_TESTS
2360    int i;
2361    int j;
2362    int rc;
2363
2364    if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
2365        char nalg[CRYPTO_MAX_ALG_NAME];
2366
2367        if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
2368            sizeof(nalg))
2369            return -ENAMETOOLONG;
2370
2371        i = alg_find_test(nalg);
2372        if (i < 0)
2373            goto notest;
2374
2375        if (fips_enabled && !alg_test_descs[i].fips_allowed)
2376            goto non_fips_alg;
2377
2378        rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
2379        goto test_done;
2380    }
2381
2382    i = alg_find_test(alg);
2383    j = alg_find_test(driver);
2384    if (i < 0 && j < 0)
2385        goto notest;
2386
2387    if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
2388                 (j >= 0 && !alg_test_descs[j].fips_allowed)))
2389        goto non_fips_alg;
2390
2391    rc = 0;
2392    if (i >= 0)
2393        rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
2394                         type, mask);
2395    if (j >= 0)
2396        rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
2397                         type, mask);
2398
2399test_done:
2400    if (fips_enabled && rc)
2401        panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
2402
2403    if (fips_enabled && !rc)
2404        printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
2405               driver, alg);
2406
2407    return rc;
2408
2409notest:
2410    printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
2411    return 0;
2412non_fips_alg:
2413    return -EINVAL;
2414#else /* CONFIG_CRYPTO_MANAGER_NO_TESTS */
2415    return 0;
2416#endif /* CONFIG_CRYPTO_MANAGER_NO_TESTS */
2417}
2418EXPORT_SYMBOL_GPL(alg_test);
2419

Archive Download this file



interactive