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 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
16 #include <crypto/hash.h>
17 #include <linux/err.h>
18 #include <linux/module.h>
19 #include <linux/scatterlist.h>
20 #include <linux/slab.h>
21 #include <linux/string.h>
22 #include <crypto/rng.h>
26 #ifndef CONFIG_CRYPTO_MANAGER_TESTS
29 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
39 * Need slab memory for testing (size in number of pages).
44 * Indexes into the xbuf to simulate cross-page access.
56 * Used by test_cipher()
61 struct tcrypt_result
{
62 struct completion completion
;
66 struct aead_test_suite
{
68 struct aead_testvec
*vecs
;
73 struct cipher_test_suite
{
75 struct cipher_testvec
*vecs
;
80 struct comp_test_suite
{
82 struct comp_testvec
*vecs
;
87 struct pcomp_test_suite
{
89 struct pcomp_testvec
*vecs
;
94 struct hash_test_suite
{
95 struct hash_testvec
*vecs
;
99 struct cprng_test_suite
{
100 struct cprng_testvec
*vecs
;
104 struct alg_test_desc
{
106 int (*test
)(const struct alg_test_desc
*desc
, const char *driver
,
108 int fips_allowed
; /* set if alg is allowed in fips mode */
111 struct aead_test_suite aead
;
112 struct cipher_test_suite cipher
;
113 struct comp_test_suite comp
;
114 struct pcomp_test_suite pcomp
;
115 struct hash_test_suite hash
;
116 struct cprng_test_suite cprng
;
120 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
122 static void hexdump(unsigned char *buf
, unsigned int len
)
124 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
129 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
131 struct tcrypt_result
*res
= req
->data
;
133 if (err
== -EINPROGRESS
)
137 complete(&res
->completion
);
140 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
144 for (i
= 0; i
< XBUFSIZE
; i
++) {
145 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
154 free_page((unsigned long)buf
[i
]);
159 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
163 for (i
= 0; i
< XBUFSIZE
; i
++)
164 free_page((unsigned long)buf
[i
]);
167 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
170 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
171 unsigned int i
, j
, k
, temp
;
172 struct scatterlist sg
[8];
174 struct ahash_request
*req
;
175 struct tcrypt_result tresult
;
177 char *xbuf
[XBUFSIZE
];
180 if (testmgr_alloc_buf(xbuf
))
183 init_completion(&tresult
.completion
);
185 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
187 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
191 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
192 tcrypt_complete
, &tresult
);
195 for (i
= 0; i
< tcount
; i
++) {
200 memset(result
, 0, 64);
204 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
205 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
207 if (template[i
].ksize
) {
208 crypto_ahash_clear_flags(tfm
, ~0);
209 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
212 printk(KERN_ERR
"alg: hash: setkey failed on "
213 "test %d for %s: ret=%d\n", j
, algo
,
219 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
220 ret
= crypto_ahash_digest(req
);
226 ret
= wait_for_completion_interruptible(
227 &tresult
.completion
);
228 if (!ret
&& !(ret
= tresult
.err
)) {
229 INIT_COMPLETION(tresult
.completion
);
234 printk(KERN_ERR
"alg: hash: digest failed on test %d "
235 "for %s: ret=%d\n", j
, algo
, -ret
);
239 if (memcmp(result
, template[i
].digest
,
240 crypto_ahash_digestsize(tfm
))) {
241 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
243 hexdump(result
, crypto_ahash_digestsize(tfm
));
250 for (i
= 0; i
< tcount
; i
++) {
251 if (template[i
].np
) {
253 memset(result
, 0, 64);
256 sg_init_table(sg
, template[i
].np
);
258 for (k
= 0; k
< template[i
].np
; k
++) {
259 if (WARN_ON(offset_in_page(IDX
[k
]) +
260 template[i
].tap
[k
] > PAGE_SIZE
))
263 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
264 offset_in_page(IDX
[k
]),
265 template[i
].plaintext
+ temp
,
268 temp
+= template[i
].tap
[k
];
271 if (template[i
].ksize
) {
272 crypto_ahash_clear_flags(tfm
, ~0);
273 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
277 printk(KERN_ERR
"alg: hash: setkey "
278 "failed on chunking test %d "
279 "for %s: ret=%d\n", j
, algo
,
285 ahash_request_set_crypt(req
, sg
, result
,
287 ret
= crypto_ahash_digest(req
);
293 ret
= wait_for_completion_interruptible(
294 &tresult
.completion
);
295 if (!ret
&& !(ret
= tresult
.err
)) {
296 INIT_COMPLETION(tresult
.completion
);
301 printk(KERN_ERR
"alg: hash: digest failed "
302 "on chunking test %d for %s: "
303 "ret=%d\n", j
, algo
, -ret
);
307 if (memcmp(result
, template[i
].digest
,
308 crypto_ahash_digestsize(tfm
))) {
309 printk(KERN_ERR
"alg: hash: Chunking test %d "
310 "failed for %s\n", j
, algo
);
311 hexdump(result
, crypto_ahash_digestsize(tfm
));
321 ahash_request_free(req
);
323 testmgr_free_buf(xbuf
);
328 static int test_aead(struct crypto_aead
*tfm
, int enc
,
329 struct aead_testvec
*template, unsigned int tcount
)
331 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
332 unsigned int i
, j
, k
, n
, temp
;
336 struct aead_request
*req
;
337 struct scatterlist sg
[8];
338 struct scatterlist asg
[8];
340 struct tcrypt_result result
;
341 unsigned int authsize
;
345 char *xbuf
[XBUFSIZE
];
346 char *axbuf
[XBUFSIZE
];
348 if (testmgr_alloc_buf(xbuf
))
350 if (testmgr_alloc_buf(axbuf
))
358 init_completion(&result
.completion
);
360 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
362 printk(KERN_ERR
"alg: aead: Failed to allocate request for "
367 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
368 tcrypt_complete
, &result
);
370 for (i
= 0, j
= 0; i
< tcount
; i
++) {
371 if (!template[i
].np
) {
374 /* some tepmplates have no input data but they will
381 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
||
382 template[i
].alen
> PAGE_SIZE
))
385 memcpy(input
, template[i
].input
, template[i
].ilen
);
386 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
388 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
390 memset(iv
, 0, MAX_IVLEN
);
392 crypto_aead_clear_flags(tfm
, ~0);
394 crypto_aead_set_flags(
395 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
397 key
= template[i
].key
;
399 ret
= crypto_aead_setkey(tfm
, key
,
401 if (!ret
== template[i
].fail
) {
402 printk(KERN_ERR
"alg: aead: setkey failed on "
403 "test %d for %s: flags=%x\n", j
, algo
,
404 crypto_aead_get_flags(tfm
));
409 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
410 ret
= crypto_aead_setauthsize(tfm
, authsize
);
412 printk(KERN_ERR
"alg: aead: Failed to set "
413 "authsize to %u on test %d for %s\n",
418 sg_init_one(&sg
[0], input
,
419 template[i
].ilen
+ (enc
? authsize
: 0));
421 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
423 aead_request_set_crypt(req
, sg
, sg
,
424 template[i
].ilen
, iv
);
426 aead_request_set_assoc(req
, asg
, template[i
].alen
);
429 crypto_aead_encrypt(req
) :
430 crypto_aead_decrypt(req
);
434 if (template[i
].novrfy
) {
435 /* verification was supposed to fail */
436 printk(KERN_ERR
"alg: aead: %s failed "
437 "on test %d for %s: ret was 0, "
438 "expected -EBADMSG\n",
440 /* so really, we got a bad message */
447 ret
= wait_for_completion_interruptible(
449 if (!ret
&& !(ret
= result
.err
)) {
450 INIT_COMPLETION(result
.completion
);
454 if (template[i
].novrfy
)
455 /* verification failure was expected */
459 printk(KERN_ERR
"alg: aead: %s failed on test "
460 "%d for %s: ret=%d\n", e
, j
, algo
, -ret
);
465 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
466 printk(KERN_ERR
"alg: aead: Test %d failed on "
467 "%s for %s\n", j
, e
, algo
);
468 hexdump(q
, template[i
].rlen
);
475 for (i
= 0, j
= 0; i
< tcount
; i
++) {
476 if (template[i
].np
) {
480 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
482 memset(iv
, 0, MAX_IVLEN
);
484 crypto_aead_clear_flags(tfm
, ~0);
486 crypto_aead_set_flags(
487 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
488 key
= template[i
].key
;
490 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
491 if (!ret
== template[i
].fail
) {
492 printk(KERN_ERR
"alg: aead: setkey failed on "
493 "chunk test %d for %s: flags=%x\n", j
,
494 algo
, crypto_aead_get_flags(tfm
));
499 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
502 sg_init_table(sg
, template[i
].np
);
503 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
504 if (WARN_ON(offset_in_page(IDX
[k
]) +
505 template[i
].tap
[k
] > PAGE_SIZE
))
508 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
509 offset_in_page(IDX
[k
]);
511 memcpy(q
, template[i
].input
+ temp
,
514 n
= template[i
].tap
[k
];
515 if (k
== template[i
].np
- 1 && enc
)
517 if (offset_in_page(q
) + n
< PAGE_SIZE
)
520 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
521 temp
+= template[i
].tap
[k
];
524 ret
= crypto_aead_setauthsize(tfm
, authsize
);
526 printk(KERN_ERR
"alg: aead: Failed to set "
527 "authsize to %u on chunk test %d for "
528 "%s\n", authsize
, j
, algo
);
533 if (WARN_ON(sg
[k
- 1].offset
+
534 sg
[k
- 1].length
+ authsize
>
540 sg
[k
- 1].length
+= authsize
;
543 sg_init_table(asg
, template[i
].anp
);
545 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
546 if (WARN_ON(offset_in_page(IDX
[k
]) +
547 template[i
].atap
[k
] > PAGE_SIZE
))
550 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
551 offset_in_page(IDX
[k
]),
552 template[i
].assoc
+ temp
,
553 template[i
].atap
[k
]),
554 template[i
].atap
[k
]);
555 temp
+= template[i
].atap
[k
];
558 aead_request_set_crypt(req
, sg
, sg
,
562 aead_request_set_assoc(req
, asg
, template[i
].alen
);
565 crypto_aead_encrypt(req
) :
566 crypto_aead_decrypt(req
);
570 if (template[i
].novrfy
) {
571 /* verification was supposed to fail */
572 printk(KERN_ERR
"alg: aead: %s failed "
573 "on chunk test %d for %s: ret "
574 "was 0, expected -EBADMSG\n",
576 /* so really, we got a bad message */
583 ret
= wait_for_completion_interruptible(
585 if (!ret
&& !(ret
= result
.err
)) {
586 INIT_COMPLETION(result
.completion
);
590 if (template[i
].novrfy
)
591 /* verification failure was expected */
595 printk(KERN_ERR
"alg: aead: %s failed on "
596 "chunk test %d for %s: ret=%d\n", e
, j
,
602 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
603 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
604 offset_in_page(IDX
[k
]);
606 n
= template[i
].tap
[k
];
607 if (k
== template[i
].np
- 1)
608 n
+= enc
? authsize
: -authsize
;
610 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
611 printk(KERN_ERR
"alg: aead: Chunk "
612 "test %d failed on %s at page "
613 "%u for %s\n", j
, e
, k
, algo
);
619 if (k
== template[i
].np
- 1 && !enc
) {
620 if (memcmp(q
, template[i
].input
+
626 for (n
= 0; offset_in_page(q
+ n
) &&
631 printk(KERN_ERR
"alg: aead: Result "
632 "buffer corruption in chunk "
633 "test %d on %s at page %u for "
634 "%s: %u bytes:\n", j
, e
, k
,
640 temp
+= template[i
].tap
[k
];
648 aead_request_free(req
);
649 testmgr_free_buf(axbuf
);
651 testmgr_free_buf(xbuf
);
656 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
657 struct cipher_testvec
*template, unsigned int tcount
)
659 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
660 unsigned int i
, j
, k
;
664 char *xbuf
[XBUFSIZE
];
667 if (testmgr_alloc_buf(xbuf
))
676 for (i
= 0; i
< tcount
; i
++) {
683 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
687 memcpy(data
, template[i
].input
, template[i
].ilen
);
689 crypto_cipher_clear_flags(tfm
, ~0);
691 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
693 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
695 if (!ret
== template[i
].fail
) {
696 printk(KERN_ERR
"alg: cipher: setkey failed "
697 "on test %d for %s: flags=%x\n", j
,
698 algo
, crypto_cipher_get_flags(tfm
));
703 for (k
= 0; k
< template[i
].ilen
;
704 k
+= crypto_cipher_blocksize(tfm
)) {
706 crypto_cipher_encrypt_one(tfm
, data
+ k
,
709 crypto_cipher_decrypt_one(tfm
, data
+ k
,
714 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
715 printk(KERN_ERR
"alg: cipher: Test %d failed "
716 "on %s for %s\n", j
, e
, algo
);
717 hexdump(q
, template[i
].rlen
);
726 testmgr_free_buf(xbuf
);
731 static int test_skcipher(struct crypto_ablkcipher
*tfm
, int enc
,
732 struct cipher_testvec
*template, unsigned int tcount
)
735 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm
));
736 unsigned int i
, j
, k
, n
, temp
;
738 struct ablkcipher_request
*req
;
739 struct scatterlist sg
[8];
741 struct tcrypt_result result
;
744 char *xbuf
[XBUFSIZE
];
747 if (testmgr_alloc_buf(xbuf
))
755 init_completion(&result
.completion
);
757 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
759 printk(KERN_ERR
"alg: skcipher: Failed to allocate request "
764 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
765 tcrypt_complete
, &result
);
768 for (i
= 0; i
< tcount
; i
++) {
770 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
772 memset(iv
, 0, MAX_IVLEN
);
774 if (!(template[i
].np
)) {
778 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
782 memcpy(data
, template[i
].input
, template[i
].ilen
);
784 crypto_ablkcipher_clear_flags(tfm
, ~0);
786 crypto_ablkcipher_set_flags(
787 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
789 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
791 if (!ret
== template[i
].fail
) {
792 printk(KERN_ERR
"alg: skcipher: setkey failed "
793 "on test %d for %s: flags=%x\n", j
,
794 algo
, crypto_ablkcipher_get_flags(tfm
));
799 sg_init_one(&sg
[0], data
, template[i
].ilen
);
801 ablkcipher_request_set_crypt(req
, sg
, sg
,
802 template[i
].ilen
, iv
);
804 crypto_ablkcipher_encrypt(req
) :
805 crypto_ablkcipher_decrypt(req
);
812 ret
= wait_for_completion_interruptible(
814 if (!ret
&& !((ret
= result
.err
))) {
815 INIT_COMPLETION(result
.completion
);
820 printk(KERN_ERR
"alg: skcipher: %s failed on "
821 "test %d for %s: ret=%d\n", e
, j
, algo
,
827 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
828 printk(KERN_ERR
"alg: skcipher: Test %d "
829 "failed on %s for %s\n", j
, e
, algo
);
830 hexdump(q
, template[i
].rlen
);
838 for (i
= 0; i
< tcount
; i
++) {
841 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
843 memset(iv
, 0, MAX_IVLEN
);
845 if (template[i
].np
) {
848 crypto_ablkcipher_clear_flags(tfm
, ~0);
850 crypto_ablkcipher_set_flags(
851 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
853 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
855 if (!ret
== template[i
].fail
) {
856 printk(KERN_ERR
"alg: skcipher: setkey failed "
857 "on chunk test %d for %s: flags=%x\n",
859 crypto_ablkcipher_get_flags(tfm
));
866 sg_init_table(sg
, template[i
].np
);
867 for (k
= 0; k
< template[i
].np
; k
++) {
868 if (WARN_ON(offset_in_page(IDX
[k
]) +
869 template[i
].tap
[k
] > PAGE_SIZE
))
872 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
873 offset_in_page(IDX
[k
]);
875 memcpy(q
, template[i
].input
+ temp
,
878 if (offset_in_page(q
) + template[i
].tap
[k
] <
880 q
[template[i
].tap
[k
]] = 0;
882 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
884 temp
+= template[i
].tap
[k
];
887 ablkcipher_request_set_crypt(req
, sg
, sg
,
888 template[i
].ilen
, iv
);
891 crypto_ablkcipher_encrypt(req
) :
892 crypto_ablkcipher_decrypt(req
);
899 ret
= wait_for_completion_interruptible(
901 if (!ret
&& !((ret
= result
.err
))) {
902 INIT_COMPLETION(result
.completion
);
907 printk(KERN_ERR
"alg: skcipher: %s failed on "
908 "chunk test %d for %s: ret=%d\n", e
, j
,
915 for (k
= 0; k
< template[i
].np
; k
++) {
916 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
917 offset_in_page(IDX
[k
]);
919 if (memcmp(q
, template[i
].result
+ temp
,
920 template[i
].tap
[k
])) {
921 printk(KERN_ERR
"alg: skcipher: Chunk "
922 "test %d failed on %s at page "
923 "%u for %s\n", j
, e
, k
, algo
);
924 hexdump(q
, template[i
].tap
[k
]);
928 q
+= template[i
].tap
[k
];
929 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
932 printk(KERN_ERR
"alg: skcipher: "
933 "Result buffer corruption in "
934 "chunk test %d on %s at page "
935 "%u for %s: %u bytes:\n", j
, e
,
940 temp
+= template[i
].tap
[k
];
948 ablkcipher_request_free(req
);
949 testmgr_free_buf(xbuf
);
954 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
955 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
957 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
959 char result
[COMP_BUF_SIZE
];
962 for (i
= 0; i
< ctcount
; i
++) {
964 unsigned int dlen
= COMP_BUF_SIZE
;
966 memset(result
, 0, sizeof (result
));
968 ilen
= ctemplate
[i
].inlen
;
969 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
970 ilen
, result
, &dlen
);
972 printk(KERN_ERR
"alg: comp: compression failed "
973 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
978 if (dlen
!= ctemplate
[i
].outlen
) {
979 printk(KERN_ERR
"alg: comp: Compression test %d "
980 "failed for %s: output len = %d\n", i
+ 1, algo
,
986 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
987 printk(KERN_ERR
"alg: comp: Compression test %d "
988 "failed for %s\n", i
+ 1, algo
);
989 hexdump(result
, dlen
);
995 for (i
= 0; i
< dtcount
; i
++) {
997 unsigned int dlen
= COMP_BUF_SIZE
;
999 memset(result
, 0, sizeof (result
));
1001 ilen
= dtemplate
[i
].inlen
;
1002 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1003 ilen
, result
, &dlen
);
1005 printk(KERN_ERR
"alg: comp: decompression failed "
1006 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1011 if (dlen
!= dtemplate
[i
].outlen
) {
1012 printk(KERN_ERR
"alg: comp: Decompression test %d "
1013 "failed for %s: output len = %d\n", i
+ 1, algo
,
1019 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
1020 printk(KERN_ERR
"alg: comp: Decompression test %d "
1021 "failed for %s\n", i
+ 1, algo
);
1022 hexdump(result
, dlen
);
1034 static int test_pcomp(struct crypto_pcomp
*tfm
,
1035 struct pcomp_testvec
*ctemplate
,
1036 struct pcomp_testvec
*dtemplate
, int ctcount
,
1039 const char *algo
= crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm
));
1041 char result
[COMP_BUF_SIZE
];
1044 for (i
= 0; i
< ctcount
; i
++) {
1045 struct comp_request req
;
1046 unsigned int produced
= 0;
1048 res
= crypto_compress_setup(tfm
, ctemplate
[i
].params
,
1049 ctemplate
[i
].paramsize
);
1051 pr_err("alg: pcomp: compression setup failed on test "
1052 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1056 res
= crypto_compress_init(tfm
);
1058 pr_err("alg: pcomp: compression init failed on test "
1059 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1063 memset(result
, 0, sizeof(result
));
1065 req
.next_in
= ctemplate
[i
].input
;
1066 req
.avail_in
= ctemplate
[i
].inlen
/ 2;
1067 req
.next_out
= result
;
1068 req
.avail_out
= ctemplate
[i
].outlen
/ 2;
1070 res
= crypto_compress_update(tfm
, &req
);
1071 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1072 pr_err("alg: pcomp: compression update failed on test "
1073 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1079 /* Add remaining input data */
1080 req
.avail_in
+= (ctemplate
[i
].inlen
+ 1) / 2;
1082 res
= crypto_compress_update(tfm
, &req
);
1083 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1084 pr_err("alg: pcomp: compression update failed on test "
1085 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1091 /* Provide remaining output space */
1092 req
.avail_out
+= COMP_BUF_SIZE
- ctemplate
[i
].outlen
/ 2;
1094 res
= crypto_compress_final(tfm
, &req
);
1096 pr_err("alg: pcomp: compression final failed on test "
1097 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1102 if (COMP_BUF_SIZE
- req
.avail_out
!= ctemplate
[i
].outlen
) {
1103 pr_err("alg: comp: Compression test %d failed for %s: "
1104 "output len = %d (expected %d)\n", i
+ 1, algo
,
1105 COMP_BUF_SIZE
- req
.avail_out
,
1106 ctemplate
[i
].outlen
);
1110 if (produced
!= ctemplate
[i
].outlen
) {
1111 pr_err("alg: comp: Compression test %d failed for %s: "
1112 "returned len = %u (expected %d)\n", i
+ 1,
1113 algo
, produced
, ctemplate
[i
].outlen
);
1117 if (memcmp(result
, ctemplate
[i
].output
, ctemplate
[i
].outlen
)) {
1118 pr_err("alg: pcomp: Compression test %d failed for "
1119 "%s\n", i
+ 1, algo
);
1120 hexdump(result
, ctemplate
[i
].outlen
);
1125 for (i
= 0; i
< dtcount
; i
++) {
1126 struct comp_request req
;
1127 unsigned int produced
= 0;
1129 res
= crypto_decompress_setup(tfm
, dtemplate
[i
].params
,
1130 dtemplate
[i
].paramsize
);
1132 pr_err("alg: pcomp: decompression setup failed on "
1133 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1137 res
= crypto_decompress_init(tfm
);
1139 pr_err("alg: pcomp: decompression init failed on test "
1140 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1144 memset(result
, 0, sizeof(result
));
1146 req
.next_in
= dtemplate
[i
].input
;
1147 req
.avail_in
= dtemplate
[i
].inlen
/ 2;
1148 req
.next_out
= result
;
1149 req
.avail_out
= dtemplate
[i
].outlen
/ 2;
1151 res
= crypto_decompress_update(tfm
, &req
);
1152 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1153 pr_err("alg: pcomp: decompression update failed on "
1154 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1160 /* Add remaining input data */
1161 req
.avail_in
+= (dtemplate
[i
].inlen
+ 1) / 2;
1163 res
= crypto_decompress_update(tfm
, &req
);
1164 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1165 pr_err("alg: pcomp: decompression update failed on "
1166 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1172 /* Provide remaining output space */
1173 req
.avail_out
+= COMP_BUF_SIZE
- dtemplate
[i
].outlen
/ 2;
1175 res
= crypto_decompress_final(tfm
, &req
);
1176 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1177 pr_err("alg: pcomp: decompression final failed on "
1178 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1184 if (COMP_BUF_SIZE
- req
.avail_out
!= dtemplate
[i
].outlen
) {
1185 pr_err("alg: comp: Decompression test %d failed for "
1186 "%s: output len = %d (expected %d)\n", i
+ 1,
1187 algo
, COMP_BUF_SIZE
- req
.avail_out
,
1188 dtemplate
[i
].outlen
);
1192 if (produced
!= dtemplate
[i
].outlen
) {
1193 pr_err("alg: comp: Decompression test %d failed for "
1194 "%s: returned len = %u (expected %d)\n", i
+ 1,
1195 algo
, produced
, dtemplate
[i
].outlen
);
1199 if (memcmp(result
, dtemplate
[i
].output
, dtemplate
[i
].outlen
)) {
1200 pr_err("alg: pcomp: Decompression test %d failed for "
1201 "%s\n", i
+ 1, algo
);
1202 hexdump(result
, dtemplate
[i
].outlen
);
1211 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1212 unsigned int tcount
)
1214 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1215 int err
= 0, i
, j
, seedsize
;
1219 seedsize
= crypto_rng_seedsize(tfm
);
1221 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1223 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1228 for (i
= 0; i
< tcount
; i
++) {
1229 memset(result
, 0, 32);
1231 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1232 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1234 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1235 template[i
].dt
, template[i
].dtlen
);
1237 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1239 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1244 for (j
= 0; j
< template[i
].loops
; j
++) {
1245 err
= crypto_rng_get_bytes(tfm
, result
,
1247 if (err
!= template[i
].rlen
) {
1248 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1249 "the correct amount of random data for "
1250 "%s (requested %d, got %d)\n", algo
,
1251 template[i
].rlen
, err
);
1256 err
= memcmp(result
, template[i
].result
,
1259 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1261 hexdump(result
, template[i
].rlen
);
1272 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1275 struct crypto_aead
*tfm
;
1278 tfm
= crypto_alloc_aead(driver
, type
, mask
);
1280 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1281 "%ld\n", driver
, PTR_ERR(tfm
));
1282 return PTR_ERR(tfm
);
1285 if (desc
->suite
.aead
.enc
.vecs
) {
1286 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1287 desc
->suite
.aead
.enc
.count
);
1292 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1293 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1294 desc
->suite
.aead
.dec
.count
);
1297 crypto_free_aead(tfm
);
1301 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1302 const char *driver
, u32 type
, u32 mask
)
1304 struct crypto_cipher
*tfm
;
1307 tfm
= crypto_alloc_cipher(driver
, type
, mask
);
1309 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1310 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1311 return PTR_ERR(tfm
);
1314 if (desc
->suite
.cipher
.enc
.vecs
) {
1315 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1316 desc
->suite
.cipher
.enc
.count
);
1321 if (desc
->suite
.cipher
.dec
.vecs
)
1322 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1323 desc
->suite
.cipher
.dec
.count
);
1326 crypto_free_cipher(tfm
);
1330 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1331 const char *driver
, u32 type
, u32 mask
)
1333 struct crypto_ablkcipher
*tfm
;
1336 tfm
= crypto_alloc_ablkcipher(driver
, type
, mask
);
1338 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1339 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1340 return PTR_ERR(tfm
);
1343 if (desc
->suite
.cipher
.enc
.vecs
) {
1344 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1345 desc
->suite
.cipher
.enc
.count
);
1350 if (desc
->suite
.cipher
.dec
.vecs
)
1351 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1352 desc
->suite
.cipher
.dec
.count
);
1355 crypto_free_ablkcipher(tfm
);
1359 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1362 struct crypto_comp
*tfm
;
1365 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1367 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1368 "%ld\n", driver
, PTR_ERR(tfm
));
1369 return PTR_ERR(tfm
);
1372 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1373 desc
->suite
.comp
.decomp
.vecs
,
1374 desc
->suite
.comp
.comp
.count
,
1375 desc
->suite
.comp
.decomp
.count
);
1377 crypto_free_comp(tfm
);
1381 static int alg_test_pcomp(const struct alg_test_desc
*desc
, const char *driver
,
1384 struct crypto_pcomp
*tfm
;
1387 tfm
= crypto_alloc_pcomp(driver
, type
, mask
);
1389 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1390 driver
, PTR_ERR(tfm
));
1391 return PTR_ERR(tfm
);
1394 err
= test_pcomp(tfm
, desc
->suite
.pcomp
.comp
.vecs
,
1395 desc
->suite
.pcomp
.decomp
.vecs
,
1396 desc
->suite
.pcomp
.comp
.count
,
1397 desc
->suite
.pcomp
.decomp
.count
);
1399 crypto_free_pcomp(tfm
);
1403 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1406 struct crypto_ahash
*tfm
;
1409 tfm
= crypto_alloc_ahash(driver
, type
, mask
);
1411 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1412 "%ld\n", driver
, PTR_ERR(tfm
));
1413 return PTR_ERR(tfm
);
1416 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
, desc
->suite
.hash
.count
);
1418 crypto_free_ahash(tfm
);
1422 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1423 const char *driver
, u32 type
, u32 mask
)
1425 struct crypto_shash
*tfm
;
1429 err
= alg_test_hash(desc
, driver
, type
, mask
);
1433 tfm
= crypto_alloc_shash(driver
, type
, mask
);
1435 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1436 "%ld\n", driver
, PTR_ERR(tfm
));
1443 struct shash_desc shash
;
1444 char ctx
[crypto_shash_descsize(tfm
)];
1447 sdesc
.shash
.tfm
= tfm
;
1448 sdesc
.shash
.flags
= 0;
1450 *(u32
*)sdesc
.ctx
= le32_to_cpu(420553207);
1451 err
= crypto_shash_final(&sdesc
.shash
, (u8
*)&val
);
1453 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1454 "%s: %d\n", driver
, err
);
1458 if (val
!= ~420553207) {
1459 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1460 "%d\n", driver
, val
);
1465 crypto_free_shash(tfm
);
1471 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1474 struct crypto_rng
*rng
;
1477 rng
= crypto_alloc_rng(driver
, type
, mask
);
1479 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1480 "%ld\n", driver
, PTR_ERR(rng
));
1481 return PTR_ERR(rng
);
1484 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1486 crypto_free_rng(rng
);
1491 static int alg_test_null(const struct alg_test_desc
*desc
,
1492 const char *driver
, u32 type
, u32 mask
)
1497 /* Please keep this list sorted by algorithm name. */
1498 static const struct alg_test_desc alg_test_descs
[] = {
1500 .alg
= "__driver-cbc-aes-aesni",
1501 .test
= alg_test_null
,
1515 .alg
= "__driver-ecb-aes-aesni",
1516 .test
= alg_test_null
,
1530 .alg
= "__ghash-pclmulqdqni",
1531 .test
= alg_test_null
,
1539 .alg
= "ansi_cprng",
1540 .test
= alg_test_cprng
,
1544 .vecs
= ansi_cprng_aes_tv_template
,
1545 .count
= ANSI_CPRNG_AES_TEST_VECTORS
1550 .test
= alg_test_skcipher
,
1555 .vecs
= aes_cbc_enc_tv_template
,
1556 .count
= AES_CBC_ENC_TEST_VECTORS
1559 .vecs
= aes_cbc_dec_tv_template
,
1560 .count
= AES_CBC_DEC_TEST_VECTORS
1565 .alg
= "cbc(anubis)",
1566 .test
= alg_test_skcipher
,
1570 .vecs
= anubis_cbc_enc_tv_template
,
1571 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
1574 .vecs
= anubis_cbc_dec_tv_template
,
1575 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
1580 .alg
= "cbc(blowfish)",
1581 .test
= alg_test_skcipher
,
1585 .vecs
= bf_cbc_enc_tv_template
,
1586 .count
= BF_CBC_ENC_TEST_VECTORS
1589 .vecs
= bf_cbc_dec_tv_template
,
1590 .count
= BF_CBC_DEC_TEST_VECTORS
1595 .alg
= "cbc(camellia)",
1596 .test
= alg_test_skcipher
,
1600 .vecs
= camellia_cbc_enc_tv_template
,
1601 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
1604 .vecs
= camellia_cbc_dec_tv_template
,
1605 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
1611 .test
= alg_test_skcipher
,
1615 .vecs
= des_cbc_enc_tv_template
,
1616 .count
= DES_CBC_ENC_TEST_VECTORS
1619 .vecs
= des_cbc_dec_tv_template
,
1620 .count
= DES_CBC_DEC_TEST_VECTORS
1625 .alg
= "cbc(des3_ede)",
1626 .test
= alg_test_skcipher
,
1631 .vecs
= des3_ede_cbc_enc_tv_template
,
1632 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
1635 .vecs
= des3_ede_cbc_dec_tv_template
,
1636 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
1641 .alg
= "cbc(twofish)",
1642 .test
= alg_test_skcipher
,
1646 .vecs
= tf_cbc_enc_tv_template
,
1647 .count
= TF_CBC_ENC_TEST_VECTORS
1650 .vecs
= tf_cbc_dec_tv_template
,
1651 .count
= TF_CBC_DEC_TEST_VECTORS
1657 .test
= alg_test_aead
,
1662 .vecs
= aes_ccm_enc_tv_template
,
1663 .count
= AES_CCM_ENC_TEST_VECTORS
1666 .vecs
= aes_ccm_dec_tv_template
,
1667 .count
= AES_CCM_DEC_TEST_VECTORS
1673 .test
= alg_test_crc32c
,
1677 .vecs
= crc32c_tv_template
,
1678 .count
= CRC32C_TEST_VECTORS
1682 .alg
= "cryptd(__driver-ecb-aes-aesni)",
1683 .test
= alg_test_null
,
1697 .alg
= "cryptd(__ghash-pclmulqdqni)",
1698 .test
= alg_test_null
,
1707 .test
= alg_test_skcipher
,
1712 .vecs
= aes_ctr_enc_tv_template
,
1713 .count
= AES_CTR_ENC_TEST_VECTORS
1716 .vecs
= aes_ctr_dec_tv_template
,
1717 .count
= AES_CTR_DEC_TEST_VECTORS
1722 .alg
= "cts(cbc(aes))",
1723 .test
= alg_test_skcipher
,
1727 .vecs
= cts_mode_enc_tv_template
,
1728 .count
= CTS_MODE_ENC_TEST_VECTORS
1731 .vecs
= cts_mode_dec_tv_template
,
1732 .count
= CTS_MODE_DEC_TEST_VECTORS
1738 .test
= alg_test_comp
,
1742 .vecs
= deflate_comp_tv_template
,
1743 .count
= DEFLATE_COMP_TEST_VECTORS
1746 .vecs
= deflate_decomp_tv_template
,
1747 .count
= DEFLATE_DECOMP_TEST_VECTORS
1752 .alg
= "ecb(__aes-aesni)",
1753 .test
= alg_test_null
,
1768 .test
= alg_test_skcipher
,
1773 .vecs
= aes_enc_tv_template
,
1774 .count
= AES_ENC_TEST_VECTORS
1777 .vecs
= aes_dec_tv_template
,
1778 .count
= AES_DEC_TEST_VECTORS
1783 .alg
= "ecb(anubis)",
1784 .test
= alg_test_skcipher
,
1788 .vecs
= anubis_enc_tv_template
,
1789 .count
= ANUBIS_ENC_TEST_VECTORS
1792 .vecs
= anubis_dec_tv_template
,
1793 .count
= ANUBIS_DEC_TEST_VECTORS
1799 .test
= alg_test_skcipher
,
1803 .vecs
= arc4_enc_tv_template
,
1804 .count
= ARC4_ENC_TEST_VECTORS
1807 .vecs
= arc4_dec_tv_template
,
1808 .count
= ARC4_DEC_TEST_VECTORS
1813 .alg
= "ecb(blowfish)",
1814 .test
= alg_test_skcipher
,
1818 .vecs
= bf_enc_tv_template
,
1819 .count
= BF_ENC_TEST_VECTORS
1822 .vecs
= bf_dec_tv_template
,
1823 .count
= BF_DEC_TEST_VECTORS
1828 .alg
= "ecb(camellia)",
1829 .test
= alg_test_skcipher
,
1833 .vecs
= camellia_enc_tv_template
,
1834 .count
= CAMELLIA_ENC_TEST_VECTORS
1837 .vecs
= camellia_dec_tv_template
,
1838 .count
= CAMELLIA_DEC_TEST_VECTORS
1843 .alg
= "ecb(cast5)",
1844 .test
= alg_test_skcipher
,
1848 .vecs
= cast5_enc_tv_template
,
1849 .count
= CAST5_ENC_TEST_VECTORS
1852 .vecs
= cast5_dec_tv_template
,
1853 .count
= CAST5_DEC_TEST_VECTORS
1858 .alg
= "ecb(cast6)",
1859 .test
= alg_test_skcipher
,
1863 .vecs
= cast6_enc_tv_template
,
1864 .count
= CAST6_ENC_TEST_VECTORS
1867 .vecs
= cast6_dec_tv_template
,
1868 .count
= CAST6_DEC_TEST_VECTORS
1874 .test
= alg_test_skcipher
,
1879 .vecs
= des_enc_tv_template
,
1880 .count
= DES_ENC_TEST_VECTORS
1883 .vecs
= des_dec_tv_template
,
1884 .count
= DES_DEC_TEST_VECTORS
1889 .alg
= "ecb(des3_ede)",
1890 .test
= alg_test_skcipher
,
1895 .vecs
= des3_ede_enc_tv_template
,
1896 .count
= DES3_EDE_ENC_TEST_VECTORS
1899 .vecs
= des3_ede_dec_tv_template
,
1900 .count
= DES3_EDE_DEC_TEST_VECTORS
1905 .alg
= "ecb(khazad)",
1906 .test
= alg_test_skcipher
,
1910 .vecs
= khazad_enc_tv_template
,
1911 .count
= KHAZAD_ENC_TEST_VECTORS
1914 .vecs
= khazad_dec_tv_template
,
1915 .count
= KHAZAD_DEC_TEST_VECTORS
1921 .test
= alg_test_skcipher
,
1925 .vecs
= seed_enc_tv_template
,
1926 .count
= SEED_ENC_TEST_VECTORS
1929 .vecs
= seed_dec_tv_template
,
1930 .count
= SEED_DEC_TEST_VECTORS
1935 .alg
= "ecb(serpent)",
1936 .test
= alg_test_skcipher
,
1940 .vecs
= serpent_enc_tv_template
,
1941 .count
= SERPENT_ENC_TEST_VECTORS
1944 .vecs
= serpent_dec_tv_template
,
1945 .count
= SERPENT_DEC_TEST_VECTORS
1951 .test
= alg_test_skcipher
,
1955 .vecs
= tea_enc_tv_template
,
1956 .count
= TEA_ENC_TEST_VECTORS
1959 .vecs
= tea_dec_tv_template
,
1960 .count
= TEA_DEC_TEST_VECTORS
1965 .alg
= "ecb(tnepres)",
1966 .test
= alg_test_skcipher
,
1970 .vecs
= tnepres_enc_tv_template
,
1971 .count
= TNEPRES_ENC_TEST_VECTORS
1974 .vecs
= tnepres_dec_tv_template
,
1975 .count
= TNEPRES_DEC_TEST_VECTORS
1980 .alg
= "ecb(twofish)",
1981 .test
= alg_test_skcipher
,
1985 .vecs
= tf_enc_tv_template
,
1986 .count
= TF_ENC_TEST_VECTORS
1989 .vecs
= tf_dec_tv_template
,
1990 .count
= TF_DEC_TEST_VECTORS
1996 .test
= alg_test_skcipher
,
2000 .vecs
= xeta_enc_tv_template
,
2001 .count
= XETA_ENC_TEST_VECTORS
2004 .vecs
= xeta_dec_tv_template
,
2005 .count
= XETA_DEC_TEST_VECTORS
2011 .test
= alg_test_skcipher
,
2015 .vecs
= xtea_enc_tv_template
,
2016 .count
= XTEA_ENC_TEST_VECTORS
2019 .vecs
= xtea_dec_tv_template
,
2020 .count
= XTEA_DEC_TEST_VECTORS
2026 .test
= alg_test_aead
,
2031 .vecs
= aes_gcm_enc_tv_template
,
2032 .count
= AES_GCM_ENC_TEST_VECTORS
2035 .vecs
= aes_gcm_dec_tv_template
,
2036 .count
= AES_GCM_DEC_TEST_VECTORS
2042 .test
= alg_test_hash
,
2045 .vecs
= ghash_tv_template
,
2046 .count
= GHASH_TEST_VECTORS
2051 .test
= alg_test_hash
,
2054 .vecs
= hmac_md5_tv_template
,
2055 .count
= HMAC_MD5_TEST_VECTORS
2059 .alg
= "hmac(rmd128)",
2060 .test
= alg_test_hash
,
2063 .vecs
= hmac_rmd128_tv_template
,
2064 .count
= HMAC_RMD128_TEST_VECTORS
2068 .alg
= "hmac(rmd160)",
2069 .test
= alg_test_hash
,
2072 .vecs
= hmac_rmd160_tv_template
,
2073 .count
= HMAC_RMD160_TEST_VECTORS
2077 .alg
= "hmac(sha1)",
2078 .test
= alg_test_hash
,
2082 .vecs
= hmac_sha1_tv_template
,
2083 .count
= HMAC_SHA1_TEST_VECTORS
2087 .alg
= "hmac(sha224)",
2088 .test
= alg_test_hash
,
2092 .vecs
= hmac_sha224_tv_template
,
2093 .count
= HMAC_SHA224_TEST_VECTORS
2097 .alg
= "hmac(sha256)",
2098 .test
= alg_test_hash
,
2102 .vecs
= hmac_sha256_tv_template
,
2103 .count
= HMAC_SHA256_TEST_VECTORS
2107 .alg
= "hmac(sha384)",
2108 .test
= alg_test_hash
,
2112 .vecs
= hmac_sha384_tv_template
,
2113 .count
= HMAC_SHA384_TEST_VECTORS
2117 .alg
= "hmac(sha512)",
2118 .test
= alg_test_hash
,
2122 .vecs
= hmac_sha512_tv_template
,
2123 .count
= HMAC_SHA512_TEST_VECTORS
2128 .test
= alg_test_skcipher
,
2132 .vecs
= aes_lrw_enc_tv_template
,
2133 .count
= AES_LRW_ENC_TEST_VECTORS
2136 .vecs
= aes_lrw_dec_tv_template
,
2137 .count
= AES_LRW_DEC_TEST_VECTORS
2143 .test
= alg_test_comp
,
2147 .vecs
= lzo_comp_tv_template
,
2148 .count
= LZO_COMP_TEST_VECTORS
2151 .vecs
= lzo_decomp_tv_template
,
2152 .count
= LZO_DECOMP_TEST_VECTORS
2158 .test
= alg_test_hash
,
2161 .vecs
= md4_tv_template
,
2162 .count
= MD4_TEST_VECTORS
2167 .test
= alg_test_hash
,
2170 .vecs
= md5_tv_template
,
2171 .count
= MD5_TEST_VECTORS
2175 .alg
= "michael_mic",
2176 .test
= alg_test_hash
,
2179 .vecs
= michael_mic_tv_template
,
2180 .count
= MICHAEL_MIC_TEST_VECTORS
2184 .alg
= "pcbc(fcrypt)",
2185 .test
= alg_test_skcipher
,
2189 .vecs
= fcrypt_pcbc_enc_tv_template
,
2190 .count
= FCRYPT_ENC_TEST_VECTORS
2193 .vecs
= fcrypt_pcbc_dec_tv_template
,
2194 .count
= FCRYPT_DEC_TEST_VECTORS
2199 .alg
= "rfc3686(ctr(aes))",
2200 .test
= alg_test_skcipher
,
2205 .vecs
= aes_ctr_rfc3686_enc_tv_template
,
2206 .count
= AES_CTR_3686_ENC_TEST_VECTORS
2209 .vecs
= aes_ctr_rfc3686_dec_tv_template
,
2210 .count
= AES_CTR_3686_DEC_TEST_VECTORS
2215 .alg
= "rfc4309(ccm(aes))",
2216 .test
= alg_test_aead
,
2221 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
2222 .count
= AES_CCM_4309_ENC_TEST_VECTORS
2225 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
2226 .count
= AES_CCM_4309_DEC_TEST_VECTORS
2232 .test
= alg_test_hash
,
2235 .vecs
= rmd128_tv_template
,
2236 .count
= RMD128_TEST_VECTORS
2241 .test
= alg_test_hash
,
2244 .vecs
= rmd160_tv_template
,
2245 .count
= RMD160_TEST_VECTORS
2250 .test
= alg_test_hash
,
2253 .vecs
= rmd256_tv_template
,
2254 .count
= RMD256_TEST_VECTORS
2259 .test
= alg_test_hash
,
2262 .vecs
= rmd320_tv_template
,
2263 .count
= RMD320_TEST_VECTORS
2268 .test
= alg_test_skcipher
,
2272 .vecs
= salsa20_stream_enc_tv_template
,
2273 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
2279 .test
= alg_test_hash
,
2283 .vecs
= sha1_tv_template
,
2284 .count
= SHA1_TEST_VECTORS
2289 .test
= alg_test_hash
,
2293 .vecs
= sha224_tv_template
,
2294 .count
= SHA224_TEST_VECTORS
2299 .test
= alg_test_hash
,
2303 .vecs
= sha256_tv_template
,
2304 .count
= SHA256_TEST_VECTORS
2309 .test
= alg_test_hash
,
2313 .vecs
= sha384_tv_template
,
2314 .count
= SHA384_TEST_VECTORS
2319 .test
= alg_test_hash
,
2323 .vecs
= sha512_tv_template
,
2324 .count
= SHA512_TEST_VECTORS
2329 .test
= alg_test_hash
,
2332 .vecs
= tgr128_tv_template
,
2333 .count
= TGR128_TEST_VECTORS
2338 .test
= alg_test_hash
,
2341 .vecs
= tgr160_tv_template
,
2342 .count
= TGR160_TEST_VECTORS
2347 .test
= alg_test_hash
,
2350 .vecs
= tgr192_tv_template
,
2351 .count
= TGR192_TEST_VECTORS
2356 .test
= alg_test_hash
,
2359 .vecs
= aes_vmac128_tv_template
,
2360 .count
= VMAC_AES_TEST_VECTORS
2365 .test
= alg_test_hash
,
2368 .vecs
= wp256_tv_template
,
2369 .count
= WP256_TEST_VECTORS
2374 .test
= alg_test_hash
,
2377 .vecs
= wp384_tv_template
,
2378 .count
= WP384_TEST_VECTORS
2383 .test
= alg_test_hash
,
2386 .vecs
= wp512_tv_template
,
2387 .count
= WP512_TEST_VECTORS
2392 .test
= alg_test_hash
,
2395 .vecs
= aes_xcbc128_tv_template
,
2396 .count
= XCBC_AES_TEST_VECTORS
2401 .test
= alg_test_skcipher
,
2405 .vecs
= aes_xts_enc_tv_template
,
2406 .count
= AES_XTS_ENC_TEST_VECTORS
2409 .vecs
= aes_xts_dec_tv_template
,
2410 .count
= AES_XTS_DEC_TEST_VECTORS
2416 .test
= alg_test_pcomp
,
2420 .vecs
= zlib_comp_tv_template
,
2421 .count
= ZLIB_COMP_TEST_VECTORS
2424 .vecs
= zlib_decomp_tv_template
,
2425 .count
= ZLIB_DECOMP_TEST_VECTORS
2432 static int alg_find_test(const char *alg
)
2435 int end
= ARRAY_SIZE(alg_test_descs
);
2437 while (start
< end
) {
2438 int i
= (start
+ end
) / 2;
2439 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
2457 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
2463 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
2464 char nalg
[CRYPTO_MAX_ALG_NAME
];
2466 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
2468 return -ENAMETOOLONG
;
2470 i
= alg_find_test(nalg
);
2474 if (fips_enabled
&& !alg_test_descs
[i
].fips_allowed
)
2477 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
2481 i
= alg_find_test(alg
);
2482 j
= alg_find_test(driver
);
2486 if (fips_enabled
&& ((i
>= 0 && !alg_test_descs
[i
].fips_allowed
) ||
2487 (j
>= 0 && !alg_test_descs
[j
].fips_allowed
)))
2492 rc
|= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
2495 rc
|= alg_test_descs
[j
].test(alg_test_descs
+ j
, driver
,
2499 if (fips_enabled
&& rc
)
2500 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
2502 if (fips_enabled
&& !rc
)
2503 printk(KERN_INFO
"alg: self-tests for %s (%s) passed\n",
2509 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
2515 #endif /* CONFIG_CRYPTO_MANAGER_TESTS */
2517 EXPORT_SYMBOL_GPL(alg_test
);