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>
35 #include <crypto/kpp.h>
40 module_param(notests
, bool, 0644);
41 MODULE_PARM_DESC(notests
, "disable crypto self-tests");
43 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
46 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
56 * Need slab memory for testing (size in number of pages).
61 * Indexes into the xbuf to simulate cross-page access.
73 * Used by test_cipher()
78 struct tcrypt_result
{
79 struct completion completion
;
83 struct aead_test_suite
{
85 struct aead_testvec
*vecs
;
90 struct cipher_test_suite
{
92 struct cipher_testvec
*vecs
;
97 struct comp_test_suite
{
99 struct comp_testvec
*vecs
;
104 struct hash_test_suite
{
105 struct hash_testvec
*vecs
;
109 struct cprng_test_suite
{
110 struct cprng_testvec
*vecs
;
114 struct drbg_test_suite
{
115 struct drbg_testvec
*vecs
;
119 struct akcipher_test_suite
{
120 struct akcipher_testvec
*vecs
;
124 struct kpp_test_suite
{
125 struct kpp_testvec
*vecs
;
129 struct alg_test_desc
{
131 int (*test
)(const struct alg_test_desc
*desc
, const char *driver
,
133 int fips_allowed
; /* set if alg is allowed in fips mode */
136 struct aead_test_suite aead
;
137 struct cipher_test_suite cipher
;
138 struct comp_test_suite comp
;
139 struct hash_test_suite hash
;
140 struct cprng_test_suite cprng
;
141 struct drbg_test_suite drbg
;
142 struct akcipher_test_suite akcipher
;
143 struct kpp_test_suite kpp
;
147 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
149 static void hexdump(unsigned char *buf
, unsigned int len
)
151 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
156 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
158 struct tcrypt_result
*res
= req
->data
;
160 if (err
== -EINPROGRESS
)
164 complete(&res
->completion
);
167 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
171 for (i
= 0; i
< XBUFSIZE
; i
++) {
172 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
181 free_page((unsigned long)buf
[i
]);
186 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
190 for (i
= 0; i
< XBUFSIZE
; i
++)
191 free_page((unsigned long)buf
[i
]);
194 static int wait_async_op(struct tcrypt_result
*tr
, int ret
)
196 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
197 wait_for_completion(&tr
->completion
);
198 reinit_completion(&tr
->completion
);
204 static int ahash_partial_update(struct ahash_request
**preq
,
205 struct crypto_ahash
*tfm
, struct hash_testvec
*template,
206 void *hash_buff
, int k
, int temp
, struct scatterlist
*sg
,
207 const char *algo
, char *result
, struct tcrypt_result
*tresult
)
210 struct ahash_request
*req
;
211 int statesize
, ret
= -EINVAL
;
214 statesize
= crypto_ahash_statesize(
215 crypto_ahash_reqtfm(req
));
216 state
= kmalloc(statesize
, GFP_KERNEL
);
218 pr_err("alt: hash: Failed to alloc state for %s\n", algo
);
221 ret
= crypto_ahash_export(req
, state
);
223 pr_err("alt: hash: Failed to export() for %s\n", algo
);
226 ahash_request_free(req
);
227 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
229 pr_err("alg: hash: Failed to alloc request for %s\n", algo
);
232 ahash_request_set_callback(req
,
233 CRYPTO_TFM_REQ_MAY_BACKLOG
,
234 tcrypt_complete
, tresult
);
236 memcpy(hash_buff
, template->plaintext
+ temp
,
238 sg_init_one(&sg
[0], hash_buff
, template->tap
[k
]);
239 ahash_request_set_crypt(req
, sg
, result
, template->tap
[k
]);
240 ret
= crypto_ahash_import(req
, state
);
242 pr_err("alg: hash: Failed to import() for %s\n", algo
);
245 ret
= wait_async_op(tresult
, crypto_ahash_update(req
));
252 ahash_request_free(req
);
259 static int __test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
260 unsigned int tcount
, bool use_digest
,
261 const int align_offset
)
263 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
264 unsigned int i
, j
, k
, temp
;
265 struct scatterlist sg
[8];
268 struct ahash_request
*req
;
269 struct tcrypt_result tresult
;
271 char *xbuf
[XBUFSIZE
];
274 result
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
277 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
280 if (testmgr_alloc_buf(xbuf
))
283 init_completion(&tresult
.completion
);
285 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
287 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
291 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
292 tcrypt_complete
, &tresult
);
295 for (i
= 0; i
< tcount
; i
++) {
300 if (WARN_ON(align_offset
+ template[i
].psize
> PAGE_SIZE
))
304 memset(result
, 0, MAX_DIGEST_SIZE
);
307 hash_buff
+= align_offset
;
309 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
310 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
312 if (template[i
].ksize
) {
313 crypto_ahash_clear_flags(tfm
, ~0);
314 if (template[i
].ksize
> MAX_KEYLEN
) {
315 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
316 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
320 memcpy(key
, template[i
].key
, template[i
].ksize
);
321 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
323 printk(KERN_ERR
"alg: hash: setkey failed on "
324 "test %d for %s: ret=%d\n", j
, algo
,
330 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
332 ret
= wait_async_op(&tresult
, crypto_ahash_digest(req
));
334 pr_err("alg: hash: digest failed on test %d "
335 "for %s: ret=%d\n", j
, algo
, -ret
);
339 ret
= wait_async_op(&tresult
, crypto_ahash_init(req
));
341 pr_err("alt: hash: init failed on test %d "
342 "for %s: ret=%d\n", j
, algo
, -ret
);
345 ret
= wait_async_op(&tresult
, crypto_ahash_update(req
));
347 pr_err("alt: hash: update failed on test %d "
348 "for %s: ret=%d\n", j
, algo
, -ret
);
351 ret
= wait_async_op(&tresult
, crypto_ahash_final(req
));
353 pr_err("alt: hash: final failed on test %d "
354 "for %s: ret=%d\n", j
, algo
, -ret
);
359 if (memcmp(result
, template[i
].digest
,
360 crypto_ahash_digestsize(tfm
))) {
361 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
363 hexdump(result
, crypto_ahash_digestsize(tfm
));
370 for (i
= 0; i
< tcount
; i
++) {
371 /* alignment tests are only done with continuous buffers */
372 if (align_offset
!= 0)
379 memset(result
, 0, MAX_DIGEST_SIZE
);
382 sg_init_table(sg
, template[i
].np
);
384 for (k
= 0; k
< template[i
].np
; k
++) {
385 if (WARN_ON(offset_in_page(IDX
[k
]) +
386 template[i
].tap
[k
] > PAGE_SIZE
))
389 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
390 offset_in_page(IDX
[k
]),
391 template[i
].plaintext
+ temp
,
394 temp
+= template[i
].tap
[k
];
397 if (template[i
].ksize
) {
398 if (template[i
].ksize
> MAX_KEYLEN
) {
399 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
400 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
404 crypto_ahash_clear_flags(tfm
, ~0);
405 memcpy(key
, template[i
].key
, template[i
].ksize
);
406 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
409 printk(KERN_ERR
"alg: hash: setkey "
410 "failed on chunking test %d "
411 "for %s: ret=%d\n", j
, algo
, -ret
);
416 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
417 ret
= crypto_ahash_digest(req
);
423 wait_for_completion(&tresult
.completion
);
424 reinit_completion(&tresult
.completion
);
430 printk(KERN_ERR
"alg: hash: digest failed "
431 "on chunking test %d for %s: "
432 "ret=%d\n", j
, algo
, -ret
);
436 if (memcmp(result
, template[i
].digest
,
437 crypto_ahash_digestsize(tfm
))) {
438 printk(KERN_ERR
"alg: hash: Chunking test %d "
439 "failed for %s\n", j
, algo
);
440 hexdump(result
, crypto_ahash_digestsize(tfm
));
446 /* partial update exercise */
448 for (i
= 0; i
< tcount
; i
++) {
449 /* alignment tests are only done with continuous buffers */
450 if (align_offset
!= 0)
453 if (template[i
].np
< 2)
457 memset(result
, 0, MAX_DIGEST_SIZE
);
461 memcpy(hash_buff
, template[i
].plaintext
,
463 sg_init_one(&sg
[0], hash_buff
, template[i
].tap
[0]);
465 if (template[i
].ksize
) {
466 crypto_ahash_clear_flags(tfm
, ~0);
467 if (template[i
].ksize
> MAX_KEYLEN
) {
468 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
469 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
473 memcpy(key
, template[i
].key
, template[i
].ksize
);
474 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
476 pr_err("alg: hash: setkey failed on test %d for %s: ret=%d\n",
482 ahash_request_set_crypt(req
, sg
, result
, template[i
].tap
[0]);
483 ret
= wait_async_op(&tresult
, crypto_ahash_init(req
));
485 pr_err("alt: hash: init failed on test %d for %s: ret=%d\n",
489 ret
= wait_async_op(&tresult
, crypto_ahash_update(req
));
491 pr_err("alt: hash: update failed on test %d for %s: ret=%d\n",
496 temp
= template[i
].tap
[0];
497 for (k
= 1; k
< template[i
].np
; k
++) {
498 ret
= ahash_partial_update(&req
, tfm
, &template[i
],
499 hash_buff
, k
, temp
, &sg
[0], algo
, result
,
502 pr_err("hash: partial update failed on test %d for %s: ret=%d\n",
506 temp
+= template[i
].tap
[k
];
508 ret
= wait_async_op(&tresult
, crypto_ahash_final(req
));
510 pr_err("alt: hash: final failed on test %d for %s: ret=%d\n",
514 if (memcmp(result
, template[i
].digest
,
515 crypto_ahash_digestsize(tfm
))) {
516 pr_err("alg: hash: Partial Test %d failed for %s\n",
518 hexdump(result
, crypto_ahash_digestsize(tfm
));
527 ahash_request_free(req
);
529 testmgr_free_buf(xbuf
);
536 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
537 unsigned int tcount
, bool use_digest
)
539 unsigned int alignmask
;
542 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 0);
546 /* test unaligned buffers, check with one byte offset */
547 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 1);
551 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
553 /* Check if alignment mask for tfm is correctly set. */
554 ret
= __test_hash(tfm
, template, tcount
, use_digest
,
563 static int __test_aead(struct crypto_aead
*tfm
, int enc
,
564 struct aead_testvec
*template, unsigned int tcount
,
565 const bool diff_dst
, const int align_offset
)
567 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
568 unsigned int i
, j
, k
, n
, temp
;
572 struct aead_request
*req
;
573 struct scatterlist
*sg
;
574 struct scatterlist
*sgout
;
576 struct tcrypt_result result
;
577 unsigned int authsize
, iv_len
;
582 char *xbuf
[XBUFSIZE
];
583 char *xoutbuf
[XBUFSIZE
];
584 char *axbuf
[XBUFSIZE
];
586 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
589 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
592 if (testmgr_alloc_buf(xbuf
))
594 if (testmgr_alloc_buf(axbuf
))
596 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
599 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
600 sg
= kmalloc(sizeof(*sg
) * 8 * (diff_dst
? 4 : 2), GFP_KERNEL
);
615 init_completion(&result
.completion
);
617 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
619 pr_err("alg: aead%s: Failed to allocate request for %s\n",
624 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
625 tcrypt_complete
, &result
);
627 iv_len
= crypto_aead_ivsize(tfm
);
629 for (i
= 0, j
= 0; i
< tcount
; i
++) {
635 /* some templates have no input data but they will
639 input
+= align_offset
;
643 if (WARN_ON(align_offset
+ template[i
].ilen
>
644 PAGE_SIZE
|| template[i
].alen
> PAGE_SIZE
))
647 memcpy(input
, template[i
].input
, template[i
].ilen
);
648 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
650 memcpy(iv
, template[i
].iv
, iv_len
);
652 memset(iv
, 0, iv_len
);
654 crypto_aead_clear_flags(tfm
, ~0);
656 crypto_aead_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
658 if (template[i
].klen
> MAX_KEYLEN
) {
659 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
660 d
, j
, algo
, template[i
].klen
,
665 memcpy(key
, template[i
].key
, template[i
].klen
);
667 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
668 if (!ret
== template[i
].fail
) {
669 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
670 d
, j
, algo
, crypto_aead_get_flags(tfm
));
675 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
676 ret
= crypto_aead_setauthsize(tfm
, authsize
);
678 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
679 d
, authsize
, j
, algo
);
683 k
= !!template[i
].alen
;
684 sg_init_table(sg
, k
+ 1);
685 sg_set_buf(&sg
[0], assoc
, template[i
].alen
);
686 sg_set_buf(&sg
[k
], input
,
687 template[i
].ilen
+ (enc
? authsize
: 0));
691 sg_init_table(sgout
, k
+ 1);
692 sg_set_buf(&sgout
[0], assoc
, template[i
].alen
);
695 output
+= align_offset
;
696 sg_set_buf(&sgout
[k
], output
,
697 template[i
].rlen
+ (enc
? 0 : authsize
));
700 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
701 template[i
].ilen
, iv
);
703 aead_request_set_ad(req
, 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 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 test %d for %s: ret=%d\n",
732 d
, e
, j
, algo
, -ret
);
737 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
738 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
740 hexdump(q
, template[i
].rlen
);
746 for (i
= 0, j
= 0; i
< tcount
; i
++) {
747 /* alignment tests are only done with continuous buffers */
748 if (align_offset
!= 0)
757 memcpy(iv
, template[i
].iv
, iv_len
);
759 memset(iv
, 0, MAX_IVLEN
);
761 crypto_aead_clear_flags(tfm
, ~0);
763 crypto_aead_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
764 if (template[i
].klen
> MAX_KEYLEN
) {
765 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
766 d
, j
, algo
, template[i
].klen
, MAX_KEYLEN
);
770 memcpy(key
, template[i
].key
, template[i
].klen
);
772 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
773 if (!ret
== template[i
].fail
) {
774 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
775 d
, j
, algo
, crypto_aead_get_flags(tfm
));
780 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
783 sg_init_table(sg
, template[i
].anp
+ template[i
].np
);
785 sg_init_table(sgout
, template[i
].anp
+ template[i
].np
);
788 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
789 if (WARN_ON(offset_in_page(IDX
[k
]) +
790 template[i
].atap
[k
] > PAGE_SIZE
))
793 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
794 offset_in_page(IDX
[k
]),
795 template[i
].assoc
+ temp
,
796 template[i
].atap
[k
]),
797 template[i
].atap
[k
]);
799 sg_set_buf(&sgout
[k
],
800 axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
801 offset_in_page(IDX
[k
]),
802 template[i
].atap
[k
]);
803 temp
+= template[i
].atap
[k
];
806 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
807 if (WARN_ON(offset_in_page(IDX
[k
]) +
808 template[i
].tap
[k
] > PAGE_SIZE
))
811 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] + offset_in_page(IDX
[k
]);
812 memcpy(q
, template[i
].input
+ temp
, template[i
].tap
[k
]);
813 sg_set_buf(&sg
[template[i
].anp
+ k
],
814 q
, template[i
].tap
[k
]);
817 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
818 offset_in_page(IDX
[k
]);
820 memset(q
, 0, template[i
].tap
[k
]);
822 sg_set_buf(&sgout
[template[i
].anp
+ k
],
823 q
, template[i
].tap
[k
]);
826 n
= template[i
].tap
[k
];
827 if (k
== template[i
].np
- 1 && enc
)
829 if (offset_in_page(q
) + n
< PAGE_SIZE
)
832 temp
+= template[i
].tap
[k
];
835 ret
= crypto_aead_setauthsize(tfm
, authsize
);
837 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
838 d
, authsize
, j
, algo
);
843 if (WARN_ON(sg
[template[i
].anp
+ k
- 1].offset
+
844 sg
[template[i
].anp
+ k
- 1].length
+
845 authsize
> PAGE_SIZE
)) {
851 sgout
[template[i
].anp
+ k
- 1].length
+=
853 sg
[template[i
].anp
+ k
- 1].length
+= authsize
;
856 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
860 aead_request_set_ad(req
, template[i
].alen
);
862 ret
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
866 if (template[i
].novrfy
) {
867 /* verification was supposed to fail */
868 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
870 /* so really, we got a bad message */
877 wait_for_completion(&result
.completion
);
878 reinit_completion(&result
.completion
);
883 if (template[i
].novrfy
)
884 /* verification failure was expected */
888 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
889 d
, e
, j
, algo
, -ret
);
894 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
896 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
897 offset_in_page(IDX
[k
]);
899 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
900 offset_in_page(IDX
[k
]);
902 n
= template[i
].tap
[k
];
903 if (k
== template[i
].np
- 1)
904 n
+= enc
? authsize
: -authsize
;
906 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
907 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
914 if (k
== template[i
].np
- 1 && !enc
) {
916 memcmp(q
, template[i
].input
+
922 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
926 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
927 d
, j
, e
, k
, algo
, n
);
932 temp
+= template[i
].tap
[k
];
939 aead_request_free(req
);
943 testmgr_free_buf(xoutbuf
);
945 testmgr_free_buf(axbuf
);
947 testmgr_free_buf(xbuf
);
954 static int test_aead(struct crypto_aead
*tfm
, int enc
,
955 struct aead_testvec
*template, unsigned int tcount
)
957 unsigned int alignmask
;
960 /* test 'dst == src' case */
961 ret
= __test_aead(tfm
, enc
, template, tcount
, false, 0);
965 /* test 'dst != src' case */
966 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 0);
970 /* test unaligned buffers, check with one byte offset */
971 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 1);
975 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
977 /* Check if alignment mask for tfm is correctly set. */
978 ret
= __test_aead(tfm
, enc
, template, tcount
, true,
987 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
988 struct cipher_testvec
*template, unsigned int tcount
)
990 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
991 unsigned int i
, j
, k
;
995 char *xbuf
[XBUFSIZE
];
998 if (testmgr_alloc_buf(xbuf
))
1007 for (i
= 0; i
< tcount
; i
++) {
1014 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
1018 memcpy(data
, template[i
].input
, template[i
].ilen
);
1020 crypto_cipher_clear_flags(tfm
, ~0);
1022 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
1024 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
1026 if (!ret
== template[i
].fail
) {
1027 printk(KERN_ERR
"alg: cipher: setkey failed "
1028 "on test %d for %s: flags=%x\n", j
,
1029 algo
, crypto_cipher_get_flags(tfm
));
1034 for (k
= 0; k
< template[i
].ilen
;
1035 k
+= crypto_cipher_blocksize(tfm
)) {
1037 crypto_cipher_encrypt_one(tfm
, data
+ k
,
1040 crypto_cipher_decrypt_one(tfm
, data
+ k
,
1045 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
1046 printk(KERN_ERR
"alg: cipher: Test %d failed "
1047 "on %s for %s\n", j
, e
, algo
);
1048 hexdump(q
, template[i
].rlen
);
1057 testmgr_free_buf(xbuf
);
1062 static int __test_skcipher(struct crypto_skcipher
*tfm
, int enc
,
1063 struct cipher_testvec
*template, unsigned int tcount
,
1064 const bool diff_dst
, const int align_offset
)
1067 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm
));
1068 unsigned int i
, j
, k
, n
, temp
;
1070 struct skcipher_request
*req
;
1071 struct scatterlist sg
[8];
1072 struct scatterlist sgout
[8];
1074 struct tcrypt_result result
;
1077 char *xbuf
[XBUFSIZE
];
1078 char *xoutbuf
[XBUFSIZE
];
1080 unsigned int ivsize
= crypto_skcipher_ivsize(tfm
);
1082 if (testmgr_alloc_buf(xbuf
))
1085 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
1098 init_completion(&result
.completion
);
1100 req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
1102 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
1107 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1108 tcrypt_complete
, &result
);
1111 for (i
= 0; i
< tcount
; i
++) {
1112 if (template[i
].np
&& !template[i
].also_non_np
)
1116 memcpy(iv
, template[i
].iv
, ivsize
);
1118 memset(iv
, 0, MAX_IVLEN
);
1122 if (WARN_ON(align_offset
+ template[i
].ilen
> PAGE_SIZE
))
1126 data
+= align_offset
;
1127 memcpy(data
, template[i
].input
, template[i
].ilen
);
1129 crypto_skcipher_clear_flags(tfm
, ~0);
1131 crypto_skcipher_set_flags(tfm
,
1132 CRYPTO_TFM_REQ_WEAK_KEY
);
1134 ret
= crypto_skcipher_setkey(tfm
, template[i
].key
,
1136 if (!ret
== template[i
].fail
) {
1137 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
1138 d
, j
, algo
, crypto_skcipher_get_flags(tfm
));
1143 sg_init_one(&sg
[0], data
, template[i
].ilen
);
1146 data
+= align_offset
;
1147 sg_init_one(&sgout
[0], data
, template[i
].ilen
);
1150 skcipher_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
1151 template[i
].ilen
, iv
);
1152 ret
= enc
? crypto_skcipher_encrypt(req
) :
1153 crypto_skcipher_decrypt(req
);
1160 wait_for_completion(&result
.completion
);
1161 reinit_completion(&result
.completion
);
1167 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1168 d
, e
, j
, algo
, -ret
);
1173 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
1174 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
1176 hexdump(q
, template[i
].rlen
);
1181 if (template[i
].iv_out
&&
1182 memcmp(iv
, template[i
].iv_out
,
1183 crypto_skcipher_ivsize(tfm
))) {
1184 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1186 hexdump(iv
, crypto_skcipher_ivsize(tfm
));
1193 for (i
= 0; i
< tcount
; i
++) {
1194 /* alignment tests are only done with continuous buffers */
1195 if (align_offset
!= 0)
1198 if (!template[i
].np
)
1202 memcpy(iv
, template[i
].iv
, ivsize
);
1204 memset(iv
, 0, MAX_IVLEN
);
1207 crypto_skcipher_clear_flags(tfm
, ~0);
1209 crypto_skcipher_set_flags(tfm
,
1210 CRYPTO_TFM_REQ_WEAK_KEY
);
1212 ret
= crypto_skcipher_setkey(tfm
, template[i
].key
,
1214 if (!ret
== template[i
].fail
) {
1215 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1216 d
, j
, algo
, crypto_skcipher_get_flags(tfm
));
1223 sg_init_table(sg
, template[i
].np
);
1225 sg_init_table(sgout
, template[i
].np
);
1226 for (k
= 0; k
< template[i
].np
; k
++) {
1227 if (WARN_ON(offset_in_page(IDX
[k
]) +
1228 template[i
].tap
[k
] > PAGE_SIZE
))
1231 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] + offset_in_page(IDX
[k
]);
1233 memcpy(q
, template[i
].input
+ temp
, template[i
].tap
[k
]);
1235 if (offset_in_page(q
) + template[i
].tap
[k
] < PAGE_SIZE
)
1236 q
[template[i
].tap
[k
]] = 0;
1238 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
1240 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1241 offset_in_page(IDX
[k
]);
1243 sg_set_buf(&sgout
[k
], q
, template[i
].tap
[k
]);
1245 memset(q
, 0, template[i
].tap
[k
]);
1246 if (offset_in_page(q
) +
1247 template[i
].tap
[k
] < PAGE_SIZE
)
1248 q
[template[i
].tap
[k
]] = 0;
1251 temp
+= template[i
].tap
[k
];
1254 skcipher_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
1255 template[i
].ilen
, iv
);
1257 ret
= enc
? crypto_skcipher_encrypt(req
) :
1258 crypto_skcipher_decrypt(req
);
1265 wait_for_completion(&result
.completion
);
1266 reinit_completion(&result
.completion
);
1272 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1273 d
, e
, j
, algo
, -ret
);
1279 for (k
= 0; k
< template[i
].np
; k
++) {
1281 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1282 offset_in_page(IDX
[k
]);
1284 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1285 offset_in_page(IDX
[k
]);
1287 if (memcmp(q
, template[i
].result
+ temp
,
1288 template[i
].tap
[k
])) {
1289 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1291 hexdump(q
, template[i
].tap
[k
]);
1295 q
+= template[i
].tap
[k
];
1296 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
1299 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1300 d
, j
, e
, k
, algo
, n
);
1304 temp
+= template[i
].tap
[k
];
1311 skcipher_request_free(req
);
1313 testmgr_free_buf(xoutbuf
);
1315 testmgr_free_buf(xbuf
);
1320 static int test_skcipher(struct crypto_skcipher
*tfm
, int enc
,
1321 struct cipher_testvec
*template, unsigned int tcount
)
1323 unsigned int alignmask
;
1326 /* test 'dst == src' case */
1327 ret
= __test_skcipher(tfm
, enc
, template, tcount
, false, 0);
1331 /* test 'dst != src' case */
1332 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 0);
1336 /* test unaligned buffers, check with one byte offset */
1337 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 1);
1341 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
1343 /* Check if alignment mask for tfm is correctly set. */
1344 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true,
1353 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
1354 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1356 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
1358 char result
[COMP_BUF_SIZE
];
1361 for (i
= 0; i
< ctcount
; i
++) {
1363 unsigned int dlen
= COMP_BUF_SIZE
;
1365 memset(result
, 0, sizeof (result
));
1367 ilen
= ctemplate
[i
].inlen
;
1368 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1369 ilen
, result
, &dlen
);
1371 printk(KERN_ERR
"alg: comp: compression failed "
1372 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1377 if (dlen
!= ctemplate
[i
].outlen
) {
1378 printk(KERN_ERR
"alg: comp: Compression test %d "
1379 "failed for %s: output len = %d\n", i
+ 1, algo
,
1385 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
1386 printk(KERN_ERR
"alg: comp: Compression test %d "
1387 "failed for %s\n", i
+ 1, algo
);
1388 hexdump(result
, dlen
);
1394 for (i
= 0; i
< dtcount
; i
++) {
1396 unsigned int dlen
= COMP_BUF_SIZE
;
1398 memset(result
, 0, sizeof (result
));
1400 ilen
= dtemplate
[i
].inlen
;
1401 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1402 ilen
, result
, &dlen
);
1404 printk(KERN_ERR
"alg: comp: decompression failed "
1405 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1410 if (dlen
!= dtemplate
[i
].outlen
) {
1411 printk(KERN_ERR
"alg: comp: Decompression test %d "
1412 "failed for %s: output len = %d\n", i
+ 1, algo
,
1418 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
1419 printk(KERN_ERR
"alg: comp: Decompression test %d "
1420 "failed for %s\n", i
+ 1, algo
);
1421 hexdump(result
, dlen
);
1433 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1434 unsigned int tcount
)
1436 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1437 int err
= 0, i
, j
, seedsize
;
1441 seedsize
= crypto_rng_seedsize(tfm
);
1443 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1445 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1450 for (i
= 0; i
< tcount
; i
++) {
1451 memset(result
, 0, 32);
1453 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1454 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1456 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1457 template[i
].dt
, template[i
].dtlen
);
1459 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1461 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1466 for (j
= 0; j
< template[i
].loops
; j
++) {
1467 err
= crypto_rng_get_bytes(tfm
, result
,
1470 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1471 "the correct amount of random data for "
1472 "%s (requested %d)\n", algo
,
1478 err
= memcmp(result
, template[i
].result
,
1481 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1483 hexdump(result
, template[i
].rlen
);
1494 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1497 struct crypto_aead
*tfm
;
1500 tfm
= crypto_alloc_aead(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1502 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1503 "%ld\n", driver
, PTR_ERR(tfm
));
1504 return PTR_ERR(tfm
);
1507 if (desc
->suite
.aead
.enc
.vecs
) {
1508 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1509 desc
->suite
.aead
.enc
.count
);
1514 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1515 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1516 desc
->suite
.aead
.dec
.count
);
1519 crypto_free_aead(tfm
);
1523 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1524 const char *driver
, u32 type
, u32 mask
)
1526 struct crypto_cipher
*tfm
;
1529 tfm
= crypto_alloc_cipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1531 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1532 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1533 return PTR_ERR(tfm
);
1536 if (desc
->suite
.cipher
.enc
.vecs
) {
1537 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1538 desc
->suite
.cipher
.enc
.count
);
1543 if (desc
->suite
.cipher
.dec
.vecs
)
1544 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1545 desc
->suite
.cipher
.dec
.count
);
1548 crypto_free_cipher(tfm
);
1552 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1553 const char *driver
, u32 type
, u32 mask
)
1555 struct crypto_skcipher
*tfm
;
1558 tfm
= crypto_alloc_skcipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1560 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1561 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1562 return PTR_ERR(tfm
);
1565 if (desc
->suite
.cipher
.enc
.vecs
) {
1566 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1567 desc
->suite
.cipher
.enc
.count
);
1572 if (desc
->suite
.cipher
.dec
.vecs
)
1573 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1574 desc
->suite
.cipher
.dec
.count
);
1577 crypto_free_skcipher(tfm
);
1581 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1584 struct crypto_comp
*tfm
;
1587 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1589 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1590 "%ld\n", driver
, PTR_ERR(tfm
));
1591 return PTR_ERR(tfm
);
1594 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1595 desc
->suite
.comp
.decomp
.vecs
,
1596 desc
->suite
.comp
.comp
.count
,
1597 desc
->suite
.comp
.decomp
.count
);
1599 crypto_free_comp(tfm
);
1603 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1606 struct crypto_ahash
*tfm
;
1609 tfm
= crypto_alloc_ahash(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1611 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1612 "%ld\n", driver
, PTR_ERR(tfm
));
1613 return PTR_ERR(tfm
);
1616 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1617 desc
->suite
.hash
.count
, true);
1619 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1620 desc
->suite
.hash
.count
, false);
1622 crypto_free_ahash(tfm
);
1626 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1627 const char *driver
, u32 type
, u32 mask
)
1629 struct crypto_shash
*tfm
;
1633 err
= alg_test_hash(desc
, driver
, type
, mask
);
1637 tfm
= crypto_alloc_shash(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1639 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1640 "%ld\n", driver
, PTR_ERR(tfm
));
1646 SHASH_DESC_ON_STACK(shash
, tfm
);
1647 u32
*ctx
= (u32
*)shash_desc_ctx(shash
);
1652 *ctx
= le32_to_cpu(420553207);
1653 err
= crypto_shash_final(shash
, (u8
*)&val
);
1655 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1656 "%s: %d\n", driver
, err
);
1660 if (val
!= ~420553207) {
1661 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1662 "%d\n", driver
, val
);
1667 crypto_free_shash(tfm
);
1673 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1676 struct crypto_rng
*rng
;
1679 rng
= crypto_alloc_rng(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1681 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1682 "%ld\n", driver
, PTR_ERR(rng
));
1683 return PTR_ERR(rng
);
1686 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1688 crypto_free_rng(rng
);
1694 static int drbg_cavs_test(struct drbg_testvec
*test
, int pr
,
1695 const char *driver
, u32 type
, u32 mask
)
1698 struct crypto_rng
*drng
;
1699 struct drbg_test_data test_data
;
1700 struct drbg_string addtl
, pers
, testentropy
;
1701 unsigned char *buf
= kzalloc(test
->expectedlen
, GFP_KERNEL
);
1706 drng
= crypto_alloc_rng(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1708 printk(KERN_ERR
"alg: drbg: could not allocate DRNG handle for "
1714 test_data
.testentropy
= &testentropy
;
1715 drbg_string_fill(&testentropy
, test
->entropy
, test
->entropylen
);
1716 drbg_string_fill(&pers
, test
->pers
, test
->perslen
);
1717 ret
= crypto_drbg_reset_test(drng
, &pers
, &test_data
);
1719 printk(KERN_ERR
"alg: drbg: Failed to reset rng\n");
1723 drbg_string_fill(&addtl
, test
->addtla
, test
->addtllen
);
1725 drbg_string_fill(&testentropy
, test
->entpra
, test
->entprlen
);
1726 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1727 buf
, test
->expectedlen
, &addtl
, &test_data
);
1729 ret
= crypto_drbg_get_bytes_addtl(drng
,
1730 buf
, test
->expectedlen
, &addtl
);
1733 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1734 "driver %s\n", driver
);
1738 drbg_string_fill(&addtl
, test
->addtlb
, test
->addtllen
);
1740 drbg_string_fill(&testentropy
, test
->entprb
, test
->entprlen
);
1741 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1742 buf
, test
->expectedlen
, &addtl
, &test_data
);
1744 ret
= crypto_drbg_get_bytes_addtl(drng
,
1745 buf
, test
->expectedlen
, &addtl
);
1748 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1749 "driver %s\n", driver
);
1753 ret
= memcmp(test
->expected
, buf
, test
->expectedlen
);
1756 crypto_free_rng(drng
);
1762 static int alg_test_drbg(const struct alg_test_desc
*desc
, const char *driver
,
1768 struct drbg_testvec
*template = desc
->suite
.drbg
.vecs
;
1769 unsigned int tcount
= desc
->suite
.drbg
.count
;
1771 if (0 == memcmp(driver
, "drbg_pr_", 8))
1774 for (i
= 0; i
< tcount
; i
++) {
1775 err
= drbg_cavs_test(&template[i
], pr
, driver
, type
, mask
);
1777 printk(KERN_ERR
"alg: drbg: Test %d failed for %s\n",
1787 static int do_test_kpp(struct crypto_kpp
*tfm
, struct kpp_testvec
*vec
,
1790 struct kpp_request
*req
;
1791 void *input_buf
= NULL
;
1792 void *output_buf
= NULL
;
1793 struct tcrypt_result result
;
1794 unsigned int out_len_max
;
1796 struct scatterlist src
, dst
;
1798 req
= kpp_request_alloc(tfm
, GFP_KERNEL
);
1802 init_completion(&result
.completion
);
1804 err
= crypto_kpp_set_secret(tfm
, vec
->secret
, vec
->secret_size
);
1808 out_len_max
= crypto_kpp_maxsize(tfm
);
1809 output_buf
= kzalloc(out_len_max
, GFP_KERNEL
);
1815 /* Use appropriate parameter as base */
1816 kpp_request_set_input(req
, NULL
, 0);
1817 sg_init_one(&dst
, output_buf
, out_len_max
);
1818 kpp_request_set_output(req
, &dst
, out_len_max
);
1819 kpp_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1820 tcrypt_complete
, &result
);
1822 /* Compute public key */
1823 err
= wait_async_op(&result
, crypto_kpp_generate_public_key(req
));
1825 pr_err("alg: %s: generate public key test failed. err %d\n",
1829 /* Verify calculated public key */
1830 if (memcmp(vec
->expected_a_public
, sg_virt(req
->dst
),
1831 vec
->expected_a_public_size
)) {
1832 pr_err("alg: %s: generate public key test failed. Invalid output\n",
1838 /* Calculate shared secret key by using counter part (b) public key. */
1839 input_buf
= kzalloc(vec
->b_public_size
, GFP_KERNEL
);
1845 memcpy(input_buf
, vec
->b_public
, vec
->b_public_size
);
1846 sg_init_one(&src
, input_buf
, vec
->b_public_size
);
1847 sg_init_one(&dst
, output_buf
, out_len_max
);
1848 kpp_request_set_input(req
, &src
, vec
->b_public_size
);
1849 kpp_request_set_output(req
, &dst
, out_len_max
);
1850 kpp_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1851 tcrypt_complete
, &result
);
1852 err
= wait_async_op(&result
, crypto_kpp_compute_shared_secret(req
));
1854 pr_err("alg: %s: compute shard secret test failed. err %d\n",
1859 * verify shared secret from which the user will derive
1860 * secret key by executing whatever hash it has chosen
1862 if (memcmp(vec
->expected_ss
, sg_virt(req
->dst
),
1863 vec
->expected_ss_size
)) {
1864 pr_err("alg: %s: compute shared secret test failed. Invalid output\n",
1874 kpp_request_free(req
);
1878 static int test_kpp(struct crypto_kpp
*tfm
, const char *alg
,
1879 struct kpp_testvec
*vecs
, unsigned int tcount
)
1883 for (i
= 0; i
< tcount
; i
++) {
1884 ret
= do_test_kpp(tfm
, vecs
++, alg
);
1886 pr_err("alg: %s: test failed on vector %d, err=%d\n",
1894 static int alg_test_kpp(const struct alg_test_desc
*desc
, const char *driver
,
1897 struct crypto_kpp
*tfm
;
1900 tfm
= crypto_alloc_kpp(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1902 pr_err("alg: kpp: Failed to load tfm for %s: %ld\n",
1903 driver
, PTR_ERR(tfm
));
1904 return PTR_ERR(tfm
);
1906 if (desc
->suite
.kpp
.vecs
)
1907 err
= test_kpp(tfm
, desc
->alg
, desc
->suite
.kpp
.vecs
,
1908 desc
->suite
.kpp
.count
);
1910 crypto_free_kpp(tfm
);
1914 static int test_akcipher_one(struct crypto_akcipher
*tfm
,
1915 struct akcipher_testvec
*vecs
)
1917 char *xbuf
[XBUFSIZE
];
1918 struct akcipher_request
*req
;
1919 void *outbuf_enc
= NULL
;
1920 void *outbuf_dec
= NULL
;
1921 struct tcrypt_result result
;
1922 unsigned int out_len_max
, out_len
= 0;
1924 struct scatterlist src
, dst
, src_tab
[2];
1926 if (testmgr_alloc_buf(xbuf
))
1929 req
= akcipher_request_alloc(tfm
, GFP_KERNEL
);
1933 init_completion(&result
.completion
);
1935 if (vecs
->public_key_vec
)
1936 err
= crypto_akcipher_set_pub_key(tfm
, vecs
->key
,
1939 err
= crypto_akcipher_set_priv_key(tfm
, vecs
->key
,
1945 out_len_max
= crypto_akcipher_maxsize(tfm
);
1946 outbuf_enc
= kzalloc(out_len_max
, GFP_KERNEL
);
1950 if (WARN_ON(vecs
->m_size
> PAGE_SIZE
))
1953 memcpy(xbuf
[0], vecs
->m
, vecs
->m_size
);
1955 sg_init_table(src_tab
, 2);
1956 sg_set_buf(&src_tab
[0], xbuf
[0], 8);
1957 sg_set_buf(&src_tab
[1], xbuf
[0] + 8, vecs
->m_size
- 8);
1958 sg_init_one(&dst
, outbuf_enc
, out_len_max
);
1959 akcipher_request_set_crypt(req
, src_tab
, &dst
, vecs
->m_size
,
1961 akcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1962 tcrypt_complete
, &result
);
1964 /* Run RSA encrypt - c = m^e mod n;*/
1965 err
= wait_async_op(&result
, crypto_akcipher_encrypt(req
));
1967 pr_err("alg: akcipher: encrypt test failed. err %d\n", err
);
1970 if (req
->dst_len
!= vecs
->c_size
) {
1971 pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
1975 /* verify that encrypted message is equal to expected */
1976 if (memcmp(vecs
->c
, outbuf_enc
, vecs
->c_size
)) {
1977 pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
1978 hexdump(outbuf_enc
, vecs
->c_size
);
1982 /* Don't invoke decrypt for vectors with public key */
1983 if (vecs
->public_key_vec
) {
1987 outbuf_dec
= kzalloc(out_len_max
, GFP_KERNEL
);
1993 if (WARN_ON(vecs
->c_size
> PAGE_SIZE
))
1996 memcpy(xbuf
[0], vecs
->c
, vecs
->c_size
);
1998 sg_init_one(&src
, xbuf
[0], vecs
->c_size
);
1999 sg_init_one(&dst
, outbuf_dec
, out_len_max
);
2000 init_completion(&result
.completion
);
2001 akcipher_request_set_crypt(req
, &src
, &dst
, vecs
->c_size
, out_len_max
);
2003 /* Run RSA decrypt - m = c^d mod n;*/
2004 err
= wait_async_op(&result
, crypto_akcipher_decrypt(req
));
2006 pr_err("alg: akcipher: decrypt test failed. err %d\n", err
);
2009 out_len
= req
->dst_len
;
2010 if (out_len
< vecs
->m_size
) {
2011 pr_err("alg: akcipher: decrypt test failed. "
2012 "Invalid output len %u\n", out_len
);
2016 /* verify that decrypted message is equal to the original msg */
2017 if (memchr_inv(outbuf_dec
, 0, out_len
- vecs
->m_size
) ||
2018 memcmp(vecs
->m
, outbuf_dec
+ out_len
- vecs
->m_size
,
2020 pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
2021 hexdump(outbuf_dec
, out_len
);
2028 akcipher_request_free(req
);
2030 testmgr_free_buf(xbuf
);
2034 static int test_akcipher(struct crypto_akcipher
*tfm
, const char *alg
,
2035 struct akcipher_testvec
*vecs
, unsigned int tcount
)
2038 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm
));
2041 for (i
= 0; i
< tcount
; i
++) {
2042 ret
= test_akcipher_one(tfm
, vecs
++);
2046 pr_err("alg: akcipher: test %d failed for %s, err=%d\n",
2053 static int alg_test_akcipher(const struct alg_test_desc
*desc
,
2054 const char *driver
, u32 type
, u32 mask
)
2056 struct crypto_akcipher
*tfm
;
2059 tfm
= crypto_alloc_akcipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
2061 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
2062 driver
, PTR_ERR(tfm
));
2063 return PTR_ERR(tfm
);
2065 if (desc
->suite
.akcipher
.vecs
)
2066 err
= test_akcipher(tfm
, desc
->alg
, desc
->suite
.akcipher
.vecs
,
2067 desc
->suite
.akcipher
.count
);
2069 crypto_free_akcipher(tfm
);
2073 static int alg_test_null(const struct alg_test_desc
*desc
,
2074 const char *driver
, u32 type
, u32 mask
)
2079 /* Please keep this list sorted by algorithm name. */
2080 static const struct alg_test_desc alg_test_descs
[] = {
2082 .alg
= "__cbc-cast5-avx",
2083 .test
= alg_test_null
,
2085 .alg
= "__cbc-cast6-avx",
2086 .test
= alg_test_null
,
2088 .alg
= "__cbc-serpent-avx",
2089 .test
= alg_test_null
,
2091 .alg
= "__cbc-serpent-avx2",
2092 .test
= alg_test_null
,
2094 .alg
= "__cbc-serpent-sse2",
2095 .test
= alg_test_null
,
2097 .alg
= "__cbc-twofish-avx",
2098 .test
= alg_test_null
,
2100 .alg
= "__driver-cbc-aes-aesni",
2101 .test
= alg_test_null
,
2104 .alg
= "__driver-cbc-camellia-aesni",
2105 .test
= alg_test_null
,
2107 .alg
= "__driver-cbc-camellia-aesni-avx2",
2108 .test
= alg_test_null
,
2110 .alg
= "__driver-cbc-cast5-avx",
2111 .test
= alg_test_null
,
2113 .alg
= "__driver-cbc-cast6-avx",
2114 .test
= alg_test_null
,
2116 .alg
= "__driver-cbc-serpent-avx",
2117 .test
= alg_test_null
,
2119 .alg
= "__driver-cbc-serpent-avx2",
2120 .test
= alg_test_null
,
2122 .alg
= "__driver-cbc-serpent-sse2",
2123 .test
= alg_test_null
,
2125 .alg
= "__driver-cbc-twofish-avx",
2126 .test
= alg_test_null
,
2128 .alg
= "__driver-ecb-aes-aesni",
2129 .test
= alg_test_null
,
2132 .alg
= "__driver-ecb-camellia-aesni",
2133 .test
= alg_test_null
,
2135 .alg
= "__driver-ecb-camellia-aesni-avx2",
2136 .test
= alg_test_null
,
2138 .alg
= "__driver-ecb-cast5-avx",
2139 .test
= alg_test_null
,
2141 .alg
= "__driver-ecb-cast6-avx",
2142 .test
= alg_test_null
,
2144 .alg
= "__driver-ecb-serpent-avx",
2145 .test
= alg_test_null
,
2147 .alg
= "__driver-ecb-serpent-avx2",
2148 .test
= alg_test_null
,
2150 .alg
= "__driver-ecb-serpent-sse2",
2151 .test
= alg_test_null
,
2153 .alg
= "__driver-ecb-twofish-avx",
2154 .test
= alg_test_null
,
2156 .alg
= "__driver-gcm-aes-aesni",
2157 .test
= alg_test_null
,
2160 .alg
= "__ghash-pclmulqdqni",
2161 .test
= alg_test_null
,
2164 .alg
= "ansi_cprng",
2165 .test
= alg_test_cprng
,
2168 .vecs
= ansi_cprng_aes_tv_template
,
2169 .count
= ANSI_CPRNG_AES_TEST_VECTORS
2173 .alg
= "authenc(hmac(md5),ecb(cipher_null))",
2174 .test
= alg_test_aead
,
2178 .vecs
= hmac_md5_ecb_cipher_null_enc_tv_template
,
2179 .count
= HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
2182 .vecs
= hmac_md5_ecb_cipher_null_dec_tv_template
,
2183 .count
= HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
2188 .alg
= "authenc(hmac(sha1),cbc(aes))",
2189 .test
= alg_test_aead
,
2194 hmac_sha1_aes_cbc_enc_tv_temp
,
2196 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
2201 .alg
= "authenc(hmac(sha1),cbc(des))",
2202 .test
= alg_test_aead
,
2207 hmac_sha1_des_cbc_enc_tv_temp
,
2209 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2214 .alg
= "authenc(hmac(sha1),cbc(des3_ede))",
2215 .test
= alg_test_aead
,
2221 hmac_sha1_des3_ede_cbc_enc_tv_temp
,
2223 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
2228 .alg
= "authenc(hmac(sha1),ctr(aes))",
2229 .test
= alg_test_null
,
2232 .alg
= "authenc(hmac(sha1),ecb(cipher_null))",
2233 .test
= alg_test_aead
,
2238 hmac_sha1_ecb_cipher_null_enc_tv_temp
,
2240 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
2244 hmac_sha1_ecb_cipher_null_dec_tv_temp
,
2246 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2251 .alg
= "authenc(hmac(sha1),rfc3686(ctr(aes)))",
2252 .test
= alg_test_null
,
2255 .alg
= "authenc(hmac(sha224),cbc(des))",
2256 .test
= alg_test_aead
,
2261 hmac_sha224_des_cbc_enc_tv_temp
,
2263 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2268 .alg
= "authenc(hmac(sha224),cbc(des3_ede))",
2269 .test
= alg_test_aead
,
2275 hmac_sha224_des3_ede_cbc_enc_tv_temp
,
2277 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
2282 .alg
= "authenc(hmac(sha256),cbc(aes))",
2283 .test
= alg_test_aead
,
2289 hmac_sha256_aes_cbc_enc_tv_temp
,
2291 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2296 .alg
= "authenc(hmac(sha256),cbc(des))",
2297 .test
= alg_test_aead
,
2302 hmac_sha256_des_cbc_enc_tv_temp
,
2304 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2309 .alg
= "authenc(hmac(sha256),cbc(des3_ede))",
2310 .test
= alg_test_aead
,
2316 hmac_sha256_des3_ede_cbc_enc_tv_temp
,
2318 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2323 .alg
= "authenc(hmac(sha256),ctr(aes))",
2324 .test
= alg_test_null
,
2327 .alg
= "authenc(hmac(sha256),rfc3686(ctr(aes)))",
2328 .test
= alg_test_null
,
2331 .alg
= "authenc(hmac(sha384),cbc(des))",
2332 .test
= alg_test_aead
,
2337 hmac_sha384_des_cbc_enc_tv_temp
,
2339 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2344 .alg
= "authenc(hmac(sha384),cbc(des3_ede))",
2345 .test
= alg_test_aead
,
2351 hmac_sha384_des3_ede_cbc_enc_tv_temp
,
2353 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
2358 .alg
= "authenc(hmac(sha384),ctr(aes))",
2359 .test
= alg_test_null
,
2362 .alg
= "authenc(hmac(sha384),rfc3686(ctr(aes)))",
2363 .test
= alg_test_null
,
2366 .alg
= "authenc(hmac(sha512),cbc(aes))",
2368 .test
= alg_test_aead
,
2373 hmac_sha512_aes_cbc_enc_tv_temp
,
2375 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2380 .alg
= "authenc(hmac(sha512),cbc(des))",
2381 .test
= alg_test_aead
,
2386 hmac_sha512_des_cbc_enc_tv_temp
,
2388 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2393 .alg
= "authenc(hmac(sha512),cbc(des3_ede))",
2394 .test
= alg_test_aead
,
2400 hmac_sha512_des3_ede_cbc_enc_tv_temp
,
2402 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2407 .alg
= "authenc(hmac(sha512),ctr(aes))",
2408 .test
= alg_test_null
,
2411 .alg
= "authenc(hmac(sha512),rfc3686(ctr(aes)))",
2412 .test
= alg_test_null
,
2416 .test
= alg_test_skcipher
,
2421 .vecs
= aes_cbc_enc_tv_template
,
2422 .count
= AES_CBC_ENC_TEST_VECTORS
2425 .vecs
= aes_cbc_dec_tv_template
,
2426 .count
= AES_CBC_DEC_TEST_VECTORS
2431 .alg
= "cbc(anubis)",
2432 .test
= alg_test_skcipher
,
2436 .vecs
= anubis_cbc_enc_tv_template
,
2437 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
2440 .vecs
= anubis_cbc_dec_tv_template
,
2441 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
2446 .alg
= "cbc(blowfish)",
2447 .test
= alg_test_skcipher
,
2451 .vecs
= bf_cbc_enc_tv_template
,
2452 .count
= BF_CBC_ENC_TEST_VECTORS
2455 .vecs
= bf_cbc_dec_tv_template
,
2456 .count
= BF_CBC_DEC_TEST_VECTORS
2461 .alg
= "cbc(camellia)",
2462 .test
= alg_test_skcipher
,
2466 .vecs
= camellia_cbc_enc_tv_template
,
2467 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
2470 .vecs
= camellia_cbc_dec_tv_template
,
2471 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
2476 .alg
= "cbc(cast5)",
2477 .test
= alg_test_skcipher
,
2481 .vecs
= cast5_cbc_enc_tv_template
,
2482 .count
= CAST5_CBC_ENC_TEST_VECTORS
2485 .vecs
= cast5_cbc_dec_tv_template
,
2486 .count
= CAST5_CBC_DEC_TEST_VECTORS
2491 .alg
= "cbc(cast6)",
2492 .test
= alg_test_skcipher
,
2496 .vecs
= cast6_cbc_enc_tv_template
,
2497 .count
= CAST6_CBC_ENC_TEST_VECTORS
2500 .vecs
= cast6_cbc_dec_tv_template
,
2501 .count
= CAST6_CBC_DEC_TEST_VECTORS
2507 .test
= alg_test_skcipher
,
2511 .vecs
= des_cbc_enc_tv_template
,
2512 .count
= DES_CBC_ENC_TEST_VECTORS
2515 .vecs
= des_cbc_dec_tv_template
,
2516 .count
= DES_CBC_DEC_TEST_VECTORS
2521 .alg
= "cbc(des3_ede)",
2522 .test
= alg_test_skcipher
,
2527 .vecs
= des3_ede_cbc_enc_tv_template
,
2528 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
2531 .vecs
= des3_ede_cbc_dec_tv_template
,
2532 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
2537 .alg
= "cbc(serpent)",
2538 .test
= alg_test_skcipher
,
2542 .vecs
= serpent_cbc_enc_tv_template
,
2543 .count
= SERPENT_CBC_ENC_TEST_VECTORS
2546 .vecs
= serpent_cbc_dec_tv_template
,
2547 .count
= SERPENT_CBC_DEC_TEST_VECTORS
2552 .alg
= "cbc(twofish)",
2553 .test
= alg_test_skcipher
,
2557 .vecs
= tf_cbc_enc_tv_template
,
2558 .count
= TF_CBC_ENC_TEST_VECTORS
2561 .vecs
= tf_cbc_dec_tv_template
,
2562 .count
= TF_CBC_DEC_TEST_VECTORS
2568 .test
= alg_test_aead
,
2573 .vecs
= aes_ccm_enc_tv_template
,
2574 .count
= AES_CCM_ENC_TEST_VECTORS
2577 .vecs
= aes_ccm_dec_tv_template
,
2578 .count
= AES_CCM_DEC_TEST_VECTORS
2584 .test
= alg_test_skcipher
,
2588 .vecs
= chacha20_enc_tv_template
,
2589 .count
= CHACHA20_ENC_TEST_VECTORS
2592 .vecs
= chacha20_enc_tv_template
,
2593 .count
= CHACHA20_ENC_TEST_VECTORS
2600 .test
= alg_test_hash
,
2603 .vecs
= aes_cmac128_tv_template
,
2604 .count
= CMAC_AES_TEST_VECTORS
2608 .alg
= "cmac(des3_ede)",
2610 .test
= alg_test_hash
,
2613 .vecs
= des3_ede_cmac64_tv_template
,
2614 .count
= CMAC_DES3_EDE_TEST_VECTORS
2618 .alg
= "compress_null",
2619 .test
= alg_test_null
,
2622 .test
= alg_test_hash
,
2625 .vecs
= crc32_tv_template
,
2626 .count
= CRC32_TEST_VECTORS
2631 .test
= alg_test_crc32c
,
2635 .vecs
= crc32c_tv_template
,
2636 .count
= CRC32C_TEST_VECTORS
2641 .test
= alg_test_hash
,
2645 .vecs
= crct10dif_tv_template
,
2646 .count
= CRCT10DIF_TEST_VECTORS
2650 .alg
= "cryptd(__driver-cbc-aes-aesni)",
2651 .test
= alg_test_null
,
2654 .alg
= "cryptd(__driver-cbc-camellia-aesni)",
2655 .test
= alg_test_null
,
2657 .alg
= "cryptd(__driver-cbc-camellia-aesni-avx2)",
2658 .test
= alg_test_null
,
2660 .alg
= "cryptd(__driver-cbc-serpent-avx2)",
2661 .test
= alg_test_null
,
2663 .alg
= "cryptd(__driver-ecb-aes-aesni)",
2664 .test
= alg_test_null
,
2667 .alg
= "cryptd(__driver-ecb-camellia-aesni)",
2668 .test
= alg_test_null
,
2670 .alg
= "cryptd(__driver-ecb-camellia-aesni-avx2)",
2671 .test
= alg_test_null
,
2673 .alg
= "cryptd(__driver-ecb-cast5-avx)",
2674 .test
= alg_test_null
,
2676 .alg
= "cryptd(__driver-ecb-cast6-avx)",
2677 .test
= alg_test_null
,
2679 .alg
= "cryptd(__driver-ecb-serpent-avx)",
2680 .test
= alg_test_null
,
2682 .alg
= "cryptd(__driver-ecb-serpent-avx2)",
2683 .test
= alg_test_null
,
2685 .alg
= "cryptd(__driver-ecb-serpent-sse2)",
2686 .test
= alg_test_null
,
2688 .alg
= "cryptd(__driver-ecb-twofish-avx)",
2689 .test
= alg_test_null
,
2691 .alg
= "cryptd(__driver-gcm-aes-aesni)",
2692 .test
= alg_test_null
,
2695 .alg
= "cryptd(__ghash-pclmulqdqni)",
2696 .test
= alg_test_null
,
2700 .test
= alg_test_skcipher
,
2705 .vecs
= aes_ctr_enc_tv_template
,
2706 .count
= AES_CTR_ENC_TEST_VECTORS
2709 .vecs
= aes_ctr_dec_tv_template
,
2710 .count
= AES_CTR_DEC_TEST_VECTORS
2715 .alg
= "ctr(blowfish)",
2716 .test
= alg_test_skcipher
,
2720 .vecs
= bf_ctr_enc_tv_template
,
2721 .count
= BF_CTR_ENC_TEST_VECTORS
2724 .vecs
= bf_ctr_dec_tv_template
,
2725 .count
= BF_CTR_DEC_TEST_VECTORS
2730 .alg
= "ctr(camellia)",
2731 .test
= alg_test_skcipher
,
2735 .vecs
= camellia_ctr_enc_tv_template
,
2736 .count
= CAMELLIA_CTR_ENC_TEST_VECTORS
2739 .vecs
= camellia_ctr_dec_tv_template
,
2740 .count
= CAMELLIA_CTR_DEC_TEST_VECTORS
2745 .alg
= "ctr(cast5)",
2746 .test
= alg_test_skcipher
,
2750 .vecs
= cast5_ctr_enc_tv_template
,
2751 .count
= CAST5_CTR_ENC_TEST_VECTORS
2754 .vecs
= cast5_ctr_dec_tv_template
,
2755 .count
= CAST5_CTR_DEC_TEST_VECTORS
2760 .alg
= "ctr(cast6)",
2761 .test
= alg_test_skcipher
,
2765 .vecs
= cast6_ctr_enc_tv_template
,
2766 .count
= CAST6_CTR_ENC_TEST_VECTORS
2769 .vecs
= cast6_ctr_dec_tv_template
,
2770 .count
= CAST6_CTR_DEC_TEST_VECTORS
2776 .test
= alg_test_skcipher
,
2780 .vecs
= des_ctr_enc_tv_template
,
2781 .count
= DES_CTR_ENC_TEST_VECTORS
2784 .vecs
= des_ctr_dec_tv_template
,
2785 .count
= DES_CTR_DEC_TEST_VECTORS
2790 .alg
= "ctr(des3_ede)",
2791 .test
= alg_test_skcipher
,
2795 .vecs
= des3_ede_ctr_enc_tv_template
,
2796 .count
= DES3_EDE_CTR_ENC_TEST_VECTORS
2799 .vecs
= des3_ede_ctr_dec_tv_template
,
2800 .count
= DES3_EDE_CTR_DEC_TEST_VECTORS
2805 .alg
= "ctr(serpent)",
2806 .test
= alg_test_skcipher
,
2810 .vecs
= serpent_ctr_enc_tv_template
,
2811 .count
= SERPENT_CTR_ENC_TEST_VECTORS
2814 .vecs
= serpent_ctr_dec_tv_template
,
2815 .count
= SERPENT_CTR_DEC_TEST_VECTORS
2820 .alg
= "ctr(twofish)",
2821 .test
= alg_test_skcipher
,
2825 .vecs
= tf_ctr_enc_tv_template
,
2826 .count
= TF_CTR_ENC_TEST_VECTORS
2829 .vecs
= tf_ctr_dec_tv_template
,
2830 .count
= TF_CTR_DEC_TEST_VECTORS
2835 .alg
= "cts(cbc(aes))",
2836 .test
= alg_test_skcipher
,
2840 .vecs
= cts_mode_enc_tv_template
,
2841 .count
= CTS_MODE_ENC_TEST_VECTORS
2844 .vecs
= cts_mode_dec_tv_template
,
2845 .count
= CTS_MODE_DEC_TEST_VECTORS
2851 .test
= alg_test_comp
,
2856 .vecs
= deflate_comp_tv_template
,
2857 .count
= DEFLATE_COMP_TEST_VECTORS
2860 .vecs
= deflate_decomp_tv_template
,
2861 .count
= DEFLATE_DECOMP_TEST_VECTORS
2867 .test
= alg_test_kpp
,
2871 .vecs
= dh_tv_template
,
2872 .count
= DH_TEST_VECTORS
2876 .alg
= "digest_null",
2877 .test
= alg_test_null
,
2879 .alg
= "drbg_nopr_ctr_aes128",
2880 .test
= alg_test_drbg
,
2884 .vecs
= drbg_nopr_ctr_aes128_tv_template
,
2885 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template
)
2889 .alg
= "drbg_nopr_ctr_aes192",
2890 .test
= alg_test_drbg
,
2894 .vecs
= drbg_nopr_ctr_aes192_tv_template
,
2895 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template
)
2899 .alg
= "drbg_nopr_ctr_aes256",
2900 .test
= alg_test_drbg
,
2904 .vecs
= drbg_nopr_ctr_aes256_tv_template
,
2905 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template
)
2910 * There is no need to specifically test the DRBG with every
2911 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2913 .alg
= "drbg_nopr_hmac_sha1",
2915 .test
= alg_test_null
,
2917 .alg
= "drbg_nopr_hmac_sha256",
2918 .test
= alg_test_drbg
,
2922 .vecs
= drbg_nopr_hmac_sha256_tv_template
,
2924 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template
)
2928 /* covered by drbg_nopr_hmac_sha256 test */
2929 .alg
= "drbg_nopr_hmac_sha384",
2931 .test
= alg_test_null
,
2933 .alg
= "drbg_nopr_hmac_sha512",
2934 .test
= alg_test_null
,
2937 .alg
= "drbg_nopr_sha1",
2939 .test
= alg_test_null
,
2941 .alg
= "drbg_nopr_sha256",
2942 .test
= alg_test_drbg
,
2946 .vecs
= drbg_nopr_sha256_tv_template
,
2947 .count
= ARRAY_SIZE(drbg_nopr_sha256_tv_template
)
2951 /* covered by drbg_nopr_sha256 test */
2952 .alg
= "drbg_nopr_sha384",
2954 .test
= alg_test_null
,
2956 .alg
= "drbg_nopr_sha512",
2958 .test
= alg_test_null
,
2960 .alg
= "drbg_pr_ctr_aes128",
2961 .test
= alg_test_drbg
,
2965 .vecs
= drbg_pr_ctr_aes128_tv_template
,
2966 .count
= ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template
)
2970 /* covered by drbg_pr_ctr_aes128 test */
2971 .alg
= "drbg_pr_ctr_aes192",
2973 .test
= alg_test_null
,
2975 .alg
= "drbg_pr_ctr_aes256",
2977 .test
= alg_test_null
,
2979 .alg
= "drbg_pr_hmac_sha1",
2981 .test
= alg_test_null
,
2983 .alg
= "drbg_pr_hmac_sha256",
2984 .test
= alg_test_drbg
,
2988 .vecs
= drbg_pr_hmac_sha256_tv_template
,
2989 .count
= ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template
)
2993 /* covered by drbg_pr_hmac_sha256 test */
2994 .alg
= "drbg_pr_hmac_sha384",
2996 .test
= alg_test_null
,
2998 .alg
= "drbg_pr_hmac_sha512",
2999 .test
= alg_test_null
,
3002 .alg
= "drbg_pr_sha1",
3004 .test
= alg_test_null
,
3006 .alg
= "drbg_pr_sha256",
3007 .test
= alg_test_drbg
,
3011 .vecs
= drbg_pr_sha256_tv_template
,
3012 .count
= ARRAY_SIZE(drbg_pr_sha256_tv_template
)
3016 /* covered by drbg_pr_sha256 test */
3017 .alg
= "drbg_pr_sha384",
3019 .test
= alg_test_null
,
3021 .alg
= "drbg_pr_sha512",
3023 .test
= alg_test_null
,
3025 .alg
= "ecb(__aes-aesni)",
3026 .test
= alg_test_null
,
3030 .test
= alg_test_skcipher
,
3035 .vecs
= aes_enc_tv_template
,
3036 .count
= AES_ENC_TEST_VECTORS
3039 .vecs
= aes_dec_tv_template
,
3040 .count
= AES_DEC_TEST_VECTORS
3045 .alg
= "ecb(anubis)",
3046 .test
= alg_test_skcipher
,
3050 .vecs
= anubis_enc_tv_template
,
3051 .count
= ANUBIS_ENC_TEST_VECTORS
3054 .vecs
= anubis_dec_tv_template
,
3055 .count
= ANUBIS_DEC_TEST_VECTORS
3061 .test
= alg_test_skcipher
,
3065 .vecs
= arc4_enc_tv_template
,
3066 .count
= ARC4_ENC_TEST_VECTORS
3069 .vecs
= arc4_dec_tv_template
,
3070 .count
= ARC4_DEC_TEST_VECTORS
3075 .alg
= "ecb(blowfish)",
3076 .test
= alg_test_skcipher
,
3080 .vecs
= bf_enc_tv_template
,
3081 .count
= BF_ENC_TEST_VECTORS
3084 .vecs
= bf_dec_tv_template
,
3085 .count
= BF_DEC_TEST_VECTORS
3090 .alg
= "ecb(camellia)",
3091 .test
= alg_test_skcipher
,
3095 .vecs
= camellia_enc_tv_template
,
3096 .count
= CAMELLIA_ENC_TEST_VECTORS
3099 .vecs
= camellia_dec_tv_template
,
3100 .count
= CAMELLIA_DEC_TEST_VECTORS
3105 .alg
= "ecb(cast5)",
3106 .test
= alg_test_skcipher
,
3110 .vecs
= cast5_enc_tv_template
,
3111 .count
= CAST5_ENC_TEST_VECTORS
3114 .vecs
= cast5_dec_tv_template
,
3115 .count
= CAST5_DEC_TEST_VECTORS
3120 .alg
= "ecb(cast6)",
3121 .test
= alg_test_skcipher
,
3125 .vecs
= cast6_enc_tv_template
,
3126 .count
= CAST6_ENC_TEST_VECTORS
3129 .vecs
= cast6_dec_tv_template
,
3130 .count
= CAST6_DEC_TEST_VECTORS
3135 .alg
= "ecb(cipher_null)",
3136 .test
= alg_test_null
,
3139 .test
= alg_test_skcipher
,
3143 .vecs
= des_enc_tv_template
,
3144 .count
= DES_ENC_TEST_VECTORS
3147 .vecs
= des_dec_tv_template
,
3148 .count
= DES_DEC_TEST_VECTORS
3153 .alg
= "ecb(des3_ede)",
3154 .test
= alg_test_skcipher
,
3159 .vecs
= des3_ede_enc_tv_template
,
3160 .count
= DES3_EDE_ENC_TEST_VECTORS
3163 .vecs
= des3_ede_dec_tv_template
,
3164 .count
= DES3_EDE_DEC_TEST_VECTORS
3169 .alg
= "ecb(fcrypt)",
3170 .test
= alg_test_skcipher
,
3174 .vecs
= fcrypt_pcbc_enc_tv_template
,
3178 .vecs
= fcrypt_pcbc_dec_tv_template
,
3184 .alg
= "ecb(khazad)",
3185 .test
= alg_test_skcipher
,
3189 .vecs
= khazad_enc_tv_template
,
3190 .count
= KHAZAD_ENC_TEST_VECTORS
3193 .vecs
= khazad_dec_tv_template
,
3194 .count
= KHAZAD_DEC_TEST_VECTORS
3200 .test
= alg_test_skcipher
,
3204 .vecs
= seed_enc_tv_template
,
3205 .count
= SEED_ENC_TEST_VECTORS
3208 .vecs
= seed_dec_tv_template
,
3209 .count
= SEED_DEC_TEST_VECTORS
3214 .alg
= "ecb(serpent)",
3215 .test
= alg_test_skcipher
,
3219 .vecs
= serpent_enc_tv_template
,
3220 .count
= SERPENT_ENC_TEST_VECTORS
3223 .vecs
= serpent_dec_tv_template
,
3224 .count
= SERPENT_DEC_TEST_VECTORS
3230 .test
= alg_test_skcipher
,
3234 .vecs
= tea_enc_tv_template
,
3235 .count
= TEA_ENC_TEST_VECTORS
3238 .vecs
= tea_dec_tv_template
,
3239 .count
= TEA_DEC_TEST_VECTORS
3244 .alg
= "ecb(tnepres)",
3245 .test
= alg_test_skcipher
,
3249 .vecs
= tnepres_enc_tv_template
,
3250 .count
= TNEPRES_ENC_TEST_VECTORS
3253 .vecs
= tnepres_dec_tv_template
,
3254 .count
= TNEPRES_DEC_TEST_VECTORS
3259 .alg
= "ecb(twofish)",
3260 .test
= alg_test_skcipher
,
3264 .vecs
= tf_enc_tv_template
,
3265 .count
= TF_ENC_TEST_VECTORS
3268 .vecs
= tf_dec_tv_template
,
3269 .count
= TF_DEC_TEST_VECTORS
3275 .test
= alg_test_skcipher
,
3279 .vecs
= xeta_enc_tv_template
,
3280 .count
= XETA_ENC_TEST_VECTORS
3283 .vecs
= xeta_dec_tv_template
,
3284 .count
= XETA_DEC_TEST_VECTORS
3290 .test
= alg_test_skcipher
,
3294 .vecs
= xtea_enc_tv_template
,
3295 .count
= XTEA_ENC_TEST_VECTORS
3298 .vecs
= xtea_dec_tv_template
,
3299 .count
= XTEA_DEC_TEST_VECTORS
3305 .test
= alg_test_kpp
,
3309 .vecs
= ecdh_tv_template
,
3310 .count
= ECDH_TEST_VECTORS
3315 .test
= alg_test_aead
,
3320 .vecs
= aes_gcm_enc_tv_template
,
3321 .count
= AES_GCM_ENC_TEST_VECTORS
3324 .vecs
= aes_gcm_dec_tv_template
,
3325 .count
= AES_GCM_DEC_TEST_VECTORS
3331 .test
= alg_test_hash
,
3335 .vecs
= ghash_tv_template
,
3336 .count
= GHASH_TEST_VECTORS
3340 .alg
= "hmac(crc32)",
3341 .test
= alg_test_hash
,
3344 .vecs
= bfin_crc_tv_template
,
3345 .count
= BFIN_CRC_TEST_VECTORS
3350 .test
= alg_test_hash
,
3353 .vecs
= hmac_md5_tv_template
,
3354 .count
= HMAC_MD5_TEST_VECTORS
3358 .alg
= "hmac(rmd128)",
3359 .test
= alg_test_hash
,
3362 .vecs
= hmac_rmd128_tv_template
,
3363 .count
= HMAC_RMD128_TEST_VECTORS
3367 .alg
= "hmac(rmd160)",
3368 .test
= alg_test_hash
,
3371 .vecs
= hmac_rmd160_tv_template
,
3372 .count
= HMAC_RMD160_TEST_VECTORS
3376 .alg
= "hmac(sha1)",
3377 .test
= alg_test_hash
,
3381 .vecs
= hmac_sha1_tv_template
,
3382 .count
= HMAC_SHA1_TEST_VECTORS
3386 .alg
= "hmac(sha224)",
3387 .test
= alg_test_hash
,
3391 .vecs
= hmac_sha224_tv_template
,
3392 .count
= HMAC_SHA224_TEST_VECTORS
3396 .alg
= "hmac(sha256)",
3397 .test
= alg_test_hash
,
3401 .vecs
= hmac_sha256_tv_template
,
3402 .count
= HMAC_SHA256_TEST_VECTORS
3406 .alg
= "hmac(sha3-224)",
3407 .test
= alg_test_hash
,
3411 .vecs
= hmac_sha3_224_tv_template
,
3412 .count
= HMAC_SHA3_224_TEST_VECTORS
3416 .alg
= "hmac(sha3-256)",
3417 .test
= alg_test_hash
,
3421 .vecs
= hmac_sha3_256_tv_template
,
3422 .count
= HMAC_SHA3_256_TEST_VECTORS
3426 .alg
= "hmac(sha3-384)",
3427 .test
= alg_test_hash
,
3431 .vecs
= hmac_sha3_384_tv_template
,
3432 .count
= HMAC_SHA3_384_TEST_VECTORS
3436 .alg
= "hmac(sha3-512)",
3437 .test
= alg_test_hash
,
3441 .vecs
= hmac_sha3_512_tv_template
,
3442 .count
= HMAC_SHA3_512_TEST_VECTORS
3446 .alg
= "hmac(sha384)",
3447 .test
= alg_test_hash
,
3451 .vecs
= hmac_sha384_tv_template
,
3452 .count
= HMAC_SHA384_TEST_VECTORS
3456 .alg
= "hmac(sha512)",
3457 .test
= alg_test_hash
,
3461 .vecs
= hmac_sha512_tv_template
,
3462 .count
= HMAC_SHA512_TEST_VECTORS
3466 .alg
= "jitterentropy_rng",
3468 .test
= alg_test_null
,
3471 .test
= alg_test_skcipher
,
3476 .vecs
= aes_kw_enc_tv_template
,
3477 .count
= ARRAY_SIZE(aes_kw_enc_tv_template
)
3480 .vecs
= aes_kw_dec_tv_template
,
3481 .count
= ARRAY_SIZE(aes_kw_dec_tv_template
)
3487 .test
= alg_test_skcipher
,
3491 .vecs
= aes_lrw_enc_tv_template
,
3492 .count
= AES_LRW_ENC_TEST_VECTORS
3495 .vecs
= aes_lrw_dec_tv_template
,
3496 .count
= AES_LRW_DEC_TEST_VECTORS
3501 .alg
= "lrw(camellia)",
3502 .test
= alg_test_skcipher
,
3506 .vecs
= camellia_lrw_enc_tv_template
,
3507 .count
= CAMELLIA_LRW_ENC_TEST_VECTORS
3510 .vecs
= camellia_lrw_dec_tv_template
,
3511 .count
= CAMELLIA_LRW_DEC_TEST_VECTORS
3516 .alg
= "lrw(cast6)",
3517 .test
= alg_test_skcipher
,
3521 .vecs
= cast6_lrw_enc_tv_template
,
3522 .count
= CAST6_LRW_ENC_TEST_VECTORS
3525 .vecs
= cast6_lrw_dec_tv_template
,
3526 .count
= CAST6_LRW_DEC_TEST_VECTORS
3531 .alg
= "lrw(serpent)",
3532 .test
= alg_test_skcipher
,
3536 .vecs
= serpent_lrw_enc_tv_template
,
3537 .count
= SERPENT_LRW_ENC_TEST_VECTORS
3540 .vecs
= serpent_lrw_dec_tv_template
,
3541 .count
= SERPENT_LRW_DEC_TEST_VECTORS
3546 .alg
= "lrw(twofish)",
3547 .test
= alg_test_skcipher
,
3551 .vecs
= tf_lrw_enc_tv_template
,
3552 .count
= TF_LRW_ENC_TEST_VECTORS
3555 .vecs
= tf_lrw_dec_tv_template
,
3556 .count
= TF_LRW_DEC_TEST_VECTORS
3562 .test
= alg_test_comp
,
3567 .vecs
= lz4_comp_tv_template
,
3568 .count
= LZ4_COMP_TEST_VECTORS
3571 .vecs
= lz4_decomp_tv_template
,
3572 .count
= LZ4_DECOMP_TEST_VECTORS
3578 .test
= alg_test_comp
,
3583 .vecs
= lz4hc_comp_tv_template
,
3584 .count
= LZ4HC_COMP_TEST_VECTORS
3587 .vecs
= lz4hc_decomp_tv_template
,
3588 .count
= LZ4HC_DECOMP_TEST_VECTORS
3594 .test
= alg_test_comp
,
3599 .vecs
= lzo_comp_tv_template
,
3600 .count
= LZO_COMP_TEST_VECTORS
3603 .vecs
= lzo_decomp_tv_template
,
3604 .count
= LZO_DECOMP_TEST_VECTORS
3610 .test
= alg_test_hash
,
3613 .vecs
= md4_tv_template
,
3614 .count
= MD4_TEST_VECTORS
3619 .test
= alg_test_hash
,
3622 .vecs
= md5_tv_template
,
3623 .count
= MD5_TEST_VECTORS
3627 .alg
= "michael_mic",
3628 .test
= alg_test_hash
,
3631 .vecs
= michael_mic_tv_template
,
3632 .count
= MICHAEL_MIC_TEST_VECTORS
3637 .test
= alg_test_skcipher
,
3642 .vecs
= aes_ofb_enc_tv_template
,
3643 .count
= AES_OFB_ENC_TEST_VECTORS
3646 .vecs
= aes_ofb_dec_tv_template
,
3647 .count
= AES_OFB_DEC_TEST_VECTORS
3652 .alg
= "pcbc(fcrypt)",
3653 .test
= alg_test_skcipher
,
3657 .vecs
= fcrypt_pcbc_enc_tv_template
,
3658 .count
= FCRYPT_ENC_TEST_VECTORS
3661 .vecs
= fcrypt_pcbc_dec_tv_template
,
3662 .count
= FCRYPT_DEC_TEST_VECTORS
3668 .test
= alg_test_hash
,
3671 .vecs
= poly1305_tv_template
,
3672 .count
= POLY1305_TEST_VECTORS
3676 .alg
= "rfc3686(ctr(aes))",
3677 .test
= alg_test_skcipher
,
3682 .vecs
= aes_ctr_rfc3686_enc_tv_template
,
3683 .count
= AES_CTR_3686_ENC_TEST_VECTORS
3686 .vecs
= aes_ctr_rfc3686_dec_tv_template
,
3687 .count
= AES_CTR_3686_DEC_TEST_VECTORS
3692 .alg
= "rfc4106(gcm(aes))",
3693 .test
= alg_test_aead
,
3698 .vecs
= aes_gcm_rfc4106_enc_tv_template
,
3699 .count
= AES_GCM_4106_ENC_TEST_VECTORS
3702 .vecs
= aes_gcm_rfc4106_dec_tv_template
,
3703 .count
= AES_GCM_4106_DEC_TEST_VECTORS
3708 .alg
= "rfc4309(ccm(aes))",
3709 .test
= alg_test_aead
,
3714 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
3715 .count
= AES_CCM_4309_ENC_TEST_VECTORS
3718 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
3719 .count
= AES_CCM_4309_DEC_TEST_VECTORS
3724 .alg
= "rfc4543(gcm(aes))",
3725 .test
= alg_test_aead
,
3729 .vecs
= aes_gcm_rfc4543_enc_tv_template
,
3730 .count
= AES_GCM_4543_ENC_TEST_VECTORS
3733 .vecs
= aes_gcm_rfc4543_dec_tv_template
,
3734 .count
= AES_GCM_4543_DEC_TEST_VECTORS
3739 .alg
= "rfc7539(chacha20,poly1305)",
3740 .test
= alg_test_aead
,
3744 .vecs
= rfc7539_enc_tv_template
,
3745 .count
= RFC7539_ENC_TEST_VECTORS
3748 .vecs
= rfc7539_dec_tv_template
,
3749 .count
= RFC7539_DEC_TEST_VECTORS
3754 .alg
= "rfc7539esp(chacha20,poly1305)",
3755 .test
= alg_test_aead
,
3759 .vecs
= rfc7539esp_enc_tv_template
,
3760 .count
= RFC7539ESP_ENC_TEST_VECTORS
3763 .vecs
= rfc7539esp_dec_tv_template
,
3764 .count
= RFC7539ESP_DEC_TEST_VECTORS
3770 .test
= alg_test_hash
,
3773 .vecs
= rmd128_tv_template
,
3774 .count
= RMD128_TEST_VECTORS
3779 .test
= alg_test_hash
,
3782 .vecs
= rmd160_tv_template
,
3783 .count
= RMD160_TEST_VECTORS
3788 .test
= alg_test_hash
,
3791 .vecs
= rmd256_tv_template
,
3792 .count
= RMD256_TEST_VECTORS
3797 .test
= alg_test_hash
,
3800 .vecs
= rmd320_tv_template
,
3801 .count
= RMD320_TEST_VECTORS
3806 .test
= alg_test_akcipher
,
3810 .vecs
= rsa_tv_template
,
3811 .count
= RSA_TEST_VECTORS
3816 .test
= alg_test_skcipher
,
3820 .vecs
= salsa20_stream_enc_tv_template
,
3821 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
3827 .test
= alg_test_hash
,
3831 .vecs
= sha1_tv_template
,
3832 .count
= SHA1_TEST_VECTORS
3837 .test
= alg_test_hash
,
3841 .vecs
= sha224_tv_template
,
3842 .count
= SHA224_TEST_VECTORS
3847 .test
= alg_test_hash
,
3851 .vecs
= sha256_tv_template
,
3852 .count
= SHA256_TEST_VECTORS
3857 .test
= alg_test_hash
,
3861 .vecs
= sha3_224_tv_template
,
3862 .count
= SHA3_224_TEST_VECTORS
3867 .test
= alg_test_hash
,
3871 .vecs
= sha3_256_tv_template
,
3872 .count
= SHA3_256_TEST_VECTORS
3877 .test
= alg_test_hash
,
3881 .vecs
= sha3_384_tv_template
,
3882 .count
= SHA3_384_TEST_VECTORS
3887 .test
= alg_test_hash
,
3891 .vecs
= sha3_512_tv_template
,
3892 .count
= SHA3_512_TEST_VECTORS
3897 .test
= alg_test_hash
,
3901 .vecs
= sha384_tv_template
,
3902 .count
= SHA384_TEST_VECTORS
3907 .test
= alg_test_hash
,
3911 .vecs
= sha512_tv_template
,
3912 .count
= SHA512_TEST_VECTORS
3917 .test
= alg_test_hash
,
3920 .vecs
= tgr128_tv_template
,
3921 .count
= TGR128_TEST_VECTORS
3926 .test
= alg_test_hash
,
3929 .vecs
= tgr160_tv_template
,
3930 .count
= TGR160_TEST_VECTORS
3935 .test
= alg_test_hash
,
3938 .vecs
= tgr192_tv_template
,
3939 .count
= TGR192_TEST_VECTORS
3944 .test
= alg_test_hash
,
3947 .vecs
= aes_vmac128_tv_template
,
3948 .count
= VMAC_AES_TEST_VECTORS
3953 .test
= alg_test_hash
,
3956 .vecs
= wp256_tv_template
,
3957 .count
= WP256_TEST_VECTORS
3962 .test
= alg_test_hash
,
3965 .vecs
= wp384_tv_template
,
3966 .count
= WP384_TEST_VECTORS
3971 .test
= alg_test_hash
,
3974 .vecs
= wp512_tv_template
,
3975 .count
= WP512_TEST_VECTORS
3980 .test
= alg_test_hash
,
3983 .vecs
= aes_xcbc128_tv_template
,
3984 .count
= XCBC_AES_TEST_VECTORS
3989 .test
= alg_test_skcipher
,
3994 .vecs
= aes_xts_enc_tv_template
,
3995 .count
= AES_XTS_ENC_TEST_VECTORS
3998 .vecs
= aes_xts_dec_tv_template
,
3999 .count
= AES_XTS_DEC_TEST_VECTORS
4004 .alg
= "xts(camellia)",
4005 .test
= alg_test_skcipher
,
4009 .vecs
= camellia_xts_enc_tv_template
,
4010 .count
= CAMELLIA_XTS_ENC_TEST_VECTORS
4013 .vecs
= camellia_xts_dec_tv_template
,
4014 .count
= CAMELLIA_XTS_DEC_TEST_VECTORS
4019 .alg
= "xts(cast6)",
4020 .test
= alg_test_skcipher
,
4024 .vecs
= cast6_xts_enc_tv_template
,
4025 .count
= CAST6_XTS_ENC_TEST_VECTORS
4028 .vecs
= cast6_xts_dec_tv_template
,
4029 .count
= CAST6_XTS_DEC_TEST_VECTORS
4034 .alg
= "xts(serpent)",
4035 .test
= alg_test_skcipher
,
4039 .vecs
= serpent_xts_enc_tv_template
,
4040 .count
= SERPENT_XTS_ENC_TEST_VECTORS
4043 .vecs
= serpent_xts_dec_tv_template
,
4044 .count
= SERPENT_XTS_DEC_TEST_VECTORS
4049 .alg
= "xts(twofish)",
4050 .test
= alg_test_skcipher
,
4054 .vecs
= tf_xts_enc_tv_template
,
4055 .count
= TF_XTS_ENC_TEST_VECTORS
4058 .vecs
= tf_xts_dec_tv_template
,
4059 .count
= TF_XTS_DEC_TEST_VECTORS
4066 static bool alg_test_descs_checked
;
4068 static void alg_test_descs_check_order(void)
4072 /* only check once */
4073 if (alg_test_descs_checked
)
4076 alg_test_descs_checked
= true;
4078 for (i
= 1; i
< ARRAY_SIZE(alg_test_descs
); i
++) {
4079 int diff
= strcmp(alg_test_descs
[i
- 1].alg
,
4080 alg_test_descs
[i
].alg
);
4082 if (WARN_ON(diff
> 0)) {
4083 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
4084 alg_test_descs
[i
- 1].alg
,
4085 alg_test_descs
[i
].alg
);
4088 if (WARN_ON(diff
== 0)) {
4089 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
4090 alg_test_descs
[i
].alg
);
4095 static int alg_find_test(const char *alg
)
4098 int end
= ARRAY_SIZE(alg_test_descs
);
4100 while (start
< end
) {
4101 int i
= (start
+ end
) / 2;
4102 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
4120 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
4126 if (!fips_enabled
&& notests
) {
4127 printk_once(KERN_INFO
"alg: self-tests disabled\n");
4131 alg_test_descs_check_order();
4133 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
4134 char nalg
[CRYPTO_MAX_ALG_NAME
];
4136 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
4138 return -ENAMETOOLONG
;
4140 i
= alg_find_test(nalg
);
4144 if (fips_enabled
&& !alg_test_descs
[i
].fips_allowed
)
4147 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
4151 i
= alg_find_test(alg
);
4152 j
= alg_find_test(driver
);
4156 if (fips_enabled
&& ((i
>= 0 && !alg_test_descs
[i
].fips_allowed
) ||
4157 (j
>= 0 && !alg_test_descs
[j
].fips_allowed
)))
4162 rc
|= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
4164 if (j
>= 0 && j
!= i
)
4165 rc
|= alg_test_descs
[j
].test(alg_test_descs
+ j
, driver
,
4169 if (fips_enabled
&& rc
)
4170 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
4172 if (fips_enabled
&& !rc
)
4173 pr_info("alg: self-tests for %s (%s) passed\n", driver
, alg
);
4178 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
4184 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
4186 EXPORT_SYMBOL_GPL(alg_test
);