2 * Algorithm testing framework and tests.
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>
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.
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)
23 #include <crypto/hash.h>
24 #include <linux/err.h>
25 #include <linux/module.h>
26 #include <linux/scatterlist.h>
27 #include <linux/slab.h>
28 #include <linux/string.h>
29 #include <crypto/rng.h>
30 #include <crypto/drbg.h>
34 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
37 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
47 * Need slab memory for testing (size in number of pages).
52 * Indexes into the xbuf to simulate cross-page access.
64 * Used by test_cipher()
69 struct tcrypt_result
{
70 struct completion completion
;
74 struct aead_test_suite
{
76 struct aead_testvec
*vecs
;
81 struct cipher_test_suite
{
83 struct cipher_testvec
*vecs
;
88 struct comp_test_suite
{
90 struct comp_testvec
*vecs
;
95 struct pcomp_test_suite
{
97 struct pcomp_testvec
*vecs
;
102 struct hash_test_suite
{
103 struct hash_testvec
*vecs
;
107 struct cprng_test_suite
{
108 struct cprng_testvec
*vecs
;
112 struct drbg_test_suite
{
113 struct drbg_testvec
*vecs
;
117 struct alg_test_desc
{
119 int (*test
)(const struct alg_test_desc
*desc
, const char *driver
,
121 int fips_allowed
; /* set if alg is allowed in fips mode */
124 struct aead_test_suite aead
;
125 struct cipher_test_suite cipher
;
126 struct comp_test_suite comp
;
127 struct pcomp_test_suite pcomp
;
128 struct hash_test_suite hash
;
129 struct cprng_test_suite cprng
;
130 struct drbg_test_suite drbg
;
134 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
136 static void hexdump(unsigned char *buf
, unsigned int len
)
138 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
143 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
145 struct tcrypt_result
*res
= req
->data
;
147 if (err
== -EINPROGRESS
)
151 complete(&res
->completion
);
154 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
158 for (i
= 0; i
< XBUFSIZE
; i
++) {
159 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
168 free_page((unsigned long)buf
[i
]);
173 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
177 for (i
= 0; i
< XBUFSIZE
; i
++)
178 free_page((unsigned long)buf
[i
]);
181 static int wait_async_op(struct tcrypt_result
*tr
, int ret
)
183 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
184 wait_for_completion(&tr
->completion
);
185 reinit_completion(&tr
->completion
);
191 static int __test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
192 unsigned int tcount
, bool use_digest
,
193 const int align_offset
)
195 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
196 unsigned int i
, j
, k
, temp
;
197 struct scatterlist sg
[8];
200 struct ahash_request
*req
;
201 struct tcrypt_result tresult
;
203 char *xbuf
[XBUFSIZE
];
206 result
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
209 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
212 if (testmgr_alloc_buf(xbuf
))
215 init_completion(&tresult
.completion
);
217 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
219 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
223 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
224 tcrypt_complete
, &tresult
);
227 for (i
= 0; i
< tcount
; i
++) {
232 if (WARN_ON(align_offset
+ template[i
].psize
> PAGE_SIZE
))
236 memset(result
, 0, MAX_DIGEST_SIZE
);
239 hash_buff
+= align_offset
;
241 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
242 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
244 if (template[i
].ksize
) {
245 crypto_ahash_clear_flags(tfm
, ~0);
246 if (template[i
].ksize
> MAX_KEYLEN
) {
247 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
248 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
252 memcpy(key
, template[i
].key
, template[i
].ksize
);
253 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
255 printk(KERN_ERR
"alg: hash: setkey failed on "
256 "test %d for %s: ret=%d\n", j
, algo
,
262 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
264 ret
= wait_async_op(&tresult
, crypto_ahash_digest(req
));
266 pr_err("alg: hash: digest failed on test %d "
267 "for %s: ret=%d\n", j
, algo
, -ret
);
271 ret
= wait_async_op(&tresult
, crypto_ahash_init(req
));
273 pr_err("alt: hash: init failed on test %d "
274 "for %s: ret=%d\n", j
, algo
, -ret
);
277 ret
= wait_async_op(&tresult
, crypto_ahash_update(req
));
279 pr_err("alt: hash: update failed on test %d "
280 "for %s: ret=%d\n", j
, algo
, -ret
);
283 ret
= wait_async_op(&tresult
, crypto_ahash_final(req
));
285 pr_err("alt: hash: final failed on test %d "
286 "for %s: ret=%d\n", j
, algo
, -ret
);
291 if (memcmp(result
, template[i
].digest
,
292 crypto_ahash_digestsize(tfm
))) {
293 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
295 hexdump(result
, crypto_ahash_digestsize(tfm
));
302 for (i
= 0; i
< tcount
; i
++) {
303 /* alignment tests are only done with continuous buffers */
304 if (align_offset
!= 0)
311 memset(result
, 0, MAX_DIGEST_SIZE
);
314 sg_init_table(sg
, template[i
].np
);
316 for (k
= 0; k
< template[i
].np
; k
++) {
317 if (WARN_ON(offset_in_page(IDX
[k
]) +
318 template[i
].tap
[k
] > PAGE_SIZE
))
321 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
322 offset_in_page(IDX
[k
]),
323 template[i
].plaintext
+ temp
,
326 temp
+= template[i
].tap
[k
];
329 if (template[i
].ksize
) {
330 if (template[i
].ksize
> MAX_KEYLEN
) {
331 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
332 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
336 crypto_ahash_clear_flags(tfm
, ~0);
337 memcpy(key
, template[i
].key
, template[i
].ksize
);
338 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
341 printk(KERN_ERR
"alg: hash: setkey "
342 "failed on chunking test %d "
343 "for %s: ret=%d\n", j
, algo
, -ret
);
348 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
349 ret
= crypto_ahash_digest(req
);
355 wait_for_completion(&tresult
.completion
);
356 reinit_completion(&tresult
.completion
);
362 printk(KERN_ERR
"alg: hash: digest failed "
363 "on chunking test %d for %s: "
364 "ret=%d\n", j
, algo
, -ret
);
368 if (memcmp(result
, template[i
].digest
,
369 crypto_ahash_digestsize(tfm
))) {
370 printk(KERN_ERR
"alg: hash: Chunking test %d "
371 "failed for %s\n", j
, algo
);
372 hexdump(result
, crypto_ahash_digestsize(tfm
));
381 ahash_request_free(req
);
383 testmgr_free_buf(xbuf
);
390 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
391 unsigned int tcount
, bool use_digest
)
393 unsigned int alignmask
;
396 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 0);
400 /* test unaligned buffers, check with one byte offset */
401 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 1);
405 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
407 /* Check if alignment mask for tfm is correctly set. */
408 ret
= __test_hash(tfm
, template, tcount
, use_digest
,
417 static int __test_aead(struct crypto_aead
*tfm
, int enc
,
418 struct aead_testvec
*template, unsigned int tcount
,
419 const bool diff_dst
, const int align_offset
)
421 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
422 unsigned int i
, j
, k
, n
, temp
;
426 struct aead_request
*req
;
427 struct scatterlist
*sg
;
428 struct scatterlist
*asg
;
429 struct scatterlist
*sgout
;
431 struct tcrypt_result result
;
432 unsigned int authsize
;
437 char *xbuf
[XBUFSIZE
];
438 char *xoutbuf
[XBUFSIZE
];
439 char *axbuf
[XBUFSIZE
];
441 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
444 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
447 if (testmgr_alloc_buf(xbuf
))
449 if (testmgr_alloc_buf(axbuf
))
451 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
454 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
455 sg
= kmalloc(sizeof(*sg
) * 8 * (diff_dst
? 3 : 2), GFP_KERNEL
);
471 init_completion(&result
.completion
);
473 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
475 pr_err("alg: aead%s: Failed to allocate request for %s\n",
480 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
481 tcrypt_complete
, &result
);
483 for (i
= 0, j
= 0; i
< tcount
; i
++) {
489 /* some templates have no input data but they will
493 input
+= align_offset
;
497 if (WARN_ON(align_offset
+ template[i
].ilen
>
498 PAGE_SIZE
|| template[i
].alen
> PAGE_SIZE
))
501 memcpy(input
, template[i
].input
, template[i
].ilen
);
502 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
504 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
506 memset(iv
, 0, MAX_IVLEN
);
508 crypto_aead_clear_flags(tfm
, ~0);
510 crypto_aead_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
512 if (template[i
].klen
> MAX_KEYLEN
) {
513 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
514 d
, j
, algo
, template[i
].klen
,
519 memcpy(key
, template[i
].key
, template[i
].klen
);
521 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
522 if (!ret
== template[i
].fail
) {
523 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
524 d
, j
, algo
, crypto_aead_get_flags(tfm
));
529 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
530 ret
= crypto_aead_setauthsize(tfm
, authsize
);
532 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
533 d
, authsize
, j
, algo
);
539 output
+= align_offset
;
540 sg_init_one(&sg
[0], input
, template[i
].ilen
);
541 sg_init_one(&sgout
[0], output
, template[i
].rlen
);
543 sg_init_one(&sg
[0], input
,
544 template[i
].ilen
+ (enc
? authsize
: 0));
548 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
550 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
551 template[i
].ilen
, iv
);
553 aead_request_set_assoc(req
, asg
, template[i
].alen
);
555 ret
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
559 if (template[i
].novrfy
) {
560 /* verification was supposed to fail */
561 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
563 /* so really, we got a bad message */
570 wait_for_completion(&result
.completion
);
571 reinit_completion(&result
.completion
);
576 if (template[i
].novrfy
)
577 /* verification failure was expected */
581 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
582 d
, e
, j
, algo
, -ret
);
587 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
588 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
590 hexdump(q
, template[i
].rlen
);
596 for (i
= 0, j
= 0; i
< tcount
; i
++) {
597 /* alignment tests are only done with continuous buffers */
598 if (align_offset
!= 0)
607 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
609 memset(iv
, 0, MAX_IVLEN
);
611 crypto_aead_clear_flags(tfm
, ~0);
613 crypto_aead_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
614 if (template[i
].klen
> MAX_KEYLEN
) {
615 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
616 d
, j
, algo
, template[i
].klen
, MAX_KEYLEN
);
620 memcpy(key
, template[i
].key
, template[i
].klen
);
622 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
623 if (!ret
== template[i
].fail
) {
624 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
625 d
, j
, algo
, crypto_aead_get_flags(tfm
));
630 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
633 sg_init_table(sg
, template[i
].np
);
635 sg_init_table(sgout
, template[i
].np
);
636 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
637 if (WARN_ON(offset_in_page(IDX
[k
]) +
638 template[i
].tap
[k
] > PAGE_SIZE
))
641 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] + offset_in_page(IDX
[k
]);
642 memcpy(q
, template[i
].input
+ temp
, template[i
].tap
[k
]);
643 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
646 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
647 offset_in_page(IDX
[k
]);
649 memset(q
, 0, template[i
].tap
[k
]);
651 sg_set_buf(&sgout
[k
], q
, template[i
].tap
[k
]);
654 n
= template[i
].tap
[k
];
655 if (k
== template[i
].np
- 1 && enc
)
657 if (offset_in_page(q
) + n
< PAGE_SIZE
)
660 temp
+= template[i
].tap
[k
];
663 ret
= crypto_aead_setauthsize(tfm
, authsize
);
665 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
666 d
, authsize
, j
, algo
);
671 if (WARN_ON(sg
[k
- 1].offset
+
672 sg
[k
- 1].length
+ authsize
>
679 sgout
[k
- 1].length
+= authsize
;
681 sg
[k
- 1].length
+= authsize
;
684 sg_init_table(asg
, template[i
].anp
);
686 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
687 if (WARN_ON(offset_in_page(IDX
[k
]) +
688 template[i
].atap
[k
] > PAGE_SIZE
))
691 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
692 offset_in_page(IDX
[k
]),
693 template[i
].assoc
+ temp
,
694 template[i
].atap
[k
]),
695 template[i
].atap
[k
]);
696 temp
+= template[i
].atap
[k
];
699 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
703 aead_request_set_assoc(req
, asg
, template[i
].alen
);
705 ret
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
709 if (template[i
].novrfy
) {
710 /* verification was supposed to fail */
711 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
713 /* so really, we got a bad message */
720 wait_for_completion(&result
.completion
);
721 reinit_completion(&result
.completion
);
726 if (template[i
].novrfy
)
727 /* verification failure was expected */
731 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
732 d
, e
, j
, algo
, -ret
);
737 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
739 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
740 offset_in_page(IDX
[k
]);
742 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
743 offset_in_page(IDX
[k
]);
745 n
= template[i
].tap
[k
];
746 if (k
== template[i
].np
- 1)
747 n
+= enc
? authsize
: -authsize
;
749 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
750 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
757 if (k
== template[i
].np
- 1 && !enc
) {
759 memcmp(q
, template[i
].input
+
765 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
769 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
770 d
, j
, e
, k
, algo
, n
);
775 temp
+= template[i
].tap
[k
];
782 aead_request_free(req
);
786 testmgr_free_buf(xoutbuf
);
788 testmgr_free_buf(axbuf
);
790 testmgr_free_buf(xbuf
);
797 static int test_aead(struct crypto_aead
*tfm
, int enc
,
798 struct aead_testvec
*template, unsigned int tcount
)
800 unsigned int alignmask
;
803 /* test 'dst == src' case */
804 ret
= __test_aead(tfm
, enc
, template, tcount
, false, 0);
808 /* test 'dst != src' case */
809 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 0);
813 /* test unaligned buffers, check with one byte offset */
814 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 1);
818 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
820 /* Check if alignment mask for tfm is correctly set. */
821 ret
= __test_aead(tfm
, enc
, template, tcount
, true,
830 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
831 struct cipher_testvec
*template, unsigned int tcount
)
833 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
834 unsigned int i
, j
, k
;
838 char *xbuf
[XBUFSIZE
];
841 if (testmgr_alloc_buf(xbuf
))
850 for (i
= 0; i
< tcount
; i
++) {
857 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
861 memcpy(data
, template[i
].input
, template[i
].ilen
);
863 crypto_cipher_clear_flags(tfm
, ~0);
865 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
867 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
869 if (!ret
== template[i
].fail
) {
870 printk(KERN_ERR
"alg: cipher: setkey failed "
871 "on test %d for %s: flags=%x\n", j
,
872 algo
, crypto_cipher_get_flags(tfm
));
877 for (k
= 0; k
< template[i
].ilen
;
878 k
+= crypto_cipher_blocksize(tfm
)) {
880 crypto_cipher_encrypt_one(tfm
, data
+ k
,
883 crypto_cipher_decrypt_one(tfm
, data
+ k
,
888 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
889 printk(KERN_ERR
"alg: cipher: Test %d failed "
890 "on %s for %s\n", j
, e
, algo
);
891 hexdump(q
, template[i
].rlen
);
900 testmgr_free_buf(xbuf
);
905 static int __test_skcipher(struct crypto_ablkcipher
*tfm
, int enc
,
906 struct cipher_testvec
*template, unsigned int tcount
,
907 const bool diff_dst
, const int align_offset
)
910 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm
));
911 unsigned int i
, j
, k
, n
, temp
;
913 struct ablkcipher_request
*req
;
914 struct scatterlist sg
[8];
915 struct scatterlist sgout
[8];
917 struct tcrypt_result result
;
920 char *xbuf
[XBUFSIZE
];
921 char *xoutbuf
[XBUFSIZE
];
924 if (testmgr_alloc_buf(xbuf
))
927 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
940 init_completion(&result
.completion
);
942 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
944 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
949 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
950 tcrypt_complete
, &result
);
953 for (i
= 0; i
< tcount
; i
++) {
954 if (template[i
].np
&& !template[i
].also_non_np
)
958 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
960 memset(iv
, 0, MAX_IVLEN
);
964 if (WARN_ON(align_offset
+ template[i
].ilen
> PAGE_SIZE
))
968 data
+= align_offset
;
969 memcpy(data
, template[i
].input
, template[i
].ilen
);
971 crypto_ablkcipher_clear_flags(tfm
, ~0);
973 crypto_ablkcipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
975 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
977 if (!ret
== template[i
].fail
) {
978 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
979 d
, j
, algo
, crypto_ablkcipher_get_flags(tfm
));
984 sg_init_one(&sg
[0], data
, template[i
].ilen
);
987 data
+= align_offset
;
988 sg_init_one(&sgout
[0], data
, template[i
].ilen
);
991 ablkcipher_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
992 template[i
].ilen
, iv
);
993 ret
= enc
? crypto_ablkcipher_encrypt(req
) :
994 crypto_ablkcipher_decrypt(req
);
1001 wait_for_completion(&result
.completion
);
1002 reinit_completion(&result
.completion
);
1008 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1009 d
, e
, j
, algo
, -ret
);
1014 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
1015 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1017 hexdump(q
, template[i
].rlen
);
1024 for (i
= 0; i
< tcount
; i
++) {
1025 /* alignment tests are only done with continuous buffers */
1026 if (align_offset
!= 0)
1029 if (!template[i
].np
)
1033 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
1035 memset(iv
, 0, MAX_IVLEN
);
1038 crypto_ablkcipher_clear_flags(tfm
, ~0);
1040 crypto_ablkcipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
1042 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
1044 if (!ret
== template[i
].fail
) {
1045 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1046 d
, j
, algo
, crypto_ablkcipher_get_flags(tfm
));
1053 sg_init_table(sg
, template[i
].np
);
1055 sg_init_table(sgout
, template[i
].np
);
1056 for (k
= 0; k
< template[i
].np
; k
++) {
1057 if (WARN_ON(offset_in_page(IDX
[k
]) +
1058 template[i
].tap
[k
] > PAGE_SIZE
))
1061 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] + offset_in_page(IDX
[k
]);
1063 memcpy(q
, template[i
].input
+ temp
, template[i
].tap
[k
]);
1065 if (offset_in_page(q
) + template[i
].tap
[k
] < PAGE_SIZE
)
1066 q
[template[i
].tap
[k
]] = 0;
1068 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
1070 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1071 offset_in_page(IDX
[k
]);
1073 sg_set_buf(&sgout
[k
], q
, template[i
].tap
[k
]);
1075 memset(q
, 0, template[i
].tap
[k
]);
1076 if (offset_in_page(q
) +
1077 template[i
].tap
[k
] < PAGE_SIZE
)
1078 q
[template[i
].tap
[k
]] = 0;
1081 temp
+= template[i
].tap
[k
];
1084 ablkcipher_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
1085 template[i
].ilen
, iv
);
1087 ret
= enc
? crypto_ablkcipher_encrypt(req
) :
1088 crypto_ablkcipher_decrypt(req
);
1095 wait_for_completion(&result
.completion
);
1096 reinit_completion(&result
.completion
);
1102 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1103 d
, e
, j
, algo
, -ret
);
1109 for (k
= 0; k
< template[i
].np
; k
++) {
1111 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1112 offset_in_page(IDX
[k
]);
1114 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1115 offset_in_page(IDX
[k
]);
1117 if (memcmp(q
, template[i
].result
+ temp
,
1118 template[i
].tap
[k
])) {
1119 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1121 hexdump(q
, template[i
].tap
[k
]);
1125 q
+= template[i
].tap
[k
];
1126 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
1129 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1130 d
, j
, e
, k
, algo
, n
);
1134 temp
+= template[i
].tap
[k
];
1141 ablkcipher_request_free(req
);
1143 testmgr_free_buf(xoutbuf
);
1145 testmgr_free_buf(xbuf
);
1150 static int test_skcipher(struct crypto_ablkcipher
*tfm
, int enc
,
1151 struct cipher_testvec
*template, unsigned int tcount
)
1153 unsigned int alignmask
;
1156 /* test 'dst == src' case */
1157 ret
= __test_skcipher(tfm
, enc
, template, tcount
, false, 0);
1161 /* test 'dst != src' case */
1162 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 0);
1166 /* test unaligned buffers, check with one byte offset */
1167 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 1);
1171 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
1173 /* Check if alignment mask for tfm is correctly set. */
1174 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true,
1183 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
1184 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1186 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
1188 char result
[COMP_BUF_SIZE
];
1191 for (i
= 0; i
< ctcount
; i
++) {
1193 unsigned int dlen
= COMP_BUF_SIZE
;
1195 memset(result
, 0, sizeof (result
));
1197 ilen
= ctemplate
[i
].inlen
;
1198 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1199 ilen
, result
, &dlen
);
1201 printk(KERN_ERR
"alg: comp: compression failed "
1202 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1207 if (dlen
!= ctemplate
[i
].outlen
) {
1208 printk(KERN_ERR
"alg: comp: Compression test %d "
1209 "failed for %s: output len = %d\n", i
+ 1, algo
,
1215 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
1216 printk(KERN_ERR
"alg: comp: Compression test %d "
1217 "failed for %s\n", i
+ 1, algo
);
1218 hexdump(result
, dlen
);
1224 for (i
= 0; i
< dtcount
; i
++) {
1226 unsigned int dlen
= COMP_BUF_SIZE
;
1228 memset(result
, 0, sizeof (result
));
1230 ilen
= dtemplate
[i
].inlen
;
1231 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1232 ilen
, result
, &dlen
);
1234 printk(KERN_ERR
"alg: comp: decompression failed "
1235 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1240 if (dlen
!= dtemplate
[i
].outlen
) {
1241 printk(KERN_ERR
"alg: comp: Decompression test %d "
1242 "failed for %s: output len = %d\n", i
+ 1, algo
,
1248 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
1249 printk(KERN_ERR
"alg: comp: Decompression test %d "
1250 "failed for %s\n", i
+ 1, algo
);
1251 hexdump(result
, dlen
);
1263 static int test_pcomp(struct crypto_pcomp
*tfm
,
1264 struct pcomp_testvec
*ctemplate
,
1265 struct pcomp_testvec
*dtemplate
, int ctcount
,
1268 const char *algo
= crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm
));
1270 char result
[COMP_BUF_SIZE
];
1273 for (i
= 0; i
< ctcount
; i
++) {
1274 struct comp_request req
;
1275 unsigned int produced
= 0;
1277 res
= crypto_compress_setup(tfm
, ctemplate
[i
].params
,
1278 ctemplate
[i
].paramsize
);
1280 pr_err("alg: pcomp: compression setup failed on test "
1281 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1285 res
= crypto_compress_init(tfm
);
1287 pr_err("alg: pcomp: compression init failed on test "
1288 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1292 memset(result
, 0, sizeof(result
));
1294 req
.next_in
= ctemplate
[i
].input
;
1295 req
.avail_in
= ctemplate
[i
].inlen
/ 2;
1296 req
.next_out
= result
;
1297 req
.avail_out
= ctemplate
[i
].outlen
/ 2;
1299 res
= crypto_compress_update(tfm
, &req
);
1300 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1301 pr_err("alg: pcomp: compression update failed on test "
1302 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1308 /* Add remaining input data */
1309 req
.avail_in
+= (ctemplate
[i
].inlen
+ 1) / 2;
1311 res
= crypto_compress_update(tfm
, &req
);
1312 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1313 pr_err("alg: pcomp: compression update failed on test "
1314 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1320 /* Provide remaining output space */
1321 req
.avail_out
+= COMP_BUF_SIZE
- ctemplate
[i
].outlen
/ 2;
1323 res
= crypto_compress_final(tfm
, &req
);
1325 pr_err("alg: pcomp: compression final failed on test "
1326 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1331 if (COMP_BUF_SIZE
- req
.avail_out
!= ctemplate
[i
].outlen
) {
1332 pr_err("alg: comp: Compression test %d failed for %s: "
1333 "output len = %d (expected %d)\n", i
+ 1, algo
,
1334 COMP_BUF_SIZE
- req
.avail_out
,
1335 ctemplate
[i
].outlen
);
1339 if (produced
!= ctemplate
[i
].outlen
) {
1340 pr_err("alg: comp: Compression test %d failed for %s: "
1341 "returned len = %u (expected %d)\n", i
+ 1,
1342 algo
, produced
, ctemplate
[i
].outlen
);
1346 if (memcmp(result
, ctemplate
[i
].output
, ctemplate
[i
].outlen
)) {
1347 pr_err("alg: pcomp: Compression test %d failed for "
1348 "%s\n", i
+ 1, algo
);
1349 hexdump(result
, ctemplate
[i
].outlen
);
1354 for (i
= 0; i
< dtcount
; i
++) {
1355 struct comp_request req
;
1356 unsigned int produced
= 0;
1358 res
= crypto_decompress_setup(tfm
, dtemplate
[i
].params
,
1359 dtemplate
[i
].paramsize
);
1361 pr_err("alg: pcomp: decompression setup failed on "
1362 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1366 res
= crypto_decompress_init(tfm
);
1368 pr_err("alg: pcomp: decompression init failed on test "
1369 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1373 memset(result
, 0, sizeof(result
));
1375 req
.next_in
= dtemplate
[i
].input
;
1376 req
.avail_in
= dtemplate
[i
].inlen
/ 2;
1377 req
.next_out
= result
;
1378 req
.avail_out
= dtemplate
[i
].outlen
/ 2;
1380 res
= crypto_decompress_update(tfm
, &req
);
1381 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1382 pr_err("alg: pcomp: decompression update failed on "
1383 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1389 /* Add remaining input data */
1390 req
.avail_in
+= (dtemplate
[i
].inlen
+ 1) / 2;
1392 res
= crypto_decompress_update(tfm
, &req
);
1393 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1394 pr_err("alg: pcomp: decompression update failed on "
1395 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1401 /* Provide remaining output space */
1402 req
.avail_out
+= COMP_BUF_SIZE
- dtemplate
[i
].outlen
/ 2;
1404 res
= crypto_decompress_final(tfm
, &req
);
1405 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1406 pr_err("alg: pcomp: decompression final failed on "
1407 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1413 if (COMP_BUF_SIZE
- req
.avail_out
!= dtemplate
[i
].outlen
) {
1414 pr_err("alg: comp: Decompression test %d failed for "
1415 "%s: output len = %d (expected %d)\n", i
+ 1,
1416 algo
, COMP_BUF_SIZE
- req
.avail_out
,
1417 dtemplate
[i
].outlen
);
1421 if (produced
!= dtemplate
[i
].outlen
) {
1422 pr_err("alg: comp: Decompression test %d failed for "
1423 "%s: returned len = %u (expected %d)\n", i
+ 1,
1424 algo
, produced
, dtemplate
[i
].outlen
);
1428 if (memcmp(result
, dtemplate
[i
].output
, dtemplate
[i
].outlen
)) {
1429 pr_err("alg: pcomp: Decompression test %d failed for "
1430 "%s\n", i
+ 1, algo
);
1431 hexdump(result
, dtemplate
[i
].outlen
);
1440 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1441 unsigned int tcount
)
1443 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1444 int err
= 0, i
, j
, seedsize
;
1448 seedsize
= crypto_rng_seedsize(tfm
);
1450 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1452 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1457 for (i
= 0; i
< tcount
; i
++) {
1458 memset(result
, 0, 32);
1460 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1461 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1463 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1464 template[i
].dt
, template[i
].dtlen
);
1466 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1468 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1473 for (j
= 0; j
< template[i
].loops
; j
++) {
1474 err
= crypto_rng_get_bytes(tfm
, result
,
1476 if (err
!= template[i
].rlen
) {
1477 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1478 "the correct amount of random data for "
1479 "%s (requested %d, got %d)\n", algo
,
1480 template[i
].rlen
, err
);
1485 err
= memcmp(result
, template[i
].result
,
1488 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1490 hexdump(result
, template[i
].rlen
);
1501 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1504 struct crypto_aead
*tfm
;
1507 tfm
= crypto_alloc_aead(driver
, type
, mask
);
1509 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1510 "%ld\n", driver
, PTR_ERR(tfm
));
1511 return PTR_ERR(tfm
);
1514 if (desc
->suite
.aead
.enc
.vecs
) {
1515 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1516 desc
->suite
.aead
.enc
.count
);
1521 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1522 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1523 desc
->suite
.aead
.dec
.count
);
1526 crypto_free_aead(tfm
);
1530 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1531 const char *driver
, u32 type
, u32 mask
)
1533 struct crypto_cipher
*tfm
;
1536 tfm
= crypto_alloc_cipher(driver
, type
, mask
);
1538 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1539 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1540 return PTR_ERR(tfm
);
1543 if (desc
->suite
.cipher
.enc
.vecs
) {
1544 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1545 desc
->suite
.cipher
.enc
.count
);
1550 if (desc
->suite
.cipher
.dec
.vecs
)
1551 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1552 desc
->suite
.cipher
.dec
.count
);
1555 crypto_free_cipher(tfm
);
1559 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1560 const char *driver
, u32 type
, u32 mask
)
1562 struct crypto_ablkcipher
*tfm
;
1565 tfm
= crypto_alloc_ablkcipher(driver
, type
, mask
);
1567 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1568 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1569 return PTR_ERR(tfm
);
1572 if (desc
->suite
.cipher
.enc
.vecs
) {
1573 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1574 desc
->suite
.cipher
.enc
.count
);
1579 if (desc
->suite
.cipher
.dec
.vecs
)
1580 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1581 desc
->suite
.cipher
.dec
.count
);
1584 crypto_free_ablkcipher(tfm
);
1588 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1591 struct crypto_comp
*tfm
;
1594 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1596 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1597 "%ld\n", driver
, PTR_ERR(tfm
));
1598 return PTR_ERR(tfm
);
1601 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1602 desc
->suite
.comp
.decomp
.vecs
,
1603 desc
->suite
.comp
.comp
.count
,
1604 desc
->suite
.comp
.decomp
.count
);
1606 crypto_free_comp(tfm
);
1610 static int alg_test_pcomp(const struct alg_test_desc
*desc
, const char *driver
,
1613 struct crypto_pcomp
*tfm
;
1616 tfm
= crypto_alloc_pcomp(driver
, type
, mask
);
1618 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1619 driver
, PTR_ERR(tfm
));
1620 return PTR_ERR(tfm
);
1623 err
= test_pcomp(tfm
, desc
->suite
.pcomp
.comp
.vecs
,
1624 desc
->suite
.pcomp
.decomp
.vecs
,
1625 desc
->suite
.pcomp
.comp
.count
,
1626 desc
->suite
.pcomp
.decomp
.count
);
1628 crypto_free_pcomp(tfm
);
1632 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1635 struct crypto_ahash
*tfm
;
1638 tfm
= crypto_alloc_ahash(driver
, type
, mask
);
1640 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1641 "%ld\n", driver
, PTR_ERR(tfm
));
1642 return PTR_ERR(tfm
);
1645 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1646 desc
->suite
.hash
.count
, true);
1648 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1649 desc
->suite
.hash
.count
, false);
1651 crypto_free_ahash(tfm
);
1655 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1656 const char *driver
, u32 type
, u32 mask
)
1658 struct crypto_shash
*tfm
;
1662 err
= alg_test_hash(desc
, driver
, type
, mask
);
1666 tfm
= crypto_alloc_shash(driver
, type
, mask
);
1668 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1669 "%ld\n", driver
, PTR_ERR(tfm
));
1675 SHASH_DESC_ON_STACK(shash
, tfm
);
1676 u32
*ctx
= (u32
*)shash_desc_ctx(shash
);
1681 *ctx
= le32_to_cpu(420553207);
1682 err
= crypto_shash_final(shash
, (u8
*)&val
);
1684 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1685 "%s: %d\n", driver
, err
);
1689 if (val
!= ~420553207) {
1690 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1691 "%d\n", driver
, val
);
1696 crypto_free_shash(tfm
);
1702 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1705 struct crypto_rng
*rng
;
1708 rng
= crypto_alloc_rng(driver
, type
, mask
);
1710 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1711 "%ld\n", driver
, PTR_ERR(rng
));
1712 return PTR_ERR(rng
);
1715 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1717 crypto_free_rng(rng
);
1723 static int drbg_cavs_test(struct drbg_testvec
*test
, int pr
,
1724 const char *driver
, u32 type
, u32 mask
)
1727 struct crypto_rng
*drng
;
1728 struct drbg_test_data test_data
;
1729 struct drbg_string addtl
, pers
, testentropy
;
1730 unsigned char *buf
= kzalloc(test
->expectedlen
, GFP_KERNEL
);
1735 drng
= crypto_alloc_rng(driver
, type
, mask
);
1737 printk(KERN_ERR
"alg: drbg: could not allocate DRNG handle for "
1743 test_data
.testentropy
= &testentropy
;
1744 drbg_string_fill(&testentropy
, test
->entropy
, test
->entropylen
);
1745 drbg_string_fill(&pers
, test
->pers
, test
->perslen
);
1746 ret
= crypto_drbg_reset_test(drng
, &pers
, &test_data
);
1748 printk(KERN_ERR
"alg: drbg: Failed to reset rng\n");
1752 drbg_string_fill(&addtl
, test
->addtla
, test
->addtllen
);
1754 drbg_string_fill(&testentropy
, test
->entpra
, test
->entprlen
);
1755 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1756 buf
, test
->expectedlen
, &addtl
, &test_data
);
1758 ret
= crypto_drbg_get_bytes_addtl(drng
,
1759 buf
, test
->expectedlen
, &addtl
);
1762 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1763 "driver %s\n", driver
);
1767 drbg_string_fill(&addtl
, test
->addtlb
, test
->addtllen
);
1769 drbg_string_fill(&testentropy
, test
->entprb
, test
->entprlen
);
1770 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1771 buf
, test
->expectedlen
, &addtl
, &test_data
);
1773 ret
= crypto_drbg_get_bytes_addtl(drng
,
1774 buf
, test
->expectedlen
, &addtl
);
1777 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1778 "driver %s\n", driver
);
1782 ret
= memcmp(test
->expected
, buf
, test
->expectedlen
);
1785 crypto_free_rng(drng
);
1791 static int alg_test_drbg(const struct alg_test_desc
*desc
, const char *driver
,
1797 struct drbg_testvec
*template = desc
->suite
.drbg
.vecs
;
1798 unsigned int tcount
= desc
->suite
.drbg
.count
;
1800 if (0 == memcmp(driver
, "drbg_pr_", 8))
1803 for (i
= 0; i
< tcount
; i
++) {
1804 err
= drbg_cavs_test(&template[i
], pr
, driver
, type
, mask
);
1806 printk(KERN_ERR
"alg: drbg: Test %d failed for %s\n",
1816 static int alg_test_null(const struct alg_test_desc
*desc
,
1817 const char *driver
, u32 type
, u32 mask
)
1822 /* Please keep this list sorted by algorithm name. */
1823 static const struct alg_test_desc alg_test_descs
[] = {
1825 .alg
= "__cbc-cast5-avx",
1826 .test
= alg_test_null
,
1828 .alg
= "__cbc-cast6-avx",
1829 .test
= alg_test_null
,
1831 .alg
= "__cbc-serpent-avx",
1832 .test
= alg_test_null
,
1834 .alg
= "__cbc-serpent-avx2",
1835 .test
= alg_test_null
,
1837 .alg
= "__cbc-serpent-sse2",
1838 .test
= alg_test_null
,
1840 .alg
= "__cbc-twofish-avx",
1841 .test
= alg_test_null
,
1843 .alg
= "__driver-cbc-aes-aesni",
1844 .test
= alg_test_null
,
1847 .alg
= "__driver-cbc-camellia-aesni",
1848 .test
= alg_test_null
,
1850 .alg
= "__driver-cbc-camellia-aesni-avx2",
1851 .test
= alg_test_null
,
1853 .alg
= "__driver-cbc-cast5-avx",
1854 .test
= alg_test_null
,
1856 .alg
= "__driver-cbc-cast6-avx",
1857 .test
= alg_test_null
,
1859 .alg
= "__driver-cbc-serpent-avx",
1860 .test
= alg_test_null
,
1862 .alg
= "__driver-cbc-serpent-avx2",
1863 .test
= alg_test_null
,
1865 .alg
= "__driver-cbc-serpent-sse2",
1866 .test
= alg_test_null
,
1868 .alg
= "__driver-cbc-twofish-avx",
1869 .test
= alg_test_null
,
1871 .alg
= "__driver-ecb-aes-aesni",
1872 .test
= alg_test_null
,
1875 .alg
= "__driver-ecb-camellia-aesni",
1876 .test
= alg_test_null
,
1878 .alg
= "__driver-ecb-camellia-aesni-avx2",
1879 .test
= alg_test_null
,
1881 .alg
= "__driver-ecb-cast5-avx",
1882 .test
= alg_test_null
,
1884 .alg
= "__driver-ecb-cast6-avx",
1885 .test
= alg_test_null
,
1887 .alg
= "__driver-ecb-serpent-avx",
1888 .test
= alg_test_null
,
1890 .alg
= "__driver-ecb-serpent-avx2",
1891 .test
= alg_test_null
,
1893 .alg
= "__driver-ecb-serpent-sse2",
1894 .test
= alg_test_null
,
1896 .alg
= "__driver-ecb-twofish-avx",
1897 .test
= alg_test_null
,
1899 .alg
= "__ghash-pclmulqdqni",
1900 .test
= alg_test_null
,
1903 .alg
= "ansi_cprng",
1904 .test
= alg_test_cprng
,
1908 .vecs
= ansi_cprng_aes_tv_template
,
1909 .count
= ANSI_CPRNG_AES_TEST_VECTORS
1913 .alg
= "authenc(hmac(md5),ecb(cipher_null))",
1914 .test
= alg_test_aead
,
1919 .vecs
= hmac_md5_ecb_cipher_null_enc_tv_template
,
1920 .count
= HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1923 .vecs
= hmac_md5_ecb_cipher_null_dec_tv_template
,
1924 .count
= HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1929 .alg
= "authenc(hmac(sha1),cbc(aes))",
1930 .test
= alg_test_aead
,
1936 hmac_sha1_aes_cbc_enc_tv_temp
,
1938 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1943 .alg
= "authenc(hmac(sha1),cbc(des))",
1944 .test
= alg_test_aead
,
1950 hmac_sha1_des_cbc_enc_tv_temp
,
1952 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1957 .alg
= "authenc(hmac(sha1),cbc(des3_ede))",
1958 .test
= alg_test_aead
,
1964 hmac_sha1_des3_ede_cbc_enc_tv_temp
,
1966 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
1971 .alg
= "authenc(hmac(sha1),ecb(cipher_null))",
1972 .test
= alg_test_aead
,
1978 hmac_sha1_ecb_cipher_null_enc_tv_temp
,
1980 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
1984 hmac_sha1_ecb_cipher_null_dec_tv_temp
,
1986 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1991 .alg
= "authenc(hmac(sha224),cbc(des))",
1992 .test
= alg_test_aead
,
1998 hmac_sha224_des_cbc_enc_tv_temp
,
2000 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2005 .alg
= "authenc(hmac(sha224),cbc(des3_ede))",
2006 .test
= alg_test_aead
,
2012 hmac_sha224_des3_ede_cbc_enc_tv_temp
,
2014 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
2019 .alg
= "authenc(hmac(sha256),cbc(aes))",
2020 .test
= alg_test_aead
,
2026 hmac_sha256_aes_cbc_enc_tv_temp
,
2028 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2033 .alg
= "authenc(hmac(sha256),cbc(des))",
2034 .test
= alg_test_aead
,
2040 hmac_sha256_des_cbc_enc_tv_temp
,
2042 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2047 .alg
= "authenc(hmac(sha256),cbc(des3_ede))",
2048 .test
= alg_test_aead
,
2054 hmac_sha256_des3_ede_cbc_enc_tv_temp
,
2056 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2061 .alg
= "authenc(hmac(sha384),cbc(des))",
2062 .test
= alg_test_aead
,
2068 hmac_sha384_des_cbc_enc_tv_temp
,
2070 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2075 .alg
= "authenc(hmac(sha384),cbc(des3_ede))",
2076 .test
= alg_test_aead
,
2082 hmac_sha384_des3_ede_cbc_enc_tv_temp
,
2084 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
2089 .alg
= "authenc(hmac(sha512),cbc(aes))",
2090 .test
= alg_test_aead
,
2096 hmac_sha512_aes_cbc_enc_tv_temp
,
2098 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2103 .alg
= "authenc(hmac(sha512),cbc(des))",
2104 .test
= alg_test_aead
,
2110 hmac_sha512_des_cbc_enc_tv_temp
,
2112 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2117 .alg
= "authenc(hmac(sha512),cbc(des3_ede))",
2118 .test
= alg_test_aead
,
2124 hmac_sha512_des3_ede_cbc_enc_tv_temp
,
2126 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2132 .test
= alg_test_skcipher
,
2137 .vecs
= aes_cbc_enc_tv_template
,
2138 .count
= AES_CBC_ENC_TEST_VECTORS
2141 .vecs
= aes_cbc_dec_tv_template
,
2142 .count
= AES_CBC_DEC_TEST_VECTORS
2147 .alg
= "cbc(anubis)",
2148 .test
= alg_test_skcipher
,
2152 .vecs
= anubis_cbc_enc_tv_template
,
2153 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
2156 .vecs
= anubis_cbc_dec_tv_template
,
2157 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
2162 .alg
= "cbc(blowfish)",
2163 .test
= alg_test_skcipher
,
2167 .vecs
= bf_cbc_enc_tv_template
,
2168 .count
= BF_CBC_ENC_TEST_VECTORS
2171 .vecs
= bf_cbc_dec_tv_template
,
2172 .count
= BF_CBC_DEC_TEST_VECTORS
2177 .alg
= "cbc(camellia)",
2178 .test
= alg_test_skcipher
,
2182 .vecs
= camellia_cbc_enc_tv_template
,
2183 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
2186 .vecs
= camellia_cbc_dec_tv_template
,
2187 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
2192 .alg
= "cbc(cast5)",
2193 .test
= alg_test_skcipher
,
2197 .vecs
= cast5_cbc_enc_tv_template
,
2198 .count
= CAST5_CBC_ENC_TEST_VECTORS
2201 .vecs
= cast5_cbc_dec_tv_template
,
2202 .count
= CAST5_CBC_DEC_TEST_VECTORS
2207 .alg
= "cbc(cast6)",
2208 .test
= alg_test_skcipher
,
2212 .vecs
= cast6_cbc_enc_tv_template
,
2213 .count
= CAST6_CBC_ENC_TEST_VECTORS
2216 .vecs
= cast6_cbc_dec_tv_template
,
2217 .count
= CAST6_CBC_DEC_TEST_VECTORS
2223 .test
= alg_test_skcipher
,
2227 .vecs
= des_cbc_enc_tv_template
,
2228 .count
= DES_CBC_ENC_TEST_VECTORS
2231 .vecs
= des_cbc_dec_tv_template
,
2232 .count
= DES_CBC_DEC_TEST_VECTORS
2237 .alg
= "cbc(des3_ede)",
2238 .test
= alg_test_skcipher
,
2243 .vecs
= des3_ede_cbc_enc_tv_template
,
2244 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
2247 .vecs
= des3_ede_cbc_dec_tv_template
,
2248 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
2253 .alg
= "cbc(serpent)",
2254 .test
= alg_test_skcipher
,
2258 .vecs
= serpent_cbc_enc_tv_template
,
2259 .count
= SERPENT_CBC_ENC_TEST_VECTORS
2262 .vecs
= serpent_cbc_dec_tv_template
,
2263 .count
= SERPENT_CBC_DEC_TEST_VECTORS
2268 .alg
= "cbc(twofish)",
2269 .test
= alg_test_skcipher
,
2273 .vecs
= tf_cbc_enc_tv_template
,
2274 .count
= TF_CBC_ENC_TEST_VECTORS
2277 .vecs
= tf_cbc_dec_tv_template
,
2278 .count
= TF_CBC_DEC_TEST_VECTORS
2284 .test
= alg_test_aead
,
2289 .vecs
= aes_ccm_enc_tv_template
,
2290 .count
= AES_CCM_ENC_TEST_VECTORS
2293 .vecs
= aes_ccm_dec_tv_template
,
2294 .count
= AES_CCM_DEC_TEST_VECTORS
2300 .test
= alg_test_hash
,
2303 .vecs
= aes_cmac128_tv_template
,
2304 .count
= CMAC_AES_TEST_VECTORS
2308 .alg
= "cmac(des3_ede)",
2309 .test
= alg_test_hash
,
2312 .vecs
= des3_ede_cmac64_tv_template
,
2313 .count
= CMAC_DES3_EDE_TEST_VECTORS
2317 .alg
= "compress_null",
2318 .test
= alg_test_null
,
2321 .test
= alg_test_crc32c
,
2325 .vecs
= crc32c_tv_template
,
2326 .count
= CRC32C_TEST_VECTORS
2331 .test
= alg_test_hash
,
2335 .vecs
= crct10dif_tv_template
,
2336 .count
= CRCT10DIF_TEST_VECTORS
2340 .alg
= "cryptd(__driver-cbc-aes-aesni)",
2341 .test
= alg_test_null
,
2344 .alg
= "cryptd(__driver-cbc-camellia-aesni)",
2345 .test
= alg_test_null
,
2347 .alg
= "cryptd(__driver-cbc-camellia-aesni-avx2)",
2348 .test
= alg_test_null
,
2350 .alg
= "cryptd(__driver-cbc-serpent-avx2)",
2351 .test
= alg_test_null
,
2353 .alg
= "cryptd(__driver-ecb-aes-aesni)",
2354 .test
= alg_test_null
,
2357 .alg
= "cryptd(__driver-ecb-camellia-aesni)",
2358 .test
= alg_test_null
,
2360 .alg
= "cryptd(__driver-ecb-camellia-aesni-avx2)",
2361 .test
= alg_test_null
,
2363 .alg
= "cryptd(__driver-ecb-cast5-avx)",
2364 .test
= alg_test_null
,
2366 .alg
= "cryptd(__driver-ecb-cast6-avx)",
2367 .test
= alg_test_null
,
2369 .alg
= "cryptd(__driver-ecb-serpent-avx)",
2370 .test
= alg_test_null
,
2372 .alg
= "cryptd(__driver-ecb-serpent-avx2)",
2373 .test
= alg_test_null
,
2375 .alg
= "cryptd(__driver-ecb-serpent-sse2)",
2376 .test
= alg_test_null
,
2378 .alg
= "cryptd(__driver-ecb-twofish-avx)",
2379 .test
= alg_test_null
,
2381 .alg
= "cryptd(__driver-gcm-aes-aesni)",
2382 .test
= alg_test_null
,
2385 .alg
= "cryptd(__ghash-pclmulqdqni)",
2386 .test
= alg_test_null
,
2390 .test
= alg_test_skcipher
,
2395 .vecs
= aes_ctr_enc_tv_template
,
2396 .count
= AES_CTR_ENC_TEST_VECTORS
2399 .vecs
= aes_ctr_dec_tv_template
,
2400 .count
= AES_CTR_DEC_TEST_VECTORS
2405 .alg
= "ctr(blowfish)",
2406 .test
= alg_test_skcipher
,
2410 .vecs
= bf_ctr_enc_tv_template
,
2411 .count
= BF_CTR_ENC_TEST_VECTORS
2414 .vecs
= bf_ctr_dec_tv_template
,
2415 .count
= BF_CTR_DEC_TEST_VECTORS
2420 .alg
= "ctr(camellia)",
2421 .test
= alg_test_skcipher
,
2425 .vecs
= camellia_ctr_enc_tv_template
,
2426 .count
= CAMELLIA_CTR_ENC_TEST_VECTORS
2429 .vecs
= camellia_ctr_dec_tv_template
,
2430 .count
= CAMELLIA_CTR_DEC_TEST_VECTORS
2435 .alg
= "ctr(cast5)",
2436 .test
= alg_test_skcipher
,
2440 .vecs
= cast5_ctr_enc_tv_template
,
2441 .count
= CAST5_CTR_ENC_TEST_VECTORS
2444 .vecs
= cast5_ctr_dec_tv_template
,
2445 .count
= CAST5_CTR_DEC_TEST_VECTORS
2450 .alg
= "ctr(cast6)",
2451 .test
= alg_test_skcipher
,
2455 .vecs
= cast6_ctr_enc_tv_template
,
2456 .count
= CAST6_CTR_ENC_TEST_VECTORS
2459 .vecs
= cast6_ctr_dec_tv_template
,
2460 .count
= CAST6_CTR_DEC_TEST_VECTORS
2466 .test
= alg_test_skcipher
,
2470 .vecs
= des_ctr_enc_tv_template
,
2471 .count
= DES_CTR_ENC_TEST_VECTORS
2474 .vecs
= des_ctr_dec_tv_template
,
2475 .count
= DES_CTR_DEC_TEST_VECTORS
2480 .alg
= "ctr(des3_ede)",
2481 .test
= alg_test_skcipher
,
2485 .vecs
= des3_ede_ctr_enc_tv_template
,
2486 .count
= DES3_EDE_CTR_ENC_TEST_VECTORS
2489 .vecs
= des3_ede_ctr_dec_tv_template
,
2490 .count
= DES3_EDE_CTR_DEC_TEST_VECTORS
2495 .alg
= "ctr(serpent)",
2496 .test
= alg_test_skcipher
,
2500 .vecs
= serpent_ctr_enc_tv_template
,
2501 .count
= SERPENT_CTR_ENC_TEST_VECTORS
2504 .vecs
= serpent_ctr_dec_tv_template
,
2505 .count
= SERPENT_CTR_DEC_TEST_VECTORS
2510 .alg
= "ctr(twofish)",
2511 .test
= alg_test_skcipher
,
2515 .vecs
= tf_ctr_enc_tv_template
,
2516 .count
= TF_CTR_ENC_TEST_VECTORS
2519 .vecs
= tf_ctr_dec_tv_template
,
2520 .count
= TF_CTR_DEC_TEST_VECTORS
2525 .alg
= "cts(cbc(aes))",
2526 .test
= alg_test_skcipher
,
2530 .vecs
= cts_mode_enc_tv_template
,
2531 .count
= CTS_MODE_ENC_TEST_VECTORS
2534 .vecs
= cts_mode_dec_tv_template
,
2535 .count
= CTS_MODE_DEC_TEST_VECTORS
2541 .test
= alg_test_comp
,
2546 .vecs
= deflate_comp_tv_template
,
2547 .count
= DEFLATE_COMP_TEST_VECTORS
2550 .vecs
= deflate_decomp_tv_template
,
2551 .count
= DEFLATE_DECOMP_TEST_VECTORS
2556 .alg
= "digest_null",
2557 .test
= alg_test_null
,
2559 .alg
= "drbg_nopr_ctr_aes128",
2560 .test
= alg_test_drbg
,
2564 .vecs
= drbg_nopr_ctr_aes128_tv_template
,
2565 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template
)
2569 .alg
= "drbg_nopr_ctr_aes192",
2570 .test
= alg_test_drbg
,
2574 .vecs
= drbg_nopr_ctr_aes192_tv_template
,
2575 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template
)
2579 .alg
= "drbg_nopr_ctr_aes256",
2580 .test
= alg_test_drbg
,
2584 .vecs
= drbg_nopr_ctr_aes256_tv_template
,
2585 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template
)
2590 * There is no need to specifically test the DRBG with every
2591 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2593 .alg
= "drbg_nopr_hmac_sha1",
2595 .test
= alg_test_null
,
2597 .alg
= "drbg_nopr_hmac_sha256",
2598 .test
= alg_test_drbg
,
2602 .vecs
= drbg_nopr_hmac_sha256_tv_template
,
2604 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template
)
2608 /* covered by drbg_nopr_hmac_sha256 test */
2609 .alg
= "drbg_nopr_hmac_sha384",
2611 .test
= alg_test_null
,
2613 .alg
= "drbg_nopr_hmac_sha512",
2614 .test
= alg_test_null
,
2617 .alg
= "drbg_nopr_sha1",
2619 .test
= alg_test_null
,
2621 .alg
= "drbg_nopr_sha256",
2622 .test
= alg_test_drbg
,
2626 .vecs
= drbg_nopr_sha256_tv_template
,
2627 .count
= ARRAY_SIZE(drbg_nopr_sha256_tv_template
)
2631 /* covered by drbg_nopr_sha256 test */
2632 .alg
= "drbg_nopr_sha384",
2634 .test
= alg_test_null
,
2636 .alg
= "drbg_nopr_sha512",
2638 .test
= alg_test_null
,
2640 .alg
= "drbg_pr_ctr_aes128",
2641 .test
= alg_test_drbg
,
2645 .vecs
= drbg_pr_ctr_aes128_tv_template
,
2646 .count
= ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template
)
2650 /* covered by drbg_pr_ctr_aes128 test */
2651 .alg
= "drbg_pr_ctr_aes192",
2653 .test
= alg_test_null
,
2655 .alg
= "drbg_pr_ctr_aes256",
2657 .test
= alg_test_null
,
2659 .alg
= "drbg_pr_hmac_sha1",
2661 .test
= alg_test_null
,
2663 .alg
= "drbg_pr_hmac_sha256",
2664 .test
= alg_test_drbg
,
2668 .vecs
= drbg_pr_hmac_sha256_tv_template
,
2669 .count
= ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template
)
2673 /* covered by drbg_pr_hmac_sha256 test */
2674 .alg
= "drbg_pr_hmac_sha384",
2676 .test
= alg_test_null
,
2678 .alg
= "drbg_pr_hmac_sha512",
2679 .test
= alg_test_null
,
2682 .alg
= "drbg_pr_sha1",
2684 .test
= alg_test_null
,
2686 .alg
= "drbg_pr_sha256",
2687 .test
= alg_test_drbg
,
2691 .vecs
= drbg_pr_sha256_tv_template
,
2692 .count
= ARRAY_SIZE(drbg_pr_sha256_tv_template
)
2696 /* covered by drbg_pr_sha256 test */
2697 .alg
= "drbg_pr_sha384",
2699 .test
= alg_test_null
,
2701 .alg
= "drbg_pr_sha512",
2703 .test
= alg_test_null
,
2705 .alg
= "ecb(__aes-aesni)",
2706 .test
= alg_test_null
,
2710 .test
= alg_test_skcipher
,
2715 .vecs
= aes_enc_tv_template
,
2716 .count
= AES_ENC_TEST_VECTORS
2719 .vecs
= aes_dec_tv_template
,
2720 .count
= AES_DEC_TEST_VECTORS
2725 .alg
= "ecb(anubis)",
2726 .test
= alg_test_skcipher
,
2730 .vecs
= anubis_enc_tv_template
,
2731 .count
= ANUBIS_ENC_TEST_VECTORS
2734 .vecs
= anubis_dec_tv_template
,
2735 .count
= ANUBIS_DEC_TEST_VECTORS
2741 .test
= alg_test_skcipher
,
2745 .vecs
= arc4_enc_tv_template
,
2746 .count
= ARC4_ENC_TEST_VECTORS
2749 .vecs
= arc4_dec_tv_template
,
2750 .count
= ARC4_DEC_TEST_VECTORS
2755 .alg
= "ecb(blowfish)",
2756 .test
= alg_test_skcipher
,
2760 .vecs
= bf_enc_tv_template
,
2761 .count
= BF_ENC_TEST_VECTORS
2764 .vecs
= bf_dec_tv_template
,
2765 .count
= BF_DEC_TEST_VECTORS
2770 .alg
= "ecb(camellia)",
2771 .test
= alg_test_skcipher
,
2775 .vecs
= camellia_enc_tv_template
,
2776 .count
= CAMELLIA_ENC_TEST_VECTORS
2779 .vecs
= camellia_dec_tv_template
,
2780 .count
= CAMELLIA_DEC_TEST_VECTORS
2785 .alg
= "ecb(cast5)",
2786 .test
= alg_test_skcipher
,
2790 .vecs
= cast5_enc_tv_template
,
2791 .count
= CAST5_ENC_TEST_VECTORS
2794 .vecs
= cast5_dec_tv_template
,
2795 .count
= CAST5_DEC_TEST_VECTORS
2800 .alg
= "ecb(cast6)",
2801 .test
= alg_test_skcipher
,
2805 .vecs
= cast6_enc_tv_template
,
2806 .count
= CAST6_ENC_TEST_VECTORS
2809 .vecs
= cast6_dec_tv_template
,
2810 .count
= CAST6_DEC_TEST_VECTORS
2815 .alg
= "ecb(cipher_null)",
2816 .test
= alg_test_null
,
2819 .test
= alg_test_skcipher
,
2824 .vecs
= des_enc_tv_template
,
2825 .count
= DES_ENC_TEST_VECTORS
2828 .vecs
= des_dec_tv_template
,
2829 .count
= DES_DEC_TEST_VECTORS
2834 .alg
= "ecb(des3_ede)",
2835 .test
= alg_test_skcipher
,
2840 .vecs
= des3_ede_enc_tv_template
,
2841 .count
= DES3_EDE_ENC_TEST_VECTORS
2844 .vecs
= des3_ede_dec_tv_template
,
2845 .count
= DES3_EDE_DEC_TEST_VECTORS
2850 .alg
= "ecb(fcrypt)",
2851 .test
= alg_test_skcipher
,
2855 .vecs
= fcrypt_pcbc_enc_tv_template
,
2859 .vecs
= fcrypt_pcbc_dec_tv_template
,
2865 .alg
= "ecb(khazad)",
2866 .test
= alg_test_skcipher
,
2870 .vecs
= khazad_enc_tv_template
,
2871 .count
= KHAZAD_ENC_TEST_VECTORS
2874 .vecs
= khazad_dec_tv_template
,
2875 .count
= KHAZAD_DEC_TEST_VECTORS
2881 .test
= alg_test_skcipher
,
2885 .vecs
= seed_enc_tv_template
,
2886 .count
= SEED_ENC_TEST_VECTORS
2889 .vecs
= seed_dec_tv_template
,
2890 .count
= SEED_DEC_TEST_VECTORS
2895 .alg
= "ecb(serpent)",
2896 .test
= alg_test_skcipher
,
2900 .vecs
= serpent_enc_tv_template
,
2901 .count
= SERPENT_ENC_TEST_VECTORS
2904 .vecs
= serpent_dec_tv_template
,
2905 .count
= SERPENT_DEC_TEST_VECTORS
2911 .test
= alg_test_skcipher
,
2915 .vecs
= tea_enc_tv_template
,
2916 .count
= TEA_ENC_TEST_VECTORS
2919 .vecs
= tea_dec_tv_template
,
2920 .count
= TEA_DEC_TEST_VECTORS
2925 .alg
= "ecb(tnepres)",
2926 .test
= alg_test_skcipher
,
2930 .vecs
= tnepres_enc_tv_template
,
2931 .count
= TNEPRES_ENC_TEST_VECTORS
2934 .vecs
= tnepres_dec_tv_template
,
2935 .count
= TNEPRES_DEC_TEST_VECTORS
2940 .alg
= "ecb(twofish)",
2941 .test
= alg_test_skcipher
,
2945 .vecs
= tf_enc_tv_template
,
2946 .count
= TF_ENC_TEST_VECTORS
2949 .vecs
= tf_dec_tv_template
,
2950 .count
= TF_DEC_TEST_VECTORS
2956 .test
= alg_test_skcipher
,
2960 .vecs
= xeta_enc_tv_template
,
2961 .count
= XETA_ENC_TEST_VECTORS
2964 .vecs
= xeta_dec_tv_template
,
2965 .count
= XETA_DEC_TEST_VECTORS
2971 .test
= alg_test_skcipher
,
2975 .vecs
= xtea_enc_tv_template
,
2976 .count
= XTEA_ENC_TEST_VECTORS
2979 .vecs
= xtea_dec_tv_template
,
2980 .count
= XTEA_DEC_TEST_VECTORS
2986 .test
= alg_test_aead
,
2991 .vecs
= aes_gcm_enc_tv_template
,
2992 .count
= AES_GCM_ENC_TEST_VECTORS
2995 .vecs
= aes_gcm_dec_tv_template
,
2996 .count
= AES_GCM_DEC_TEST_VECTORS
3002 .test
= alg_test_hash
,
3006 .vecs
= ghash_tv_template
,
3007 .count
= GHASH_TEST_VECTORS
3011 .alg
= "hmac(crc32)",
3012 .test
= alg_test_hash
,
3015 .vecs
= bfin_crc_tv_template
,
3016 .count
= BFIN_CRC_TEST_VECTORS
3021 .test
= alg_test_hash
,
3024 .vecs
= hmac_md5_tv_template
,
3025 .count
= HMAC_MD5_TEST_VECTORS
3029 .alg
= "hmac(rmd128)",
3030 .test
= alg_test_hash
,
3033 .vecs
= hmac_rmd128_tv_template
,
3034 .count
= HMAC_RMD128_TEST_VECTORS
3038 .alg
= "hmac(rmd160)",
3039 .test
= alg_test_hash
,
3042 .vecs
= hmac_rmd160_tv_template
,
3043 .count
= HMAC_RMD160_TEST_VECTORS
3047 .alg
= "hmac(sha1)",
3048 .test
= alg_test_hash
,
3052 .vecs
= hmac_sha1_tv_template
,
3053 .count
= HMAC_SHA1_TEST_VECTORS
3057 .alg
= "hmac(sha224)",
3058 .test
= alg_test_hash
,
3062 .vecs
= hmac_sha224_tv_template
,
3063 .count
= HMAC_SHA224_TEST_VECTORS
3067 .alg
= "hmac(sha256)",
3068 .test
= alg_test_hash
,
3072 .vecs
= hmac_sha256_tv_template
,
3073 .count
= HMAC_SHA256_TEST_VECTORS
3077 .alg
= "hmac(sha384)",
3078 .test
= alg_test_hash
,
3082 .vecs
= hmac_sha384_tv_template
,
3083 .count
= HMAC_SHA384_TEST_VECTORS
3087 .alg
= "hmac(sha512)",
3088 .test
= alg_test_hash
,
3092 .vecs
= hmac_sha512_tv_template
,
3093 .count
= HMAC_SHA512_TEST_VECTORS
3098 .test
= alg_test_skcipher
,
3102 .vecs
= aes_lrw_enc_tv_template
,
3103 .count
= AES_LRW_ENC_TEST_VECTORS
3106 .vecs
= aes_lrw_dec_tv_template
,
3107 .count
= AES_LRW_DEC_TEST_VECTORS
3112 .alg
= "lrw(camellia)",
3113 .test
= alg_test_skcipher
,
3117 .vecs
= camellia_lrw_enc_tv_template
,
3118 .count
= CAMELLIA_LRW_ENC_TEST_VECTORS
3121 .vecs
= camellia_lrw_dec_tv_template
,
3122 .count
= CAMELLIA_LRW_DEC_TEST_VECTORS
3127 .alg
= "lrw(cast6)",
3128 .test
= alg_test_skcipher
,
3132 .vecs
= cast6_lrw_enc_tv_template
,
3133 .count
= CAST6_LRW_ENC_TEST_VECTORS
3136 .vecs
= cast6_lrw_dec_tv_template
,
3137 .count
= CAST6_LRW_DEC_TEST_VECTORS
3142 .alg
= "lrw(serpent)",
3143 .test
= alg_test_skcipher
,
3147 .vecs
= serpent_lrw_enc_tv_template
,
3148 .count
= SERPENT_LRW_ENC_TEST_VECTORS
3151 .vecs
= serpent_lrw_dec_tv_template
,
3152 .count
= SERPENT_LRW_DEC_TEST_VECTORS
3157 .alg
= "lrw(twofish)",
3158 .test
= alg_test_skcipher
,
3162 .vecs
= tf_lrw_enc_tv_template
,
3163 .count
= TF_LRW_ENC_TEST_VECTORS
3166 .vecs
= tf_lrw_dec_tv_template
,
3167 .count
= TF_LRW_DEC_TEST_VECTORS
3173 .test
= alg_test_comp
,
3178 .vecs
= lz4_comp_tv_template
,
3179 .count
= LZ4_COMP_TEST_VECTORS
3182 .vecs
= lz4_decomp_tv_template
,
3183 .count
= LZ4_DECOMP_TEST_VECTORS
3189 .test
= alg_test_comp
,
3194 .vecs
= lz4hc_comp_tv_template
,
3195 .count
= LZ4HC_COMP_TEST_VECTORS
3198 .vecs
= lz4hc_decomp_tv_template
,
3199 .count
= LZ4HC_DECOMP_TEST_VECTORS
3205 .test
= alg_test_comp
,
3210 .vecs
= lzo_comp_tv_template
,
3211 .count
= LZO_COMP_TEST_VECTORS
3214 .vecs
= lzo_decomp_tv_template
,
3215 .count
= LZO_DECOMP_TEST_VECTORS
3221 .test
= alg_test_hash
,
3224 .vecs
= md4_tv_template
,
3225 .count
= MD4_TEST_VECTORS
3230 .test
= alg_test_hash
,
3233 .vecs
= md5_tv_template
,
3234 .count
= MD5_TEST_VECTORS
3238 .alg
= "michael_mic",
3239 .test
= alg_test_hash
,
3242 .vecs
= michael_mic_tv_template
,
3243 .count
= MICHAEL_MIC_TEST_VECTORS
3248 .test
= alg_test_skcipher
,
3253 .vecs
= aes_ofb_enc_tv_template
,
3254 .count
= AES_OFB_ENC_TEST_VECTORS
3257 .vecs
= aes_ofb_dec_tv_template
,
3258 .count
= AES_OFB_DEC_TEST_VECTORS
3263 .alg
= "pcbc(fcrypt)",
3264 .test
= alg_test_skcipher
,
3268 .vecs
= fcrypt_pcbc_enc_tv_template
,
3269 .count
= FCRYPT_ENC_TEST_VECTORS
3272 .vecs
= fcrypt_pcbc_dec_tv_template
,
3273 .count
= FCRYPT_DEC_TEST_VECTORS
3278 .alg
= "rfc3686(ctr(aes))",
3279 .test
= alg_test_skcipher
,
3284 .vecs
= aes_ctr_rfc3686_enc_tv_template
,
3285 .count
= AES_CTR_3686_ENC_TEST_VECTORS
3288 .vecs
= aes_ctr_rfc3686_dec_tv_template
,
3289 .count
= AES_CTR_3686_DEC_TEST_VECTORS
3294 .alg
= "rfc4106(gcm(aes))",
3295 .test
= alg_test_aead
,
3299 .vecs
= aes_gcm_rfc4106_enc_tv_template
,
3300 .count
= AES_GCM_4106_ENC_TEST_VECTORS
3303 .vecs
= aes_gcm_rfc4106_dec_tv_template
,
3304 .count
= AES_GCM_4106_DEC_TEST_VECTORS
3309 .alg
= "rfc4309(ccm(aes))",
3310 .test
= alg_test_aead
,
3315 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
3316 .count
= AES_CCM_4309_ENC_TEST_VECTORS
3319 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
3320 .count
= AES_CCM_4309_DEC_TEST_VECTORS
3325 .alg
= "rfc4543(gcm(aes))",
3326 .test
= alg_test_aead
,
3330 .vecs
= aes_gcm_rfc4543_enc_tv_template
,
3331 .count
= AES_GCM_4543_ENC_TEST_VECTORS
3334 .vecs
= aes_gcm_rfc4543_dec_tv_template
,
3335 .count
= AES_GCM_4543_DEC_TEST_VECTORS
3341 .test
= alg_test_hash
,
3344 .vecs
= rmd128_tv_template
,
3345 .count
= RMD128_TEST_VECTORS
3350 .test
= alg_test_hash
,
3353 .vecs
= rmd160_tv_template
,
3354 .count
= RMD160_TEST_VECTORS
3359 .test
= alg_test_hash
,
3362 .vecs
= rmd256_tv_template
,
3363 .count
= RMD256_TEST_VECTORS
3368 .test
= alg_test_hash
,
3371 .vecs
= rmd320_tv_template
,
3372 .count
= RMD320_TEST_VECTORS
3377 .test
= alg_test_skcipher
,
3381 .vecs
= salsa20_stream_enc_tv_template
,
3382 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
3388 .test
= alg_test_hash
,
3392 .vecs
= sha1_tv_template
,
3393 .count
= SHA1_TEST_VECTORS
3398 .test
= alg_test_hash
,
3402 .vecs
= sha224_tv_template
,
3403 .count
= SHA224_TEST_VECTORS
3408 .test
= alg_test_hash
,
3412 .vecs
= sha256_tv_template
,
3413 .count
= SHA256_TEST_VECTORS
3418 .test
= alg_test_hash
,
3422 .vecs
= sha384_tv_template
,
3423 .count
= SHA384_TEST_VECTORS
3428 .test
= alg_test_hash
,
3432 .vecs
= sha512_tv_template
,
3433 .count
= SHA512_TEST_VECTORS
3438 .test
= alg_test_hash
,
3441 .vecs
= tgr128_tv_template
,
3442 .count
= TGR128_TEST_VECTORS
3447 .test
= alg_test_hash
,
3450 .vecs
= tgr160_tv_template
,
3451 .count
= TGR160_TEST_VECTORS
3456 .test
= alg_test_hash
,
3459 .vecs
= tgr192_tv_template
,
3460 .count
= TGR192_TEST_VECTORS
3465 .test
= alg_test_hash
,
3468 .vecs
= aes_vmac128_tv_template
,
3469 .count
= VMAC_AES_TEST_VECTORS
3474 .test
= alg_test_hash
,
3477 .vecs
= wp256_tv_template
,
3478 .count
= WP256_TEST_VECTORS
3483 .test
= alg_test_hash
,
3486 .vecs
= wp384_tv_template
,
3487 .count
= WP384_TEST_VECTORS
3492 .test
= alg_test_hash
,
3495 .vecs
= wp512_tv_template
,
3496 .count
= WP512_TEST_VECTORS
3501 .test
= alg_test_hash
,
3504 .vecs
= aes_xcbc128_tv_template
,
3505 .count
= XCBC_AES_TEST_VECTORS
3510 .test
= alg_test_skcipher
,
3515 .vecs
= aes_xts_enc_tv_template
,
3516 .count
= AES_XTS_ENC_TEST_VECTORS
3519 .vecs
= aes_xts_dec_tv_template
,
3520 .count
= AES_XTS_DEC_TEST_VECTORS
3525 .alg
= "xts(camellia)",
3526 .test
= alg_test_skcipher
,
3530 .vecs
= camellia_xts_enc_tv_template
,
3531 .count
= CAMELLIA_XTS_ENC_TEST_VECTORS
3534 .vecs
= camellia_xts_dec_tv_template
,
3535 .count
= CAMELLIA_XTS_DEC_TEST_VECTORS
3540 .alg
= "xts(cast6)",
3541 .test
= alg_test_skcipher
,
3545 .vecs
= cast6_xts_enc_tv_template
,
3546 .count
= CAST6_XTS_ENC_TEST_VECTORS
3549 .vecs
= cast6_xts_dec_tv_template
,
3550 .count
= CAST6_XTS_DEC_TEST_VECTORS
3555 .alg
= "xts(serpent)",
3556 .test
= alg_test_skcipher
,
3560 .vecs
= serpent_xts_enc_tv_template
,
3561 .count
= SERPENT_XTS_ENC_TEST_VECTORS
3564 .vecs
= serpent_xts_dec_tv_template
,
3565 .count
= SERPENT_XTS_DEC_TEST_VECTORS
3570 .alg
= "xts(twofish)",
3571 .test
= alg_test_skcipher
,
3575 .vecs
= tf_xts_enc_tv_template
,
3576 .count
= TF_XTS_ENC_TEST_VECTORS
3579 .vecs
= tf_xts_dec_tv_template
,
3580 .count
= TF_XTS_DEC_TEST_VECTORS
3586 .test
= alg_test_pcomp
,
3591 .vecs
= zlib_comp_tv_template
,
3592 .count
= ZLIB_COMP_TEST_VECTORS
3595 .vecs
= zlib_decomp_tv_template
,
3596 .count
= ZLIB_DECOMP_TEST_VECTORS
3603 static bool alg_test_descs_checked
;
3605 static void alg_test_descs_check_order(void)
3609 /* only check once */
3610 if (alg_test_descs_checked
)
3613 alg_test_descs_checked
= true;
3615 for (i
= 1; i
< ARRAY_SIZE(alg_test_descs
); i
++) {
3616 int diff
= strcmp(alg_test_descs
[i
- 1].alg
,
3617 alg_test_descs
[i
].alg
);
3619 if (WARN_ON(diff
> 0)) {
3620 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3621 alg_test_descs
[i
- 1].alg
,
3622 alg_test_descs
[i
].alg
);
3625 if (WARN_ON(diff
== 0)) {
3626 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3627 alg_test_descs
[i
].alg
);
3632 static int alg_find_test(const char *alg
)
3635 int end
= ARRAY_SIZE(alg_test_descs
);
3637 while (start
< end
) {
3638 int i
= (start
+ end
) / 2;
3639 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
3657 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
3663 alg_test_descs_check_order();
3665 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
3666 char nalg
[CRYPTO_MAX_ALG_NAME
];
3668 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
3670 return -ENAMETOOLONG
;
3672 i
= alg_find_test(nalg
);
3676 if (fips_enabled
&& !alg_test_descs
[i
].fips_allowed
)
3679 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
3683 i
= alg_find_test(alg
);
3684 j
= alg_find_test(driver
);
3688 if (fips_enabled
&& ((i
>= 0 && !alg_test_descs
[i
].fips_allowed
) ||
3689 (j
>= 0 && !alg_test_descs
[j
].fips_allowed
)))
3694 rc
|= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
3696 if (j
>= 0 && j
!= i
)
3697 rc
|= alg_test_descs
[j
].test(alg_test_descs
+ j
, driver
,
3701 if (fips_enabled
&& rc
)
3702 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
3704 if (fips_enabled
&& !rc
)
3705 pr_info("alg: self-tests for %s (%s) passed\n", driver
, alg
);
3710 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
3716 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3718 EXPORT_SYMBOL_GPL(alg_test
);