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/aead.h>
24 #include <crypto/hash.h>
25 #include <crypto/skcipher.h>
26 #include <linux/err.h>
27 #include <linux/fips.h>
28 #include <linux/module.h>
29 #include <linux/scatterlist.h>
30 #include <linux/slab.h>
31 #include <linux/string.h>
32 #include <crypto/rng.h>
33 #include <crypto/drbg.h>
34 #include <crypto/akcipher.h>
38 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
41 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
51 * Need slab memory for testing (size in number of pages).
56 * Indexes into the xbuf to simulate cross-page access.
68 * Used by test_cipher()
73 struct tcrypt_result
{
74 struct completion completion
;
78 struct aead_test_suite
{
80 struct aead_testvec
*vecs
;
85 struct cipher_test_suite
{
87 struct cipher_testvec
*vecs
;
92 struct comp_test_suite
{
94 struct comp_testvec
*vecs
;
99 struct pcomp_test_suite
{
101 struct pcomp_testvec
*vecs
;
106 struct hash_test_suite
{
107 struct hash_testvec
*vecs
;
111 struct cprng_test_suite
{
112 struct cprng_testvec
*vecs
;
116 struct drbg_test_suite
{
117 struct drbg_testvec
*vecs
;
121 struct akcipher_test_suite
{
122 struct akcipher_testvec
*vecs
;
126 struct alg_test_desc
{
128 int (*test
)(const struct alg_test_desc
*desc
, const char *driver
,
130 int fips_allowed
; /* set if alg is allowed in fips mode */
133 struct aead_test_suite aead
;
134 struct cipher_test_suite cipher
;
135 struct comp_test_suite comp
;
136 struct pcomp_test_suite pcomp
;
137 struct hash_test_suite hash
;
138 struct cprng_test_suite cprng
;
139 struct drbg_test_suite drbg
;
140 struct akcipher_test_suite akcipher
;
144 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
146 static void hexdump(unsigned char *buf
, unsigned int len
)
148 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
153 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
155 struct tcrypt_result
*res
= req
->data
;
157 if (err
== -EINPROGRESS
)
161 complete(&res
->completion
);
164 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
168 for (i
= 0; i
< XBUFSIZE
; i
++) {
169 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
178 free_page((unsigned long)buf
[i
]);
183 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
187 for (i
= 0; i
< XBUFSIZE
; i
++)
188 free_page((unsigned long)buf
[i
]);
191 static int wait_async_op(struct tcrypt_result
*tr
, int ret
)
193 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
194 wait_for_completion(&tr
->completion
);
195 reinit_completion(&tr
->completion
);
201 static int __test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
202 unsigned int tcount
, bool use_digest
,
203 const int align_offset
)
205 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
206 unsigned int i
, j
, k
, temp
;
207 struct scatterlist sg
[8];
210 struct ahash_request
*req
;
211 struct tcrypt_result tresult
;
213 char *xbuf
[XBUFSIZE
];
216 result
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
219 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
222 if (testmgr_alloc_buf(xbuf
))
225 init_completion(&tresult
.completion
);
227 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
229 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
233 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
234 tcrypt_complete
, &tresult
);
237 for (i
= 0; i
< tcount
; i
++) {
242 if (WARN_ON(align_offset
+ template[i
].psize
> PAGE_SIZE
))
246 memset(result
, 0, MAX_DIGEST_SIZE
);
249 hash_buff
+= align_offset
;
251 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
252 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
254 if (template[i
].ksize
) {
255 crypto_ahash_clear_flags(tfm
, ~0);
256 if (template[i
].ksize
> MAX_KEYLEN
) {
257 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
258 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
262 memcpy(key
, template[i
].key
, template[i
].ksize
);
263 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
265 printk(KERN_ERR
"alg: hash: setkey failed on "
266 "test %d for %s: ret=%d\n", j
, algo
,
272 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
274 ret
= wait_async_op(&tresult
, crypto_ahash_digest(req
));
276 pr_err("alg: hash: digest failed on test %d "
277 "for %s: ret=%d\n", j
, algo
, -ret
);
281 ret
= wait_async_op(&tresult
, crypto_ahash_init(req
));
283 pr_err("alt: hash: init failed on test %d "
284 "for %s: ret=%d\n", j
, algo
, -ret
);
287 ret
= wait_async_op(&tresult
, crypto_ahash_update(req
));
289 pr_err("alt: hash: update failed on test %d "
290 "for %s: ret=%d\n", j
, algo
, -ret
);
293 ret
= wait_async_op(&tresult
, crypto_ahash_final(req
));
295 pr_err("alt: hash: final failed on test %d "
296 "for %s: ret=%d\n", j
, algo
, -ret
);
301 if (memcmp(result
, template[i
].digest
,
302 crypto_ahash_digestsize(tfm
))) {
303 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
305 hexdump(result
, crypto_ahash_digestsize(tfm
));
312 for (i
= 0; i
< tcount
; i
++) {
313 /* alignment tests are only done with continuous buffers */
314 if (align_offset
!= 0)
321 memset(result
, 0, MAX_DIGEST_SIZE
);
324 sg_init_table(sg
, template[i
].np
);
326 for (k
= 0; k
< template[i
].np
; k
++) {
327 if (WARN_ON(offset_in_page(IDX
[k
]) +
328 template[i
].tap
[k
] > PAGE_SIZE
))
331 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
332 offset_in_page(IDX
[k
]),
333 template[i
].plaintext
+ temp
,
336 temp
+= template[i
].tap
[k
];
339 if (template[i
].ksize
) {
340 if (template[i
].ksize
> MAX_KEYLEN
) {
341 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
342 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
346 crypto_ahash_clear_flags(tfm
, ~0);
347 memcpy(key
, template[i
].key
, template[i
].ksize
);
348 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
351 printk(KERN_ERR
"alg: hash: setkey "
352 "failed on chunking test %d "
353 "for %s: ret=%d\n", j
, algo
, -ret
);
358 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
359 ret
= crypto_ahash_digest(req
);
365 wait_for_completion(&tresult
.completion
);
366 reinit_completion(&tresult
.completion
);
372 printk(KERN_ERR
"alg: hash: digest failed "
373 "on chunking test %d for %s: "
374 "ret=%d\n", j
, algo
, -ret
);
378 if (memcmp(result
, template[i
].digest
,
379 crypto_ahash_digestsize(tfm
))) {
380 printk(KERN_ERR
"alg: hash: Chunking test %d "
381 "failed for %s\n", j
, algo
);
382 hexdump(result
, crypto_ahash_digestsize(tfm
));
391 ahash_request_free(req
);
393 testmgr_free_buf(xbuf
);
400 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
401 unsigned int tcount
, bool use_digest
)
403 unsigned int alignmask
;
406 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 0);
410 /* test unaligned buffers, check with one byte offset */
411 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 1);
415 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
417 /* Check if alignment mask for tfm is correctly set. */
418 ret
= __test_hash(tfm
, template, tcount
, use_digest
,
427 static int __test_aead(struct crypto_aead
*tfm
, int enc
,
428 struct aead_testvec
*template, unsigned int tcount
,
429 const bool diff_dst
, const int align_offset
)
431 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
432 unsigned int i
, j
, k
, n
, temp
;
436 struct aead_request
*req
;
437 struct scatterlist
*sg
;
438 struct scatterlist
*sgout
;
440 struct tcrypt_result result
;
441 unsigned int authsize
, iv_len
;
446 char *xbuf
[XBUFSIZE
];
447 char *xoutbuf
[XBUFSIZE
];
448 char *axbuf
[XBUFSIZE
];
450 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
453 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
456 if (testmgr_alloc_buf(xbuf
))
458 if (testmgr_alloc_buf(axbuf
))
460 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
463 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
464 sg
= kmalloc(sizeof(*sg
) * 8 * (diff_dst
? 4 : 2), GFP_KERNEL
);
479 init_completion(&result
.completion
);
481 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
483 pr_err("alg: aead%s: Failed to allocate request for %s\n",
488 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
489 tcrypt_complete
, &result
);
491 iv_len
= crypto_aead_ivsize(tfm
);
493 for (i
= 0, j
= 0; i
< tcount
; i
++) {
499 /* some templates have no input data but they will
503 input
+= align_offset
;
507 if (WARN_ON(align_offset
+ template[i
].ilen
>
508 PAGE_SIZE
|| template[i
].alen
> PAGE_SIZE
))
511 memcpy(input
, template[i
].input
, template[i
].ilen
);
512 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
514 memcpy(iv
, template[i
].iv
, iv_len
);
516 memset(iv
, 0, iv_len
);
518 crypto_aead_clear_flags(tfm
, ~0);
520 crypto_aead_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
522 if (template[i
].klen
> MAX_KEYLEN
) {
523 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
524 d
, j
, algo
, template[i
].klen
,
529 memcpy(key
, template[i
].key
, template[i
].klen
);
531 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
532 if (!ret
== template[i
].fail
) {
533 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
534 d
, j
, algo
, crypto_aead_get_flags(tfm
));
539 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
540 ret
= crypto_aead_setauthsize(tfm
, authsize
);
542 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
543 d
, authsize
, j
, algo
);
547 k
= !!template[i
].alen
;
548 sg_init_table(sg
, k
+ 1);
549 sg_set_buf(&sg
[0], assoc
, template[i
].alen
);
550 sg_set_buf(&sg
[k
], input
,
551 template[i
].ilen
+ (enc
? authsize
: 0));
555 sg_init_table(sgout
, k
+ 1);
556 sg_set_buf(&sgout
[0], assoc
, template[i
].alen
);
559 output
+= align_offset
;
560 sg_set_buf(&sgout
[k
], output
,
561 template[i
].rlen
+ (enc
? 0 : authsize
));
564 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
565 template[i
].ilen
, iv
);
567 aead_request_set_ad(req
, template[i
].alen
);
569 ret
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
573 if (template[i
].novrfy
) {
574 /* verification was supposed to fail */
575 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
577 /* so really, we got a bad message */
584 wait_for_completion(&result
.completion
);
585 reinit_completion(&result
.completion
);
590 if (template[i
].novrfy
)
591 /* verification failure was expected */
595 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
596 d
, e
, j
, algo
, -ret
);
601 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
602 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
604 hexdump(q
, template[i
].rlen
);
610 for (i
= 0, j
= 0; i
< tcount
; i
++) {
611 /* alignment tests are only done with continuous buffers */
612 if (align_offset
!= 0)
621 memcpy(iv
, template[i
].iv
, iv_len
);
623 memset(iv
, 0, MAX_IVLEN
);
625 crypto_aead_clear_flags(tfm
, ~0);
627 crypto_aead_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
628 if (template[i
].klen
> MAX_KEYLEN
) {
629 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
630 d
, j
, algo
, template[i
].klen
, MAX_KEYLEN
);
634 memcpy(key
, template[i
].key
, template[i
].klen
);
636 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
637 if (!ret
== template[i
].fail
) {
638 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
639 d
, j
, algo
, crypto_aead_get_flags(tfm
));
644 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
647 sg_init_table(sg
, template[i
].anp
+ template[i
].np
);
649 sg_init_table(sgout
, template[i
].anp
+ template[i
].np
);
652 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
653 if (WARN_ON(offset_in_page(IDX
[k
]) +
654 template[i
].atap
[k
] > PAGE_SIZE
))
657 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
658 offset_in_page(IDX
[k
]),
659 template[i
].assoc
+ temp
,
660 template[i
].atap
[k
]),
661 template[i
].atap
[k
]);
663 sg_set_buf(&sgout
[k
],
664 axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
665 offset_in_page(IDX
[k
]),
666 template[i
].atap
[k
]);
667 temp
+= template[i
].atap
[k
];
670 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
671 if (WARN_ON(offset_in_page(IDX
[k
]) +
672 template[i
].tap
[k
] > PAGE_SIZE
))
675 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] + offset_in_page(IDX
[k
]);
676 memcpy(q
, template[i
].input
+ temp
, template[i
].tap
[k
]);
677 sg_set_buf(&sg
[template[i
].anp
+ k
],
678 q
, template[i
].tap
[k
]);
681 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
682 offset_in_page(IDX
[k
]);
684 memset(q
, 0, template[i
].tap
[k
]);
686 sg_set_buf(&sgout
[template[i
].anp
+ k
],
687 q
, template[i
].tap
[k
]);
690 n
= template[i
].tap
[k
];
691 if (k
== template[i
].np
- 1 && enc
)
693 if (offset_in_page(q
) + n
< PAGE_SIZE
)
696 temp
+= template[i
].tap
[k
];
699 ret
= crypto_aead_setauthsize(tfm
, authsize
);
701 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
702 d
, authsize
, j
, algo
);
707 if (WARN_ON(sg
[template[i
].anp
+ k
- 1].offset
+
708 sg
[template[i
].anp
+ k
- 1].length
+
709 authsize
> PAGE_SIZE
)) {
715 sgout
[template[i
].anp
+ k
- 1].length
+=
717 sg
[template[i
].anp
+ k
- 1].length
+= authsize
;
720 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
724 aead_request_set_ad(req
, template[i
].alen
);
726 ret
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
730 if (template[i
].novrfy
) {
731 /* verification was supposed to fail */
732 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
734 /* so really, we got a bad message */
741 wait_for_completion(&result
.completion
);
742 reinit_completion(&result
.completion
);
747 if (template[i
].novrfy
)
748 /* verification failure was expected */
752 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
753 d
, e
, j
, algo
, -ret
);
758 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
760 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
761 offset_in_page(IDX
[k
]);
763 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
764 offset_in_page(IDX
[k
]);
766 n
= template[i
].tap
[k
];
767 if (k
== template[i
].np
- 1)
768 n
+= enc
? authsize
: -authsize
;
770 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
771 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
778 if (k
== template[i
].np
- 1 && !enc
) {
780 memcmp(q
, template[i
].input
+
786 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
790 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
791 d
, j
, e
, k
, algo
, n
);
796 temp
+= template[i
].tap
[k
];
803 aead_request_free(req
);
807 testmgr_free_buf(xoutbuf
);
809 testmgr_free_buf(axbuf
);
811 testmgr_free_buf(xbuf
);
818 static int test_aead(struct crypto_aead
*tfm
, int enc
,
819 struct aead_testvec
*template, unsigned int tcount
)
821 unsigned int alignmask
;
824 /* test 'dst == src' case */
825 ret
= __test_aead(tfm
, enc
, template, tcount
, false, 0);
829 /* test 'dst != src' case */
830 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 0);
834 /* test unaligned buffers, check with one byte offset */
835 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 1);
839 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
841 /* Check if alignment mask for tfm is correctly set. */
842 ret
= __test_aead(tfm
, enc
, template, tcount
, true,
851 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
852 struct cipher_testvec
*template, unsigned int tcount
)
854 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
855 unsigned int i
, j
, k
;
859 char *xbuf
[XBUFSIZE
];
862 if (testmgr_alloc_buf(xbuf
))
871 for (i
= 0; i
< tcount
; i
++) {
878 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
882 memcpy(data
, template[i
].input
, template[i
].ilen
);
884 crypto_cipher_clear_flags(tfm
, ~0);
886 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
888 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
890 if (!ret
== template[i
].fail
) {
891 printk(KERN_ERR
"alg: cipher: setkey failed "
892 "on test %d for %s: flags=%x\n", j
,
893 algo
, crypto_cipher_get_flags(tfm
));
898 for (k
= 0; k
< template[i
].ilen
;
899 k
+= crypto_cipher_blocksize(tfm
)) {
901 crypto_cipher_encrypt_one(tfm
, data
+ k
,
904 crypto_cipher_decrypt_one(tfm
, data
+ k
,
909 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
910 printk(KERN_ERR
"alg: cipher: Test %d failed "
911 "on %s for %s\n", j
, e
, algo
);
912 hexdump(q
, template[i
].rlen
);
921 testmgr_free_buf(xbuf
);
926 static int __test_skcipher(struct crypto_skcipher
*tfm
, int enc
,
927 struct cipher_testvec
*template, unsigned int tcount
,
928 const bool diff_dst
, const int align_offset
)
931 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm
));
932 unsigned int i
, j
, k
, n
, temp
;
934 struct skcipher_request
*req
;
935 struct scatterlist sg
[8];
936 struct scatterlist sgout
[8];
938 struct tcrypt_result result
;
941 char *xbuf
[XBUFSIZE
];
942 char *xoutbuf
[XBUFSIZE
];
944 unsigned int ivsize
= crypto_skcipher_ivsize(tfm
);
946 if (testmgr_alloc_buf(xbuf
))
949 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
962 init_completion(&result
.completion
);
964 req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
966 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
971 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
972 tcrypt_complete
, &result
);
975 for (i
= 0; i
< tcount
; i
++) {
976 if (template[i
].np
&& !template[i
].also_non_np
)
980 memcpy(iv
, template[i
].iv
, ivsize
);
982 memset(iv
, 0, MAX_IVLEN
);
986 if (WARN_ON(align_offset
+ template[i
].ilen
> PAGE_SIZE
))
990 data
+= align_offset
;
991 memcpy(data
, template[i
].input
, template[i
].ilen
);
993 crypto_skcipher_clear_flags(tfm
, ~0);
995 crypto_skcipher_set_flags(tfm
,
996 CRYPTO_TFM_REQ_WEAK_KEY
);
998 ret
= crypto_skcipher_setkey(tfm
, template[i
].key
,
1000 if (!ret
== template[i
].fail
) {
1001 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
1002 d
, j
, algo
, crypto_skcipher_get_flags(tfm
));
1007 sg_init_one(&sg
[0], data
, template[i
].ilen
);
1010 data
+= align_offset
;
1011 sg_init_one(&sgout
[0], data
, template[i
].ilen
);
1014 skcipher_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
1015 template[i
].ilen
, iv
);
1016 ret
= enc
? crypto_skcipher_encrypt(req
) :
1017 crypto_skcipher_decrypt(req
);
1024 wait_for_completion(&result
.completion
);
1025 reinit_completion(&result
.completion
);
1031 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1032 d
, e
, j
, algo
, -ret
);
1037 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
1038 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
1040 hexdump(q
, template[i
].rlen
);
1045 if (template[i
].iv_out
&&
1046 memcmp(iv
, template[i
].iv_out
,
1047 crypto_skcipher_ivsize(tfm
))) {
1048 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1050 hexdump(iv
, crypto_skcipher_ivsize(tfm
));
1057 for (i
= 0; i
< tcount
; i
++) {
1058 /* alignment tests are only done with continuous buffers */
1059 if (align_offset
!= 0)
1062 if (!template[i
].np
)
1066 memcpy(iv
, template[i
].iv
, ivsize
);
1068 memset(iv
, 0, MAX_IVLEN
);
1071 crypto_skcipher_clear_flags(tfm
, ~0);
1073 crypto_skcipher_set_flags(tfm
,
1074 CRYPTO_TFM_REQ_WEAK_KEY
);
1076 ret
= crypto_skcipher_setkey(tfm
, template[i
].key
,
1078 if (!ret
== template[i
].fail
) {
1079 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1080 d
, j
, algo
, crypto_skcipher_get_flags(tfm
));
1087 sg_init_table(sg
, template[i
].np
);
1089 sg_init_table(sgout
, template[i
].np
);
1090 for (k
= 0; k
< template[i
].np
; k
++) {
1091 if (WARN_ON(offset_in_page(IDX
[k
]) +
1092 template[i
].tap
[k
] > PAGE_SIZE
))
1095 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] + offset_in_page(IDX
[k
]);
1097 memcpy(q
, template[i
].input
+ temp
, template[i
].tap
[k
]);
1099 if (offset_in_page(q
) + template[i
].tap
[k
] < PAGE_SIZE
)
1100 q
[template[i
].tap
[k
]] = 0;
1102 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
1104 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1105 offset_in_page(IDX
[k
]);
1107 sg_set_buf(&sgout
[k
], q
, template[i
].tap
[k
]);
1109 memset(q
, 0, template[i
].tap
[k
]);
1110 if (offset_in_page(q
) +
1111 template[i
].tap
[k
] < PAGE_SIZE
)
1112 q
[template[i
].tap
[k
]] = 0;
1115 temp
+= template[i
].tap
[k
];
1118 skcipher_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
1119 template[i
].ilen
, iv
);
1121 ret
= enc
? crypto_skcipher_encrypt(req
) :
1122 crypto_skcipher_decrypt(req
);
1129 wait_for_completion(&result
.completion
);
1130 reinit_completion(&result
.completion
);
1136 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1137 d
, e
, j
, algo
, -ret
);
1143 for (k
= 0; k
< template[i
].np
; k
++) {
1145 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1146 offset_in_page(IDX
[k
]);
1148 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1149 offset_in_page(IDX
[k
]);
1151 if (memcmp(q
, template[i
].result
+ temp
,
1152 template[i
].tap
[k
])) {
1153 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1155 hexdump(q
, template[i
].tap
[k
]);
1159 q
+= template[i
].tap
[k
];
1160 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
1163 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1164 d
, j
, e
, k
, algo
, n
);
1168 temp
+= template[i
].tap
[k
];
1175 skcipher_request_free(req
);
1177 testmgr_free_buf(xoutbuf
);
1179 testmgr_free_buf(xbuf
);
1184 static int test_skcipher(struct crypto_skcipher
*tfm
, int enc
,
1185 struct cipher_testvec
*template, unsigned int tcount
)
1187 unsigned int alignmask
;
1190 /* test 'dst == src' case */
1191 ret
= __test_skcipher(tfm
, enc
, template, tcount
, false, 0);
1195 /* test 'dst != src' case */
1196 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 0);
1200 /* test unaligned buffers, check with one byte offset */
1201 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 1);
1205 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
1207 /* Check if alignment mask for tfm is correctly set. */
1208 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true,
1217 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
1218 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1220 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
1222 char result
[COMP_BUF_SIZE
];
1225 for (i
= 0; i
< ctcount
; i
++) {
1227 unsigned int dlen
= COMP_BUF_SIZE
;
1229 memset(result
, 0, sizeof (result
));
1231 ilen
= ctemplate
[i
].inlen
;
1232 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1233 ilen
, result
, &dlen
);
1235 printk(KERN_ERR
"alg: comp: compression failed "
1236 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1241 if (dlen
!= ctemplate
[i
].outlen
) {
1242 printk(KERN_ERR
"alg: comp: Compression test %d "
1243 "failed for %s: output len = %d\n", i
+ 1, algo
,
1249 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
1250 printk(KERN_ERR
"alg: comp: Compression test %d "
1251 "failed for %s\n", i
+ 1, algo
);
1252 hexdump(result
, dlen
);
1258 for (i
= 0; i
< dtcount
; i
++) {
1260 unsigned int dlen
= COMP_BUF_SIZE
;
1262 memset(result
, 0, sizeof (result
));
1264 ilen
= dtemplate
[i
].inlen
;
1265 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1266 ilen
, result
, &dlen
);
1268 printk(KERN_ERR
"alg: comp: decompression failed "
1269 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1274 if (dlen
!= dtemplate
[i
].outlen
) {
1275 printk(KERN_ERR
"alg: comp: Decompression test %d "
1276 "failed for %s: output len = %d\n", i
+ 1, algo
,
1282 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
1283 printk(KERN_ERR
"alg: comp: Decompression test %d "
1284 "failed for %s\n", i
+ 1, algo
);
1285 hexdump(result
, dlen
);
1297 static int test_pcomp(struct crypto_pcomp
*tfm
,
1298 struct pcomp_testvec
*ctemplate
,
1299 struct pcomp_testvec
*dtemplate
, int ctcount
,
1302 const char *algo
= crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm
));
1304 char result
[COMP_BUF_SIZE
];
1307 for (i
= 0; i
< ctcount
; i
++) {
1308 struct comp_request req
;
1309 unsigned int produced
= 0;
1311 res
= crypto_compress_setup(tfm
, ctemplate
[i
].params
,
1312 ctemplate
[i
].paramsize
);
1314 pr_err("alg: pcomp: compression setup failed on test "
1315 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1319 res
= crypto_compress_init(tfm
);
1321 pr_err("alg: pcomp: compression init failed on test "
1322 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1326 memset(result
, 0, sizeof(result
));
1328 req
.next_in
= ctemplate
[i
].input
;
1329 req
.avail_in
= ctemplate
[i
].inlen
/ 2;
1330 req
.next_out
= result
;
1331 req
.avail_out
= ctemplate
[i
].outlen
/ 2;
1333 res
= crypto_compress_update(tfm
, &req
);
1334 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1335 pr_err("alg: pcomp: compression update failed on test "
1336 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1342 /* Add remaining input data */
1343 req
.avail_in
+= (ctemplate
[i
].inlen
+ 1) / 2;
1345 res
= crypto_compress_update(tfm
, &req
);
1346 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1347 pr_err("alg: pcomp: compression update failed on test "
1348 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1354 /* Provide remaining output space */
1355 req
.avail_out
+= COMP_BUF_SIZE
- ctemplate
[i
].outlen
/ 2;
1357 res
= crypto_compress_final(tfm
, &req
);
1359 pr_err("alg: pcomp: compression final failed on test "
1360 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1365 if (COMP_BUF_SIZE
- req
.avail_out
!= ctemplate
[i
].outlen
) {
1366 pr_err("alg: comp: Compression test %d failed for %s: "
1367 "output len = %d (expected %d)\n", i
+ 1, algo
,
1368 COMP_BUF_SIZE
- req
.avail_out
,
1369 ctemplate
[i
].outlen
);
1373 if (produced
!= ctemplate
[i
].outlen
) {
1374 pr_err("alg: comp: Compression test %d failed for %s: "
1375 "returned len = %u (expected %d)\n", i
+ 1,
1376 algo
, produced
, ctemplate
[i
].outlen
);
1380 if (memcmp(result
, ctemplate
[i
].output
, ctemplate
[i
].outlen
)) {
1381 pr_err("alg: pcomp: Compression test %d failed for "
1382 "%s\n", i
+ 1, algo
);
1383 hexdump(result
, ctemplate
[i
].outlen
);
1388 for (i
= 0; i
< dtcount
; i
++) {
1389 struct comp_request req
;
1390 unsigned int produced
= 0;
1392 res
= crypto_decompress_setup(tfm
, dtemplate
[i
].params
,
1393 dtemplate
[i
].paramsize
);
1395 pr_err("alg: pcomp: decompression setup failed on "
1396 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1400 res
= crypto_decompress_init(tfm
);
1402 pr_err("alg: pcomp: decompression init failed on test "
1403 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1407 memset(result
, 0, sizeof(result
));
1409 req
.next_in
= dtemplate
[i
].input
;
1410 req
.avail_in
= dtemplate
[i
].inlen
/ 2;
1411 req
.next_out
= result
;
1412 req
.avail_out
= dtemplate
[i
].outlen
/ 2;
1414 res
= crypto_decompress_update(tfm
, &req
);
1415 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1416 pr_err("alg: pcomp: decompression update failed on "
1417 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1423 /* Add remaining input data */
1424 req
.avail_in
+= (dtemplate
[i
].inlen
+ 1) / 2;
1426 res
= crypto_decompress_update(tfm
, &req
);
1427 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1428 pr_err("alg: pcomp: decompression update failed on "
1429 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1435 /* Provide remaining output space */
1436 req
.avail_out
+= COMP_BUF_SIZE
- dtemplate
[i
].outlen
/ 2;
1438 res
= crypto_decompress_final(tfm
, &req
);
1439 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1440 pr_err("alg: pcomp: decompression final failed on "
1441 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1447 if (COMP_BUF_SIZE
- req
.avail_out
!= dtemplate
[i
].outlen
) {
1448 pr_err("alg: comp: Decompression test %d failed for "
1449 "%s: output len = %d (expected %d)\n", i
+ 1,
1450 algo
, COMP_BUF_SIZE
- req
.avail_out
,
1451 dtemplate
[i
].outlen
);
1455 if (produced
!= dtemplate
[i
].outlen
) {
1456 pr_err("alg: comp: Decompression test %d failed for "
1457 "%s: returned len = %u (expected %d)\n", i
+ 1,
1458 algo
, produced
, dtemplate
[i
].outlen
);
1462 if (memcmp(result
, dtemplate
[i
].output
, dtemplate
[i
].outlen
)) {
1463 pr_err("alg: pcomp: Decompression test %d failed for "
1464 "%s\n", i
+ 1, algo
);
1465 hexdump(result
, dtemplate
[i
].outlen
);
1474 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1475 unsigned int tcount
)
1477 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1478 int err
= 0, i
, j
, seedsize
;
1482 seedsize
= crypto_rng_seedsize(tfm
);
1484 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1486 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1491 for (i
= 0; i
< tcount
; i
++) {
1492 memset(result
, 0, 32);
1494 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1495 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1497 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1498 template[i
].dt
, template[i
].dtlen
);
1500 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1502 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1507 for (j
= 0; j
< template[i
].loops
; j
++) {
1508 err
= crypto_rng_get_bytes(tfm
, result
,
1511 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1512 "the correct amount of random data for "
1513 "%s (requested %d)\n", algo
,
1519 err
= memcmp(result
, template[i
].result
,
1522 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1524 hexdump(result
, template[i
].rlen
);
1535 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1538 struct crypto_aead
*tfm
;
1541 tfm
= crypto_alloc_aead(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1543 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1544 "%ld\n", driver
, PTR_ERR(tfm
));
1545 return PTR_ERR(tfm
);
1548 if (desc
->suite
.aead
.enc
.vecs
) {
1549 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1550 desc
->suite
.aead
.enc
.count
);
1555 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1556 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1557 desc
->suite
.aead
.dec
.count
);
1560 crypto_free_aead(tfm
);
1564 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1565 const char *driver
, u32 type
, u32 mask
)
1567 struct crypto_cipher
*tfm
;
1570 tfm
= crypto_alloc_cipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1572 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1573 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1574 return PTR_ERR(tfm
);
1577 if (desc
->suite
.cipher
.enc
.vecs
) {
1578 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1579 desc
->suite
.cipher
.enc
.count
);
1584 if (desc
->suite
.cipher
.dec
.vecs
)
1585 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1586 desc
->suite
.cipher
.dec
.count
);
1589 crypto_free_cipher(tfm
);
1593 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1594 const char *driver
, u32 type
, u32 mask
)
1596 struct crypto_skcipher
*tfm
;
1599 tfm
= crypto_alloc_skcipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1601 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1602 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1603 return PTR_ERR(tfm
);
1606 if (desc
->suite
.cipher
.enc
.vecs
) {
1607 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1608 desc
->suite
.cipher
.enc
.count
);
1613 if (desc
->suite
.cipher
.dec
.vecs
)
1614 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1615 desc
->suite
.cipher
.dec
.count
);
1618 crypto_free_skcipher(tfm
);
1622 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1625 struct crypto_comp
*tfm
;
1628 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1630 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1631 "%ld\n", driver
, PTR_ERR(tfm
));
1632 return PTR_ERR(tfm
);
1635 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1636 desc
->suite
.comp
.decomp
.vecs
,
1637 desc
->suite
.comp
.comp
.count
,
1638 desc
->suite
.comp
.decomp
.count
);
1640 crypto_free_comp(tfm
);
1644 static int alg_test_pcomp(const struct alg_test_desc
*desc
, const char *driver
,
1647 struct crypto_pcomp
*tfm
;
1650 tfm
= crypto_alloc_pcomp(driver
, type
, mask
);
1652 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1653 driver
, PTR_ERR(tfm
));
1654 return PTR_ERR(tfm
);
1657 err
= test_pcomp(tfm
, desc
->suite
.pcomp
.comp
.vecs
,
1658 desc
->suite
.pcomp
.decomp
.vecs
,
1659 desc
->suite
.pcomp
.comp
.count
,
1660 desc
->suite
.pcomp
.decomp
.count
);
1662 crypto_free_pcomp(tfm
);
1666 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1669 struct crypto_ahash
*tfm
;
1672 tfm
= crypto_alloc_ahash(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1674 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1675 "%ld\n", driver
, PTR_ERR(tfm
));
1676 return PTR_ERR(tfm
);
1679 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1680 desc
->suite
.hash
.count
, true);
1682 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1683 desc
->suite
.hash
.count
, false);
1685 crypto_free_ahash(tfm
);
1689 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1690 const char *driver
, u32 type
, u32 mask
)
1692 struct crypto_shash
*tfm
;
1696 err
= alg_test_hash(desc
, driver
, type
, mask
);
1700 tfm
= crypto_alloc_shash(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1702 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1703 "%ld\n", driver
, PTR_ERR(tfm
));
1709 SHASH_DESC_ON_STACK(shash
, tfm
);
1710 u32
*ctx
= (u32
*)shash_desc_ctx(shash
);
1715 *ctx
= le32_to_cpu(420553207);
1716 err
= crypto_shash_final(shash
, (u8
*)&val
);
1718 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1719 "%s: %d\n", driver
, err
);
1723 if (val
!= ~420553207) {
1724 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1725 "%d\n", driver
, val
);
1730 crypto_free_shash(tfm
);
1736 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1739 struct crypto_rng
*rng
;
1742 rng
= crypto_alloc_rng(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1744 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1745 "%ld\n", driver
, PTR_ERR(rng
));
1746 return PTR_ERR(rng
);
1749 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1751 crypto_free_rng(rng
);
1757 static int drbg_cavs_test(struct drbg_testvec
*test
, int pr
,
1758 const char *driver
, u32 type
, u32 mask
)
1761 struct crypto_rng
*drng
;
1762 struct drbg_test_data test_data
;
1763 struct drbg_string addtl
, pers
, testentropy
;
1764 unsigned char *buf
= kzalloc(test
->expectedlen
, GFP_KERNEL
);
1769 drng
= crypto_alloc_rng(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1771 printk(KERN_ERR
"alg: drbg: could not allocate DRNG handle for "
1777 test_data
.testentropy
= &testentropy
;
1778 drbg_string_fill(&testentropy
, test
->entropy
, test
->entropylen
);
1779 drbg_string_fill(&pers
, test
->pers
, test
->perslen
);
1780 ret
= crypto_drbg_reset_test(drng
, &pers
, &test_data
);
1782 printk(KERN_ERR
"alg: drbg: Failed to reset rng\n");
1786 drbg_string_fill(&addtl
, test
->addtla
, test
->addtllen
);
1788 drbg_string_fill(&testentropy
, test
->entpra
, test
->entprlen
);
1789 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1790 buf
, test
->expectedlen
, &addtl
, &test_data
);
1792 ret
= crypto_drbg_get_bytes_addtl(drng
,
1793 buf
, test
->expectedlen
, &addtl
);
1796 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1797 "driver %s\n", driver
);
1801 drbg_string_fill(&addtl
, test
->addtlb
, test
->addtllen
);
1803 drbg_string_fill(&testentropy
, test
->entprb
, test
->entprlen
);
1804 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1805 buf
, test
->expectedlen
, &addtl
, &test_data
);
1807 ret
= crypto_drbg_get_bytes_addtl(drng
,
1808 buf
, test
->expectedlen
, &addtl
);
1811 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1812 "driver %s\n", driver
);
1816 ret
= memcmp(test
->expected
, buf
, test
->expectedlen
);
1819 crypto_free_rng(drng
);
1825 static int alg_test_drbg(const struct alg_test_desc
*desc
, const char *driver
,
1831 struct drbg_testvec
*template = desc
->suite
.drbg
.vecs
;
1832 unsigned int tcount
= desc
->suite
.drbg
.count
;
1834 if (0 == memcmp(driver
, "drbg_pr_", 8))
1837 for (i
= 0; i
< tcount
; i
++) {
1838 err
= drbg_cavs_test(&template[i
], pr
, driver
, type
, mask
);
1840 printk(KERN_ERR
"alg: drbg: Test %d failed for %s\n",
1850 static int do_test_rsa(struct crypto_akcipher
*tfm
,
1851 struct akcipher_testvec
*vecs
)
1853 char *xbuf
[XBUFSIZE
];
1854 struct akcipher_request
*req
;
1855 void *outbuf_enc
= NULL
;
1856 void *outbuf_dec
= NULL
;
1857 struct tcrypt_result result
;
1858 unsigned int out_len_max
, out_len
= 0;
1860 struct scatterlist src
, dst
, src_tab
[2];
1862 if (testmgr_alloc_buf(xbuf
))
1865 req
= akcipher_request_alloc(tfm
, GFP_KERNEL
);
1869 init_completion(&result
.completion
);
1871 if (vecs
->public_key_vec
)
1872 err
= crypto_akcipher_set_pub_key(tfm
, vecs
->key
,
1875 err
= crypto_akcipher_set_priv_key(tfm
, vecs
->key
,
1880 out_len_max
= crypto_akcipher_maxsize(tfm
);
1881 outbuf_enc
= kzalloc(out_len_max
, GFP_KERNEL
);
1885 if (WARN_ON(vecs
->m_size
> PAGE_SIZE
))
1888 memcpy(xbuf
[0], vecs
->m
, vecs
->m_size
);
1890 sg_init_table(src_tab
, 2);
1891 sg_set_buf(&src_tab
[0], xbuf
[0], 8);
1892 sg_set_buf(&src_tab
[1], xbuf
[0] + 8, vecs
->m_size
- 8);
1893 sg_init_one(&dst
, outbuf_enc
, out_len_max
);
1894 akcipher_request_set_crypt(req
, src_tab
, &dst
, vecs
->m_size
,
1896 akcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1897 tcrypt_complete
, &result
);
1899 /* Run RSA encrypt - c = m^e mod n;*/
1900 err
= wait_async_op(&result
, crypto_akcipher_encrypt(req
));
1902 pr_err("alg: rsa: encrypt test failed. err %d\n", err
);
1905 if (req
->dst_len
!= vecs
->c_size
) {
1906 pr_err("alg: rsa: encrypt test failed. Invalid output len\n");
1910 /* verify that encrypted message is equal to expected */
1911 if (memcmp(vecs
->c
, outbuf_enc
, vecs
->c_size
)) {
1912 pr_err("alg: rsa: encrypt test failed. Invalid output\n");
1916 /* Don't invoke decrypt for vectors with public key */
1917 if (vecs
->public_key_vec
) {
1921 outbuf_dec
= kzalloc(out_len_max
, GFP_KERNEL
);
1927 if (WARN_ON(vecs
->c_size
> PAGE_SIZE
))
1930 memcpy(xbuf
[0], vecs
->c
, vecs
->c_size
);
1932 sg_init_one(&src
, xbuf
[0], vecs
->c_size
);
1933 sg_init_one(&dst
, outbuf_dec
, out_len_max
);
1934 init_completion(&result
.completion
);
1935 akcipher_request_set_crypt(req
, &src
, &dst
, vecs
->c_size
, out_len_max
);
1937 /* Run RSA decrypt - m = c^d mod n;*/
1938 err
= wait_async_op(&result
, crypto_akcipher_decrypt(req
));
1940 pr_err("alg: rsa: decrypt test failed. err %d\n", err
);
1943 out_len
= req
->dst_len
;
1944 if (out_len
!= vecs
->m_size
) {
1945 pr_err("alg: rsa: decrypt test failed. Invalid output len\n");
1949 /* verify that decrypted message is equal to the original msg */
1950 if (memcmp(vecs
->m
, outbuf_dec
, vecs
->m_size
)) {
1951 pr_err("alg: rsa: decrypt test failed. Invalid output\n");
1958 akcipher_request_free(req
);
1960 testmgr_free_buf(xbuf
);
1964 static int test_rsa(struct crypto_akcipher
*tfm
, struct akcipher_testvec
*vecs
,
1965 unsigned int tcount
)
1969 for (i
= 0; i
< tcount
; i
++) {
1970 ret
= do_test_rsa(tfm
, vecs
++);
1972 pr_err("alg: rsa: test failed on vector %d, err=%d\n",
1980 static int test_akcipher(struct crypto_akcipher
*tfm
, const char *alg
,
1981 struct akcipher_testvec
*vecs
, unsigned int tcount
)
1983 if (strncmp(alg
, "rsa", 3) == 0)
1984 return test_rsa(tfm
, vecs
, tcount
);
1989 static int alg_test_akcipher(const struct alg_test_desc
*desc
,
1990 const char *driver
, u32 type
, u32 mask
)
1992 struct crypto_akcipher
*tfm
;
1995 tfm
= crypto_alloc_akcipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1997 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
1998 driver
, PTR_ERR(tfm
));
1999 return PTR_ERR(tfm
);
2001 if (desc
->suite
.akcipher
.vecs
)
2002 err
= test_akcipher(tfm
, desc
->alg
, desc
->suite
.akcipher
.vecs
,
2003 desc
->suite
.akcipher
.count
);
2005 crypto_free_akcipher(tfm
);
2009 static int alg_test_null(const struct alg_test_desc
*desc
,
2010 const char *driver
, u32 type
, u32 mask
)
2015 /* Please keep this list sorted by algorithm name. */
2016 static const struct alg_test_desc alg_test_descs
[] = {
2018 .alg
= "__cbc-cast5-avx",
2019 .test
= alg_test_null
,
2021 .alg
= "__cbc-cast6-avx",
2022 .test
= alg_test_null
,
2024 .alg
= "__cbc-serpent-avx",
2025 .test
= alg_test_null
,
2027 .alg
= "__cbc-serpent-avx2",
2028 .test
= alg_test_null
,
2030 .alg
= "__cbc-serpent-sse2",
2031 .test
= alg_test_null
,
2033 .alg
= "__cbc-twofish-avx",
2034 .test
= alg_test_null
,
2036 .alg
= "__driver-cbc-aes-aesni",
2037 .test
= alg_test_null
,
2040 .alg
= "__driver-cbc-camellia-aesni",
2041 .test
= alg_test_null
,
2043 .alg
= "__driver-cbc-camellia-aesni-avx2",
2044 .test
= alg_test_null
,
2046 .alg
= "__driver-cbc-cast5-avx",
2047 .test
= alg_test_null
,
2049 .alg
= "__driver-cbc-cast6-avx",
2050 .test
= alg_test_null
,
2052 .alg
= "__driver-cbc-serpent-avx",
2053 .test
= alg_test_null
,
2055 .alg
= "__driver-cbc-serpent-avx2",
2056 .test
= alg_test_null
,
2058 .alg
= "__driver-cbc-serpent-sse2",
2059 .test
= alg_test_null
,
2061 .alg
= "__driver-cbc-twofish-avx",
2062 .test
= alg_test_null
,
2064 .alg
= "__driver-ecb-aes-aesni",
2065 .test
= alg_test_null
,
2068 .alg
= "__driver-ecb-camellia-aesni",
2069 .test
= alg_test_null
,
2071 .alg
= "__driver-ecb-camellia-aesni-avx2",
2072 .test
= alg_test_null
,
2074 .alg
= "__driver-ecb-cast5-avx",
2075 .test
= alg_test_null
,
2077 .alg
= "__driver-ecb-cast6-avx",
2078 .test
= alg_test_null
,
2080 .alg
= "__driver-ecb-serpent-avx",
2081 .test
= alg_test_null
,
2083 .alg
= "__driver-ecb-serpent-avx2",
2084 .test
= alg_test_null
,
2086 .alg
= "__driver-ecb-serpent-sse2",
2087 .test
= alg_test_null
,
2089 .alg
= "__driver-ecb-twofish-avx",
2090 .test
= alg_test_null
,
2092 .alg
= "__driver-gcm-aes-aesni",
2093 .test
= alg_test_null
,
2096 .alg
= "__ghash-pclmulqdqni",
2097 .test
= alg_test_null
,
2100 .alg
= "ansi_cprng",
2101 .test
= alg_test_cprng
,
2105 .vecs
= ansi_cprng_aes_tv_template
,
2106 .count
= ANSI_CPRNG_AES_TEST_VECTORS
2110 .alg
= "authenc(hmac(md5),ecb(cipher_null))",
2111 .test
= alg_test_aead
,
2115 .vecs
= hmac_md5_ecb_cipher_null_enc_tv_template
,
2116 .count
= HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
2119 .vecs
= hmac_md5_ecb_cipher_null_dec_tv_template
,
2120 .count
= HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
2125 .alg
= "authenc(hmac(sha1),cbc(aes))",
2126 .test
= alg_test_aead
,
2131 hmac_sha1_aes_cbc_enc_tv_temp
,
2133 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
2138 .alg
= "authenc(hmac(sha1),cbc(des))",
2139 .test
= alg_test_aead
,
2144 hmac_sha1_des_cbc_enc_tv_temp
,
2146 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2151 .alg
= "authenc(hmac(sha1),cbc(des3_ede))",
2152 .test
= alg_test_aead
,
2157 hmac_sha1_des3_ede_cbc_enc_tv_temp
,
2159 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
2164 .alg
= "authenc(hmac(sha1),ecb(cipher_null))",
2165 .test
= alg_test_aead
,
2170 hmac_sha1_ecb_cipher_null_enc_tv_temp
,
2172 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
2176 hmac_sha1_ecb_cipher_null_dec_tv_temp
,
2178 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2183 .alg
= "authenc(hmac(sha224),cbc(des))",
2184 .test
= alg_test_aead
,
2189 hmac_sha224_des_cbc_enc_tv_temp
,
2191 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2196 .alg
= "authenc(hmac(sha224),cbc(des3_ede))",
2197 .test
= alg_test_aead
,
2202 hmac_sha224_des3_ede_cbc_enc_tv_temp
,
2204 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
2209 .alg
= "authenc(hmac(sha256),cbc(aes))",
2210 .test
= alg_test_aead
,
2215 hmac_sha256_aes_cbc_enc_tv_temp
,
2217 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2222 .alg
= "authenc(hmac(sha256),cbc(des))",
2223 .test
= alg_test_aead
,
2228 hmac_sha256_des_cbc_enc_tv_temp
,
2230 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2235 .alg
= "authenc(hmac(sha256),cbc(des3_ede))",
2236 .test
= alg_test_aead
,
2241 hmac_sha256_des3_ede_cbc_enc_tv_temp
,
2243 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2248 .alg
= "authenc(hmac(sha384),cbc(des))",
2249 .test
= alg_test_aead
,
2254 hmac_sha384_des_cbc_enc_tv_temp
,
2256 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2261 .alg
= "authenc(hmac(sha384),cbc(des3_ede))",
2262 .test
= alg_test_aead
,
2267 hmac_sha384_des3_ede_cbc_enc_tv_temp
,
2269 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
2274 .alg
= "authenc(hmac(sha512),cbc(aes))",
2275 .test
= alg_test_aead
,
2280 hmac_sha512_aes_cbc_enc_tv_temp
,
2282 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2287 .alg
= "authenc(hmac(sha512),cbc(des))",
2288 .test
= alg_test_aead
,
2293 hmac_sha512_des_cbc_enc_tv_temp
,
2295 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2300 .alg
= "authenc(hmac(sha512),cbc(des3_ede))",
2301 .test
= alg_test_aead
,
2306 hmac_sha512_des3_ede_cbc_enc_tv_temp
,
2308 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2314 .test
= alg_test_skcipher
,
2319 .vecs
= aes_cbc_enc_tv_template
,
2320 .count
= AES_CBC_ENC_TEST_VECTORS
2323 .vecs
= aes_cbc_dec_tv_template
,
2324 .count
= AES_CBC_DEC_TEST_VECTORS
2329 .alg
= "cbc(anubis)",
2330 .test
= alg_test_skcipher
,
2334 .vecs
= anubis_cbc_enc_tv_template
,
2335 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
2338 .vecs
= anubis_cbc_dec_tv_template
,
2339 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
2344 .alg
= "cbc(blowfish)",
2345 .test
= alg_test_skcipher
,
2349 .vecs
= bf_cbc_enc_tv_template
,
2350 .count
= BF_CBC_ENC_TEST_VECTORS
2353 .vecs
= bf_cbc_dec_tv_template
,
2354 .count
= BF_CBC_DEC_TEST_VECTORS
2359 .alg
= "cbc(camellia)",
2360 .test
= alg_test_skcipher
,
2364 .vecs
= camellia_cbc_enc_tv_template
,
2365 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
2368 .vecs
= camellia_cbc_dec_tv_template
,
2369 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
2374 .alg
= "cbc(cast5)",
2375 .test
= alg_test_skcipher
,
2379 .vecs
= cast5_cbc_enc_tv_template
,
2380 .count
= CAST5_CBC_ENC_TEST_VECTORS
2383 .vecs
= cast5_cbc_dec_tv_template
,
2384 .count
= CAST5_CBC_DEC_TEST_VECTORS
2389 .alg
= "cbc(cast6)",
2390 .test
= alg_test_skcipher
,
2394 .vecs
= cast6_cbc_enc_tv_template
,
2395 .count
= CAST6_CBC_ENC_TEST_VECTORS
2398 .vecs
= cast6_cbc_dec_tv_template
,
2399 .count
= CAST6_CBC_DEC_TEST_VECTORS
2405 .test
= alg_test_skcipher
,
2409 .vecs
= des_cbc_enc_tv_template
,
2410 .count
= DES_CBC_ENC_TEST_VECTORS
2413 .vecs
= des_cbc_dec_tv_template
,
2414 .count
= DES_CBC_DEC_TEST_VECTORS
2419 .alg
= "cbc(des3_ede)",
2420 .test
= alg_test_skcipher
,
2425 .vecs
= des3_ede_cbc_enc_tv_template
,
2426 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
2429 .vecs
= des3_ede_cbc_dec_tv_template
,
2430 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
2435 .alg
= "cbc(serpent)",
2436 .test
= alg_test_skcipher
,
2440 .vecs
= serpent_cbc_enc_tv_template
,
2441 .count
= SERPENT_CBC_ENC_TEST_VECTORS
2444 .vecs
= serpent_cbc_dec_tv_template
,
2445 .count
= SERPENT_CBC_DEC_TEST_VECTORS
2450 .alg
= "cbc(twofish)",
2451 .test
= alg_test_skcipher
,
2455 .vecs
= tf_cbc_enc_tv_template
,
2456 .count
= TF_CBC_ENC_TEST_VECTORS
2459 .vecs
= tf_cbc_dec_tv_template
,
2460 .count
= TF_CBC_DEC_TEST_VECTORS
2466 .test
= alg_test_aead
,
2471 .vecs
= aes_ccm_enc_tv_template
,
2472 .count
= AES_CCM_ENC_TEST_VECTORS
2475 .vecs
= aes_ccm_dec_tv_template
,
2476 .count
= AES_CCM_DEC_TEST_VECTORS
2482 .test
= alg_test_skcipher
,
2486 .vecs
= chacha20_enc_tv_template
,
2487 .count
= CHACHA20_ENC_TEST_VECTORS
2490 .vecs
= chacha20_enc_tv_template
,
2491 .count
= CHACHA20_ENC_TEST_VECTORS
2498 .test
= alg_test_hash
,
2501 .vecs
= aes_cmac128_tv_template
,
2502 .count
= CMAC_AES_TEST_VECTORS
2506 .alg
= "cmac(des3_ede)",
2508 .test
= alg_test_hash
,
2511 .vecs
= des3_ede_cmac64_tv_template
,
2512 .count
= CMAC_DES3_EDE_TEST_VECTORS
2516 .alg
= "compress_null",
2517 .test
= alg_test_null
,
2520 .test
= alg_test_hash
,
2523 .vecs
= crc32_tv_template
,
2524 .count
= CRC32_TEST_VECTORS
2529 .test
= alg_test_crc32c
,
2533 .vecs
= crc32c_tv_template
,
2534 .count
= CRC32C_TEST_VECTORS
2539 .test
= alg_test_hash
,
2543 .vecs
= crct10dif_tv_template
,
2544 .count
= CRCT10DIF_TEST_VECTORS
2548 .alg
= "cryptd(__driver-cbc-aes-aesni)",
2549 .test
= alg_test_null
,
2552 .alg
= "cryptd(__driver-cbc-camellia-aesni)",
2553 .test
= alg_test_null
,
2555 .alg
= "cryptd(__driver-cbc-camellia-aesni-avx2)",
2556 .test
= alg_test_null
,
2558 .alg
= "cryptd(__driver-cbc-serpent-avx2)",
2559 .test
= alg_test_null
,
2561 .alg
= "cryptd(__driver-ecb-aes-aesni)",
2562 .test
= alg_test_null
,
2565 .alg
= "cryptd(__driver-ecb-camellia-aesni)",
2566 .test
= alg_test_null
,
2568 .alg
= "cryptd(__driver-ecb-camellia-aesni-avx2)",
2569 .test
= alg_test_null
,
2571 .alg
= "cryptd(__driver-ecb-cast5-avx)",
2572 .test
= alg_test_null
,
2574 .alg
= "cryptd(__driver-ecb-cast6-avx)",
2575 .test
= alg_test_null
,
2577 .alg
= "cryptd(__driver-ecb-serpent-avx)",
2578 .test
= alg_test_null
,
2580 .alg
= "cryptd(__driver-ecb-serpent-avx2)",
2581 .test
= alg_test_null
,
2583 .alg
= "cryptd(__driver-ecb-serpent-sse2)",
2584 .test
= alg_test_null
,
2586 .alg
= "cryptd(__driver-ecb-twofish-avx)",
2587 .test
= alg_test_null
,
2589 .alg
= "cryptd(__driver-gcm-aes-aesni)",
2590 .test
= alg_test_null
,
2593 .alg
= "cryptd(__ghash-pclmulqdqni)",
2594 .test
= alg_test_null
,
2598 .test
= alg_test_skcipher
,
2603 .vecs
= aes_ctr_enc_tv_template
,
2604 .count
= AES_CTR_ENC_TEST_VECTORS
2607 .vecs
= aes_ctr_dec_tv_template
,
2608 .count
= AES_CTR_DEC_TEST_VECTORS
2613 .alg
= "ctr(blowfish)",
2614 .test
= alg_test_skcipher
,
2618 .vecs
= bf_ctr_enc_tv_template
,
2619 .count
= BF_CTR_ENC_TEST_VECTORS
2622 .vecs
= bf_ctr_dec_tv_template
,
2623 .count
= BF_CTR_DEC_TEST_VECTORS
2628 .alg
= "ctr(camellia)",
2629 .test
= alg_test_skcipher
,
2633 .vecs
= camellia_ctr_enc_tv_template
,
2634 .count
= CAMELLIA_CTR_ENC_TEST_VECTORS
2637 .vecs
= camellia_ctr_dec_tv_template
,
2638 .count
= CAMELLIA_CTR_DEC_TEST_VECTORS
2643 .alg
= "ctr(cast5)",
2644 .test
= alg_test_skcipher
,
2648 .vecs
= cast5_ctr_enc_tv_template
,
2649 .count
= CAST5_CTR_ENC_TEST_VECTORS
2652 .vecs
= cast5_ctr_dec_tv_template
,
2653 .count
= CAST5_CTR_DEC_TEST_VECTORS
2658 .alg
= "ctr(cast6)",
2659 .test
= alg_test_skcipher
,
2663 .vecs
= cast6_ctr_enc_tv_template
,
2664 .count
= CAST6_CTR_ENC_TEST_VECTORS
2667 .vecs
= cast6_ctr_dec_tv_template
,
2668 .count
= CAST6_CTR_DEC_TEST_VECTORS
2674 .test
= alg_test_skcipher
,
2678 .vecs
= des_ctr_enc_tv_template
,
2679 .count
= DES_CTR_ENC_TEST_VECTORS
2682 .vecs
= des_ctr_dec_tv_template
,
2683 .count
= DES_CTR_DEC_TEST_VECTORS
2688 .alg
= "ctr(des3_ede)",
2689 .test
= alg_test_skcipher
,
2693 .vecs
= des3_ede_ctr_enc_tv_template
,
2694 .count
= DES3_EDE_CTR_ENC_TEST_VECTORS
2697 .vecs
= des3_ede_ctr_dec_tv_template
,
2698 .count
= DES3_EDE_CTR_DEC_TEST_VECTORS
2703 .alg
= "ctr(serpent)",
2704 .test
= alg_test_skcipher
,
2708 .vecs
= serpent_ctr_enc_tv_template
,
2709 .count
= SERPENT_CTR_ENC_TEST_VECTORS
2712 .vecs
= serpent_ctr_dec_tv_template
,
2713 .count
= SERPENT_CTR_DEC_TEST_VECTORS
2718 .alg
= "ctr(twofish)",
2719 .test
= alg_test_skcipher
,
2723 .vecs
= tf_ctr_enc_tv_template
,
2724 .count
= TF_CTR_ENC_TEST_VECTORS
2727 .vecs
= tf_ctr_dec_tv_template
,
2728 .count
= TF_CTR_DEC_TEST_VECTORS
2733 .alg
= "cts(cbc(aes))",
2734 .test
= alg_test_skcipher
,
2738 .vecs
= cts_mode_enc_tv_template
,
2739 .count
= CTS_MODE_ENC_TEST_VECTORS
2742 .vecs
= cts_mode_dec_tv_template
,
2743 .count
= CTS_MODE_DEC_TEST_VECTORS
2749 .test
= alg_test_comp
,
2754 .vecs
= deflate_comp_tv_template
,
2755 .count
= DEFLATE_COMP_TEST_VECTORS
2758 .vecs
= deflate_decomp_tv_template
,
2759 .count
= DEFLATE_DECOMP_TEST_VECTORS
2764 .alg
= "digest_null",
2765 .test
= alg_test_null
,
2767 .alg
= "drbg_nopr_ctr_aes128",
2768 .test
= alg_test_drbg
,
2772 .vecs
= drbg_nopr_ctr_aes128_tv_template
,
2773 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template
)
2777 .alg
= "drbg_nopr_ctr_aes192",
2778 .test
= alg_test_drbg
,
2782 .vecs
= drbg_nopr_ctr_aes192_tv_template
,
2783 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template
)
2787 .alg
= "drbg_nopr_ctr_aes256",
2788 .test
= alg_test_drbg
,
2792 .vecs
= drbg_nopr_ctr_aes256_tv_template
,
2793 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template
)
2798 * There is no need to specifically test the DRBG with every
2799 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2801 .alg
= "drbg_nopr_hmac_sha1",
2803 .test
= alg_test_null
,
2805 .alg
= "drbg_nopr_hmac_sha256",
2806 .test
= alg_test_drbg
,
2810 .vecs
= drbg_nopr_hmac_sha256_tv_template
,
2812 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template
)
2816 /* covered by drbg_nopr_hmac_sha256 test */
2817 .alg
= "drbg_nopr_hmac_sha384",
2819 .test
= alg_test_null
,
2821 .alg
= "drbg_nopr_hmac_sha512",
2822 .test
= alg_test_null
,
2825 .alg
= "drbg_nopr_sha1",
2827 .test
= alg_test_null
,
2829 .alg
= "drbg_nopr_sha256",
2830 .test
= alg_test_drbg
,
2834 .vecs
= drbg_nopr_sha256_tv_template
,
2835 .count
= ARRAY_SIZE(drbg_nopr_sha256_tv_template
)
2839 /* covered by drbg_nopr_sha256 test */
2840 .alg
= "drbg_nopr_sha384",
2842 .test
= alg_test_null
,
2844 .alg
= "drbg_nopr_sha512",
2846 .test
= alg_test_null
,
2848 .alg
= "drbg_pr_ctr_aes128",
2849 .test
= alg_test_drbg
,
2853 .vecs
= drbg_pr_ctr_aes128_tv_template
,
2854 .count
= ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template
)
2858 /* covered by drbg_pr_ctr_aes128 test */
2859 .alg
= "drbg_pr_ctr_aes192",
2861 .test
= alg_test_null
,
2863 .alg
= "drbg_pr_ctr_aes256",
2865 .test
= alg_test_null
,
2867 .alg
= "drbg_pr_hmac_sha1",
2869 .test
= alg_test_null
,
2871 .alg
= "drbg_pr_hmac_sha256",
2872 .test
= alg_test_drbg
,
2876 .vecs
= drbg_pr_hmac_sha256_tv_template
,
2877 .count
= ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template
)
2881 /* covered by drbg_pr_hmac_sha256 test */
2882 .alg
= "drbg_pr_hmac_sha384",
2884 .test
= alg_test_null
,
2886 .alg
= "drbg_pr_hmac_sha512",
2887 .test
= alg_test_null
,
2890 .alg
= "drbg_pr_sha1",
2892 .test
= alg_test_null
,
2894 .alg
= "drbg_pr_sha256",
2895 .test
= alg_test_drbg
,
2899 .vecs
= drbg_pr_sha256_tv_template
,
2900 .count
= ARRAY_SIZE(drbg_pr_sha256_tv_template
)
2904 /* covered by drbg_pr_sha256 test */
2905 .alg
= "drbg_pr_sha384",
2907 .test
= alg_test_null
,
2909 .alg
= "drbg_pr_sha512",
2911 .test
= alg_test_null
,
2913 .alg
= "ecb(__aes-aesni)",
2914 .test
= alg_test_null
,
2918 .test
= alg_test_skcipher
,
2923 .vecs
= aes_enc_tv_template
,
2924 .count
= AES_ENC_TEST_VECTORS
2927 .vecs
= aes_dec_tv_template
,
2928 .count
= AES_DEC_TEST_VECTORS
2933 .alg
= "ecb(anubis)",
2934 .test
= alg_test_skcipher
,
2938 .vecs
= anubis_enc_tv_template
,
2939 .count
= ANUBIS_ENC_TEST_VECTORS
2942 .vecs
= anubis_dec_tv_template
,
2943 .count
= ANUBIS_DEC_TEST_VECTORS
2949 .test
= alg_test_skcipher
,
2953 .vecs
= arc4_enc_tv_template
,
2954 .count
= ARC4_ENC_TEST_VECTORS
2957 .vecs
= arc4_dec_tv_template
,
2958 .count
= ARC4_DEC_TEST_VECTORS
2963 .alg
= "ecb(blowfish)",
2964 .test
= alg_test_skcipher
,
2968 .vecs
= bf_enc_tv_template
,
2969 .count
= BF_ENC_TEST_VECTORS
2972 .vecs
= bf_dec_tv_template
,
2973 .count
= BF_DEC_TEST_VECTORS
2978 .alg
= "ecb(camellia)",
2979 .test
= alg_test_skcipher
,
2983 .vecs
= camellia_enc_tv_template
,
2984 .count
= CAMELLIA_ENC_TEST_VECTORS
2987 .vecs
= camellia_dec_tv_template
,
2988 .count
= CAMELLIA_DEC_TEST_VECTORS
2993 .alg
= "ecb(cast5)",
2994 .test
= alg_test_skcipher
,
2998 .vecs
= cast5_enc_tv_template
,
2999 .count
= CAST5_ENC_TEST_VECTORS
3002 .vecs
= cast5_dec_tv_template
,
3003 .count
= CAST5_DEC_TEST_VECTORS
3008 .alg
= "ecb(cast6)",
3009 .test
= alg_test_skcipher
,
3013 .vecs
= cast6_enc_tv_template
,
3014 .count
= CAST6_ENC_TEST_VECTORS
3017 .vecs
= cast6_dec_tv_template
,
3018 .count
= CAST6_DEC_TEST_VECTORS
3023 .alg
= "ecb(cipher_null)",
3024 .test
= alg_test_null
,
3027 .test
= alg_test_skcipher
,
3031 .vecs
= des_enc_tv_template
,
3032 .count
= DES_ENC_TEST_VECTORS
3035 .vecs
= des_dec_tv_template
,
3036 .count
= DES_DEC_TEST_VECTORS
3041 .alg
= "ecb(des3_ede)",
3042 .test
= alg_test_skcipher
,
3047 .vecs
= des3_ede_enc_tv_template
,
3048 .count
= DES3_EDE_ENC_TEST_VECTORS
3051 .vecs
= des3_ede_dec_tv_template
,
3052 .count
= DES3_EDE_DEC_TEST_VECTORS
3057 .alg
= "ecb(fcrypt)",
3058 .test
= alg_test_skcipher
,
3062 .vecs
= fcrypt_pcbc_enc_tv_template
,
3066 .vecs
= fcrypt_pcbc_dec_tv_template
,
3072 .alg
= "ecb(khazad)",
3073 .test
= alg_test_skcipher
,
3077 .vecs
= khazad_enc_tv_template
,
3078 .count
= KHAZAD_ENC_TEST_VECTORS
3081 .vecs
= khazad_dec_tv_template
,
3082 .count
= KHAZAD_DEC_TEST_VECTORS
3088 .test
= alg_test_skcipher
,
3092 .vecs
= seed_enc_tv_template
,
3093 .count
= SEED_ENC_TEST_VECTORS
3096 .vecs
= seed_dec_tv_template
,
3097 .count
= SEED_DEC_TEST_VECTORS
3102 .alg
= "ecb(serpent)",
3103 .test
= alg_test_skcipher
,
3107 .vecs
= serpent_enc_tv_template
,
3108 .count
= SERPENT_ENC_TEST_VECTORS
3111 .vecs
= serpent_dec_tv_template
,
3112 .count
= SERPENT_DEC_TEST_VECTORS
3118 .test
= alg_test_skcipher
,
3122 .vecs
= tea_enc_tv_template
,
3123 .count
= TEA_ENC_TEST_VECTORS
3126 .vecs
= tea_dec_tv_template
,
3127 .count
= TEA_DEC_TEST_VECTORS
3132 .alg
= "ecb(tnepres)",
3133 .test
= alg_test_skcipher
,
3137 .vecs
= tnepres_enc_tv_template
,
3138 .count
= TNEPRES_ENC_TEST_VECTORS
3141 .vecs
= tnepres_dec_tv_template
,
3142 .count
= TNEPRES_DEC_TEST_VECTORS
3147 .alg
= "ecb(twofish)",
3148 .test
= alg_test_skcipher
,
3152 .vecs
= tf_enc_tv_template
,
3153 .count
= TF_ENC_TEST_VECTORS
3156 .vecs
= tf_dec_tv_template
,
3157 .count
= TF_DEC_TEST_VECTORS
3163 .test
= alg_test_skcipher
,
3167 .vecs
= xeta_enc_tv_template
,
3168 .count
= XETA_ENC_TEST_VECTORS
3171 .vecs
= xeta_dec_tv_template
,
3172 .count
= XETA_DEC_TEST_VECTORS
3178 .test
= alg_test_skcipher
,
3182 .vecs
= xtea_enc_tv_template
,
3183 .count
= XTEA_ENC_TEST_VECTORS
3186 .vecs
= xtea_dec_tv_template
,
3187 .count
= XTEA_DEC_TEST_VECTORS
3193 .test
= alg_test_aead
,
3198 .vecs
= aes_gcm_enc_tv_template
,
3199 .count
= AES_GCM_ENC_TEST_VECTORS
3202 .vecs
= aes_gcm_dec_tv_template
,
3203 .count
= AES_GCM_DEC_TEST_VECTORS
3209 .test
= alg_test_hash
,
3213 .vecs
= ghash_tv_template
,
3214 .count
= GHASH_TEST_VECTORS
3218 .alg
= "hmac(crc32)",
3219 .test
= alg_test_hash
,
3222 .vecs
= bfin_crc_tv_template
,
3223 .count
= BFIN_CRC_TEST_VECTORS
3228 .test
= alg_test_hash
,
3231 .vecs
= hmac_md5_tv_template
,
3232 .count
= HMAC_MD5_TEST_VECTORS
3236 .alg
= "hmac(rmd128)",
3237 .test
= alg_test_hash
,
3240 .vecs
= hmac_rmd128_tv_template
,
3241 .count
= HMAC_RMD128_TEST_VECTORS
3245 .alg
= "hmac(rmd160)",
3246 .test
= alg_test_hash
,
3249 .vecs
= hmac_rmd160_tv_template
,
3250 .count
= HMAC_RMD160_TEST_VECTORS
3254 .alg
= "hmac(sha1)",
3255 .test
= alg_test_hash
,
3259 .vecs
= hmac_sha1_tv_template
,
3260 .count
= HMAC_SHA1_TEST_VECTORS
3264 .alg
= "hmac(sha224)",
3265 .test
= alg_test_hash
,
3269 .vecs
= hmac_sha224_tv_template
,
3270 .count
= HMAC_SHA224_TEST_VECTORS
3274 .alg
= "hmac(sha256)",
3275 .test
= alg_test_hash
,
3279 .vecs
= hmac_sha256_tv_template
,
3280 .count
= HMAC_SHA256_TEST_VECTORS
3284 .alg
= "hmac(sha384)",
3285 .test
= alg_test_hash
,
3289 .vecs
= hmac_sha384_tv_template
,
3290 .count
= HMAC_SHA384_TEST_VECTORS
3294 .alg
= "hmac(sha512)",
3295 .test
= alg_test_hash
,
3299 .vecs
= hmac_sha512_tv_template
,
3300 .count
= HMAC_SHA512_TEST_VECTORS
3304 .alg
= "jitterentropy_rng",
3306 .test
= alg_test_null
,
3309 .test
= alg_test_skcipher
,
3314 .vecs
= aes_kw_enc_tv_template
,
3315 .count
= ARRAY_SIZE(aes_kw_enc_tv_template
)
3318 .vecs
= aes_kw_dec_tv_template
,
3319 .count
= ARRAY_SIZE(aes_kw_dec_tv_template
)
3325 .test
= alg_test_skcipher
,
3329 .vecs
= aes_lrw_enc_tv_template
,
3330 .count
= AES_LRW_ENC_TEST_VECTORS
3333 .vecs
= aes_lrw_dec_tv_template
,
3334 .count
= AES_LRW_DEC_TEST_VECTORS
3339 .alg
= "lrw(camellia)",
3340 .test
= alg_test_skcipher
,
3344 .vecs
= camellia_lrw_enc_tv_template
,
3345 .count
= CAMELLIA_LRW_ENC_TEST_VECTORS
3348 .vecs
= camellia_lrw_dec_tv_template
,
3349 .count
= CAMELLIA_LRW_DEC_TEST_VECTORS
3354 .alg
= "lrw(cast6)",
3355 .test
= alg_test_skcipher
,
3359 .vecs
= cast6_lrw_enc_tv_template
,
3360 .count
= CAST6_LRW_ENC_TEST_VECTORS
3363 .vecs
= cast6_lrw_dec_tv_template
,
3364 .count
= CAST6_LRW_DEC_TEST_VECTORS
3369 .alg
= "lrw(serpent)",
3370 .test
= alg_test_skcipher
,
3374 .vecs
= serpent_lrw_enc_tv_template
,
3375 .count
= SERPENT_LRW_ENC_TEST_VECTORS
3378 .vecs
= serpent_lrw_dec_tv_template
,
3379 .count
= SERPENT_LRW_DEC_TEST_VECTORS
3384 .alg
= "lrw(twofish)",
3385 .test
= alg_test_skcipher
,
3389 .vecs
= tf_lrw_enc_tv_template
,
3390 .count
= TF_LRW_ENC_TEST_VECTORS
3393 .vecs
= tf_lrw_dec_tv_template
,
3394 .count
= TF_LRW_DEC_TEST_VECTORS
3400 .test
= alg_test_comp
,
3405 .vecs
= lz4_comp_tv_template
,
3406 .count
= LZ4_COMP_TEST_VECTORS
3409 .vecs
= lz4_decomp_tv_template
,
3410 .count
= LZ4_DECOMP_TEST_VECTORS
3416 .test
= alg_test_comp
,
3421 .vecs
= lz4hc_comp_tv_template
,
3422 .count
= LZ4HC_COMP_TEST_VECTORS
3425 .vecs
= lz4hc_decomp_tv_template
,
3426 .count
= LZ4HC_DECOMP_TEST_VECTORS
3432 .test
= alg_test_comp
,
3437 .vecs
= lzo_comp_tv_template
,
3438 .count
= LZO_COMP_TEST_VECTORS
3441 .vecs
= lzo_decomp_tv_template
,
3442 .count
= LZO_DECOMP_TEST_VECTORS
3448 .test
= alg_test_hash
,
3451 .vecs
= md4_tv_template
,
3452 .count
= MD4_TEST_VECTORS
3457 .test
= alg_test_hash
,
3460 .vecs
= md5_tv_template
,
3461 .count
= MD5_TEST_VECTORS
3465 .alg
= "michael_mic",
3466 .test
= alg_test_hash
,
3469 .vecs
= michael_mic_tv_template
,
3470 .count
= MICHAEL_MIC_TEST_VECTORS
3475 .test
= alg_test_skcipher
,
3480 .vecs
= aes_ofb_enc_tv_template
,
3481 .count
= AES_OFB_ENC_TEST_VECTORS
3484 .vecs
= aes_ofb_dec_tv_template
,
3485 .count
= AES_OFB_DEC_TEST_VECTORS
3490 .alg
= "pcbc(fcrypt)",
3491 .test
= alg_test_skcipher
,
3495 .vecs
= fcrypt_pcbc_enc_tv_template
,
3496 .count
= FCRYPT_ENC_TEST_VECTORS
3499 .vecs
= fcrypt_pcbc_dec_tv_template
,
3500 .count
= FCRYPT_DEC_TEST_VECTORS
3506 .test
= alg_test_hash
,
3509 .vecs
= poly1305_tv_template
,
3510 .count
= POLY1305_TEST_VECTORS
3514 .alg
= "rfc3686(ctr(aes))",
3515 .test
= alg_test_skcipher
,
3520 .vecs
= aes_ctr_rfc3686_enc_tv_template
,
3521 .count
= AES_CTR_3686_ENC_TEST_VECTORS
3524 .vecs
= aes_ctr_rfc3686_dec_tv_template
,
3525 .count
= AES_CTR_3686_DEC_TEST_VECTORS
3530 .alg
= "rfc4106(gcm(aes))",
3531 .test
= alg_test_aead
,
3536 .vecs
= aes_gcm_rfc4106_enc_tv_template
,
3537 .count
= AES_GCM_4106_ENC_TEST_VECTORS
3540 .vecs
= aes_gcm_rfc4106_dec_tv_template
,
3541 .count
= AES_GCM_4106_DEC_TEST_VECTORS
3546 .alg
= "rfc4309(ccm(aes))",
3547 .test
= alg_test_aead
,
3552 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
3553 .count
= AES_CCM_4309_ENC_TEST_VECTORS
3556 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
3557 .count
= AES_CCM_4309_DEC_TEST_VECTORS
3562 .alg
= "rfc4543(gcm(aes))",
3563 .test
= alg_test_aead
,
3567 .vecs
= aes_gcm_rfc4543_enc_tv_template
,
3568 .count
= AES_GCM_4543_ENC_TEST_VECTORS
3571 .vecs
= aes_gcm_rfc4543_dec_tv_template
,
3572 .count
= AES_GCM_4543_DEC_TEST_VECTORS
3577 .alg
= "rfc7539(chacha20,poly1305)",
3578 .test
= alg_test_aead
,
3582 .vecs
= rfc7539_enc_tv_template
,
3583 .count
= RFC7539_ENC_TEST_VECTORS
3586 .vecs
= rfc7539_dec_tv_template
,
3587 .count
= RFC7539_DEC_TEST_VECTORS
3592 .alg
= "rfc7539esp(chacha20,poly1305)",
3593 .test
= alg_test_aead
,
3597 .vecs
= rfc7539esp_enc_tv_template
,
3598 .count
= RFC7539ESP_ENC_TEST_VECTORS
3601 .vecs
= rfc7539esp_dec_tv_template
,
3602 .count
= RFC7539ESP_DEC_TEST_VECTORS
3608 .test
= alg_test_hash
,
3611 .vecs
= rmd128_tv_template
,
3612 .count
= RMD128_TEST_VECTORS
3617 .test
= alg_test_hash
,
3620 .vecs
= rmd160_tv_template
,
3621 .count
= RMD160_TEST_VECTORS
3626 .test
= alg_test_hash
,
3629 .vecs
= rmd256_tv_template
,
3630 .count
= RMD256_TEST_VECTORS
3635 .test
= alg_test_hash
,
3638 .vecs
= rmd320_tv_template
,
3639 .count
= RMD320_TEST_VECTORS
3644 .test
= alg_test_akcipher
,
3648 .vecs
= rsa_tv_template
,
3649 .count
= RSA_TEST_VECTORS
3654 .test
= alg_test_skcipher
,
3658 .vecs
= salsa20_stream_enc_tv_template
,
3659 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
3665 .test
= alg_test_hash
,
3669 .vecs
= sha1_tv_template
,
3670 .count
= SHA1_TEST_VECTORS
3675 .test
= alg_test_hash
,
3679 .vecs
= sha224_tv_template
,
3680 .count
= SHA224_TEST_VECTORS
3685 .test
= alg_test_hash
,
3689 .vecs
= sha256_tv_template
,
3690 .count
= SHA256_TEST_VECTORS
3695 .test
= alg_test_hash
,
3699 .vecs
= sha384_tv_template
,
3700 .count
= SHA384_TEST_VECTORS
3705 .test
= alg_test_hash
,
3709 .vecs
= sha512_tv_template
,
3710 .count
= SHA512_TEST_VECTORS
3715 .test
= alg_test_hash
,
3718 .vecs
= tgr128_tv_template
,
3719 .count
= TGR128_TEST_VECTORS
3724 .test
= alg_test_hash
,
3727 .vecs
= tgr160_tv_template
,
3728 .count
= TGR160_TEST_VECTORS
3733 .test
= alg_test_hash
,
3736 .vecs
= tgr192_tv_template
,
3737 .count
= TGR192_TEST_VECTORS
3742 .test
= alg_test_hash
,
3745 .vecs
= aes_vmac128_tv_template
,
3746 .count
= VMAC_AES_TEST_VECTORS
3751 .test
= alg_test_hash
,
3754 .vecs
= wp256_tv_template
,
3755 .count
= WP256_TEST_VECTORS
3760 .test
= alg_test_hash
,
3763 .vecs
= wp384_tv_template
,
3764 .count
= WP384_TEST_VECTORS
3769 .test
= alg_test_hash
,
3772 .vecs
= wp512_tv_template
,
3773 .count
= WP512_TEST_VECTORS
3778 .test
= alg_test_hash
,
3781 .vecs
= aes_xcbc128_tv_template
,
3782 .count
= XCBC_AES_TEST_VECTORS
3787 .test
= alg_test_skcipher
,
3792 .vecs
= aes_xts_enc_tv_template
,
3793 .count
= AES_XTS_ENC_TEST_VECTORS
3796 .vecs
= aes_xts_dec_tv_template
,
3797 .count
= AES_XTS_DEC_TEST_VECTORS
3802 .alg
= "xts(camellia)",
3803 .test
= alg_test_skcipher
,
3807 .vecs
= camellia_xts_enc_tv_template
,
3808 .count
= CAMELLIA_XTS_ENC_TEST_VECTORS
3811 .vecs
= camellia_xts_dec_tv_template
,
3812 .count
= CAMELLIA_XTS_DEC_TEST_VECTORS
3817 .alg
= "xts(cast6)",
3818 .test
= alg_test_skcipher
,
3822 .vecs
= cast6_xts_enc_tv_template
,
3823 .count
= CAST6_XTS_ENC_TEST_VECTORS
3826 .vecs
= cast6_xts_dec_tv_template
,
3827 .count
= CAST6_XTS_DEC_TEST_VECTORS
3832 .alg
= "xts(serpent)",
3833 .test
= alg_test_skcipher
,
3837 .vecs
= serpent_xts_enc_tv_template
,
3838 .count
= SERPENT_XTS_ENC_TEST_VECTORS
3841 .vecs
= serpent_xts_dec_tv_template
,
3842 .count
= SERPENT_XTS_DEC_TEST_VECTORS
3847 .alg
= "xts(twofish)",
3848 .test
= alg_test_skcipher
,
3852 .vecs
= tf_xts_enc_tv_template
,
3853 .count
= TF_XTS_ENC_TEST_VECTORS
3856 .vecs
= tf_xts_dec_tv_template
,
3857 .count
= TF_XTS_DEC_TEST_VECTORS
3863 .test
= alg_test_pcomp
,
3868 .vecs
= zlib_comp_tv_template
,
3869 .count
= ZLIB_COMP_TEST_VECTORS
3872 .vecs
= zlib_decomp_tv_template
,
3873 .count
= ZLIB_DECOMP_TEST_VECTORS
3880 static bool alg_test_descs_checked
;
3882 static void alg_test_descs_check_order(void)
3886 /* only check once */
3887 if (alg_test_descs_checked
)
3890 alg_test_descs_checked
= true;
3892 for (i
= 1; i
< ARRAY_SIZE(alg_test_descs
); i
++) {
3893 int diff
= strcmp(alg_test_descs
[i
- 1].alg
,
3894 alg_test_descs
[i
].alg
);
3896 if (WARN_ON(diff
> 0)) {
3897 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3898 alg_test_descs
[i
- 1].alg
,
3899 alg_test_descs
[i
].alg
);
3902 if (WARN_ON(diff
== 0)) {
3903 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3904 alg_test_descs
[i
].alg
);
3909 static int alg_find_test(const char *alg
)
3912 int end
= ARRAY_SIZE(alg_test_descs
);
3914 while (start
< end
) {
3915 int i
= (start
+ end
) / 2;
3916 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
3934 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
3940 alg_test_descs_check_order();
3942 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
3943 char nalg
[CRYPTO_MAX_ALG_NAME
];
3945 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
3947 return -ENAMETOOLONG
;
3949 i
= alg_find_test(nalg
);
3953 if (fips_enabled
&& !alg_test_descs
[i
].fips_allowed
)
3956 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
3960 i
= alg_find_test(alg
);
3961 j
= alg_find_test(driver
);
3965 if (fips_enabled
&& ((i
>= 0 && !alg_test_descs
[i
].fips_allowed
) ||
3966 (j
>= 0 && !alg_test_descs
[j
].fips_allowed
)))
3971 rc
|= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
3973 if (j
>= 0 && j
!= i
)
3974 rc
|= alg_test_descs
[j
].test(alg_test_descs
+ j
, driver
,
3978 if (fips_enabled
&& rc
)
3979 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
3981 if (fips_enabled
&& !rc
)
3982 pr_info("alg: self-tests for %s (%s) passed\n", driver
, alg
);
3987 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
3993 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3995 EXPORT_SYMBOL_GPL(alg_test
);