aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-06-13 16:08:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-13 16:08:01 -0400
commit32f44d62e463f66307513e90c09b4ceeac13cc22 (patch)
treea0e0c33b3c9c4474787ebb007ff15d6600fb053f
parentf3ad116588151b3371ae4e092290e4f48e62b8bb (diff)
parent08ced854fc4a979d9e59ba01000bf96e7057cfbc (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (35 commits) hwrng: timeriomem - Fix potential oops (request_mem_region/__devinit) crypto: api - Use formatting of module name crypto: testmgr - Allow hash test vectors longer than a page crypto: testmgr - Check all test vector lengths crypto: hifn_795x - fix __dev{init,exit} markings crypto: tcrypt - Do not exit on success in fips mode crypto: compress - Return produced bytes in crypto_{,de}compress_{update,final} hwrng: via_rng - Support VIA Nano hardware RNG on X86_64 builds hwrng: via_rng - Support VIA Nano hardware RNG hwrng: via_rng - The VIA Hardware RNG driver is for the CPU, not Chipset crypto: testmgr - Skip algs not flagged fips_allowed in fips mode crypto: testmgr - Mark algs allowed in fips mode crypto: testmgr - Add ctr(aes) test vectors crypto: testmgr - Dynamically allocate xbuf and axbuf crypto: testmgr - Print self-test pass notices in fips mode crypto: testmgr - Catch base cipher self-test failures in fips mode crypto: testmgr - Add ansi_cprng test vectors crypto: testmgr - Add infrastructure for ansi_cprng self-tests crypto: testmgr - Add self-tests for rfc4309(ccm(aes)) crypto: testmgr - Handle AEAD test vectors expected to fail verification ...
-rw-r--r--arch/x86/crypto/Makefile2
-rw-r--r--arch/x86/crypto/aesni-intel_glue.c267
-rw-r--r--arch/x86/crypto/fpu.c166
-rw-r--r--crypto/Kconfig10
-rw-r--r--crypto/algboss.c18
-rw-r--r--crypto/api.c14
-rw-r--r--crypto/cryptd.c14
-rw-r--r--crypto/internal.h3
-rw-r--r--crypto/pcompress.c1
-rw-r--r--crypto/tcrypt.c183
-rw-r--r--crypto/testmgr.c470
-rw-r--r--crypto/testmgr.h645
-rw-r--r--crypto/zlib.c24
-rw-r--r--drivers/char/hw_random/Kconfig2
-rw-r--r--drivers/char/hw_random/omap-rng.c2
-rw-r--r--drivers/char/hw_random/timeriomem-rng.c26
-rw-r--r--drivers/char/hw_random/via-rng.c15
-rw-r--r--drivers/crypto/Kconfig2
-rw-r--r--drivers/crypto/hifn_795x.c8
-rw-r--r--drivers/crypto/padlock-aes.c13
-rw-r--r--drivers/crypto/talitos.c713
21 files changed, 2141 insertions, 457 deletions
diff --git a/arch/x86/crypto/Makefile b/arch/x86/crypto/Makefile
index ebe7deedd5b4..cfb0010fa940 100644
--- a/arch/x86/crypto/Makefile
+++ b/arch/x86/crypto/Makefile
@@ -2,6 +2,8 @@
2# Arch-specific CryptoAPI modules. 2# Arch-specific CryptoAPI modules.
3# 3#
4 4
5obj-$(CONFIG_CRYPTO_FPU) += fpu.o
6
5obj-$(CONFIG_CRYPTO_AES_586) += aes-i586.o 7obj-$(CONFIG_CRYPTO_AES_586) += aes-i586.o
6obj-$(CONFIG_CRYPTO_TWOFISH_586) += twofish-i586.o 8obj-$(CONFIG_CRYPTO_TWOFISH_586) += twofish-i586.o
7obj-$(CONFIG_CRYPTO_SALSA20_586) += salsa20-i586.o 9obj-$(CONFIG_CRYPTO_SALSA20_586) += salsa20-i586.o
diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
index 02af0af65497..4e663398f77f 100644
--- a/arch/x86/crypto/aesni-intel_glue.c
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -21,6 +21,22 @@
21#include <asm/i387.h> 21#include <asm/i387.h>
22#include <asm/aes.h> 22#include <asm/aes.h>
23 23
24#if defined(CONFIG_CRYPTO_CTR) || defined(CONFIG_CRYPTO_CTR_MODULE)
25#define HAS_CTR
26#endif
27
28#if defined(CONFIG_CRYPTO_LRW) || defined(CONFIG_CRYPTO_LRW_MODULE)
29#define HAS_LRW
30#endif
31
32#if defined(CONFIG_CRYPTO_PCBC) || defined(CONFIG_CRYPTO_PCBC_MODULE)
33#define HAS_PCBC
34#endif
35
36#if defined(CONFIG_CRYPTO_XTS) || defined(CONFIG_CRYPTO_XTS_MODULE)
37#define HAS_XTS
38#endif
39
24struct async_aes_ctx { 40struct async_aes_ctx {
25 struct cryptd_ablkcipher *cryptd_tfm; 41 struct cryptd_ablkcipher *cryptd_tfm;
26}; 42};
@@ -137,6 +153,41 @@ static struct crypto_alg aesni_alg = {
137 } 153 }
138}; 154};
139 155
156static void __aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
157{
158 struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
159
160 aesni_enc(ctx, dst, src);
161}
162
163static void __aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
164{
165 struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
166
167 aesni_dec(ctx, dst, src);
168}
169
170static struct crypto_alg __aesni_alg = {
171 .cra_name = "__aes-aesni",
172 .cra_driver_name = "__driver-aes-aesni",
173 .cra_priority = 0,
174 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
175 .cra_blocksize = AES_BLOCK_SIZE,
176 .cra_ctxsize = sizeof(struct crypto_aes_ctx)+AESNI_ALIGN-1,
177 .cra_alignmask = 0,
178 .cra_module = THIS_MODULE,
179 .cra_list = LIST_HEAD_INIT(__aesni_alg.cra_list),
180 .cra_u = {
181 .cipher = {
182 .cia_min_keysize = AES_MIN_KEY_SIZE,
183 .cia_max_keysize = AES_MAX_KEY_SIZE,
184 .cia_setkey = aes_set_key,
185 .cia_encrypt = __aes_encrypt,
186 .cia_decrypt = __aes_decrypt
187 }
188 }
189};
190
140static int ecb_encrypt(struct blkcipher_desc *desc, 191static int ecb_encrypt(struct blkcipher_desc *desc,
141 struct scatterlist *dst, struct scatterlist *src, 192 struct scatterlist *dst, struct scatterlist *src,
142 unsigned int nbytes) 193 unsigned int nbytes)
@@ -277,8 +328,16 @@ static int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
277 unsigned int key_len) 328 unsigned int key_len)
278{ 329{
279 struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm); 330 struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
331 struct crypto_ablkcipher *child = &ctx->cryptd_tfm->base;
332 int err;
280 333
281 return crypto_ablkcipher_setkey(&ctx->cryptd_tfm->base, key, key_len); 334 crypto_ablkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
335 crypto_ablkcipher_set_flags(child, crypto_ablkcipher_get_flags(tfm)
336 & CRYPTO_TFM_REQ_MASK);
337 err = crypto_ablkcipher_setkey(child, key, key_len);
338 crypto_ablkcipher_set_flags(tfm, crypto_ablkcipher_get_flags(child)
339 & CRYPTO_TFM_RES_MASK);
340 return err;
282} 341}
283 342
284static int ablk_encrypt(struct ablkcipher_request *req) 343static int ablk_encrypt(struct ablkcipher_request *req)
@@ -411,6 +470,163 @@ static struct crypto_alg ablk_cbc_alg = {
411 }, 470 },
412}; 471};
413 472
473#ifdef HAS_CTR
474static int ablk_ctr_init(struct crypto_tfm *tfm)
475{
476 struct cryptd_ablkcipher *cryptd_tfm;
477
478 cryptd_tfm = cryptd_alloc_ablkcipher("fpu(ctr(__driver-aes-aesni))",
479 0, 0);
480 if (IS_ERR(cryptd_tfm))
481 return PTR_ERR(cryptd_tfm);
482 ablk_init_common(tfm, cryptd_tfm);
483 return 0;
484}
485
486static struct crypto_alg ablk_ctr_alg = {
487 .cra_name = "ctr(aes)",
488 .cra_driver_name = "ctr-aes-aesni",
489 .cra_priority = 400,
490 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
491 .cra_blocksize = 1,
492 .cra_ctxsize = sizeof(struct async_aes_ctx),
493 .cra_alignmask = 0,
494 .cra_type = &crypto_ablkcipher_type,
495 .cra_module = THIS_MODULE,
496 .cra_list = LIST_HEAD_INIT(ablk_ctr_alg.cra_list),
497 .cra_init = ablk_ctr_init,
498 .cra_exit = ablk_exit,
499 .cra_u = {
500 .ablkcipher = {
501 .min_keysize = AES_MIN_KEY_SIZE,
502 .max_keysize = AES_MAX_KEY_SIZE,
503 .ivsize = AES_BLOCK_SIZE,
504 .setkey = ablk_set_key,
505 .encrypt = ablk_encrypt,
506 .decrypt = ablk_decrypt,
507 .geniv = "chainiv",
508 },
509 },
510};
511#endif
512
513#ifdef HAS_LRW
514static int ablk_lrw_init(struct crypto_tfm *tfm)
515{
516 struct cryptd_ablkcipher *cryptd_tfm;
517
518 cryptd_tfm = cryptd_alloc_ablkcipher("fpu(lrw(__driver-aes-aesni))",
519 0, 0);
520 if (IS_ERR(cryptd_tfm))
521 return PTR_ERR(cryptd_tfm);
522 ablk_init_common(tfm, cryptd_tfm);
523 return 0;
524}
525
526static struct crypto_alg ablk_lrw_alg = {
527 .cra_name = "lrw(aes)",
528 .cra_driver_name = "lrw-aes-aesni",
529 .cra_priority = 400,
530 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
531 .cra_blocksize = AES_BLOCK_SIZE,
532 .cra_ctxsize = sizeof(struct async_aes_ctx),
533 .cra_alignmask = 0,
534 .cra_type = &crypto_ablkcipher_type,
535 .cra_module = THIS_MODULE,
536 .cra_list = LIST_HEAD_INIT(ablk_lrw_alg.cra_list),
537 .cra_init = ablk_lrw_init,
538 .cra_exit = ablk_exit,
539 .cra_u = {
540 .ablkcipher = {
541 .min_keysize = AES_MIN_KEY_SIZE + AES_BLOCK_SIZE,
542 .max_keysize = AES_MAX_KEY_SIZE + AES_BLOCK_SIZE,
543 .ivsize = AES_BLOCK_SIZE,
544 .setkey = ablk_set_key,
545 .encrypt = ablk_encrypt,
546 .decrypt = ablk_decrypt,
547 },
548 },
549};
550#endif
551
552#ifdef HAS_PCBC
553static int ablk_pcbc_init(struct crypto_tfm *tfm)
554{
555 struct cryptd_ablkcipher *cryptd_tfm;
556
557 cryptd_tfm = cryptd_alloc_ablkcipher("fpu(pcbc(__driver-aes-aesni))",
558 0, 0);
559 if (IS_ERR(cryptd_tfm))
560 return PTR_ERR(cryptd_tfm);
561 ablk_init_common(tfm, cryptd_tfm);
562 return 0;
563}
564
565static struct crypto_alg ablk_pcbc_alg = {
566 .cra_name = "pcbc(aes)",
567 .cra_driver_name = "pcbc-aes-aesni",
568 .cra_priority = 400,
569 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
570 .cra_blocksize = AES_BLOCK_SIZE,
571 .cra_ctxsize = sizeof(struct async_aes_ctx),
572 .cra_alignmask = 0,
573 .cra_type = &crypto_ablkcipher_type,
574 .cra_module = THIS_MODULE,
575 .cra_list = LIST_HEAD_INIT(ablk_pcbc_alg.cra_list),
576 .cra_init = ablk_pcbc_init,
577 .cra_exit = ablk_exit,
578 .cra_u = {
579 .ablkcipher = {
580 .min_keysize = AES_MIN_KEY_SIZE,
581 .max_keysize = AES_MAX_KEY_SIZE,
582 .ivsize = AES_BLOCK_SIZE,
583 .setkey = ablk_set_key,
584 .encrypt = ablk_encrypt,
585 .decrypt = ablk_decrypt,
586 },
587 },
588};
589#endif
590
591#ifdef HAS_XTS
592static int ablk_xts_init(struct crypto_tfm *tfm)
593{
594 struct cryptd_ablkcipher *cryptd_tfm;
595
596 cryptd_tfm = cryptd_alloc_ablkcipher("fpu(xts(__driver-aes-aesni))",
597 0, 0);
598 if (IS_ERR(cryptd_tfm))
599 return PTR_ERR(cryptd_tfm);
600 ablk_init_common(tfm, cryptd_tfm);
601 return 0;
602}
603
604static struct crypto_alg ablk_xts_alg = {
605 .cra_name = "xts(aes)",
606 .cra_driver_name = "xts-aes-aesni",
607 .cra_priority = 400,
608 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
609 .cra_blocksize = AES_BLOCK_SIZE,
610 .cra_ctxsize = sizeof(struct async_aes_ctx),
611 .cra_alignmask = 0,
612 .cra_type = &crypto_ablkcipher_type,
613 .cra_module = THIS_MODULE,
614 .cra_list = LIST_HEAD_INIT(ablk_xts_alg.cra_list),
615 .cra_init = ablk_xts_init,
616 .cra_exit = ablk_exit,
617 .cra_u = {
618 .ablkcipher = {
619 .min_keysize = 2 * AES_MIN_KEY_SIZE,
620 .max_keysize = 2 * AES_MAX_KEY_SIZE,
621 .ivsize = AES_BLOCK_SIZE,
622 .setkey = ablk_set_key,
623 .encrypt = ablk_encrypt,
624 .decrypt = ablk_decrypt,
625 },
626 },
627};
628#endif
629
414static int __init aesni_init(void) 630static int __init aesni_init(void)
415{ 631{
416 int err; 632 int err;
@@ -421,6 +637,8 @@ static int __init aesni_init(void)
421 } 637 }
422 if ((err = crypto_register_alg(&aesni_alg))) 638 if ((err = crypto_register_alg(&aesni_alg)))
423 goto aes_err; 639 goto aes_err;
640 if ((err = crypto_register_alg(&__aesni_alg)))
641 goto __aes_err;
424 if ((err = crypto_register_alg(&blk_ecb_alg))) 642 if ((err = crypto_register_alg(&blk_ecb_alg)))
425 goto blk_ecb_err; 643 goto blk_ecb_err;
426 if ((err = crypto_register_alg(&blk_cbc_alg))) 644 if ((err = crypto_register_alg(&blk_cbc_alg)))
@@ -429,9 +647,41 @@ static int __init aesni_init(void)
429 goto ablk_ecb_err; 647 goto ablk_ecb_err;
430 if ((err = crypto_register_alg(&ablk_cbc_alg))) 648 if ((err = crypto_register_alg(&ablk_cbc_alg)))
431 goto ablk_cbc_err; 649 goto ablk_cbc_err;
650#ifdef HAS_CTR
651 if ((err = crypto_register_alg(&ablk_ctr_alg)))
652 goto ablk_ctr_err;
653#endif
654#ifdef HAS_LRW
655 if ((err = crypto_register_alg(&ablk_lrw_alg)))
656 goto ablk_lrw_err;
657#endif
658#ifdef HAS_PCBC
659 if ((err = crypto_register_alg(&ablk_pcbc_alg)))
660 goto ablk_pcbc_err;
661#endif
662#ifdef HAS_XTS
663 if ((err = crypto_register_alg(&ablk_xts_alg)))
664 goto ablk_xts_err;
665#endif
432 666
433 return err; 667 return err;
434 668
669#ifdef HAS_XTS
670ablk_xts_err:
671#endif
672#ifdef HAS_PCBC
673 crypto_unregister_alg(&ablk_pcbc_alg);
674ablk_pcbc_err:
675#endif
676#ifdef HAS_LRW
677 crypto_unregister_alg(&ablk_lrw_alg);
678ablk_lrw_err:
679#endif
680#ifdef HAS_CTR
681 crypto_unregister_alg(&ablk_ctr_alg);
682ablk_ctr_err:
683#endif
684 crypto_unregister_alg(&ablk_cbc_alg);
435ablk_cbc_err: 685ablk_cbc_err:
436 crypto_unregister_alg(&ablk_ecb_alg); 686 crypto_unregister_alg(&ablk_ecb_alg);
437ablk_ecb_err: 687ablk_ecb_err:
@@ -439,6 +689,8 @@ ablk_ecb_err:
439blk_cbc_err: 689blk_cbc_err:
440 crypto_unregister_alg(&blk_ecb_alg); 690 crypto_unregister_alg(&blk_ecb_alg);
441blk_ecb_err: 691blk_ecb_err:
692 crypto_unregister_alg(&__aesni_alg);
693__aes_err:
442 crypto_unregister_alg(&aesni_alg); 694 crypto_unregister_alg(&aesni_alg);
443aes_err: 695aes_err:
444 return err; 696 return err;
@@ -446,10 +698,23 @@ aes_err:
446 698
447static void __exit aesni_exit(void) 699static void __exit aesni_exit(void)
448{ 700{
701#ifdef HAS_XTS
702 crypto_unregister_alg(&ablk_xts_alg);
703#endif
704#ifdef HAS_PCBC
705 crypto_unregister_alg(&ablk_pcbc_alg);
706#endif
707#ifdef HAS_LRW
708 crypto_unregister_alg(&ablk_lrw_alg);
709#endif
710#ifdef HAS_CTR
711 crypto_unregister_alg(&ablk_ctr_alg);
712#endif
449 crypto_unregister_alg(&ablk_cbc_alg); 713 crypto_unregister_alg(&ablk_cbc_alg);
450 crypto_unregister_alg(&ablk_ecb_alg); 714 crypto_unregister_alg(&ablk_ecb_alg);
451 crypto_unregister_alg(&blk_cbc_alg); 715 crypto_unregister_alg(&blk_cbc_alg);
452 crypto_unregister_alg(&blk_ecb_alg); 716 crypto_unregister_alg(&blk_ecb_alg);
717 crypto_unregister_alg(&__aesni_alg);
453 crypto_unregister_alg(&aesni_alg); 718 crypto_unregister_alg(&aesni_alg);
454} 719}
455 720
diff --git a/arch/x86/crypto/fpu.c b/arch/x86/crypto/fpu.c
new file mode 100644
index 000000000000..5f9781a3815f
--- /dev/null
+++ b/arch/x86/crypto/fpu.c
@@ -0,0 +1,166 @@
1/*
2 * FPU: Wrapper for blkcipher touching fpu
3 *
4 * Copyright (c) Intel Corp.
5 * Author: Huang Ying <ying.huang@intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 */
13
14#include <crypto/algapi.h>
15#include <linux/err.h>
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <asm/i387.h>
20
21struct crypto_fpu_ctx {
22 struct crypto_blkcipher *child;
23};
24
25static int crypto_fpu_setkey(struct crypto_tfm *parent, const u8 *key,
26 unsigned int keylen)
27{
28 struct crypto_fpu_ctx *ctx = crypto_tfm_ctx(parent);
29 struct crypto_blkcipher *child = ctx->child;
30 int err;
31
32 crypto_blkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
33 crypto_blkcipher_set_flags(child, crypto_tfm_get_flags(parent) &
34 CRYPTO_TFM_REQ_MASK);
35 err = crypto_blkcipher_setkey(child, key, keylen);
36 crypto_tfm_set_flags(parent, crypto_blkcipher_get_flags(child) &
37 CRYPTO_TFM_RES_MASK);
38 return err;
39}
40
41static int crypto_fpu_encrypt(struct blkcipher_desc *desc_in,
42 struct scatterlist *dst, struct scatterlist *src,
43 unsigned int nbytes)
44{
45 int err;
46 struct crypto_fpu_ctx *ctx = crypto_blkcipher_ctx(desc_in->tfm);
47 struct crypto_blkcipher *child = ctx->child;
48 struct blkcipher_desc desc = {
49 .tfm = child,
50 .info = desc_in->info,
51 .flags = desc_in->flags,
52 };
53
54 kernel_fpu_begin();
55 err = crypto_blkcipher_crt(desc.tfm)->encrypt(&desc, dst, src, nbytes);
56 kernel_fpu_end();
57 return err;
58}
59
60static int crypto_fpu_decrypt(struct blkcipher_desc *desc_in,
61 struct scatterlist *dst, struct scatterlist *src,
62 unsigned int nbytes)
63{
64 int err;
65 struct crypto_fpu_ctx *ctx = crypto_blkcipher_ctx(desc_in->tfm);
66 struct crypto_blkcipher *child = ctx->child;
67 struct blkcipher_desc desc = {
68 .tfm = child,
69 .info = desc_in->info,
70 .flags = desc_in->flags,
71 };
72
73 kernel_fpu_begin();
74 err = crypto_blkcipher_crt(desc.tfm)->decrypt(&desc, dst, src, nbytes);
75 kernel_fpu_end();
76 return err;
77}
78
79static int crypto_fpu_init_tfm(struct crypto_tfm *tfm)
80{
81 struct crypto_instance *inst = crypto_tfm_alg_instance(tfm);
82 struct crypto_spawn *spawn = crypto_instance_ctx(inst);
83 struct crypto_fpu_ctx *ctx = crypto_tfm_ctx(tfm);
84 struct crypto_blkcipher *cipher;
85
86 cipher = crypto_spawn_blkcipher(spawn);
87 if (IS_ERR(cipher))
88 return PTR_ERR(cipher);
89
90 ctx->child = cipher;
91 return 0;
92}
93
94static void crypto_fpu_exit_tfm(struct crypto_tfm *tfm)
95{
96 struct crypto_fpu_ctx *ctx = crypto_tfm_ctx(tfm);
97 crypto_free_blkcipher(ctx->child);
98}
99
100static struct crypto_instance *crypto_fpu_alloc(struct rtattr **tb)
101{
102 struct crypto_instance *inst;
103 struct crypto_alg *alg;
104 int err;
105
106 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
107 if (err)
108 return ERR_PTR(err);
109
110 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
111 CRYPTO_ALG_TYPE_MASK);
112 if (IS_ERR(alg))
113 return ERR_CAST(alg);
114
115 inst = crypto_alloc_instance("fpu", alg);
116 if (IS_ERR(inst))
117 goto out_put_alg;
118
119 inst->alg.cra_flags = alg->cra_flags;
120 inst->alg.cra_priority = alg->cra_priority;
121 inst->alg.cra_blocksize = alg->cra_blocksize;
122 inst->alg.cra_alignmask = alg->cra_alignmask;
123 inst->alg.cra_type = alg->cra_type;
124 inst->alg.cra_blkcipher.ivsize = alg->cra_blkcipher.ivsize;
125 inst->alg.cra_blkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
126 inst->alg.cra_blkcipher.max_keysize = alg->cra_blkcipher.max_keysize;
127 inst->alg.cra_ctxsize = sizeof(struct crypto_fpu_ctx);
128 inst->alg.cra_init = crypto_fpu_init_tfm;
129 inst->alg.cra_exit = crypto_fpu_exit_tfm;
130 inst->alg.cra_blkcipher.setkey = crypto_fpu_setkey;
131 inst->alg.cra_blkcipher.encrypt = crypto_fpu_encrypt;
132 inst->alg.cra_blkcipher.decrypt = crypto_fpu_decrypt;
133
134out_put_alg:
135 crypto_mod_put(alg);
136 return inst;
137}
138
139static void crypto_fpu_free(struct crypto_instance *inst)
140{
141 crypto_drop_spawn(crypto_instance_ctx(inst));
142 kfree(inst);
143}
144
145static struct crypto_template crypto_fpu_tmpl = {
146 .name = "fpu",
147 .alloc = crypto_fpu_alloc,
148 .free = crypto_fpu_free,
149 .module = THIS_MODULE,
150};
151
152static int __init crypto_fpu_module_init(void)
153{
154 return crypto_register_template(&crypto_fpu_tmpl);
155}
156
157static void __exit crypto_fpu_module_exit(void)
158{
159 crypto_unregister_template(&crypto_fpu_tmpl);
160}
161
162module_init(crypto_fpu_module_init);
163module_exit(crypto_fpu_module_exit);
164
165MODULE_LICENSE("GPL");
166MODULE_DESCRIPTION("FPU block cipher wrapper");
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 74d0e622a515..4dfdd03e708f 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -241,6 +241,11 @@ config CRYPTO_XTS
241 key size 256, 384 or 512 bits. This implementation currently 241 key size 256, 384 or 512 bits. This implementation currently
242 can't handle a sectorsize which is not a multiple of 16 bytes. 242 can't handle a sectorsize which is not a multiple of 16 bytes.
243 243
244config CRYPTO_FPU
245 tristate
246 select CRYPTO_BLKCIPHER
247 select CRYPTO_MANAGER
248
244comment "Hash modes" 249comment "Hash modes"
245 250
246config CRYPTO_HMAC 251config CRYPTO_HMAC
@@ -486,6 +491,7 @@ config CRYPTO_AES_NI_INTEL
486 select CRYPTO_AES_X86_64 491 select CRYPTO_AES_X86_64
487 select CRYPTO_CRYPTD 492 select CRYPTO_CRYPTD
488 select CRYPTO_ALGAPI 493 select CRYPTO_ALGAPI
494 select CRYPTO_FPU
489 help 495 help
490 Use Intel AES-NI instructions for AES algorithm. 496 Use Intel AES-NI instructions for AES algorithm.
491 497
@@ -505,6 +511,10 @@ config CRYPTO_AES_NI_INTEL
505 511
506 See <http://csrc.nist.gov/encryption/aes/> for more information. 512 See <http://csrc.nist.gov/encryption/aes/> for more information.
507 513
514 In addition to AES cipher algorithm support, the
515 acceleration for some popular block cipher mode is supported
516 too, including ECB, CBC, CTR, LRW, PCBC, XTS.
517
508config CRYPTO_ANUBIS 518config CRYPTO_ANUBIS
509 tristate "Anubis cipher algorithm" 519 tristate "Anubis cipher algorithm"
510 select CRYPTO_ALGAPI 520 select CRYPTO_ALGAPI
diff --git a/crypto/algboss.c b/crypto/algboss.c
index 6906f92aeac0..9908dd830c26 100644
--- a/crypto/algboss.c
+++ b/crypto/algboss.c
@@ -280,29 +280,13 @@ static struct notifier_block cryptomgr_notifier = {
280 280
281static int __init cryptomgr_init(void) 281static int __init cryptomgr_init(void)
282{ 282{
283 int err; 283 return crypto_register_notifier(&cryptomgr_notifier);
284
285 err = testmgr_init();
286 if (err)
287 return err;
288
289 err = crypto_register_notifier(&cryptomgr_notifier);
290 if (err)
291 goto free_testmgr;
292
293 return 0;
294
295free_testmgr:
296 testmgr_exit();
297 return err;
298} 284}
299 285
300static void __exit cryptomgr_exit(void) 286static void __exit cryptomgr_exit(void)
301{ 287{
302 int err = crypto_unregister_notifier(&cryptomgr_notifier); 288 int err = crypto_unregister_notifier(&cryptomgr_notifier);
303 BUG_ON(err); 289 BUG_ON(err);
304
305 testmgr_exit();
306} 290}
307 291
308subsys_initcall(cryptomgr_init); 292subsys_initcall(cryptomgr_init);
diff --git a/crypto/api.c b/crypto/api.c
index fd2545decb28..d5944f92b416 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -217,14 +217,11 @@ struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask)
217 217
218 alg = crypto_alg_lookup(name, type, mask); 218 alg = crypto_alg_lookup(name, type, mask);
219 if (!alg) { 219 if (!alg) {
220 char tmp[CRYPTO_MAX_ALG_NAME]; 220 request_module("%s", name);
221
222 request_module(name);
223 221
224 if (!((type ^ CRYPTO_ALG_NEED_FALLBACK) & mask & 222 if (!((type ^ CRYPTO_ALG_NEED_FALLBACK) & mask &
225 CRYPTO_ALG_NEED_FALLBACK) && 223 CRYPTO_ALG_NEED_FALLBACK))
226 snprintf(tmp, sizeof(tmp), "%s-all", name) < sizeof(tmp)) 224 request_module("%s-all", name);
227 request_module(tmp);
228 225
229 alg = crypto_alg_lookup(name, type, mask); 226 alg = crypto_alg_lookup(name, type, mask);
230 } 227 }
@@ -580,20 +577,17 @@ EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
580void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm) 577void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm)
581{ 578{
582 struct crypto_alg *alg; 579 struct crypto_alg *alg;
583 int size;
584 580
585 if (unlikely(!mem)) 581 if (unlikely(!mem))
586 return; 582 return;
587 583
588 alg = tfm->__crt_alg; 584 alg = tfm->__crt_alg;
589 size = ksize(mem);
590 585
591 if (!tfm->exit && alg->cra_exit) 586 if (!tfm->exit && alg->cra_exit)
592 alg->cra_exit(tfm); 587 alg->cra_exit(tfm);
593 crypto_exit_ops(tfm); 588 crypto_exit_ops(tfm);
594 crypto_mod_put(alg); 589 crypto_mod_put(alg);
595 memset(mem, 0, size); 590 kzfree(mem);
596 kfree(mem);
597} 591}
598EXPORT_SYMBOL_GPL(crypto_destroy_tfm); 592EXPORT_SYMBOL_GPL(crypto_destroy_tfm);
599 593
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index d14b22658d7a..ae5fa99d5d36 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -586,20 +586,24 @@ struct cryptd_ablkcipher *cryptd_alloc_ablkcipher(const char *alg_name,
586 u32 type, u32 mask) 586 u32 type, u32 mask)
587{ 587{
588 char cryptd_alg_name[CRYPTO_MAX_ALG_NAME]; 588 char cryptd_alg_name[CRYPTO_MAX_ALG_NAME];
589 struct crypto_ablkcipher *tfm; 589 struct crypto_tfm *tfm;
590 590
591 if (snprintf(cryptd_alg_name, CRYPTO_MAX_ALG_NAME, 591 if (snprintf(cryptd_alg_name, CRYPTO_MAX_ALG_NAME,
592 "cryptd(%s)", alg_name) >= CRYPTO_MAX_ALG_NAME) 592 "cryptd(%s)", alg_name) >= CRYPTO_MAX_ALG_NAME)
593 return ERR_PTR(-EINVAL); 593 return ERR_PTR(-EINVAL);
594 tfm = crypto_alloc_ablkcipher(cryptd_alg_name, type, mask); 594 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
595 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
596 mask &= ~CRYPTO_ALG_TYPE_MASK;
597 mask |= (CRYPTO_ALG_GENIV | CRYPTO_ALG_TYPE_BLKCIPHER_MASK);
598 tfm = crypto_alloc_base(cryptd_alg_name, type, mask);
595 if (IS_ERR(tfm)) 599 if (IS_ERR(tfm))
596 return ERR_CAST(tfm); 600 return ERR_CAST(tfm);
597 if (crypto_ablkcipher_tfm(tfm)->__crt_alg->cra_module != THIS_MODULE) { 601 if (tfm->__crt_alg->cra_module != THIS_MODULE) {
598 crypto_free_ablkcipher(tfm); 602 crypto_free_tfm(tfm);
599 return ERR_PTR(-EINVAL); 603 return ERR_PTR(-EINVAL);
600 } 604 }
601 605
602 return __cryptd_ablkcipher_cast(tfm); 606 return __cryptd_ablkcipher_cast(__crypto_ablkcipher_cast(tfm));
603} 607}
604EXPORT_SYMBOL_GPL(cryptd_alloc_ablkcipher); 608EXPORT_SYMBOL_GPL(cryptd_alloc_ablkcipher);
605 609
diff --git a/crypto/internal.h b/crypto/internal.h
index fc76e1f37fc3..113579a82dff 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -121,9 +121,6 @@ int crypto_register_notifier(struct notifier_block *nb);
121int crypto_unregister_notifier(struct notifier_block *nb); 121int crypto_unregister_notifier(struct notifier_block *nb);
122int crypto_probing_notify(unsigned long val, void *v); 122int crypto_probing_notify(unsigned long val, void *v);
123 123
124int __init testmgr_init(void);
125void testmgr_exit(void);
126
127static inline void crypto_alg_put(struct crypto_alg *alg) 124static inline void crypto_alg_put(struct crypto_alg *alg)
128{ 125{
129 if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy) 126 if (atomic_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy)
diff --git a/crypto/pcompress.c b/crypto/pcompress.c
index ca9a4af91efe..bcadc03726b7 100644
--- a/crypto/pcompress.c
+++ b/crypto/pcompress.c
@@ -26,6 +26,7 @@
26#include <linux/string.h> 26#include <linux/string.h>
27 27
28#include <crypto/compress.h> 28#include <crypto/compress.h>
29#include <crypto/internal/compress.h>
29 30
30#include "internal.h" 31#include "internal.h"
31 32
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index c3c9124209a1..d59ba5079d14 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -27,6 +27,7 @@
27#include <linux/timex.h> 27#include <linux/timex.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include "tcrypt.h" 29#include "tcrypt.h"
30#include "internal.h"
30 31
31/* 32/*
32 * Need slab memory for testing (size in number of pages). 33 * Need slab memory for testing (size in number of pages).
@@ -396,16 +397,16 @@ static void test_hash_speed(const char *algo, unsigned int sec,
396 struct scatterlist sg[TVMEMSIZE]; 397 struct scatterlist sg[TVMEMSIZE];
397 struct crypto_hash *tfm; 398 struct crypto_hash *tfm;
398 struct hash_desc desc; 399 struct hash_desc desc;
399 char output[1024]; 400 static char output[1024];
400 int i; 401 int i;
401 int ret; 402 int ret;
402 403
403 printk("\ntesting speed of %s\n", algo); 404 printk(KERN_INFO "\ntesting speed of %s\n", algo);
404 405
405 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); 406 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
406 407
407 if (IS_ERR(tfm)) { 408 if (IS_ERR(tfm)) {
408 printk("failed to load transform for %s: %ld\n", algo, 409 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
409 PTR_ERR(tfm)); 410 PTR_ERR(tfm));
410 return; 411 return;
411 } 412 }
@@ -414,7 +415,7 @@ static void test_hash_speed(const char *algo, unsigned int sec,
414 desc.flags = 0; 415 desc.flags = 0;
415 416
416 if (crypto_hash_digestsize(tfm) > sizeof(output)) { 417 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
417 printk("digestsize(%u) > outputbuffer(%zu)\n", 418 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
418 crypto_hash_digestsize(tfm), sizeof(output)); 419 crypto_hash_digestsize(tfm), sizeof(output));
419 goto out; 420 goto out;
420 } 421 }
@@ -427,12 +428,14 @@ static void test_hash_speed(const char *algo, unsigned int sec,
427 428
428 for (i = 0; speed[i].blen != 0; i++) { 429 for (i = 0; speed[i].blen != 0; i++) {
429 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { 430 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
430 printk("template (%u) too big for tvmem (%lu)\n", 431 printk(KERN_ERR
432 "template (%u) too big for tvmem (%lu)\n",
431 speed[i].blen, TVMEMSIZE * PAGE_SIZE); 433 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
432 goto out; 434 goto out;
433 } 435 }
434 436
435 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ", 437 printk(KERN_INFO "test%3u "
438 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
436 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); 439 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
437 440
438 if (sec) 441 if (sec)
@@ -443,7 +446,7 @@ static void test_hash_speed(const char *algo, unsigned int sec,
443 speed[i].plen, output); 446 speed[i].plen, output);
444 447
445 if (ret) { 448 if (ret) {
446 printk("hashing failed ret=%d\n", ret); 449 printk(KERN_ERR "hashing failed ret=%d\n", ret);
447 break; 450 break;
448 } 451 }
449 } 452 }
@@ -466,239 +469,255 @@ static void test_available(void)
466 469
467static inline int tcrypt_test(const char *alg) 470static inline int tcrypt_test(const char *alg)
468{ 471{
469 return alg_test(alg, alg, 0, 0); 472 int ret;
473
474 ret = alg_test(alg, alg, 0, 0);
475 /* non-fips algs return -EINVAL in fips mode */
476 if (fips_enabled && ret == -EINVAL)
477 ret = 0;
478 return ret;
470} 479}
471 480
472static void do_test(int m) 481static int do_test(int m)
473{ 482{
474 int i; 483 int i;
484 int ret = 0;
475 485
476 switch (m) { 486 switch (m) {
477 case 0: 487 case 0:
478 for (i = 1; i < 200; i++) 488 for (i = 1; i < 200; i++)
479 do_test(i); 489 ret += do_test(i);
480 break; 490 break;
481 491
482 case 1: 492 case 1:
483 tcrypt_test("md5"); 493 ret += tcrypt_test("md5");
484 break; 494 break;
485 495
486 case 2: 496 case 2:
487 tcrypt_test("sha1"); 497 ret += tcrypt_test("sha1");
488 break; 498 break;
489 499
490 case 3: 500 case 3:
491 tcrypt_test("ecb(des)"); 501 ret += tcrypt_test("ecb(des)");
492 tcrypt_test("cbc(des)"); 502 ret += tcrypt_test("cbc(des)");
493 break; 503 break;
494 504
495 case 4: 505 case 4:
496 tcrypt_test("ecb(des3_ede)"); 506 ret += tcrypt_test("ecb(des3_ede)");
497 tcrypt_test("cbc(des3_ede)"); 507 ret += tcrypt_test("cbc(des3_ede)");
498 break; 508 break;
499 509
500 case 5: 510 case 5:
501 tcrypt_test("md4"); 511 ret += tcrypt_test("md4");
502 break; 512 break;
503 513
504 case 6: 514 case 6:
505 tcrypt_test("sha256"); 515 ret += tcrypt_test("sha256");
506 break; 516 break;
507 517
508 case 7: 518 case 7:
509 tcrypt_test("ecb(blowfish)"); 519 ret += tcrypt_test("ecb(blowfish)");
510 tcrypt_test("cbc(blowfish)"); 520 ret += tcrypt_test("cbc(blowfish)");
511 break; 521 break;
512 522
513 case 8: 523 case 8:
514 tcrypt_test("ecb(twofish)"); 524 ret += tcrypt_test("ecb(twofish)");
515 tcrypt_test("cbc(twofish)"); 525 ret += tcrypt_test("cbc(twofish)");
516 break; 526 break;
517 527
518 case 9: 528 case 9:
519 tcrypt_test("ecb(serpent)"); 529 ret += tcrypt_test("ecb(serpent)");
520 break; 530 break;
521 531
522 case 10: 532 case 10:
523 tcrypt_test("ecb(aes)"); 533 ret += tcrypt_test("ecb(aes)");
524 tcrypt_test("cbc(aes)"); 534 ret += tcrypt_test("cbc(aes)");
525 tcrypt_test("lrw(aes)"); 535 ret += tcrypt_test("lrw(aes)");
526 tcrypt_test("xts(aes)"); 536 ret += tcrypt_test("xts(aes)");
527 tcrypt_test("rfc3686(ctr(aes))"); 537 ret += tcrypt_test("ctr(aes)");
538 ret += tcrypt_test("rfc3686(ctr(aes))");
528 break; 539 break;
529 540
530 case 11: 541 case 11:
531 tcrypt_test("sha384"); 542 ret += tcrypt_test("sha384");
532 break; 543 break;
533 544
534 case 12: 545 case 12:
535 tcrypt_test("sha512"); 546 ret += tcrypt_test("sha512");
536 break; 547 break;
537 548
538 case 13: 549 case 13:
539 tcrypt_test("deflate"); 550 ret += tcrypt_test("deflate");
540 break; 551 break;
541 552
542 case 14: 553 case 14:
543 tcrypt_test("ecb(cast5)"); 554 ret += tcrypt_test("ecb(cast5)");
544 break; 555 break;
545 556
546 case 15: 557 case 15:
547 tcrypt_test("ecb(cast6)"); 558 ret += tcrypt_test("ecb(cast6)");
548 break; 559 break;
549 560
550 case 16: 561 case 16:
551 tcrypt_test("ecb(arc4)"); 562 ret += tcrypt_test("ecb(arc4)");
552 break; 563 break;
553 564
554 case 17: 565 case 17:
555 tcrypt_test("michael_mic"); 566 ret += tcrypt_test("michael_mic");
556 break; 567 break;
557 568
558 case 18: 569 case 18:
559 tcrypt_test("crc32c"); 570 ret += tcrypt_test("crc32c");
560 break; 571 break;
561 572
562 case 19: 573 case 19:
563 tcrypt_test("ecb(tea)"); 574 ret += tcrypt_test("ecb(tea)");
564 break; 575 break;
565 576
566 case 20: 577 case 20:
567 tcrypt_test("ecb(xtea)"); 578 ret += tcrypt_test("ecb(xtea)");
568 break; 579 break;
569 580
570 case 21: 581 case 21:
571 tcrypt_test("ecb(khazad)"); 582 ret += tcrypt_test("ecb(khazad)");
572 break; 583 break;
573 584
574 case 22: 585 case 22:
575 tcrypt_test("wp512"); 586 ret += tcrypt_test("wp512");
576 break; 587 break;
577 588
578 case 23: 589 case 23:
579 tcrypt_test("wp384"); 590 ret += tcrypt_test("wp384");
580 break; 591 break;
581 592
582 case 24: 593 case 24:
583 tcrypt_test("wp256"); 594 ret += tcrypt_test("wp256");
584 break; 595 break;
585 596
586 case 25: 597 case 25:
587 tcrypt_test("ecb(tnepres)"); 598 ret += tcrypt_test("ecb(tnepres)");
588 break; 599 break;
589 600
590 case 26: 601 case 26:
591 tcrypt_test("ecb(anubis)"); 602 ret += tcrypt_test("ecb(anubis)");
592 tcrypt_test("cbc(anubis)"); 603 ret += tcrypt_test("cbc(anubis)");
593 break; 604 break;
594 605
595 case 27: 606 case 27:
596 tcrypt_test("tgr192"); 607 ret += tcrypt_test("tgr192");
597 break; 608 break;
598 609
599 case 28: 610 case 28:
600 611
601 tcrypt_test("tgr160"); 612 ret += tcrypt_test("tgr160");
602 break; 613 break;
603 614
604 case 29: 615 case 29:
605 tcrypt_test("tgr128"); 616 ret += tcrypt_test("tgr128");
606 break; 617 break;
607 618
608 case 30: 619 case 30:
609 tcrypt_test("ecb(xeta)"); 620 ret += tcrypt_test("ecb(xeta)");
610 break; 621 break;
611 622
612 case 31: 623 case 31:
613 tcrypt_test("pcbc(fcrypt)"); 624 ret += tcrypt_test("pcbc(fcrypt)");
614 break; 625 break;
615 626
616 case 32: 627 case 32:
617 tcrypt_test("ecb(camellia)"); 628 ret += tcrypt_test("ecb(camellia)");
618 tcrypt_test("cbc(camellia)"); 629 ret += tcrypt_test("cbc(camellia)");
619 break; 630 break;
620 case 33: 631 case 33:
621 tcrypt_test("sha224"); 632 ret += tcrypt_test("sha224");
622 break; 633 break;
623 634
624 case 34: 635 case 34:
625 tcrypt_test("salsa20"); 636 ret += tcrypt_test("salsa20");
626 break; 637 break;
627 638
628 case 35: 639 case 35:
629 tcrypt_test("gcm(aes)"); 640 ret += tcrypt_test("gcm(aes)");
630 break; 641 break;
631 642
632 case 36: 643 case 36:
633 tcrypt_test("lzo"); 644 ret += tcrypt_test("lzo");
634 break; 645 break;
635 646
636 case 37: 647 case 37:
637 tcrypt_test("ccm(aes)"); 648 ret += tcrypt_test("ccm(aes)");
638 break; 649 break;
639 650
640 case 38: 651 case 38:
641 tcrypt_test("cts(cbc(aes))"); 652 ret += tcrypt_test("cts(cbc(aes))");
642 break; 653 break;
643 654
644 case 39: 655 case 39:
645 tcrypt_test("rmd128"); 656 ret += tcrypt_test("rmd128");
646 break; 657 break;
647 658
648 case 40: 659 case 40:
649 tcrypt_test("rmd160"); 660 ret += tcrypt_test("rmd160");
650 break; 661 break;
651 662
652 case 41: 663 case 41:
653 tcrypt_test("rmd256"); 664 ret += tcrypt_test("rmd256");
654 break; 665 break;
655 666
656 case 42: 667 case 42:
657 tcrypt_test("rmd320"); 668 ret += tcrypt_test("rmd320");
658 break; 669 break;
659 670
660 case 43: 671 case 43:
661 tcrypt_test("ecb(seed)"); 672 ret += tcrypt_test("ecb(seed)");
662 break; 673 break;
663 674
664 case 44: 675 case 44:
665 tcrypt_test("zlib"); 676 ret += tcrypt_test("zlib");
677 break;
678
679 case 45:
680 ret += tcrypt_test("rfc4309(ccm(aes))");
666 break; 681 break;
667 682
668 case 100: 683 case 100:
669 tcrypt_test("hmac(md5)"); 684 ret += tcrypt_test("hmac(md5)");
670 break; 685 break;
671 686
672 case 101: 687 case 101:
673 tcrypt_test("hmac(sha1)"); 688 ret += tcrypt_test("hmac(sha1)");
674 break; 689 break;
675 690
676 case 102: 691 case 102:
677 tcrypt_test("hmac(sha256)"); 692 ret += tcrypt_test("hmac(sha256)");
678 break; 693 break;
679 694
680 case 103: 695 case 103:
681 tcrypt_test("hmac(sha384)"); 696 ret += tcrypt_test("hmac(sha384)");
682 break; 697 break;
683 698
684 case 104: 699 case 104:
685 tcrypt_test("hmac(sha512)"); 700 ret += tcrypt_test("hmac(sha512)");
686 break; 701 break;
687 702
688 case 105: 703 case 105:
689 tcrypt_test("hmac(sha224)"); 704 ret += tcrypt_test("hmac(sha224)");
690 break; 705 break;
691 706
692 case 106: 707 case 106:
693 tcrypt_test("xcbc(aes)"); 708 ret += tcrypt_test("xcbc(aes)");
694 break; 709 break;
695 710
696 case 107: 711 case 107:
697 tcrypt_test("hmac(rmd128)"); 712 ret += tcrypt_test("hmac(rmd128)");
698 break; 713 break;
699 714
700 case 108: 715 case 108:
701 tcrypt_test("hmac(rmd160)"); 716 ret += tcrypt_test("hmac(rmd160)");
717 break;
718
719 case 150:
720 ret += tcrypt_test("ansi_cprng");
702 break; 721 break;
703 722
704 case 200: 723 case 200:
@@ -862,6 +881,8 @@ static void do_test(int m)
862 test_available(); 881 test_available();
863 break; 882 break;
864 } 883 }
884
885 return ret;
865} 886}
866 887
867static int __init tcrypt_mod_init(void) 888static int __init tcrypt_mod_init(void)
@@ -875,15 +896,21 @@ static int __init tcrypt_mod_init(void)
875 goto err_free_tv; 896 goto err_free_tv;
876 } 897 }
877 898
878 do_test(mode); 899 err = do_test(mode);
900 if (err) {
901 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
902 goto err_free_tv;
903 }
879 904
880 /* We intentionaly return -EAGAIN to prevent keeping 905 /* We intentionaly return -EAGAIN to prevent keeping the module,
881 * the module. It does all its work from init() 906 * unless we're running in fips mode. It does all its work from
882 * and doesn't offer any runtime functionality 907 * init() and doesn't offer any runtime functionality, but in
908 * the fips case, checking for a successful load is helpful.
883 * => we don't need it in the memory, do we? 909 * => we don't need it in the memory, do we?
884 * -- mludvig 910 * -- mludvig
885 */ 911 */
886 err = -EAGAIN; 912 if (!fips_enabled)
913 err = -EAGAIN;
887 914
888err_free_tv: 915err_free_tv:
889 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) 916 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index b50c3c6b17a2..e9e9d84293b9 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -19,6 +19,7 @@
19#include <linux/scatterlist.h> 19#include <linux/scatterlist.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/string.h> 21#include <linux/string.h>
22#include <crypto/rng.h>
22 23
23#include "internal.h" 24#include "internal.h"
24#include "testmgr.h" 25#include "testmgr.h"
@@ -84,10 +85,16 @@ struct hash_test_suite {
84 unsigned int count; 85 unsigned int count;
85}; 86};
86 87
88struct cprng_test_suite {
89 struct cprng_testvec *vecs;
90 unsigned int count;
91};
92
87struct alg_test_desc { 93struct alg_test_desc {
88 const char *alg; 94 const char *alg;
89 int (*test)(const struct alg_test_desc *desc, const char *driver, 95 int (*test)(const struct alg_test_desc *desc, const char *driver,
90 u32 type, u32 mask); 96 u32 type, u32 mask);
97 int fips_allowed; /* set if alg is allowed in fips mode */
91 98
92 union { 99 union {
93 struct aead_test_suite aead; 100 struct aead_test_suite aead;
@@ -95,14 +102,12 @@ struct alg_test_desc {
95 struct comp_test_suite comp; 102 struct comp_test_suite comp;
96 struct pcomp_test_suite pcomp; 103 struct pcomp_test_suite pcomp;
97 struct hash_test_suite hash; 104 struct hash_test_suite hash;
105 struct cprng_test_suite cprng;
98 } suite; 106 } suite;
99}; 107};
100 108
101static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; 109static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
102 110
103static char *xbuf[XBUFSIZE];
104static char *axbuf[XBUFSIZE];
105
106static void hexdump(unsigned char *buf, unsigned int len) 111static void hexdump(unsigned char *buf, unsigned int len)
107{ 112{
108 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET, 113 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
@@ -121,6 +126,33 @@ static void tcrypt_complete(struct crypto_async_request *req, int err)
121 complete(&res->completion); 126 complete(&res->completion);
122} 127}
123 128
129static int testmgr_alloc_buf(char *buf[XBUFSIZE])
130{
131 int i;
132
133 for (i = 0; i < XBUFSIZE; i++) {
134 buf[i] = (void *)__get_free_page(GFP_KERNEL);
135 if (!buf[i])
136 goto err_free_buf;
137 }
138
139 return 0;
140
141err_free_buf:
142 while (i-- > 0)
143 free_page((unsigned long)buf[i]);
144
145 return -ENOMEM;
146}
147
148static void testmgr_free_buf(char *buf[XBUFSIZE])
149{
150 int i;
151
152 for (i = 0; i < XBUFSIZE; i++)
153 free_page((unsigned long)buf[i]);
154}
155
124static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, 156static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
125 unsigned int tcount) 157 unsigned int tcount)
126{ 158{
@@ -130,8 +162,12 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
130 char result[64]; 162 char result[64];
131 struct ahash_request *req; 163 struct ahash_request *req;
132 struct tcrypt_result tresult; 164 struct tcrypt_result tresult;
133 int ret;
134 void *hash_buff; 165 void *hash_buff;
166 char *xbuf[XBUFSIZE];
167 int ret = -ENOMEM;
168
169 if (testmgr_alloc_buf(xbuf))
170 goto out_nobuf;
135 171
136 init_completion(&tresult.completion); 172 init_completion(&tresult.completion);
137 173
@@ -139,17 +175,25 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
139 if (!req) { 175 if (!req) {
140 printk(KERN_ERR "alg: hash: Failed to allocate request for " 176 printk(KERN_ERR "alg: hash: Failed to allocate request for "
141 "%s\n", algo); 177 "%s\n", algo);
142 ret = -ENOMEM;
143 goto out_noreq; 178 goto out_noreq;
144 } 179 }
145 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 180 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
146 tcrypt_complete, &tresult); 181 tcrypt_complete, &tresult);
147 182
183 j = 0;
148 for (i = 0; i < tcount; i++) { 184 for (i = 0; i < tcount; i++) {
185 if (template[i].np)
186 continue;
187
188 j++;
149 memset(result, 0, 64); 189 memset(result, 0, 64);
150 190
151 hash_buff = xbuf[0]; 191 hash_buff = xbuf[0];
152 192
193 ret = -EINVAL;
194 if (WARN_ON(template[i].psize > PAGE_SIZE))
195 goto out;
196
153 memcpy(hash_buff, template[i].plaintext, template[i].psize); 197 memcpy(hash_buff, template[i].plaintext, template[i].psize);
154 sg_init_one(&sg[0], hash_buff, template[i].psize); 198 sg_init_one(&sg[0], hash_buff, template[i].psize);
155 199
@@ -159,7 +203,7 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
159 template[i].ksize); 203 template[i].ksize);
160 if (ret) { 204 if (ret) {
161 printk(KERN_ERR "alg: hash: setkey failed on " 205 printk(KERN_ERR "alg: hash: setkey failed on "
162 "test %d for %s: ret=%d\n", i + 1, algo, 206 "test %d for %s: ret=%d\n", j, algo,
163 -ret); 207 -ret);
164 goto out; 208 goto out;
165 } 209 }
@@ -181,14 +225,14 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
181 /* fall through */ 225 /* fall through */
182 default: 226 default:
183 printk(KERN_ERR "alg: hash: digest failed on test %d " 227 printk(KERN_ERR "alg: hash: digest failed on test %d "
184 "for %s: ret=%d\n", i + 1, algo, -ret); 228 "for %s: ret=%d\n", j, algo, -ret);
185 goto out; 229 goto out;
186 } 230 }
187 231
188 if (memcmp(result, template[i].digest, 232 if (memcmp(result, template[i].digest,
189 crypto_ahash_digestsize(tfm))) { 233 crypto_ahash_digestsize(tfm))) {
190 printk(KERN_ERR "alg: hash: Test %d failed for %s\n", 234 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
191 i + 1, algo); 235 j, algo);
192 hexdump(result, crypto_ahash_digestsize(tfm)); 236 hexdump(result, crypto_ahash_digestsize(tfm));
193 ret = -EINVAL; 237 ret = -EINVAL;
194 goto out; 238 goto out;
@@ -203,7 +247,11 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
203 247
204 temp = 0; 248 temp = 0;
205 sg_init_table(sg, template[i].np); 249 sg_init_table(sg, template[i].np);
250 ret = -EINVAL;
206 for (k = 0; k < template[i].np; k++) { 251 for (k = 0; k < template[i].np; k++) {
252 if (WARN_ON(offset_in_page(IDX[k]) +
253 template[i].tap[k] > PAGE_SIZE))
254 goto out;
207 sg_set_buf(&sg[k], 255 sg_set_buf(&sg[k],
208 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] + 256 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
209 offset_in_page(IDX[k]), 257 offset_in_page(IDX[k]),
@@ -265,6 +313,8 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
265out: 313out:
266 ahash_request_free(req); 314 ahash_request_free(req);
267out_noreq: 315out_noreq:
316 testmgr_free_buf(xbuf);
317out_nobuf:
268 return ret; 318 return ret;
269} 319}
270 320
@@ -273,7 +323,7 @@ static int test_aead(struct crypto_aead *tfm, int enc,
273{ 323{
274 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); 324 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
275 unsigned int i, j, k, n, temp; 325 unsigned int i, j, k, n, temp;
276 int ret = 0; 326 int ret = -ENOMEM;
277 char *q; 327 char *q;
278 char *key; 328 char *key;
279 struct aead_request *req; 329 struct aead_request *req;
@@ -285,6 +335,13 @@ static int test_aead(struct crypto_aead *tfm, int enc,
285 void *input; 335 void *input;
286 void *assoc; 336 void *assoc;
287 char iv[MAX_IVLEN]; 337 char iv[MAX_IVLEN];
338 char *xbuf[XBUFSIZE];
339 char *axbuf[XBUFSIZE];
340
341 if (testmgr_alloc_buf(xbuf))
342 goto out_noxbuf;
343 if (testmgr_alloc_buf(axbuf))
344 goto out_noaxbuf;
288 345
289 if (enc == ENCRYPT) 346 if (enc == ENCRYPT)
290 e = "encryption"; 347 e = "encryption";
@@ -297,7 +354,6 @@ static int test_aead(struct crypto_aead *tfm, int enc,
297 if (!req) { 354 if (!req) {
298 printk(KERN_ERR "alg: aead: Failed to allocate request for " 355 printk(KERN_ERR "alg: aead: Failed to allocate request for "
299 "%s\n", algo); 356 "%s\n", algo);
300 ret = -ENOMEM;
301 goto out; 357 goto out;
302 } 358 }
303 359
@@ -314,6 +370,11 @@ static int test_aead(struct crypto_aead *tfm, int enc,
314 input = xbuf[0]; 370 input = xbuf[0];
315 assoc = axbuf[0]; 371 assoc = axbuf[0];
316 372
373 ret = -EINVAL;
374 if (WARN_ON(template[i].ilen > PAGE_SIZE ||
375 template[i].alen > PAGE_SIZE))
376 goto out;
377
317 memcpy(input, template[i].input, template[i].ilen); 378 memcpy(input, template[i].input, template[i].ilen);
318 memcpy(assoc, template[i].assoc, template[i].alen); 379 memcpy(assoc, template[i].assoc, template[i].alen);
319 if (template[i].iv) 380 if (template[i].iv)
@@ -363,6 +424,16 @@ static int test_aead(struct crypto_aead *tfm, int enc,
363 424
364 switch (ret) { 425 switch (ret) {
365 case 0: 426 case 0:
427 if (template[i].novrfy) {
428 /* verification was supposed to fail */
429 printk(KERN_ERR "alg: aead: %s failed "
430 "on test %d for %s: ret was 0, "
431 "expected -EBADMSG\n",
432 e, j, algo);
433 /* so really, we got a bad message */
434 ret = -EBADMSG;
435 goto out;
436 }
366 break; 437 break;
367 case -EINPROGRESS: 438 case -EINPROGRESS:
368 case -EBUSY: 439 case -EBUSY:
@@ -372,6 +443,10 @@ static int test_aead(struct crypto_aead *tfm, int enc,
372 INIT_COMPLETION(result.completion); 443 INIT_COMPLETION(result.completion);
373 break; 444 break;
374 } 445 }
446 case -EBADMSG:
447 if (template[i].novrfy)
448 /* verification failure was expected */
449 continue;
375 /* fall through */ 450 /* fall through */
376 default: 451 default:
377 printk(KERN_ERR "alg: aead: %s failed on test " 452 printk(KERN_ERR "alg: aead: %s failed on test "
@@ -459,7 +534,11 @@ static int test_aead(struct crypto_aead *tfm, int enc,
459 } 534 }
460 535
461 sg_init_table(asg, template[i].anp); 536 sg_init_table(asg, template[i].anp);
537 ret = -EINVAL;
462 for (k = 0, temp = 0; k < template[i].anp; k++) { 538 for (k = 0, temp = 0; k < template[i].anp; k++) {
539 if (WARN_ON(offset_in_page(IDX[k]) +
540 template[i].atap[k] > PAGE_SIZE))
541 goto out;
463 sg_set_buf(&asg[k], 542 sg_set_buf(&asg[k],
464 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] + 543 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
465 offset_in_page(IDX[k]), 544 offset_in_page(IDX[k]),
@@ -481,6 +560,16 @@ static int test_aead(struct crypto_aead *tfm, int enc,
481 560
482 switch (ret) { 561 switch (ret) {
483 case 0: 562 case 0:
563 if (template[i].novrfy) {
564 /* verification was supposed to fail */
565 printk(KERN_ERR "alg: aead: %s failed "
566 "on chunk test %d for %s: ret "
567 "was 0, expected -EBADMSG\n",
568 e, j, algo);
569 /* so really, we got a bad message */
570 ret = -EBADMSG;
571 goto out;
572 }
484 break; 573 break;
485 case -EINPROGRESS: 574 case -EINPROGRESS:
486 case -EBUSY: 575 case -EBUSY:
@@ -490,6 +579,10 @@ static int test_aead(struct crypto_aead *tfm, int enc,
490 INIT_COMPLETION(result.completion); 579 INIT_COMPLETION(result.completion);
491 break; 580 break;
492 } 581 }
582 case -EBADMSG:
583 if (template[i].novrfy)
584 /* verification failure was expected */
585 continue;
493 /* fall through */ 586 /* fall through */
494 default: 587 default:
495 printk(KERN_ERR "alg: aead: %s failed on " 588 printk(KERN_ERR "alg: aead: %s failed on "
@@ -546,6 +639,10 @@ static int test_aead(struct crypto_aead *tfm, int enc,
546 639
547out: 640out:
548 aead_request_free(req); 641 aead_request_free(req);
642 testmgr_free_buf(axbuf);
643out_noaxbuf:
644 testmgr_free_buf(xbuf);
645out_noxbuf:
549 return ret; 646 return ret;
550} 647}
551 648
@@ -554,10 +651,14 @@ static int test_cipher(struct crypto_cipher *tfm, int enc,
554{ 651{
555 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm)); 652 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
556 unsigned int i, j, k; 653 unsigned int i, j, k;
557 int ret;
558 char *q; 654 char *q;
559 const char *e; 655 const char *e;
560 void *data; 656 void *data;
657 char *xbuf[XBUFSIZE];
658 int ret = -ENOMEM;
659
660 if (testmgr_alloc_buf(xbuf))
661 goto out_nobuf;
561 662
562 if (enc == ENCRYPT) 663 if (enc == ENCRYPT)
563 e = "encryption"; 664 e = "encryption";
@@ -571,6 +672,10 @@ static int test_cipher(struct crypto_cipher *tfm, int enc,
571 672
572 j++; 673 j++;
573 674
675 ret = -EINVAL;
676 if (WARN_ON(template[i].ilen > PAGE_SIZE))
677 goto out;
678
574 data = xbuf[0]; 679 data = xbuf[0];
575 memcpy(data, template[i].input, template[i].ilen); 680 memcpy(data, template[i].input, template[i].ilen);
576 681
@@ -611,6 +716,8 @@ static int test_cipher(struct crypto_cipher *tfm, int enc,
611 ret = 0; 716 ret = 0;
612 717
613out: 718out:
719 testmgr_free_buf(xbuf);
720out_nobuf:
614 return ret; 721 return ret;
615} 722}
616 723
@@ -620,7 +727,6 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
620 const char *algo = 727 const char *algo =
621 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm)); 728 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
622 unsigned int i, j, k, n, temp; 729 unsigned int i, j, k, n, temp;
623 int ret;
624 char *q; 730 char *q;
625 struct ablkcipher_request *req; 731 struct ablkcipher_request *req;
626 struct scatterlist sg[8]; 732 struct scatterlist sg[8];
@@ -628,6 +734,11 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
628 struct tcrypt_result result; 734 struct tcrypt_result result;
629 void *data; 735 void *data;
630 char iv[MAX_IVLEN]; 736 char iv[MAX_IVLEN];
737 char *xbuf[XBUFSIZE];
738 int ret = -ENOMEM;
739
740 if (testmgr_alloc_buf(xbuf))
741 goto out_nobuf;
631 742
632 if (enc == ENCRYPT) 743 if (enc == ENCRYPT)
633 e = "encryption"; 744 e = "encryption";
@@ -640,7 +751,6 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
640 if (!req) { 751 if (!req) {
641 printk(KERN_ERR "alg: skcipher: Failed to allocate request " 752 printk(KERN_ERR "alg: skcipher: Failed to allocate request "
642 "for %s\n", algo); 753 "for %s\n", algo);
643 ret = -ENOMEM;
644 goto out; 754 goto out;
645 } 755 }
646 756
@@ -657,6 +767,10 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
657 if (!(template[i].np)) { 767 if (!(template[i].np)) {
658 j++; 768 j++;
659 769
770 ret = -EINVAL;
771 if (WARN_ON(template[i].ilen > PAGE_SIZE))
772 goto out;
773
660 data = xbuf[0]; 774 data = xbuf[0];
661 memcpy(data, template[i].input, template[i].ilen); 775 memcpy(data, template[i].input, template[i].ilen);
662 776
@@ -825,6 +939,8 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
825 939
826out: 940out:
827 ablkcipher_request_free(req); 941 ablkcipher_request_free(req);
942 testmgr_free_buf(xbuf);
943out_nobuf:
828 return ret; 944 return ret;
829} 945}
830 946
@@ -837,7 +953,8 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
837 int ret; 953 int ret;
838 954
839 for (i = 0; i < ctcount; i++) { 955 for (i = 0; i < ctcount; i++) {
840 int ilen, dlen = COMP_BUF_SIZE; 956 int ilen;
957 unsigned int dlen = COMP_BUF_SIZE;
841 958
842 memset(result, 0, sizeof (result)); 959 memset(result, 0, sizeof (result));
843 960
@@ -869,7 +986,8 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
869 } 986 }
870 987
871 for (i = 0; i < dtcount; i++) { 988 for (i = 0; i < dtcount; i++) {
872 int ilen, dlen = COMP_BUF_SIZE; 989 int ilen;
990 unsigned int dlen = COMP_BUF_SIZE;
873 991
874 memset(result, 0, sizeof (result)); 992 memset(result, 0, sizeof (result));
875 993
@@ -914,24 +1032,25 @@ static int test_pcomp(struct crypto_pcomp *tfm,
914 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm)); 1032 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
915 unsigned int i; 1033 unsigned int i;
916 char result[COMP_BUF_SIZE]; 1034 char result[COMP_BUF_SIZE];
917 int error; 1035 int res;
918 1036
919 for (i = 0; i < ctcount; i++) { 1037 for (i = 0; i < ctcount; i++) {
920 struct comp_request req; 1038 struct comp_request req;
1039 unsigned int produced = 0;
921 1040
922 error = crypto_compress_setup(tfm, ctemplate[i].params, 1041 res = crypto_compress_setup(tfm, ctemplate[i].params,
923 ctemplate[i].paramsize); 1042 ctemplate[i].paramsize);
924 if (error) { 1043 if (res) {
925 pr_err("alg: pcomp: compression setup failed on test " 1044 pr_err("alg: pcomp: compression setup failed on test "
926 "%d for %s: error=%d\n", i + 1, algo, error); 1045 "%d for %s: error=%d\n", i + 1, algo, res);
927 return error; 1046 return res;
928 } 1047 }
929 1048
930 error = crypto_compress_init(tfm); 1049 res = crypto_compress_init(tfm);
931 if (error) { 1050 if (res) {
932 pr_err("alg: pcomp: compression init failed on test " 1051 pr_err("alg: pcomp: compression init failed on test "
933 "%d for %s: error=%d\n", i + 1, algo, error); 1052 "%d for %s: error=%d\n", i + 1, algo, res);
934 return error; 1053 return res;
935 } 1054 }
936 1055
937 memset(result, 0, sizeof(result)); 1056 memset(result, 0, sizeof(result));
@@ -941,32 +1060,37 @@ static int test_pcomp(struct crypto_pcomp *tfm,
941 req.next_out = result; 1060 req.next_out = result;
942 req.avail_out = ctemplate[i].outlen / 2; 1061 req.avail_out = ctemplate[i].outlen / 2;
943 1062
944 error = crypto_compress_update(tfm, &req); 1063 res = crypto_compress_update(tfm, &req);
945 if (error && (error != -EAGAIN || req.avail_in)) { 1064 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
946 pr_err("alg: pcomp: compression update failed on test " 1065 pr_err("alg: pcomp: compression update failed on test "
947 "%d for %s: error=%d\n", i + 1, algo, error); 1066 "%d for %s: error=%d\n", i + 1, algo, res);
948 return error; 1067 return res;
949 } 1068 }
1069 if (res > 0)
1070 produced += res;
950 1071
951 /* Add remaining input data */ 1072 /* Add remaining input data */
952 req.avail_in += (ctemplate[i].inlen + 1) / 2; 1073 req.avail_in += (ctemplate[i].inlen + 1) / 2;
953 1074
954 error = crypto_compress_update(tfm, &req); 1075 res = crypto_compress_update(tfm, &req);
955 if (error && (error != -EAGAIN || req.avail_in)) { 1076 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
956 pr_err("alg: pcomp: compression update failed on test " 1077 pr_err("alg: pcomp: compression update failed on test "
957 "%d for %s: error=%d\n", i + 1, algo, error); 1078 "%d for %s: error=%d\n", i + 1, algo, res);
958 return error; 1079 return res;
959 } 1080 }
1081 if (res > 0)
1082 produced += res;
960 1083
961 /* Provide remaining output space */ 1084 /* Provide remaining output space */
962 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2; 1085 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
963 1086
964 error = crypto_compress_final(tfm, &req); 1087 res = crypto_compress_final(tfm, &req);
965 if (error) { 1088 if (res < 0) {
966 pr_err("alg: pcomp: compression final failed on test " 1089 pr_err("alg: pcomp: compression final failed on test "
967 "%d for %s: error=%d\n", i + 1, algo, error); 1090 "%d for %s: error=%d\n", i + 1, algo, res);
968 return error; 1091 return res;
969 } 1092 }
1093 produced += res;
970 1094
971 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) { 1095 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
972 pr_err("alg: comp: Compression test %d failed for %s: " 1096 pr_err("alg: comp: Compression test %d failed for %s: "
@@ -976,6 +1100,13 @@ static int test_pcomp(struct crypto_pcomp *tfm,
976 return -EINVAL; 1100 return -EINVAL;
977 } 1101 }
978 1102
1103 if (produced != ctemplate[i].outlen) {
1104 pr_err("alg: comp: Compression test %d failed for %s: "
1105 "returned len = %u (expected %d)\n", i + 1,
1106 algo, produced, ctemplate[i].outlen);
1107 return -EINVAL;
1108 }
1109
979 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) { 1110 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
980 pr_err("alg: pcomp: Compression test %d failed for " 1111 pr_err("alg: pcomp: Compression test %d failed for "
981 "%s\n", i + 1, algo); 1112 "%s\n", i + 1, algo);
@@ -986,21 +1117,21 @@ static int test_pcomp(struct crypto_pcomp *tfm,
986 1117
987 for (i = 0; i < dtcount; i++) { 1118 for (i = 0; i < dtcount; i++) {
988 struct comp_request req; 1119 struct comp_request req;
1120 unsigned int produced = 0;
989 1121
990 error = crypto_decompress_setup(tfm, dtemplate[i].params, 1122 res = crypto_decompress_setup(tfm, dtemplate[i].params,
991 dtemplate[i].paramsize); 1123 dtemplate[i].paramsize);
992 if (error) { 1124 if (res) {
993 pr_err("alg: pcomp: decompression setup failed on " 1125 pr_err("alg: pcomp: decompression setup failed on "
994 "test %d for %s: error=%d\n", i + 1, algo, 1126 "test %d for %s: error=%d\n", i + 1, algo, res);
995 error); 1127 return res;
996 return error;
997 } 1128 }
998 1129
999 error = crypto_decompress_init(tfm); 1130 res = crypto_decompress_init(tfm);
1000 if (error) { 1131 if (res) {
1001 pr_err("alg: pcomp: decompression init failed on test " 1132 pr_err("alg: pcomp: decompression init failed on test "
1002 "%d for %s: error=%d\n", i + 1, algo, error); 1133 "%d for %s: error=%d\n", i + 1, algo, res);
1003 return error; 1134 return res;
1004 } 1135 }
1005 1136
1006 memset(result, 0, sizeof(result)); 1137 memset(result, 0, sizeof(result));
@@ -1010,35 +1141,38 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1010 req.next_out = result; 1141 req.next_out = result;
1011 req.avail_out = dtemplate[i].outlen / 2; 1142 req.avail_out = dtemplate[i].outlen / 2;
1012 1143
1013 error = crypto_decompress_update(tfm, &req); 1144 res = crypto_decompress_update(tfm, &req);
1014 if (error && (error != -EAGAIN || req.avail_in)) { 1145 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1015 pr_err("alg: pcomp: decompression update failed on " 1146 pr_err("alg: pcomp: decompression update failed on "
1016 "test %d for %s: error=%d\n", i + 1, algo, 1147 "test %d for %s: error=%d\n", i + 1, algo, res);
1017 error); 1148 return res;
1018 return error;
1019 } 1149 }
1150 if (res > 0)
1151 produced += res;
1020 1152
1021 /* Add remaining input data */ 1153 /* Add remaining input data */
1022 req.avail_in += (dtemplate[i].inlen + 1) / 2; 1154 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1023 1155
1024 error = crypto_decompress_update(tfm, &req); 1156 res = crypto_decompress_update(tfm, &req);
1025 if (error && (error != -EAGAIN || req.avail_in)) { 1157 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1026 pr_err("alg: pcomp: decompression update failed on " 1158 pr_err("alg: pcomp: decompression update failed on "
1027 "test %d for %s: error=%d\n", i + 1, algo, 1159 "test %d for %s: error=%d\n", i + 1, algo, res);
1028 error); 1160 return res;
1029 return error;
1030 } 1161 }
1162 if (res > 0)
1163 produced += res;
1031 1164
1032 /* Provide remaining output space */ 1165 /* Provide remaining output space */
1033 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2; 1166 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1034 1167
1035 error = crypto_decompress_final(tfm, &req); 1168 res = crypto_decompress_final(tfm, &req);
1036 if (error && (error != -EAGAIN || req.avail_in)) { 1169 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1037 pr_err("alg: pcomp: decompression final failed on " 1170 pr_err("alg: pcomp: decompression final failed on "
1038 "test %d for %s: error=%d\n", i + 1, algo, 1171 "test %d for %s: error=%d\n", i + 1, algo, res);
1039 error); 1172 return res;
1040 return error;
1041 } 1173 }
1174 if (res > 0)
1175 produced += res;
1042 1176
1043 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) { 1177 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1044 pr_err("alg: comp: Decompression test %d failed for " 1178 pr_err("alg: comp: Decompression test %d failed for "
@@ -1048,6 +1182,13 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1048 return -EINVAL; 1182 return -EINVAL;
1049 } 1183 }
1050 1184
1185 if (produced != dtemplate[i].outlen) {
1186 pr_err("alg: comp: Decompression test %d failed for "
1187 "%s: returned len = %u (expected %d)\n", i + 1,
1188 algo, produced, dtemplate[i].outlen);
1189 return -EINVAL;
1190 }
1191
1051 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) { 1192 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1052 pr_err("alg: pcomp: Decompression test %d failed for " 1193 pr_err("alg: pcomp: Decompression test %d failed for "
1053 "%s\n", i + 1, algo); 1194 "%s\n", i + 1, algo);
@@ -1059,6 +1200,68 @@ static int test_pcomp(struct crypto_pcomp *tfm,
1059 return 0; 1200 return 0;
1060} 1201}
1061 1202
1203
1204static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1205 unsigned int tcount)
1206{
1207 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1208 int err, i, j, seedsize;
1209 u8 *seed;
1210 char result[32];
1211
1212 seedsize = crypto_rng_seedsize(tfm);
1213
1214 seed = kmalloc(seedsize, GFP_KERNEL);
1215 if (!seed) {
1216 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1217 "for %s\n", algo);
1218 return -ENOMEM;
1219 }
1220
1221 for (i = 0; i < tcount; i++) {
1222 memset(result, 0, 32);
1223
1224 memcpy(seed, template[i].v, template[i].vlen);
1225 memcpy(seed + template[i].vlen, template[i].key,
1226 template[i].klen);
1227 memcpy(seed + template[i].vlen + template[i].klen,
1228 template[i].dt, template[i].dtlen);
1229
1230 err = crypto_rng_reset(tfm, seed, seedsize);
1231 if (err) {
1232 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1233 "for %s\n", algo);
1234 goto out;
1235 }
1236
1237 for (j = 0; j < template[i].loops; j++) {
1238 err = crypto_rng_get_bytes(tfm, result,
1239 template[i].rlen);
1240 if (err != template[i].rlen) {
1241 printk(KERN_ERR "alg: cprng: Failed to obtain "
1242 "the correct amount of random data for "
1243 "%s (requested %d, got %d)\n", algo,
1244 template[i].rlen, err);
1245 goto out;
1246 }
1247 }
1248
1249 err = memcmp(result, template[i].result,
1250 template[i].rlen);
1251 if (err) {
1252 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1253 i, algo);
1254 hexdump(result, template[i].rlen);
1255 err = -EINVAL;
1256 goto out;
1257 }
1258 }
1259
1260out:
1261 kfree(seed);
1262 return err;
1263}
1264
1062static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, 1265static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1063 u32 type, u32 mask) 1266 u32 type, u32 mask)
1064{ 1267{
@@ -1258,11 +1461,42 @@ out:
1258 return err; 1461 return err;
1259} 1462}
1260 1463
1464static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1465 u32 type, u32 mask)
1466{
1467 struct crypto_rng *rng;
1468 int err;
1469
1470 rng = crypto_alloc_rng(driver, type, mask);
1471 if (IS_ERR(rng)) {
1472 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1473 "%ld\n", driver, PTR_ERR(rng));
1474 return PTR_ERR(rng);
1475 }
1476
1477 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1478
1479 crypto_free_rng(rng);
1480
1481 return err;
1482}
1483
1261/* Please keep this list sorted by algorithm name. */ 1484/* Please keep this list sorted by algorithm name. */
1262static const struct alg_test_desc alg_test_descs[] = { 1485static const struct alg_test_desc alg_test_descs[] = {
1263 { 1486 {
1487 .alg = "ansi_cprng",
1488 .test = alg_test_cprng,
1489 .fips_allowed = 1,
1490 .suite = {
1491 .cprng = {
1492 .vecs = ansi_cprng_aes_tv_template,
1493 .count = ANSI_CPRNG_AES_TEST_VECTORS
1494 }
1495 }
1496 }, {
1264 .alg = "cbc(aes)", 1497 .alg = "cbc(aes)",
1265 .test = alg_test_skcipher, 1498 .test = alg_test_skcipher,
1499 .fips_allowed = 1,
1266 .suite = { 1500 .suite = {
1267 .cipher = { 1501 .cipher = {
1268 .enc = { 1502 .enc = {
@@ -1338,6 +1572,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1338 }, { 1572 }, {
1339 .alg = "cbc(des3_ede)", 1573 .alg = "cbc(des3_ede)",
1340 .test = alg_test_skcipher, 1574 .test = alg_test_skcipher,
1575 .fips_allowed = 1,
1341 .suite = { 1576 .suite = {
1342 .cipher = { 1577 .cipher = {
1343 .enc = { 1578 .enc = {
@@ -1368,6 +1603,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1368 }, { 1603 }, {
1369 .alg = "ccm(aes)", 1604 .alg = "ccm(aes)",
1370 .test = alg_test_aead, 1605 .test = alg_test_aead,
1606 .fips_allowed = 1,
1371 .suite = { 1607 .suite = {
1372 .aead = { 1608 .aead = {
1373 .enc = { 1609 .enc = {
@@ -1383,6 +1619,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1383 }, { 1619 }, {
1384 .alg = "crc32c", 1620 .alg = "crc32c",
1385 .test = alg_test_crc32c, 1621 .test = alg_test_crc32c,
1622 .fips_allowed = 1,
1386 .suite = { 1623 .suite = {
1387 .hash = { 1624 .hash = {
1388 .vecs = crc32c_tv_template, 1625 .vecs = crc32c_tv_template,
@@ -1390,6 +1627,22 @@ static const struct alg_test_desc alg_test_descs[] = {
1390 } 1627 }
1391 } 1628 }
1392 }, { 1629 }, {
1630 .alg = "ctr(aes)",
1631 .test = alg_test_skcipher,
1632 .fips_allowed = 1,
1633 .suite = {
1634 .cipher = {
1635 .enc = {
1636 .vecs = aes_ctr_enc_tv_template,
1637 .count = AES_CTR_ENC_TEST_VECTORS
1638 },
1639 .dec = {
1640 .vecs = aes_ctr_dec_tv_template,
1641 .count = AES_CTR_DEC_TEST_VECTORS
1642 }
1643 }
1644 }
1645 }, {
1393 .alg = "cts(cbc(aes))", 1646 .alg = "cts(cbc(aes))",
1394 .test = alg_test_skcipher, 1647 .test = alg_test_skcipher,
1395 .suite = { 1648 .suite = {
@@ -1422,6 +1675,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1422 }, { 1675 }, {
1423 .alg = "ecb(aes)", 1676 .alg = "ecb(aes)",
1424 .test = alg_test_skcipher, 1677 .test = alg_test_skcipher,
1678 .fips_allowed = 1,
1425 .suite = { 1679 .suite = {
1426 .cipher = { 1680 .cipher = {
1427 .enc = { 1681 .enc = {
@@ -1527,6 +1781,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1527 }, { 1781 }, {
1528 .alg = "ecb(des)", 1782 .alg = "ecb(des)",
1529 .test = alg_test_skcipher, 1783 .test = alg_test_skcipher,
1784 .fips_allowed = 1,
1530 .suite = { 1785 .suite = {
1531 .cipher = { 1786 .cipher = {
1532 .enc = { 1787 .enc = {
@@ -1542,6 +1797,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1542 }, { 1797 }, {
1543 .alg = "ecb(des3_ede)", 1798 .alg = "ecb(des3_ede)",
1544 .test = alg_test_skcipher, 1799 .test = alg_test_skcipher,
1800 .fips_allowed = 1,
1545 .suite = { 1801 .suite = {
1546 .cipher = { 1802 .cipher = {
1547 .enc = { 1803 .enc = {
@@ -1677,6 +1933,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1677 }, { 1933 }, {
1678 .alg = "gcm(aes)", 1934 .alg = "gcm(aes)",
1679 .test = alg_test_aead, 1935 .test = alg_test_aead,
1936 .fips_allowed = 1,
1680 .suite = { 1937 .suite = {
1681 .aead = { 1938 .aead = {
1682 .enc = { 1939 .enc = {
@@ -1719,6 +1976,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1719 }, { 1976 }, {
1720 .alg = "hmac(sha1)", 1977 .alg = "hmac(sha1)",
1721 .test = alg_test_hash, 1978 .test = alg_test_hash,
1979 .fips_allowed = 1,
1722 .suite = { 1980 .suite = {
1723 .hash = { 1981 .hash = {
1724 .vecs = hmac_sha1_tv_template, 1982 .vecs = hmac_sha1_tv_template,
@@ -1728,6 +1986,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1728 }, { 1986 }, {
1729 .alg = "hmac(sha224)", 1987 .alg = "hmac(sha224)",
1730 .test = alg_test_hash, 1988 .test = alg_test_hash,
1989 .fips_allowed = 1,
1731 .suite = { 1990 .suite = {
1732 .hash = { 1991 .hash = {
1733 .vecs = hmac_sha224_tv_template, 1992 .vecs = hmac_sha224_tv_template,
@@ -1737,6 +1996,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1737 }, { 1996 }, {
1738 .alg = "hmac(sha256)", 1997 .alg = "hmac(sha256)",
1739 .test = alg_test_hash, 1998 .test = alg_test_hash,
1999 .fips_allowed = 1,
1740 .suite = { 2000 .suite = {
1741 .hash = { 2001 .hash = {
1742 .vecs = hmac_sha256_tv_template, 2002 .vecs = hmac_sha256_tv_template,
@@ -1746,6 +2006,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1746 }, { 2006 }, {
1747 .alg = "hmac(sha384)", 2007 .alg = "hmac(sha384)",
1748 .test = alg_test_hash, 2008 .test = alg_test_hash,
2009 .fips_allowed = 1,
1749 .suite = { 2010 .suite = {
1750 .hash = { 2011 .hash = {
1751 .vecs = hmac_sha384_tv_template, 2012 .vecs = hmac_sha384_tv_template,
@@ -1755,6 +2016,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1755 }, { 2016 }, {
1756 .alg = "hmac(sha512)", 2017 .alg = "hmac(sha512)",
1757 .test = alg_test_hash, 2018 .test = alg_test_hash,
2019 .fips_allowed = 1,
1758 .suite = { 2020 .suite = {
1759 .hash = { 2021 .hash = {
1760 .vecs = hmac_sha512_tv_template, 2022 .vecs = hmac_sha512_tv_template,
@@ -1836,15 +2098,32 @@ static const struct alg_test_desc alg_test_descs[] = {
1836 }, { 2098 }, {
1837 .alg = "rfc3686(ctr(aes))", 2099 .alg = "rfc3686(ctr(aes))",
1838 .test = alg_test_skcipher, 2100 .test = alg_test_skcipher,
2101 .fips_allowed = 1,
1839 .suite = { 2102 .suite = {
1840 .cipher = { 2103 .cipher = {
1841 .enc = { 2104 .enc = {
1842 .vecs = aes_ctr_enc_tv_template, 2105 .vecs = aes_ctr_rfc3686_enc_tv_template,
1843 .count = AES_CTR_ENC_TEST_VECTORS 2106 .count = AES_CTR_3686_ENC_TEST_VECTORS
1844 }, 2107 },
1845 .dec = { 2108 .dec = {
1846 .vecs = aes_ctr_dec_tv_template, 2109 .vecs = aes_ctr_rfc3686_dec_tv_template,
1847 .count = AES_CTR_DEC_TEST_VECTORS 2110 .count = AES_CTR_3686_DEC_TEST_VECTORS
2111 }
2112 }
2113 }
2114 }, {
2115 .alg = "rfc4309(ccm(aes))",
2116 .test = alg_test_aead,
2117 .fips_allowed = 1,
2118 .suite = {
2119 .aead = {
2120 .enc = {
2121 .vecs = aes_ccm_rfc4309_enc_tv_template,
2122 .count = AES_CCM_4309_ENC_TEST_VECTORS
2123 },
2124 .dec = {
2125 .vecs = aes_ccm_rfc4309_dec_tv_template,
2126 .count = AES_CCM_4309_DEC_TEST_VECTORS
1848 } 2127 }
1849 } 2128 }
1850 } 2129 }
@@ -1898,6 +2177,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1898 }, { 2177 }, {
1899 .alg = "sha1", 2178 .alg = "sha1",
1900 .test = alg_test_hash, 2179 .test = alg_test_hash,
2180 .fips_allowed = 1,
1901 .suite = { 2181 .suite = {
1902 .hash = { 2182 .hash = {
1903 .vecs = sha1_tv_template, 2183 .vecs = sha1_tv_template,
@@ -1907,6 +2187,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1907 }, { 2187 }, {
1908 .alg = "sha224", 2188 .alg = "sha224",
1909 .test = alg_test_hash, 2189 .test = alg_test_hash,
2190 .fips_allowed = 1,
1910 .suite = { 2191 .suite = {
1911 .hash = { 2192 .hash = {
1912 .vecs = sha224_tv_template, 2193 .vecs = sha224_tv_template,
@@ -1916,6 +2197,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1916 }, { 2197 }, {
1917 .alg = "sha256", 2198 .alg = "sha256",
1918 .test = alg_test_hash, 2199 .test = alg_test_hash,
2200 .fips_allowed = 1,
1919 .suite = { 2201 .suite = {
1920 .hash = { 2202 .hash = {
1921 .vecs = sha256_tv_template, 2203 .vecs = sha256_tv_template,
@@ -1925,6 +2207,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1925 }, { 2207 }, {
1926 .alg = "sha384", 2208 .alg = "sha384",
1927 .test = alg_test_hash, 2209 .test = alg_test_hash,
2210 .fips_allowed = 1,
1928 .suite = { 2211 .suite = {
1929 .hash = { 2212 .hash = {
1930 .vecs = sha384_tv_template, 2213 .vecs = sha384_tv_template,
@@ -1934,6 +2217,7 @@ static const struct alg_test_desc alg_test_descs[] = {
1934 }, { 2217 }, {
1935 .alg = "sha512", 2218 .alg = "sha512",
1936 .test = alg_test_hash, 2219 .test = alg_test_hash,
2220 .fips_allowed = 1,
1937 .suite = { 2221 .suite = {
1938 .hash = { 2222 .hash = {
1939 .vecs = sha512_tv_template, 2223 .vecs = sha512_tv_template,
@@ -2077,60 +2361,36 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
2077 if (i < 0) 2361 if (i < 0)
2078 goto notest; 2362 goto notest;
2079 2363
2080 return alg_test_cipher(alg_test_descs + i, driver, type, mask); 2364 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2365 goto non_fips_alg;
2366
2367 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
2368 goto test_done;
2081 } 2369 }
2082 2370
2083 i = alg_find_test(alg); 2371 i = alg_find_test(alg);
2084 if (i < 0) 2372 if (i < 0)
2085 goto notest; 2373 goto notest;
2086 2374
2375 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2376 goto non_fips_alg;
2377
2087 rc = alg_test_descs[i].test(alg_test_descs + i, driver, 2378 rc = alg_test_descs[i].test(alg_test_descs + i, driver,
2088 type, mask); 2379 type, mask);
2380test_done:
2089 if (fips_enabled && rc) 2381 if (fips_enabled && rc)
2090 panic("%s: %s alg self test failed in fips mode!\n", driver, alg); 2382 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
2091 2383
2384 if (fips_enabled && !rc)
2385 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
2386 driver, alg);
2387
2092 return rc; 2388 return rc;
2093 2389
2094notest: 2390notest:
2095 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver); 2391 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
2096 return 0; 2392 return 0;
2393non_fips_alg:
2394 return -EINVAL;
2097} 2395}
2098EXPORT_SYMBOL_GPL(alg_test); 2396EXPORT_SYMBOL_GPL(alg_test);
2099
2100int __init testmgr_init(void)
2101{
2102 int i;
2103
2104 for (i = 0; i < XBUFSIZE; i++) {
2105 xbuf[i] = (void *)__get_free_page(GFP_KERNEL);
2106 if (!xbuf[i])
2107 goto err_free_xbuf;
2108 }
2109
2110 for (i = 0; i < XBUFSIZE; i++) {
2111 axbuf[i] = (void *)__get_free_page(GFP_KERNEL);
2112 if (!axbuf[i])
2113 goto err_free_axbuf;
2114 }
2115
2116 return 0;
2117
2118err_free_axbuf:
2119 for (i = 0; i < XBUFSIZE && axbuf[i]; i++)
2120 free_page((unsigned long)axbuf[i]);
2121err_free_xbuf:
2122 for (i = 0; i < XBUFSIZE && xbuf[i]; i++)
2123 free_page((unsigned long)xbuf[i]);
2124
2125 return -ENOMEM;
2126}
2127
2128void testmgr_exit(void)
2129{
2130 int i;
2131
2132 for (i = 0; i < XBUFSIZE; i++)
2133 free_page((unsigned long)axbuf[i]);
2134 for (i = 0; i < XBUFSIZE; i++)
2135 free_page((unsigned long)xbuf[i]);
2136}
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 526f00a9c72f..69316228fc19 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -62,6 +62,7 @@ struct aead_testvec {
62 int np; 62 int np;
63 int anp; 63 int anp;
64 unsigned char fail; 64 unsigned char fail;
65 unsigned char novrfy; /* ccm dec verification failure expected */
65 unsigned char wk; /* weak key flag */ 66 unsigned char wk; /* weak key flag */
66 unsigned char klen; 67 unsigned char klen;
67 unsigned short ilen; 68 unsigned short ilen;
@@ -69,6 +70,18 @@ struct aead_testvec {
69 unsigned short rlen; 70 unsigned short rlen;
70}; 71};
71 72
73struct cprng_testvec {
74 char *key;
75 char *dt;
76 char *v;
77 char *result;
78 unsigned char klen;
79 unsigned short dtlen;
80 unsigned short vlen;
81 unsigned short rlen;
82 unsigned short loops;
83};
84
72static char zeroed_string[48]; 85static char zeroed_string[48];
73 86
74/* 87/*
@@ -2841,12 +2854,16 @@ static struct cipher_testvec cast6_dec_tv_template[] = {
2841#define AES_LRW_DEC_TEST_VECTORS 8 2854#define AES_LRW_DEC_TEST_VECTORS 8
2842#define AES_XTS_ENC_TEST_VECTORS 4 2855#define AES_XTS_ENC_TEST_VECTORS 4
2843#define AES_XTS_DEC_TEST_VECTORS 4 2856#define AES_XTS_DEC_TEST_VECTORS 4
2844#define AES_CTR_ENC_TEST_VECTORS 7 2857#define AES_CTR_ENC_TEST_VECTORS 3
2845#define AES_CTR_DEC_TEST_VECTORS 6 2858#define AES_CTR_DEC_TEST_VECTORS 3
2859#define AES_CTR_3686_ENC_TEST_VECTORS 7
2860#define AES_CTR_3686_DEC_TEST_VECTORS 6
2846#define AES_GCM_ENC_TEST_VECTORS 9 2861#define AES_GCM_ENC_TEST_VECTORS 9
2847#define AES_GCM_DEC_TEST_VECTORS 8 2862#define AES_GCM_DEC_TEST_VECTORS 8
2848#define AES_CCM_ENC_TEST_VECTORS 7 2863#define AES_CCM_ENC_TEST_VECTORS 7
2849#define AES_CCM_DEC_TEST_VECTORS 7 2864#define AES_CCM_DEC_TEST_VECTORS 7
2865#define AES_CCM_4309_ENC_TEST_VECTORS 7
2866#define AES_CCM_4309_DEC_TEST_VECTORS 10
2850 2867
2851static struct cipher_testvec aes_enc_tv_template[] = { 2868static struct cipher_testvec aes_enc_tv_template[] = {
2852 { /* From FIPS-197 */ 2869 { /* From FIPS-197 */
@@ -3983,6 +4000,164 @@ static struct cipher_testvec aes_xts_dec_tv_template[] = {
3983 4000
3984 4001
3985static struct cipher_testvec aes_ctr_enc_tv_template[] = { 4002static struct cipher_testvec aes_ctr_enc_tv_template[] = {
4003 { /* From NIST Special Publication 800-38A, Appendix F.5 */
4004 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
4005 "\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
4006 .klen = 16,
4007 .iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
4008 "\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
4009 .input = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4010 "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4011 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4012 "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4013 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11"
4014 "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
4015 "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17"
4016 "\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
4017 .ilen = 64,
4018 .result = "\x87\x4d\x61\x91\xb6\x20\xe3\x26"
4019 "\x1b\xef\x68\x64\x99\x0d\xb6\xce"
4020 "\x98\x06\xf6\x6b\x79\x70\xfd\xff"
4021 "\x86\x17\x18\x7b\xb9\xff\xfd\xff"
4022 "\x5a\xe4\xdf\x3e\xdb\xd5\xd3\x5e"
4023 "\x5b\x4f\x09\x02\x0d\xb0\x3e\xab"
4024 "\x1e\x03\x1d\xda\x2f\xbe\x03\xd1"
4025 "\x79\x21\x70\xa0\xf3\x00\x9c\xee",
4026 .rlen = 64,
4027 }, {
4028 .key = "\x8e\x73\xb0\xf7\xda\x0e\x64\x52"
4029 "\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
4030 "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
4031 .klen = 24,
4032 .iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
4033 "\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
4034 .input = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4035 "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4036 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4037 "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4038 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11"
4039 "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
4040 "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17"
4041 "\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
4042 .ilen = 64,
4043 .result = "\x1a\xbc\x93\x24\x17\x52\x1c\xa2"
4044 "\x4f\x2b\x04\x59\xfe\x7e\x6e\x0b"
4045 "\x09\x03\x39\xec\x0a\xa6\xfa\xef"
4046 "\xd5\xcc\xc2\xc6\xf4\xce\x8e\x94"
4047 "\x1e\x36\xb2\x6b\xd1\xeb\xc6\x70"
4048 "\xd1\xbd\x1d\x66\x56\x20\xab\xf7"
4049 "\x4f\x78\xa7\xf6\xd2\x98\x09\x58"
4050 "\x5a\x97\xda\xec\x58\xc6\xb0\x50",
4051 .rlen = 64,
4052 }, {
4053 .key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe"
4054 "\x2b\x73\xae\xf0\x85\x7d\x77\x81"
4055 "\x1f\x35\x2c\x07\x3b\x61\x08\xd7"
4056 "\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
4057 .klen = 32,
4058 .iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
4059 "\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
4060 .input = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4061 "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4062 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4063 "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4064 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11"
4065 "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
4066 "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17"
4067 "\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
4068 .ilen = 64,
4069 .result = "\x60\x1e\xc3\x13\x77\x57\x89\xa5"
4070 "\xb7\xa7\xf5\x04\xbb\xf3\xd2\x28"
4071 "\xf4\x43\xe3\xca\x4d\x62\xb5\x9a"
4072 "\xca\x84\xe9\x90\xca\xca\xf5\xc5"
4073 "\x2b\x09\x30\xda\xa2\x3d\xe9\x4c"
4074 "\xe8\x70\x17\xba\x2d\x84\x98\x8d"
4075 "\xdf\xc9\xc5\x8d\xb6\x7a\xad\xa6"
4076 "\x13\xc2\xdd\x08\x45\x79\x41\xa6",
4077 .rlen = 64,
4078 }
4079};
4080
4081static struct cipher_testvec aes_ctr_dec_tv_template[] = {
4082 { /* From NIST Special Publication 800-38A, Appendix F.5 */
4083 .key = "\x2b\x7e\x15\x16\x28\xae\xd2\xa6"
4084 "\xab\xf7\x15\x88\x09\xcf\x4f\x3c",
4085 .klen = 16,
4086 .iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
4087 "\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
4088 .input = "\x87\x4d\x61\x91\xb6\x20\xe3\x26"
4089 "\x1b\xef\x68\x64\x99\x0d\xb6\xce"
4090 "\x98\x06\xf6\x6b\x79\x70\xfd\xff"
4091 "\x86\x17\x18\x7b\xb9\xff\xfd\xff"
4092 "\x5a\xe4\xdf\x3e\xdb\xd5\xd3\x5e"
4093 "\x5b\x4f\x09\x02\x0d\xb0\x3e\xab"
4094 "\x1e\x03\x1d\xda\x2f\xbe\x03\xd1"
4095 "\x79\x21\x70\xa0\xf3\x00\x9c\xee",
4096 .ilen = 64,
4097 .result = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4098 "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4099 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4100 "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4101 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11"
4102 "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
4103 "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17"
4104 "\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
4105 .rlen = 64,
4106 }, {
4107 .key = "\x8e\x73\xb0\xf7\xda\x0e\x64\x52"
4108 "\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
4109 "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b",
4110 .klen = 24,
4111 .iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
4112 "\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
4113 .input = "\x1a\xbc\x93\x24\x17\x52\x1c\xa2"
4114 "\x4f\x2b\x04\x59\xfe\x7e\x6e\x0b"
4115 "\x09\x03\x39\xec\x0a\xa6\xfa\xef"
4116 "\xd5\xcc\xc2\xc6\xf4\xce\x8e\x94"
4117 "\x1e\x36\xb2\x6b\xd1\xeb\xc6\x70"
4118 "\xd1\xbd\x1d\x66\x56\x20\xab\xf7"
4119 "\x4f\x78\xa7\xf6\xd2\x98\x09\x58"
4120 "\x5a\x97\xda\xec\x58\xc6\xb0\x50",
4121 .ilen = 64,
4122 .result = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4123 "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4124 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4125 "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4126 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11"
4127 "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
4128 "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17"
4129 "\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
4130 .rlen = 64,
4131 }, {
4132 .key = "\x60\x3d\xeb\x10\x15\xca\x71\xbe"
4133 "\x2b\x73\xae\xf0\x85\x7d\x77\x81"
4134 "\x1f\x35\x2c\x07\x3b\x61\x08\xd7"
4135 "\x2d\x98\x10\xa3\x09\x14\xdf\xf4",
4136 .klen = 32,
4137 .iv = "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7"
4138 "\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
4139 .input = "\x60\x1e\xc3\x13\x77\x57\x89\xa5"
4140 "\xb7\xa7\xf5\x04\xbb\xf3\xd2\x28"
4141 "\xf4\x43\xe3\xca\x4d\x62\xb5\x9a"
4142 "\xca\x84\xe9\x90\xca\xca\xf5\xc5"
4143 "\x2b\x09\x30\xda\xa2\x3d\xe9\x4c"
4144 "\xe8\x70\x17\xba\x2d\x84\x98\x8d"
4145 "\xdf\xc9\xc5\x8d\xb6\x7a\xad\xa6"
4146 "\x13\xc2\xdd\x08\x45\x79\x41\xa6",
4147 .ilen = 64,
4148 .result = "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96"
4149 "\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
4150 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c"
4151 "\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
4152 "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11"
4153 "\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
4154 "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17"
4155 "\xad\x2b\x41\x7b\xe6\x6c\x37\x10",
4156 .rlen = 64,
4157 }
4158};
4159
4160static struct cipher_testvec aes_ctr_rfc3686_enc_tv_template[] = {
3986 { /* From RFC 3686 */ 4161 { /* From RFC 3686 */
3987 .key = "\xae\x68\x52\xf8\x12\x10\x67\xcc" 4162 .key = "\xae\x68\x52\xf8\x12\x10\x67\xcc"
3988 "\x4b\xf7\xa5\x76\x55\x77\xf3\x9e" 4163 "\x4b\xf7\xa5\x76\x55\x77\xf3\x9e"
@@ -5114,7 +5289,7 @@ static struct cipher_testvec aes_ctr_enc_tv_template[] = {
5114 }, 5289 },
5115}; 5290};
5116 5291
5117static struct cipher_testvec aes_ctr_dec_tv_template[] = { 5292static struct cipher_testvec aes_ctr_rfc3686_dec_tv_template[] = {
5118 { /* From RFC 3686 */ 5293 { /* From RFC 3686 */
5119 .key = "\xae\x68\x52\xf8\x12\x10\x67\xcc" 5294 .key = "\xae\x68\x52\xf8\x12\x10\x67\xcc"
5120 "\x4b\xf7\xa5\x76\x55\x77\xf3\x9e" 5295 "\x4b\xf7\xa5\x76\x55\x77\xf3\x9e"
@@ -5825,6 +6000,470 @@ static struct aead_testvec aes_ccm_dec_tv_template[] = {
5825 }, 6000 },
5826}; 6001};
5827 6002
6003/*
6004 * rfc4309 refers to section 8 of rfc3610 for test vectors, but they all
6005 * use a 13-byte nonce, we only support an 11-byte nonce. Similarly, all of
6006 * Special Publication 800-38C's test vectors also use nonce lengths our
6007 * implementation doesn't support. The following are taken from fips cavs
6008 * fax files on hand at Red Hat.
6009 *
6010 * nb: actual key lengths are (klen - 3), the last 3 bytes are actually
6011 * part of the nonce which combine w/the iv, but need to be input this way.
6012 */
6013static struct aead_testvec aes_ccm_rfc4309_enc_tv_template[] = {
6014 {
6015 .key = "\x83\xac\x54\x66\xc2\xeb\xe5\x05"
6016 "\x2e\x01\xd1\xfc\x5d\x82\x66\x2e"
6017 "\x96\xac\x59",
6018 .klen = 19,
6019 .iv = "\x30\x07\xa1\xe2\xa2\xc7\x55\x24",
6020 .alen = 0,
6021 .input = "\x19\xc8\x81\xf6\xe9\x86\xff\x93"
6022 "\x0b\x78\x67\xe5\xbb\xb7\xfc\x6e"
6023 "\x83\x77\xb3\xa6\x0c\x8c\x9f\x9c"
6024 "\x35\x2e\xad\xe0\x62\xf9\x91\xa1",
6025 .ilen = 32,
6026 .result = "\xab\x6f\xe1\x69\x1d\x19\x99\xa8"
6027 "\x92\xa0\xc4\x6f\x7e\xe2\x8b\xb1"
6028 "\x70\xbb\x8c\xa6\x4c\x6e\x97\x8a"
6029 "\x57\x2b\xbe\x5d\x98\xa6\xb1\x32"
6030 "\xda\x24\xea\xd9\xa1\x39\x98\xfd"
6031 "\xa4\xbe\xd9\xf2\x1a\x6d\x22\xa8",
6032 .rlen = 48,
6033 }, {
6034 .key = "\x1e\x2c\x7e\x01\x41\x9a\xef\xc0"
6035 "\x0d\x58\x96\x6e\x5c\xa2\x4b\xd3"
6036 "\x4f\xa3\x19",
6037 .klen = 19,
6038 .iv = "\xd3\x01\x5a\xd8\x30\x60\x15\x56",
6039 .assoc = "\xda\xe6\x28\x9c\x45\x2d\xfd\x63"
6040 "\x5e\xda\x4c\xb6\xe6\xfc\xf9\xb7"
6041 "\x0c\x56\xcb\xe4\xe0\x05\x7a\xe1"
6042 "\x0a\x63\x09\x78\xbc\x2c\x55\xde",
6043 .alen = 32,
6044 .input = "\x87\xa3\x36\xfd\x96\xb3\x93\x78"
6045 "\xa9\x28\x63\xba\x12\xa3\x14\x85"
6046 "\x57\x1e\x06\xc9\x7b\x21\xef\x76"
6047 "\x7f\x38\x7e\x8e\x29\xa4\x3e\x7e",
6048 .ilen = 32,
6049 .result = "\x8a\x1e\x11\xf0\x02\x6b\xe2\x19"
6050 "\xfc\x70\xc4\x6d\x8e\xb7\x99\xab"
6051 "\xc5\x4b\xa2\xac\xd3\xf3\x48\xff"
6052 "\x3b\xb5\xce\x53\xef\xde\xbb\x02"
6053 "\xa9\x86\x15\x6c\x13\xfe\xda\x0a"
6054 "\x22\xb8\x29\x3d\xd8\x39\x9a\x23",
6055 .rlen = 48,
6056 }, {
6057 .key = "\xf4\x6b\xc2\x75\x62\xfe\xb4\xe1"
6058 "\xa3\xf0\xff\xdd\x4e\x4b\x12\x75"
6059 "\x53\x14\x73\x66\x8d\x88\xf6\x80"
6060 "\xa0\x20\x35",
6061 .klen = 27,
6062 .iv = "\x26\xf2\x21\x8d\x50\x20\xda\xe2",
6063 .assoc = "\x5b\x9e\x13\x67\x02\x5e\xef\xc1"
6064 "\x6c\xf9\xd7\x1e\x52\x8f\x7a\x47"
6065 "\xe9\xd4\xcf\x20\x14\x6e\xf0\x2d"
6066 "\xd8\x9e\x2b\x56\x10\x23\x56\xe7",
6067 .alen = 32,
6068 .ilen = 0,
6069 .result = "\x36\xea\x7a\x70\x08\xdc\x6a\xbc"
6070 "\xad\x0c\x7a\x63\xf6\x61\xfd\x9b",
6071 .rlen = 16,
6072 }, {
6073 .key = "\x56\xdf\x5c\x8f\x26\x3f\x0e\x42"
6074 "\xef\x7a\xd3\xce\xfc\x84\x60\x62"
6075 "\xca\xb4\x40\xaf\x5f\xc9\xc9\x01"
6076 "\xd6\x3c\x8c",
6077 .klen = 27,
6078 .iv = "\x86\x84\xb6\xcd\xef\x09\x2e\x94",
6079 .assoc = "\x02\x65\x78\x3c\xe9\x21\x30\x91"
6080 "\xb1\xb9\xda\x76\x9a\x78\x6d\x95"
6081 "\xf2\x88\x32\xa3\xf2\x50\xcb\x4c"
6082 "\xe3\x00\x73\x69\x84\x69\x87\x79",
6083 .alen = 32,
6084 .input = "\x9f\xd2\x02\x4b\x52\x49\x31\x3c"
6085 "\x43\x69\x3a\x2d\x8e\x70\xad\x7e"
6086 "\xe0\xe5\x46\x09\x80\x89\x13\xb2"
6087 "\x8c\x8b\xd9\x3f\x86\xfb\xb5\x6b",
6088 .ilen = 32,
6089 .result = "\x39\xdf\x7c\x3c\x5a\x29\xb9\x62"
6090 "\x5d\x51\xc2\x16\xd8\xbd\x06\x9f"
6091 "\x9b\x6a\x09\x70\xc1\x51\x83\xc2"
6092 "\x66\x88\x1d\x4f\x9a\xda\xe0\x1e"
6093 "\xc7\x79\x11\x58\xe5\x6b\x20\x40"
6094 "\x7a\xea\x46\x42\x8b\xe4\x6f\xe1",
6095 .rlen = 48,
6096 }, {
6097 .key = "\xe0\x8d\x99\x71\x60\xd7\x97\x1a"
6098 "\xbd\x01\x99\xd5\x8a\xdf\x71\x3a"
6099 "\xd3\xdf\x24\x4b\x5e\x3d\x4b\x4e"
6100 "\x30\x7a\xb9\xd8\x53\x0a\x5e\x2b"
6101 "\x1e\x29\x91",
6102 .klen = 35,
6103 .iv = "\xad\x8e\xc1\x53\x0a\xcf\x2d\xbe",
6104 .assoc = "\x19\xb6\x1f\x57\xc4\xf3\xf0\x8b"
6105 "\x78\x2b\x94\x02\x29\x0f\x42\x27"
6106 "\x6b\x75\xcb\x98\x34\x08\x7e\x79"
6107 "\xe4\x3e\x49\x0d\x84\x8b\x22\x87",
6108 .alen = 32,
6109 .input = "\xe1\xd9\xd8\x13\xeb\x3a\x75\x3f"
6110 "\x9d\xbd\x5f\x66\xbe\xdc\xbb\x66"
6111 "\xbf\x17\x99\x62\x4a\x39\x27\x1f"
6112 "\x1d\xdc\x24\xae\x19\x2f\x98\x4c",
6113 .ilen = 32,
6114 .result = "\x19\xb8\x61\x33\x45\x2b\x43\x96"
6115 "\x6f\x51\xd0\x20\x30\x7d\x9b\xc6"
6116 "\x26\x3d\xf8\xc9\x65\x16\xa8\x9f"
6117 "\xf0\x62\x17\x34\xf2\x1e\x8d\x75"
6118 "\x4e\x13\xcc\xc0\xc3\x2a\x54\x2d",
6119 .rlen = 40,
6120 }, {
6121 .key = "\x7c\xc8\x18\x3b\x8d\x99\xe0\x7c"
6122 "\x45\x41\xb8\xbd\x5c\xa7\xc2\x32"
6123 "\x8a\xb8\x02\x59\xa4\xfe\xa9\x2c"
6124 "\x09\x75\x9a\x9b\x3c\x9b\x27\x39"
6125 "\xf9\xd9\x4e",
6126 .klen = 35,
6127 .iv = "\x63\xb5\x3d\x9d\x43\xf6\x1e\x50",
6128 .assoc = "\x57\xf5\x6b\x8b\x57\x5c\x3d\x3b"
6129 "\x13\x02\x01\x0c\x83\x4c\x96\x35"
6130 "\x8e\xd6\x39\xcf\x7d\x14\x9b\x94"
6131 "\xb0\x39\x36\xe6\x8f\x57\xe0\x13",
6132 .alen = 32,
6133 .input = "\x3b\x6c\x29\x36\xb6\xef\x07\xa6"
6134 "\x83\x72\x07\x4f\xcf\xfa\x66\x89"
6135 "\x5f\xca\xb1\xba\xd5\x8f\x2c\x27"
6136 "\x30\xdb\x75\x09\x93\xd4\x65\xe4",
6137 .ilen = 32,
6138 .result = "\xb0\x88\x5a\x33\xaa\xe5\xc7\x1d"
6139 "\x85\x23\xc7\xc6\x2f\xf4\x1e\x3d"
6140 "\xcc\x63\x44\x25\x07\x78\x4f\x9e"
6141 "\x96\xb8\x88\xeb\xbc\x48\x1f\x06"
6142 "\x39\xaf\x39\xac\xd8\x4a\x80\x39"
6143 "\x7b\x72\x8a\xf7",
6144 .rlen = 44,
6145 }, {
6146 .key = "\xab\xd0\xe9\x33\x07\x26\xe5\x83"
6147 "\x8c\x76\x95\xd4\xb6\xdc\xf3\x46"
6148 "\xf9\x8f\xad\xe3\x02\x13\x83\x77"
6149 "\x3f\xb0\xf1\xa1\xa1\x22\x0f\x2b"
6150 "\x24\xa7\x8b",
6151 .klen = 35,
6152 .iv = "\x07\xcb\xcc\x0e\xe6\x33\xbf\xf5",
6153 .assoc = "\xd4\xdb\x30\x1d\x03\xfe\xfd\x5f"
6154 "\x87\xd4\x8c\xb6\xb6\xf1\x7a\x5d"
6155 "\xab\x90\x65\x8d\x8e\xca\x4d\x4f"
6156 "\x16\x0c\x40\x90\x4b\xc7\x36\x73",
6157 .alen = 32,
6158 .input = "\xf5\xc6\x7d\x48\xc1\xb7\xe6\x92"
6159 "\x97\x5a\xca\xc4\xa9\x6d\xf9\x3d"
6160 "\x6c\xde\xbc\xf1\x90\xea\x6a\xb2"
6161 "\x35\x86\x36\xaf\x5c\xfe\x4b\x3a",
6162 .ilen = 32,
6163 .result = "\x83\x6f\x40\x87\x72\xcf\xc1\x13"
6164 "\xef\xbb\x80\x21\x04\x6c\x58\x09"
6165 "\x07\x1b\xfc\xdf\xc0\x3f\x5b\xc7"
6166 "\xe0\x79\xa8\x6e\x71\x7c\x3f\xcf"
6167 "\x5c\xda\xb2\x33\xe5\x13\xe2\x0d"
6168 "\x74\xd1\xef\xb5\x0f\x3a\xb5\xf8",
6169 .rlen = 48,
6170 },
6171};
6172
6173static struct aead_testvec aes_ccm_rfc4309_dec_tv_template[] = {
6174 {
6175 .key = "\xab\x2f\x8a\x74\xb7\x1c\xd2\xb1"
6176 "\xff\x80\x2e\x48\x7d\x82\xf8\xb9"
6177 "\xc6\xfb\x7d",
6178 .klen = 19,
6179 .iv = "\x80\x0d\x13\xab\xd8\xa6\xb2\xd8",
6180 .alen = 0,
6181 .input = "\xd5\xe8\x93\x9f\xc7\x89\x2e\x2b",
6182 .ilen = 8,
6183 .result = "\x00",
6184 .rlen = 0,
6185 .novrfy = 1,
6186 }, {
6187 .key = "\xab\x2f\x8a\x74\xb7\x1c\xd2\xb1"
6188 "\xff\x80\x2e\x48\x7d\x82\xf8\xb9"
6189 "\xaf\x94\x87",
6190 .klen = 19,
6191 .iv = "\x78\x35\x82\x81\x7f\x88\x94\x68",
6192 .alen = 0,
6193 .input = "\x41\x3c\xb8\x87\x73\xcb\xf3\xf3",
6194 .ilen = 8,
6195 .result = "\x00",
6196 .rlen = 0,
6197 }, {
6198 .key = "\x61\x0e\x8c\xae\xe3\x23\xb6\x38"
6199 "\x76\x1c\xf6\x3a\x67\xa3\x9c\xd8"
6200 "\xc6\xfb\x7d",
6201 .klen = 19,
6202 .iv = "\x80\x0d\x13\xab\xd8\xa6\xb2\xd8",
6203 .assoc = "\xf3\x94\x87\x78\x35\x82\x81\x7f"
6204 "\x88\x94\x68\xb1\x78\x6b\x2b\xd6"
6205 "\x04\x1f\x4e\xed\x78\xd5\x33\x66"
6206 "\xd8\x94\x99\x91\x81\x54\x62\x57",
6207 .alen = 32,
6208 .input = "\xf0\x7c\x29\x02\xae\x1c\x2f\x55"
6209 "\xd0\xd1\x3d\x1a\xa3\x6d\xe4\x0a"
6210 "\x86\xb0\x87\x6b\x62\x33\x8c\x34"
6211 "\xce\xab\x57\xcc\x79\x0b\xe0\x6f"
6212 "\x5c\x3e\x48\x1f\x6c\x46\xf7\x51"
6213 "\x8b\x84\x83\x2a\xc1\x05\xb8\xc5",
6214 .ilen = 48,
6215 .result = "\x50\x82\x3e\x07\xe2\x1e\xb6\xfb"
6216 "\x33\xe4\x73\xce\xd2\xfb\x95\x79"
6217 "\xe8\xb4\xb5\x77\x11\x10\x62\x6f"
6218 "\x6a\x82\xd1\x13\xec\xf5\xd0\x48",
6219 .rlen = 32,
6220 .novrfy = 1,
6221 }, {
6222 .key = "\x61\x0e\x8c\xae\xe3\x23\xb6\x38"
6223 "\x76\x1c\xf6\x3a\x67\xa3\x9c\xd8"
6224 "\x05\xe0\xc9",
6225 .klen = 19,
6226 .iv = "\x0f\xed\x34\xea\x97\xd4\x3b\xdf",
6227 .assoc = "\x49\x5c\x50\x1f\x1d\x94\xcc\x81"
6228 "\xba\xb7\xb6\x03\xaf\xa5\xc1\xa1"
6229 "\xd8\x5c\x42\x68\xe0\x6c\xda\x89"
6230 "\x05\xac\x56\xac\x1b\x2a\xd3\x86",
6231 .alen = 32,
6232 .input = "\x39\xbe\x7d\x15\x62\x77\xf3\x3c"
6233 "\xad\x83\x52\x6d\x71\x03\x25\x1c"
6234 "\xed\x81\x3a\x9a\x16\x7d\x19\x80"
6235 "\x72\x04\x72\xd0\xf6\xff\x05\x0f"
6236 "\xb7\x14\x30\x00\x32\x9e\xa0\xa6"
6237 "\x9e\x5a\x18\xa1\xb8\xfe\xdb\xd3",
6238 .ilen = 48,
6239 .result = "\x75\x05\xbe\xc2\xd9\x1e\xde\x60"
6240 "\x47\x3d\x8c\x7d\xbd\xb5\xd9\xb7"
6241 "\xf2\xae\x61\x05\x8f\x82\x24\x3f"
6242 "\x9c\x67\x91\xe1\x38\x4f\xe4\x0c",
6243 .rlen = 32,
6244 }, {
6245 .key = "\x39\xbb\xa7\xbe\x59\x97\x9e\x73"
6246 "\xa2\xbc\x6b\x98\xd7\x75\x7f\xe3"
6247 "\xa4\x48\x93\x39\x26\x71\x4a\xc6"
6248 "\xee\x49\x83",
6249 .klen = 27,
6250 .iv = "\xe9\xa9\xff\xe9\x57\xba\xfd\x9e",
6251 .assoc = "\x44\xa6\x2c\x05\xe9\xe1\x43\xb1"
6252 "\x58\x7c\xf2\x5c\x6d\x39\x0a\x64"
6253 "\xa4\xf0\x13\x05\xd1\x77\x99\x67"
6254 "\x11\xc4\xc6\xdb\x00\x56\x36\x61",
6255 .alen = 32,
6256 .input = "\x71\x99\xfa\xf4\x44\x12\x68\x9b",
6257 .ilen = 8,
6258 .result = "\x00",
6259 .rlen = 0,
6260 }, {
6261 .key = "\x58\x5d\xa0\x96\x65\x1a\x04\xd7"
6262 "\x96\xe5\xc5\x68\xaa\x95\x35\xe0"
6263 "\x29\xa0\xba\x9e\x48\x78\xd1\xba"
6264 "\xee\x49\x83",
6265 .klen = 27,
6266 .iv = "\xe9\xa9\xff\xe9\x57\xba\xfd\x9e",
6267 .assoc = "\x44\xa6\x2c\x05\xe9\xe1\x43\xb1"
6268 "\x58\x7c\xf2\x5c\x6d\x39\x0a\x64"
6269 "\xa4\xf0\x13\x05\xd1\x77\x99\x67"
6270 "\x11\xc4\xc6\xdb\x00\x56\x36\x61",
6271 .alen = 32,
6272 .input = "\xfb\xe5\x5d\x34\xbe\xe5\xe8\xe7"
6273 "\x5a\xef\x2f\xbf\x1f\x7f\xd4\xb2"
6274 "\x66\xca\x61\x1e\x96\x7a\x61\xb3"
6275 "\x1c\x16\x45\x52\xba\x04\x9c\x9f"
6276 "\xb1\xd2\x40\xbc\x52\x7c\x6f\xb1",
6277 .ilen = 40,
6278 .result = "\x85\x34\x66\x42\xc8\x92\x0f\x36"
6279 "\x58\xe0\x6b\x91\x3c\x98\x5c\xbb"
6280 "\x0a\x85\xcc\x02\xad\x7a\x96\xe9"
6281 "\x65\x43\xa4\xc3\x0f\xdc\x55\x81",
6282 .rlen = 32,
6283 }, {
6284 .key = "\x58\x5d\xa0\x96\x65\x1a\x04\xd7"
6285 "\x96\xe5\xc5\x68\xaa\x95\x35\xe0"
6286 "\x29\xa0\xba\x9e\x48\x78\xd1\xba"
6287 "\xd1\xfc\x57",
6288 .klen = 27,
6289 .iv = "\x9c\xfe\xb8\x9c\xad\x71\xaa\x1f",
6290 .assoc = "\x86\x67\xa5\xa9\x14\x5f\x0d\xc6"
6291 "\xff\x14\xc7\x44\xbf\x6c\x3a\xc3"
6292 "\xff\xb6\x81\xbd\xe2\xd5\x06\xc7"
6293 "\x3c\xa1\x52\x13\x03\x8a\x23\x3a",
6294 .alen = 32,
6295 .input = "\x3f\x66\xb0\x9d\xe5\x4b\x38\x00"
6296 "\xc6\x0e\x6e\xe5\xd6\x98\xa6\x37"
6297 "\x8c\x26\x33\xc6\xb2\xa2\x17\xfa"
6298 "\x64\x19\xc0\x30\xd7\xfc\x14\x6b"
6299 "\xe3\x33\xc2\x04\xb0\x37\xbe\x3f"
6300 "\xa9\xb4\x2d\x68\x03\xa3\x44\xef",
6301 .ilen = 48,
6302 .result = "\x02\x87\x4d\x28\x80\x6e\xb2\xed"
6303 "\x99\x2a\xa8\xca\x04\x25\x45\x90"
6304 "\x1d\xdd\x5a\xd9\xe4\xdb\x9c\x9c"
6305 "\x49\xe9\x01\xfe\xa7\x80\x6d\x6b",
6306 .rlen = 32,
6307 .novrfy = 1,
6308 }, {
6309 .key = "\xa4\x4b\x54\x29\x0a\xb8\x6d\x01"
6310 "\x5b\x80\x2a\xcf\x25\xc4\xb7\x5c"
6311 "\x20\x2c\xad\x30\xc2\x2b\x41\xfb"
6312 "\x0e\x85\xbc\x33\xad\x0f\x2b\xff"
6313 "\xee\x49\x83",
6314 .klen = 35,
6315 .iv = "\xe9\xa9\xff\xe9\x57\xba\xfd\x9e",
6316 .alen = 0,
6317 .input = "\x1f\xb8\x8f\xa3\xdd\x54\x00\xf2",
6318 .ilen = 8,
6319 .result = "\x00",
6320 .rlen = 0,
6321 }, {
6322 .key = "\x39\xbb\xa7\xbe\x59\x97\x9e\x73"
6323 "\xa2\xbc\x6b\x98\xd7\x75\x7f\xe3"
6324 "\xa4\x48\x93\x39\x26\x71\x4a\xc6"
6325 "\xae\x8f\x11\x4c\xc2\x9c\x4a\xbb"
6326 "\x85\x34\x66",
6327 .klen = 35,
6328 .iv = "\x42\xc8\x92\x0f\x36\x58\xe0\x6b",
6329 .alen = 0,
6330 .input = "\x48\x01\x5e\x02\x24\x04\x66\x47"
6331 "\xa1\xea\x6f\xaf\xe8\xfc\xfb\xdd"
6332 "\xa5\xa9\x87\x8d\x84\xee\x2e\x77"
6333 "\xbb\x86\xb9\xf5\x5c\x6c\xff\xf6"
6334 "\x72\xc3\x8e\xf7\x70\xb1\xb2\x07"
6335 "\xbc\xa8\xa3\xbd\x83\x7c\x1d\x2a",
6336 .ilen = 48,
6337 .result = "\xdc\x56\xf2\x71\xb0\xb1\xa0\x6c"
6338 "\xf0\x97\x3a\xfb\x6d\xe7\x32\x99"
6339 "\x3e\xaf\x70\x5e\xb2\x4d\xea\x39"
6340 "\x89\xd4\x75\x7a\x63\xb1\xda\x93",
6341 .rlen = 32,
6342 .novrfy = 1,
6343 }, {
6344 .key = "\x58\x5d\xa0\x96\x65\x1a\x04\xd7"
6345 "\x96\xe5\xc5\x68\xaa\x95\x35\xe0"
6346 "\x29\xa0\xba\x9e\x48\x78\xd1\xba"
6347 "\x0d\x1a\x53\x3b\xb5\xe3\xf8\x8b"
6348 "\xcf\x76\x3f",
6349 .klen = 35,
6350 .iv = "\xd9\x95\x75\x8f\x44\x89\x40\x7b",
6351 .assoc = "\x8f\x86\x6c\x4d\x1d\xc5\x39\x88"
6352 "\xc8\xf3\x5c\x52\x10\x63\x6f\x2b"
6353 "\x8a\x2a\xc5\x6f\x30\x23\x58\x7b"
6354 "\xfb\x36\x03\x11\xb4\xd9\xf2\xfe",
6355 .alen = 32,
6356 .input = "\x48\x58\xd6\xf3\xad\x63\x58\xbf"
6357 "\xae\xc7\x5e\xae\x83\x8f\x7b\xe4"
6358 "\x78\x5c\x4c\x67\x71\x89\x94\xbf"
6359 "\x47\xf1\x63\x7e\x1c\x59\xbd\xc5"
6360 "\x7f\x44\x0a\x0c\x01\x18\x07\x92"
6361 "\xe1\xd3\x51\xce\x32\x6d\x0c\x5b",
6362 .ilen = 48,
6363 .result = "\xc2\x54\xc8\xde\x78\x87\x77\x40"
6364 "\x49\x71\xe4\xb7\xe7\xcb\x76\x61"
6365 "\x0a\x41\xb9\xe9\xc0\x76\x54\xab"
6366 "\x04\x49\x3b\x19\x93\x57\x25\x5d",
6367 .rlen = 32,
6368 },
6369};
6370
6371/*
6372 * ANSI X9.31 Continuous Pseudo-Random Number Generator (AES mode)
6373 * test vectors, taken from Appendix B.2.9 and B.2.10:
6374 * http://csrc.nist.gov/groups/STM/cavp/documents/rng/RNGVS.pdf
6375 * Only AES-128 is supported at this time.
6376 */
6377#define ANSI_CPRNG_AES_TEST_VECTORS 6
6378
6379static struct cprng_testvec ansi_cprng_aes_tv_template[] = {
6380 {
6381 .key = "\xf3\xb1\x66\x6d\x13\x60\x72\x42"
6382 "\xed\x06\x1c\xab\xb8\xd4\x62\x02",
6383 .klen = 16,
6384 .dt = "\xe6\xb3\xbe\x78\x2a\x23\xfa\x62"
6385 "\xd7\x1d\x4a\xfb\xb0\xe9\x22\xf9",
6386 .dtlen = 16,
6387 .v = "\x80\x00\x00\x00\x00\x00\x00\x00"
6388 "\x00\x00\x00\x00\x00\x00\x00\x00",
6389 .vlen = 16,
6390 .result = "\x59\x53\x1e\xd1\x3b\xb0\xc0\x55"
6391 "\x84\x79\x66\x85\xc1\x2f\x76\x41",
6392 .rlen = 16,
6393 .loops = 1,
6394 }, {
6395 .key = "\xf3\xb1\x66\x6d\x13\x60\x72\x42"
6396 "\xed\x06\x1c\xab\xb8\xd4\x62\x02",
6397 .klen = 16,
6398 .dt = "\xe6\xb3\xbe\x78\x2a\x23\xfa\x62"
6399 "\xd7\x1d\x4a\xfb\xb0\xe9\x22\xfa",
6400 .dtlen = 16,
6401 .v = "\xc0\x00\x00\x00\x00\x00\x00\x00"
6402 "\x00\x00\x00\x00\x00\x00\x00\x00",
6403 .vlen = 16,
6404 .result = "\x7c\x22\x2c\xf4\xca\x8f\xa2\x4c"
6405 "\x1c\x9c\xb6\x41\xa9\xf3\x22\x0d",
6406 .rlen = 16,
6407 .loops = 1,
6408 }, {
6409 .key = "\xf3\xb1\x66\x6d\x13\x60\x72\x42"
6410 "\xed\x06\x1c\xab\xb8\xd4\x62\x02",
6411 .klen = 16,
6412 .dt = "\xe6\xb3\xbe\x78\x2a\x23\xfa\x62"
6413 "\xd7\x1d\x4a\xfb\xb0\xe9\x22\xfb",
6414 .dtlen = 16,
6415 .v = "\xe0\x00\x00\x00\x00\x00\x00\x00"
6416 "\x00\x00\x00\x00\x00\x00\x00\x00",
6417 .vlen = 16,
6418 .result = "\x8a\xaa\x00\x39\x66\x67\x5b\xe5"
6419 "\x29\x14\x28\x81\xa9\x4d\x4e\xc7",
6420 .rlen = 16,
6421 .loops = 1,
6422 }, {
6423 .key = "\xf3\xb1\x66\x6d\x13\x60\x72\x42"
6424 "\xed\x06\x1c\xab\xb8\xd4\x62\x02",
6425 .klen = 16,
6426 .dt = "\xe6\xb3\xbe\x78\x2a\x23\xfa\x62"
6427 "\xd7\x1d\x4a\xfb\xb0\xe9\x22\xfc",
6428 .dtlen = 16,
6429 .v = "\xf0\x00\x00\x00\x00\x00\x00\x00"
6430 "\x00\x00\x00\x00\x00\x00\x00\x00",
6431 .vlen = 16,
6432 .result = "\x88\xdd\xa4\x56\x30\x24\x23\xe5"
6433 "\xf6\x9d\xa5\x7e\x7b\x95\xc7\x3a",
6434 .rlen = 16,
6435 .loops = 1,
6436 }, {
6437 .key = "\xf3\xb1\x66\x6d\x13\x60\x72\x42"
6438 "\xed\x06\x1c\xab\xb8\xd4\x62\x02",
6439 .klen = 16,
6440 .dt = "\xe6\xb3\xbe\x78\x2a\x23\xfa\x62"
6441 "\xd7\x1d\x4a\xfb\xb0\xe9\x22\xfd",
6442 .dtlen = 16,
6443 .v = "\xf8\x00\x00\x00\x00\x00\x00\x00"
6444 "\x00\x00\x00\x00\x00\x00\x00\x00",
6445 .vlen = 16,
6446 .result = "\x05\x25\x92\x46\x61\x79\xd2\xcb"
6447 "\x78\xc4\x0b\x14\x0a\x5a\x9a\xc8",
6448 .rlen = 16,
6449 .loops = 1,
6450 }, { /* Monte Carlo Test */
6451 .key = "\x9f\x5b\x51\x20\x0b\xf3\x34\xb5"
6452 "\xd8\x2b\xe8\xc3\x72\x55\xc8\x48",
6453 .klen = 16,
6454 .dt = "\x63\x76\xbb\xe5\x29\x02\xba\x3b"
6455 "\x67\xc9\x25\xfa\x70\x1f\x11\xac",
6456 .dtlen = 16,
6457 .v = "\x57\x2c\x8e\x76\x87\x26\x47\x97"
6458 "\x7e\x74\xfb\xdd\xc4\x95\x01\xd1",
6459 .vlen = 16,
6460 .result = "\x48\xe9\xbd\x0d\x06\xee\x18\xfb"
6461 "\xe4\x57\x90\xd5\xc3\xfc\x9b\x73",
6462 .rlen = 16,
6463 .loops = 10000,
6464 },
6465};
6466
5828/* Cast5 test vectors from RFC 2144 */ 6467/* Cast5 test vectors from RFC 2144 */
5829#define CAST5_ENC_TEST_VECTORS 3 6468#define CAST5_ENC_TEST_VECTORS 3
5830#define CAST5_DEC_TEST_VECTORS 3 6469#define CAST5_DEC_TEST_VECTORS 3
diff --git a/crypto/zlib.c b/crypto/zlib.c
index 33609bab614e..c3015733c990 100644
--- a/crypto/zlib.c
+++ b/crypto/zlib.c
@@ -165,15 +165,15 @@ static int zlib_compress_update(struct crypto_pcomp *tfm,
165 return -EINVAL; 165 return -EINVAL;
166 } 166 }
167 167
168 ret = req->avail_out - stream->avail_out;
168 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", 169 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
169 stream->avail_in, stream->avail_out, 170 stream->avail_in, stream->avail_out,
170 req->avail_in - stream->avail_in, 171 req->avail_in - stream->avail_in, ret);
171 req->avail_out - stream->avail_out);
172 req->next_in = stream->next_in; 172 req->next_in = stream->next_in;
173 req->avail_in = stream->avail_in; 173 req->avail_in = stream->avail_in;
174 req->next_out = stream->next_out; 174 req->next_out = stream->next_out;
175 req->avail_out = stream->avail_out; 175 req->avail_out = stream->avail_out;
176 return 0; 176 return ret;
177} 177}
178 178
179static int zlib_compress_final(struct crypto_pcomp *tfm, 179static int zlib_compress_final(struct crypto_pcomp *tfm,
@@ -195,15 +195,15 @@ static int zlib_compress_final(struct crypto_pcomp *tfm,
195 return -EINVAL; 195 return -EINVAL;
196 } 196 }
197 197
198 ret = req->avail_out - stream->avail_out;
198 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", 199 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
199 stream->avail_in, stream->avail_out, 200 stream->avail_in, stream->avail_out,
200 req->avail_in - stream->avail_in, 201 req->avail_in - stream->avail_in, ret);
201 req->avail_out - stream->avail_out);
202 req->next_in = stream->next_in; 202 req->next_in = stream->next_in;
203 req->avail_in = stream->avail_in; 203 req->avail_in = stream->avail_in;
204 req->next_out = stream->next_out; 204 req->next_out = stream->next_out;
205 req->avail_out = stream->avail_out; 205 req->avail_out = stream->avail_out;
206 return 0; 206 return ret;
207} 207}
208 208
209 209
@@ -280,15 +280,15 @@ static int zlib_decompress_update(struct crypto_pcomp *tfm,
280 return -EINVAL; 280 return -EINVAL;
281 } 281 }
282 282
283 ret = req->avail_out - stream->avail_out;
283 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", 284 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
284 stream->avail_in, stream->avail_out, 285 stream->avail_in, stream->avail_out,
285 req->avail_in - stream->avail_in, 286 req->avail_in - stream->avail_in, ret);
286 req->avail_out - stream->avail_out);
287 req->next_in = stream->next_in; 287 req->next_in = stream->next_in;
288 req->avail_in = stream->avail_in; 288 req->avail_in = stream->avail_in;
289 req->next_out = stream->next_out; 289 req->next_out = stream->next_out;
290 req->avail_out = stream->avail_out; 290 req->avail_out = stream->avail_out;
291 return 0; 291 return ret;
292} 292}
293 293
294static int zlib_decompress_final(struct crypto_pcomp *tfm, 294static int zlib_decompress_final(struct crypto_pcomp *tfm,
@@ -328,15 +328,15 @@ static int zlib_decompress_final(struct crypto_pcomp *tfm,
328 return -EINVAL; 328 return -EINVAL;
329 } 329 }
330 330
331 ret = req->avail_out - stream->avail_out;
331 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n", 332 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
332 stream->avail_in, stream->avail_out, 333 stream->avail_in, stream->avail_out,
333 req->avail_in - stream->avail_in, 334 req->avail_in - stream->avail_in, ret);
334 req->avail_out - stream->avail_out);
335 req->next_in = stream->next_in; 335 req->next_in = stream->next_in;
336 req->avail_in = stream->avail_in; 336 req->avail_in = stream->avail_in;
337 req->next_out = stream->next_out; 337 req->next_out = stream->next_out;
338 req->avail_out = stream->avail_out; 338 req->avail_out = stream->avail_out;
339 return 0; 339 return ret;
340} 340}
341 341
342 342
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 5fab6470f4b2..9c00440dcf86 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -88,7 +88,7 @@ config HW_RANDOM_N2RNG
88 88
89config HW_RANDOM_VIA 89config HW_RANDOM_VIA
90 tristate "VIA HW Random Number Generator support" 90 tristate "VIA HW Random Number Generator support"
91 depends on HW_RANDOM && X86_32 91 depends on HW_RANDOM && X86
92 default HW_RANDOM 92 default HW_RANDOM
93 ---help--- 93 ---help---
94 This driver provides kernel-side support for the Random Number 94 This driver provides kernel-side support for the Random Number
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 538313f9e7ac..00dd3de1be51 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -89,7 +89,7 @@ static struct hwrng omap_rng_ops = {
89 .data_read = omap_rng_data_read, 89 .data_read = omap_rng_data_read,
90}; 90};
91 91
92static int __init omap_rng_probe(struct platform_device *pdev) 92static int __devinit omap_rng_probe(struct platform_device *pdev)
93{ 93{
94 struct resource *res, *mem; 94 struct resource *res, *mem;
95 int ret; 95 int ret;
diff --git a/drivers/char/hw_random/timeriomem-rng.c b/drivers/char/hw_random/timeriomem-rng.c
index dcd352ad0e7f..a94e930575f2 100644
--- a/drivers/char/hw_random/timeriomem-rng.c
+++ b/drivers/char/hw_random/timeriomem-rng.c
@@ -88,9 +88,9 @@ static struct hwrng timeriomem_rng_ops = {
88 .priv = 0, 88 .priv = 0,
89}; 89};
90 90
91static int __init timeriomem_rng_probe(struct platform_device *pdev) 91static int __devinit timeriomem_rng_probe(struct platform_device *pdev)
92{ 92{
93 struct resource *res, *mem; 93 struct resource *res;
94 int ret; 94 int ret;
95 95
96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -98,21 +98,12 @@ static int __init timeriomem_rng_probe(struct platform_device *pdev)
98 if (!res) 98 if (!res)
99 return -ENOENT; 99 return -ENOENT;
100 100
101 mem = request_mem_region(res->start, res->end - res->start + 1,
102 pdev->name);
103 if (mem == NULL)
104 return -EBUSY;
105
106 dev_set_drvdata(&pdev->dev, mem);
107
108 timeriomem_rng_data = pdev->dev.platform_data; 101 timeriomem_rng_data = pdev->dev.platform_data;
109 102
110 timeriomem_rng_data->address = ioremap(res->start, 103 timeriomem_rng_data->address = ioremap(res->start,
111 res->end - res->start + 1); 104 res->end - res->start + 1);
112 if (!timeriomem_rng_data->address) { 105 if (!timeriomem_rng_data->address)
113 ret = -ENOMEM; 106 return -EIO;
114 goto err_ioremap;
115 }
116 107
117 if (timeriomem_rng_data->period != 0 108 if (timeriomem_rng_data->period != 0
118 && usecs_to_jiffies(timeriomem_rng_data->period) > 0) { 109 && usecs_to_jiffies(timeriomem_rng_data->period) > 0) {
@@ -125,7 +116,7 @@ static int __init timeriomem_rng_probe(struct platform_device *pdev)
125 116
126 ret = hwrng_register(&timeriomem_rng_ops); 117 ret = hwrng_register(&timeriomem_rng_ops);
127 if (ret) 118 if (ret)
128 goto err_register; 119 goto failed;
129 120
130 dev_info(&pdev->dev, "32bits from 0x%p @ %dus\n", 121 dev_info(&pdev->dev, "32bits from 0x%p @ %dus\n",
131 timeriomem_rng_data->address, 122 timeriomem_rng_data->address,
@@ -133,24 +124,19 @@ static int __init timeriomem_rng_probe(struct platform_device *pdev)
133 124
134 return 0; 125 return 0;
135 126
136err_register: 127failed:
137 dev_err(&pdev->dev, "problem registering\n"); 128 dev_err(&pdev->dev, "problem registering\n");
138 iounmap(timeriomem_rng_data->address); 129 iounmap(timeriomem_rng_data->address);
139err_ioremap:
140 release_resource(mem);
141 130
142 return ret; 131 return ret;
143} 132}
144 133
145static int __devexit timeriomem_rng_remove(struct platform_device *pdev) 134static int __devexit timeriomem_rng_remove(struct platform_device *pdev)
146{ 135{
147 struct resource *mem = dev_get_drvdata(&pdev->dev);
148
149 del_timer_sync(&timeriomem_rng_timer); 136 del_timer_sync(&timeriomem_rng_timer);
150 hwrng_unregister(&timeriomem_rng_ops); 137 hwrng_unregister(&timeriomem_rng_ops);
151 138
152 iounmap(timeriomem_rng_data->address); 139 iounmap(timeriomem_rng_data->address);
153 release_resource(mem);
154 140
155 return 0; 141 return 0;
156} 142}
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 4e9573c1d39e..794aacb715c1 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -132,6 +132,19 @@ static int via_rng_init(struct hwrng *rng)
132 struct cpuinfo_x86 *c = &cpu_data(0); 132 struct cpuinfo_x86 *c = &cpu_data(0);
133 u32 lo, hi, old_lo; 133 u32 lo, hi, old_lo;
134 134
135 /* VIA Nano CPUs don't have the MSR_VIA_RNG anymore. The RNG
136 * is always enabled if CPUID rng_en is set. There is no
137 * RNG configuration like it used to be the case in this
138 * register */
139 if ((c->x86 == 6) && (c->x86_model >= 0x0f)) {
140 if (!cpu_has_xstore_enabled) {
141 printk(KERN_ERR PFX "can't enable hardware RNG "
142 "if XSTORE is not enabled\n");
143 return -ENODEV;
144 }
145 return 0;
146 }
147
135 /* Control the RNG via MSR. Tread lightly and pay very close 148 /* Control the RNG via MSR. Tread lightly and pay very close
136 * close attention to values written, as the reserved fields 149 * close attention to values written, as the reserved fields
137 * are documented to be "undefined and unpredictable"; but it 150 * are documented to be "undefined and unpredictable"; but it
@@ -205,5 +218,5 @@ static void __exit mod_exit(void)
205module_init(mod_init); 218module_init(mod_init);
206module_exit(mod_exit); 219module_exit(mod_exit);
207 220
208MODULE_DESCRIPTION("H/W RNG driver for VIA chipsets"); 221MODULE_DESCRIPTION("H/W RNG driver for VIA CPU with PadLock");
209MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 01afd758072f..e748e55bd86b 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -12,7 +12,7 @@ if CRYPTO_HW
12 12
13config CRYPTO_DEV_PADLOCK 13config CRYPTO_DEV_PADLOCK
14 tristate "Support for VIA PadLock ACE" 14 tristate "Support for VIA PadLock ACE"
15 depends on X86_32 && !UML 15 depends on X86 && !UML
16 select CRYPTO_ALGAPI 16 select CRYPTO_ALGAPI
17 help 17 help
18 Some VIA processors come with an integrated crypto engine 18 Some VIA processors come with an integrated crypto engine
diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
index 2bef086fb342..5f753fc08730 100644
--- a/drivers/crypto/hifn_795x.c
+++ b/drivers/crypto/hifn_795x.c
@@ -2564,7 +2564,7 @@ static void hifn_tasklet_callback(unsigned long data)
2564 hifn_process_queue(dev); 2564 hifn_process_queue(dev);
2565} 2565}
2566 2566
2567static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id) 2567static int __devinit hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2568{ 2568{
2569 int err, i; 2569 int err, i;
2570 struct hifn_device *dev; 2570 struct hifn_device *dev;
@@ -2696,7 +2696,7 @@ err_out_disable_pci_device:
2696 return err; 2696 return err;
2697} 2697}
2698 2698
2699static void hifn_remove(struct pci_dev *pdev) 2699static void __devexit hifn_remove(struct pci_dev *pdev)
2700{ 2700{
2701 int i; 2701 int i;
2702 struct hifn_device *dev; 2702 struct hifn_device *dev;
@@ -2744,7 +2744,7 @@ static struct pci_driver hifn_pci_driver = {
2744 .remove = __devexit_p(hifn_remove), 2744 .remove = __devexit_p(hifn_remove),
2745}; 2745};
2746 2746
2747static int __devinit hifn_init(void) 2747static int __init hifn_init(void)
2748{ 2748{
2749 unsigned int freq; 2749 unsigned int freq;
2750 int err; 2750 int err;
@@ -2789,7 +2789,7 @@ static int __devinit hifn_init(void)
2789 return 0; 2789 return 0;
2790} 2790}
2791 2791
2792static void __devexit hifn_fini(void) 2792static void __exit hifn_fini(void)
2793{ 2793{
2794 pci_unregister_driver(&hifn_pci_driver); 2794 pci_unregister_driver(&hifn_pci_driver);
2795 2795
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 856b3cc25583..87f92c39b5f0 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -154,7 +154,11 @@ static inline void padlock_reset_key(struct cword *cword)
154 int cpu = raw_smp_processor_id(); 154 int cpu = raw_smp_processor_id();
155 155
156 if (cword != per_cpu(last_cword, cpu)) 156 if (cword != per_cpu(last_cword, cpu))
157#ifndef CONFIG_X86_64
157 asm volatile ("pushfl; popfl"); 158 asm volatile ("pushfl; popfl");
159#else
160 asm volatile ("pushfq; popfq");
161#endif
158} 162}
159 163
160static inline void padlock_store_cword(struct cword *cword) 164static inline void padlock_store_cword(struct cword *cword)
@@ -208,10 +212,19 @@ static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
208 212
209 asm volatile ("test $1, %%cl;" 213 asm volatile ("test $1, %%cl;"
210 "je 1f;" 214 "je 1f;"
215#ifndef CONFIG_X86_64
211 "lea -1(%%ecx), %%eax;" 216 "lea -1(%%ecx), %%eax;"
212 "mov $1, %%ecx;" 217 "mov $1, %%ecx;"
218#else
219 "lea -1(%%rcx), %%rax;"
220 "mov $1, %%rcx;"
221#endif
213 ".byte 0xf3,0x0f,0xa7,0xc8;" /* rep xcryptecb */ 222 ".byte 0xf3,0x0f,0xa7,0xc8;" /* rep xcryptecb */
223#ifndef CONFIG_X86_64
214 "mov %%eax, %%ecx;" 224 "mov %%eax, %%ecx;"
225#else
226 "mov %%rax, %%rcx;"
227#endif
215 "1:" 228 "1:"
216 ".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */ 229 ".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */
217 : "+S"(input), "+D"(output) 230 : "+S"(input), "+D"(output)
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index a3918c16b3db..c70775fd3ce2 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -44,6 +44,8 @@
44#include <crypto/sha.h> 44#include <crypto/sha.h>
45#include <crypto/aead.h> 45#include <crypto/aead.h>
46#include <crypto/authenc.h> 46#include <crypto/authenc.h>
47#include <crypto/skcipher.h>
48#include <crypto/scatterwalk.h>
47 49
48#include "talitos.h" 50#include "talitos.h"
49 51
@@ -339,7 +341,8 @@ static void flush_channel(struct device *dev, int ch, int error, int reset_ch)
339 status = error; 341 status = error;
340 342
341 dma_unmap_single(dev, request->dma_desc, 343 dma_unmap_single(dev, request->dma_desc,
342 sizeof(struct talitos_desc), DMA_BIDIRECTIONAL); 344 sizeof(struct talitos_desc),
345 DMA_BIDIRECTIONAL);
343 346
344 /* copy entries so we can call callback outside lock */ 347 /* copy entries so we can call callback outside lock */
345 saved_req.desc = request->desc; 348 saved_req.desc = request->desc;
@@ -413,7 +416,8 @@ static struct talitos_desc *current_desc(struct device *dev, int ch)
413/* 416/*
414 * user diagnostics; report root cause of error based on execution unit status 417 * user diagnostics; report root cause of error based on execution unit status
415 */ 418 */
416static void report_eu_error(struct device *dev, int ch, struct talitos_desc *desc) 419static void report_eu_error(struct device *dev, int ch,
420 struct talitos_desc *desc)
417{ 421{
418 struct talitos_private *priv = dev_get_drvdata(dev); 422 struct talitos_private *priv = dev_get_drvdata(dev);
419 int i; 423 int i;
@@ -684,8 +688,8 @@ struct talitos_ctx {
684 unsigned int authsize; 688 unsigned int authsize;
685}; 689};
686 690
687static int aead_authenc_setauthsize(struct crypto_aead *authenc, 691static int aead_setauthsize(struct crypto_aead *authenc,
688 unsigned int authsize) 692 unsigned int authsize)
689{ 693{
690 struct talitos_ctx *ctx = crypto_aead_ctx(authenc); 694 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
691 695
@@ -694,8 +698,8 @@ static int aead_authenc_setauthsize(struct crypto_aead *authenc,
694 return 0; 698 return 0;
695} 699}
696 700
697static int aead_authenc_setkey(struct crypto_aead *authenc, 701static int aead_setkey(struct crypto_aead *authenc,
698 const u8 *key, unsigned int keylen) 702 const u8 *key, unsigned int keylen)
699{ 703{
700 struct talitos_ctx *ctx = crypto_aead_ctx(authenc); 704 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
701 struct rtattr *rta = (void *)key; 705 struct rtattr *rta = (void *)key;
@@ -740,7 +744,7 @@ badkey:
740} 744}
741 745
742/* 746/*
743 * ipsec_esp_edesc - s/w-extended ipsec_esp descriptor 747 * talitos_edesc - s/w-extended descriptor
744 * @src_nents: number of segments in input scatterlist 748 * @src_nents: number of segments in input scatterlist
745 * @dst_nents: number of segments in output scatterlist 749 * @dst_nents: number of segments in output scatterlist
746 * @dma_len: length of dma mapped link_tbl space 750 * @dma_len: length of dma mapped link_tbl space
@@ -752,17 +756,67 @@ badkey:
752 * is greater than 1, an integrity check value is concatenated to the end 756 * is greater than 1, an integrity check value is concatenated to the end
753 * of link_tbl data 757 * of link_tbl data
754 */ 758 */
755struct ipsec_esp_edesc { 759struct talitos_edesc {
756 int src_nents; 760 int src_nents;
757 int dst_nents; 761 int dst_nents;
762 int src_is_chained;
763 int dst_is_chained;
758 int dma_len; 764 int dma_len;
759 dma_addr_t dma_link_tbl; 765 dma_addr_t dma_link_tbl;
760 struct talitos_desc desc; 766 struct talitos_desc desc;
761 struct talitos_ptr link_tbl[0]; 767 struct talitos_ptr link_tbl[0];
762}; 768};
763 769
770static int talitos_map_sg(struct device *dev, struct scatterlist *sg,
771 unsigned int nents, enum dma_data_direction dir,
772 int chained)
773{
774 if (unlikely(chained))
775 while (sg) {
776 dma_map_sg(dev, sg, 1, dir);
777 sg = scatterwalk_sg_next(sg);
778 }
779 else
780 dma_map_sg(dev, sg, nents, dir);
781 return nents;
782}
783
784static void talitos_unmap_sg_chain(struct device *dev, struct scatterlist *sg,
785 enum dma_data_direction dir)
786{
787 while (sg) {
788 dma_unmap_sg(dev, sg, 1, dir);
789 sg = scatterwalk_sg_next(sg);
790 }
791}
792
793static void talitos_sg_unmap(struct device *dev,
794 struct talitos_edesc *edesc,
795 struct scatterlist *src,
796 struct scatterlist *dst)
797{
798 unsigned int src_nents = edesc->src_nents ? : 1;
799 unsigned int dst_nents = edesc->dst_nents ? : 1;
800
801 if (src != dst) {
802 if (edesc->src_is_chained)
803 talitos_unmap_sg_chain(dev, src, DMA_TO_DEVICE);
804 else
805 dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
806
807 if (edesc->dst_is_chained)
808 talitos_unmap_sg_chain(dev, dst, DMA_FROM_DEVICE);
809 else
810 dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
811 } else
812 if (edesc->src_is_chained)
813 talitos_unmap_sg_chain(dev, src, DMA_BIDIRECTIONAL);
814 else
815 dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
816}
817
764static void ipsec_esp_unmap(struct device *dev, 818static void ipsec_esp_unmap(struct device *dev,
765 struct ipsec_esp_edesc *edesc, 819 struct talitos_edesc *edesc,
766 struct aead_request *areq) 820 struct aead_request *areq)
767{ 821{
768 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[6], DMA_FROM_DEVICE); 822 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[6], DMA_FROM_DEVICE);
@@ -772,15 +826,7 @@ static void ipsec_esp_unmap(struct device *dev,
772 826
773 dma_unmap_sg(dev, areq->assoc, 1, DMA_TO_DEVICE); 827 dma_unmap_sg(dev, areq->assoc, 1, DMA_TO_DEVICE);
774 828
775 if (areq->src != areq->dst) { 829 talitos_sg_unmap(dev, edesc, areq->src, areq->dst);
776 dma_unmap_sg(dev, areq->src, edesc->src_nents ? : 1,
777 DMA_TO_DEVICE);
778 dma_unmap_sg(dev, areq->dst, edesc->dst_nents ? : 1,
779 DMA_FROM_DEVICE);
780 } else {
781 dma_unmap_sg(dev, areq->src, edesc->src_nents ? : 1,
782 DMA_BIDIRECTIONAL);
783 }
784 830
785 if (edesc->dma_len) 831 if (edesc->dma_len)
786 dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len, 832 dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len,
@@ -795,13 +841,14 @@ static void ipsec_esp_encrypt_done(struct device *dev,
795 int err) 841 int err)
796{ 842{
797 struct aead_request *areq = context; 843 struct aead_request *areq = context;
798 struct ipsec_esp_edesc *edesc =
799 container_of(desc, struct ipsec_esp_edesc, desc);
800 struct crypto_aead *authenc = crypto_aead_reqtfm(areq); 844 struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
801 struct talitos_ctx *ctx = crypto_aead_ctx(authenc); 845 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
846 struct talitos_edesc *edesc;
802 struct scatterlist *sg; 847 struct scatterlist *sg;
803 void *icvdata; 848 void *icvdata;
804 849
850 edesc = container_of(desc, struct talitos_edesc, desc);
851
805 ipsec_esp_unmap(dev, edesc, areq); 852 ipsec_esp_unmap(dev, edesc, areq);
806 853
807 /* copy the generated ICV to dst */ 854 /* copy the generated ICV to dst */
@@ -819,17 +866,18 @@ static void ipsec_esp_encrypt_done(struct device *dev,
819} 866}
820 867
821static void ipsec_esp_decrypt_swauth_done(struct device *dev, 868static void ipsec_esp_decrypt_swauth_done(struct device *dev,
822 struct talitos_desc *desc, void *context, 869 struct talitos_desc *desc,
823 int err) 870 void *context, int err)
824{ 871{
825 struct aead_request *req = context; 872 struct aead_request *req = context;
826 struct ipsec_esp_edesc *edesc =
827 container_of(desc, struct ipsec_esp_edesc, desc);
828 struct crypto_aead *authenc = crypto_aead_reqtfm(req); 873 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
829 struct talitos_ctx *ctx = crypto_aead_ctx(authenc); 874 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
875 struct talitos_edesc *edesc;
830 struct scatterlist *sg; 876 struct scatterlist *sg;
831 void *icvdata; 877 void *icvdata;
832 878
879 edesc = container_of(desc, struct talitos_edesc, desc);
880
833 ipsec_esp_unmap(dev, edesc, req); 881 ipsec_esp_unmap(dev, edesc, req);
834 882
835 if (!err) { 883 if (!err) {
@@ -851,20 +899,20 @@ static void ipsec_esp_decrypt_swauth_done(struct device *dev,
851} 899}
852 900
853static void ipsec_esp_decrypt_hwauth_done(struct device *dev, 901static void ipsec_esp_decrypt_hwauth_done(struct device *dev,
854 struct talitos_desc *desc, void *context, 902 struct talitos_desc *desc,
855 int err) 903 void *context, int err)
856{ 904{
857 struct aead_request *req = context; 905 struct aead_request *req = context;
858 struct ipsec_esp_edesc *edesc = 906 struct talitos_edesc *edesc;
859 container_of(desc, struct ipsec_esp_edesc, desc); 907
908 edesc = container_of(desc, struct talitos_edesc, desc);
860 909
861 ipsec_esp_unmap(dev, edesc, req); 910 ipsec_esp_unmap(dev, edesc, req);
862 911
863 /* check ICV auth status */ 912 /* check ICV auth status */
864 if (!err) 913 if (!err && ((desc->hdr_lo & DESC_HDR_LO_ICCR1_MASK) !=
865 if ((desc->hdr_lo & DESC_HDR_LO_ICCR1_MASK) != 914 DESC_HDR_LO_ICCR1_PASS))
866 DESC_HDR_LO_ICCR1_PASS) 915 err = -EBADMSG;
867 err = -EBADMSG;
868 916
869 kfree(edesc); 917 kfree(edesc);
870 918
@@ -886,7 +934,7 @@ static int sg_to_link_tbl(struct scatterlist *sg, int sg_count,
886 link_tbl_ptr->j_extent = 0; 934 link_tbl_ptr->j_extent = 0;
887 link_tbl_ptr++; 935 link_tbl_ptr++;
888 cryptlen -= sg_dma_len(sg); 936 cryptlen -= sg_dma_len(sg);
889 sg = sg_next(sg); 937 sg = scatterwalk_sg_next(sg);
890 } 938 }
891 939
892 /* adjust (decrease) last one (or two) entry's len to cryptlen */ 940 /* adjust (decrease) last one (or two) entry's len to cryptlen */
@@ -910,7 +958,7 @@ static int sg_to_link_tbl(struct scatterlist *sg, int sg_count,
910/* 958/*
911 * fill in and submit ipsec_esp descriptor 959 * fill in and submit ipsec_esp descriptor
912 */ 960 */
913static int ipsec_esp(struct ipsec_esp_edesc *edesc, struct aead_request *areq, 961static int ipsec_esp(struct talitos_edesc *edesc, struct aead_request *areq,
914 u8 *giv, u64 seq, 962 u8 *giv, u64 seq,
915 void (*callback) (struct device *dev, 963 void (*callback) (struct device *dev,
916 struct talitos_desc *desc, 964 struct talitos_desc *desc,
@@ -952,32 +1000,31 @@ static int ipsec_esp(struct ipsec_esp_edesc *edesc, struct aead_request *areq,
952 desc->ptr[4].len = cpu_to_be16(cryptlen); 1000 desc->ptr[4].len = cpu_to_be16(cryptlen);
953 desc->ptr[4].j_extent = authsize; 1001 desc->ptr[4].j_extent = authsize;
954 1002
955 if (areq->src == areq->dst) 1003 sg_count = talitos_map_sg(dev, areq->src, edesc->src_nents ? : 1,
956 sg_count = dma_map_sg(dev, areq->src, edesc->src_nents ? : 1, 1004 (areq->src == areq->dst) ? DMA_BIDIRECTIONAL
957 DMA_BIDIRECTIONAL); 1005 : DMA_TO_DEVICE,
958 else 1006 edesc->src_is_chained);
959 sg_count = dma_map_sg(dev, areq->src, edesc->src_nents ? : 1,
960 DMA_TO_DEVICE);
961 1007
962 if (sg_count == 1) { 1008 if (sg_count == 1) {
963 desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->src)); 1009 desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->src));
964 } else { 1010 } else {
965 sg_link_tbl_len = cryptlen; 1011 sg_link_tbl_len = cryptlen;
966 1012
967 if ((edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV) && 1013 if (edesc->desc.hdr & DESC_HDR_MODE1_MDEU_CICV)
968 (edesc->desc.hdr & DESC_HDR_MODE0_ENCRYPT) == 0) {
969 sg_link_tbl_len = cryptlen + authsize; 1014 sg_link_tbl_len = cryptlen + authsize;
970 } 1015
971 sg_count = sg_to_link_tbl(areq->src, sg_count, sg_link_tbl_len, 1016 sg_count = sg_to_link_tbl(areq->src, sg_count, sg_link_tbl_len,
972 &edesc->link_tbl[0]); 1017 &edesc->link_tbl[0]);
973 if (sg_count > 1) { 1018 if (sg_count > 1) {
974 desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP; 1019 desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP;
975 desc->ptr[4].ptr = cpu_to_be32(edesc->dma_link_tbl); 1020 desc->ptr[4].ptr = cpu_to_be32(edesc->dma_link_tbl);
976 dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl, 1021 dma_sync_single_for_device(dev, edesc->dma_link_tbl,
977 edesc->dma_len, DMA_BIDIRECTIONAL); 1022 edesc->dma_len,
1023 DMA_BIDIRECTIONAL);
978 } else { 1024 } else {
979 /* Only one segment now, so no link tbl needed */ 1025 /* Only one segment now, so no link tbl needed */
980 desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->src)); 1026 desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->
1027 src));
981 } 1028 }
982 } 1029 }
983 1030
@@ -985,10 +1032,11 @@ static int ipsec_esp(struct ipsec_esp_edesc *edesc, struct aead_request *areq,
985 desc->ptr[5].len = cpu_to_be16(cryptlen); 1032 desc->ptr[5].len = cpu_to_be16(cryptlen);
986 desc->ptr[5].j_extent = authsize; 1033 desc->ptr[5].j_extent = authsize;
987 1034
988 if (areq->src != areq->dst) { 1035 if (areq->src != areq->dst)
989 sg_count = dma_map_sg(dev, areq->dst, edesc->dst_nents ? : 1, 1036 sg_count = talitos_map_sg(dev, areq->dst,
990 DMA_FROM_DEVICE); 1037 edesc->dst_nents ? : 1,
991 } 1038 DMA_FROM_DEVICE,
1039 edesc->dst_is_chained);
992 1040
993 if (sg_count == 1) { 1041 if (sg_count == 1) {
994 desc->ptr[5].ptr = cpu_to_be32(sg_dma_address(areq->dst)); 1042 desc->ptr[5].ptr = cpu_to_be32(sg_dma_address(areq->dst));
@@ -1033,49 +1081,55 @@ static int ipsec_esp(struct ipsec_esp_edesc *edesc, struct aead_request *areq,
1033 return ret; 1081 return ret;
1034} 1082}
1035 1083
1036
1037/* 1084/*
1038 * derive number of elements in scatterlist 1085 * derive number of elements in scatterlist
1039 */ 1086 */
1040static int sg_count(struct scatterlist *sg_list, int nbytes) 1087static int sg_count(struct scatterlist *sg_list, int nbytes, int *chained)
1041{ 1088{
1042 struct scatterlist *sg = sg_list; 1089 struct scatterlist *sg = sg_list;
1043 int sg_nents = 0; 1090 int sg_nents = 0;
1044 1091
1045 while (nbytes) { 1092 *chained = 0;
1093 while (nbytes > 0) {
1046 sg_nents++; 1094 sg_nents++;
1047 nbytes -= sg->length; 1095 nbytes -= sg->length;
1048 sg = sg_next(sg); 1096 if (!sg_is_last(sg) && (sg + 1)->length == 0)
1097 *chained = 1;
1098 sg = scatterwalk_sg_next(sg);
1049 } 1099 }
1050 1100
1051 return sg_nents; 1101 return sg_nents;
1052} 1102}
1053 1103
1054/* 1104/*
1055 * allocate and map the ipsec_esp extended descriptor 1105 * allocate and map the extended descriptor
1056 */ 1106 */
1057static struct ipsec_esp_edesc *ipsec_esp_edesc_alloc(struct aead_request *areq, 1107static struct talitos_edesc *talitos_edesc_alloc(struct device *dev,
1058 int icv_stashing) 1108 struct scatterlist *src,
1109 struct scatterlist *dst,
1110 unsigned int cryptlen,
1111 unsigned int authsize,
1112 int icv_stashing,
1113 u32 cryptoflags)
1059{ 1114{
1060 struct crypto_aead *authenc = crypto_aead_reqtfm(areq); 1115 struct talitos_edesc *edesc;
1061 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
1062 struct ipsec_esp_edesc *edesc;
1063 int src_nents, dst_nents, alloc_len, dma_len; 1116 int src_nents, dst_nents, alloc_len, dma_len;
1064 gfp_t flags = areq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : 1117 int src_chained, dst_chained = 0;
1118 gfp_t flags = cryptoflags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL :
1065 GFP_ATOMIC; 1119 GFP_ATOMIC;
1066 1120
1067 if (areq->cryptlen + ctx->authsize > TALITOS_MAX_DATA_LEN) { 1121 if (cryptlen + authsize > TALITOS_MAX_DATA_LEN) {
1068 dev_err(ctx->dev, "cryptlen exceeds h/w max limit\n"); 1122 dev_err(dev, "length exceeds h/w max limit\n");
1069 return ERR_PTR(-EINVAL); 1123 return ERR_PTR(-EINVAL);
1070 } 1124 }
1071 1125
1072 src_nents = sg_count(areq->src, areq->cryptlen + ctx->authsize); 1126 src_nents = sg_count(src, cryptlen + authsize, &src_chained);
1073 src_nents = (src_nents == 1) ? 0 : src_nents; 1127 src_nents = (src_nents == 1) ? 0 : src_nents;
1074 1128
1075 if (areq->dst == areq->src) { 1129 if (dst == src) {
1076 dst_nents = src_nents; 1130 dst_nents = src_nents;
1077 } else { 1131 } else {
1078 dst_nents = sg_count(areq->dst, areq->cryptlen + ctx->authsize); 1132 dst_nents = sg_count(dst, cryptlen + authsize, &dst_chained);
1079 dst_nents = (dst_nents == 1) ? 0 : dst_nents; 1133 dst_nents = (dst_nents == 1) ? 0 : dst_nents;
1080 } 1134 }
1081 1135
@@ -1084,39 +1138,52 @@ static struct ipsec_esp_edesc *ipsec_esp_edesc_alloc(struct aead_request *areq,
1084 * allowing for two separate entries for ICV and generated ICV (+ 2), 1138 * allowing for two separate entries for ICV and generated ICV (+ 2),
1085 * and the ICV data itself 1139 * and the ICV data itself
1086 */ 1140 */
1087 alloc_len = sizeof(struct ipsec_esp_edesc); 1141 alloc_len = sizeof(struct talitos_edesc);
1088 if (src_nents || dst_nents) { 1142 if (src_nents || dst_nents) {
1089 dma_len = (src_nents + dst_nents + 2) * 1143 dma_len = (src_nents + dst_nents + 2) *
1090 sizeof(struct talitos_ptr) + ctx->authsize; 1144 sizeof(struct talitos_ptr) + authsize;
1091 alloc_len += dma_len; 1145 alloc_len += dma_len;
1092 } else { 1146 } else {
1093 dma_len = 0; 1147 dma_len = 0;
1094 alloc_len += icv_stashing ? ctx->authsize : 0; 1148 alloc_len += icv_stashing ? authsize : 0;
1095 } 1149 }
1096 1150
1097 edesc = kmalloc(alloc_len, GFP_DMA | flags); 1151 edesc = kmalloc(alloc_len, GFP_DMA | flags);
1098 if (!edesc) { 1152 if (!edesc) {
1099 dev_err(ctx->dev, "could not allocate edescriptor\n"); 1153 dev_err(dev, "could not allocate edescriptor\n");
1100 return ERR_PTR(-ENOMEM); 1154 return ERR_PTR(-ENOMEM);
1101 } 1155 }
1102 1156
1103 edesc->src_nents = src_nents; 1157 edesc->src_nents = src_nents;
1104 edesc->dst_nents = dst_nents; 1158 edesc->dst_nents = dst_nents;
1159 edesc->src_is_chained = src_chained;
1160 edesc->dst_is_chained = dst_chained;
1105 edesc->dma_len = dma_len; 1161 edesc->dma_len = dma_len;
1106 edesc->dma_link_tbl = dma_map_single(ctx->dev, &edesc->link_tbl[0], 1162 edesc->dma_link_tbl = dma_map_single(dev, &edesc->link_tbl[0],
1107 edesc->dma_len, DMA_BIDIRECTIONAL); 1163 edesc->dma_len, DMA_BIDIRECTIONAL);
1108 1164
1109 return edesc; 1165 return edesc;
1110} 1166}
1111 1167
1112static int aead_authenc_encrypt(struct aead_request *req) 1168static struct talitos_edesc *aead_edesc_alloc(struct aead_request *areq,
1169 int icv_stashing)
1170{
1171 struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
1172 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
1173
1174 return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst,
1175 areq->cryptlen, ctx->authsize, icv_stashing,
1176 areq->base.flags);
1177}
1178
1179static int aead_encrypt(struct aead_request *req)
1113{ 1180{
1114 struct crypto_aead *authenc = crypto_aead_reqtfm(req); 1181 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
1115 struct talitos_ctx *ctx = crypto_aead_ctx(authenc); 1182 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
1116 struct ipsec_esp_edesc *edesc; 1183 struct talitos_edesc *edesc;
1117 1184
1118 /* allocate extended descriptor */ 1185 /* allocate extended descriptor */
1119 edesc = ipsec_esp_edesc_alloc(req, 0); 1186 edesc = aead_edesc_alloc(req, 0);
1120 if (IS_ERR(edesc)) 1187 if (IS_ERR(edesc))
1121 return PTR_ERR(edesc); 1188 return PTR_ERR(edesc);
1122 1189
@@ -1126,70 +1193,67 @@ static int aead_authenc_encrypt(struct aead_request *req)
1126 return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_encrypt_done); 1193 return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_encrypt_done);
1127} 1194}
1128 1195
1129 1196static int aead_decrypt(struct aead_request *req)
1130
1131static int aead_authenc_decrypt(struct aead_request *req)
1132{ 1197{
1133 struct crypto_aead *authenc = crypto_aead_reqtfm(req); 1198 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
1134 struct talitos_ctx *ctx = crypto_aead_ctx(authenc); 1199 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
1135 unsigned int authsize = ctx->authsize; 1200 unsigned int authsize = ctx->authsize;
1136 struct talitos_private *priv = dev_get_drvdata(ctx->dev); 1201 struct talitos_private *priv = dev_get_drvdata(ctx->dev);
1137 struct ipsec_esp_edesc *edesc; 1202 struct talitos_edesc *edesc;
1138 struct scatterlist *sg; 1203 struct scatterlist *sg;
1139 void *icvdata; 1204 void *icvdata;
1140 1205
1141 req->cryptlen -= authsize; 1206 req->cryptlen -= authsize;
1142 1207
1143 /* allocate extended descriptor */ 1208 /* allocate extended descriptor */
1144 edesc = ipsec_esp_edesc_alloc(req, 1); 1209 edesc = aead_edesc_alloc(req, 1);
1145 if (IS_ERR(edesc)) 1210 if (IS_ERR(edesc))
1146 return PTR_ERR(edesc); 1211 return PTR_ERR(edesc);
1147 1212
1148 if ((priv->features & TALITOS_FTR_HW_AUTH_CHECK) && 1213 if ((priv->features & TALITOS_FTR_HW_AUTH_CHECK) &&
1149 (((!edesc->src_nents && !edesc->dst_nents) || 1214 ((!edesc->src_nents && !edesc->dst_nents) ||
1150 priv->features & TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT))) { 1215 priv->features & TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT)) {
1151 1216
1152 /* decrypt and check the ICV */ 1217 /* decrypt and check the ICV */
1153 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND | 1218 edesc->desc.hdr = ctx->desc_hdr_template |
1219 DESC_HDR_DIR_INBOUND |
1154 DESC_HDR_MODE1_MDEU_CICV; 1220 DESC_HDR_MODE1_MDEU_CICV;
1155 1221
1156 /* reset integrity check result bits */ 1222 /* reset integrity check result bits */
1157 edesc->desc.hdr_lo = 0; 1223 edesc->desc.hdr_lo = 0;
1158 1224
1159 return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_decrypt_hwauth_done); 1225 return ipsec_esp(edesc, req, NULL, 0,
1226 ipsec_esp_decrypt_hwauth_done);
1160 1227
1161 } else { 1228 }
1162
1163 /* Have to check the ICV with software */
1164 1229
1165 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND; 1230 /* Have to check the ICV with software */
1231 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND;
1166 1232
1167 /* stash incoming ICV for later cmp with ICV generated by the h/w */ 1233 /* stash incoming ICV for later cmp with ICV generated by the h/w */
1168 if (edesc->dma_len) 1234 if (edesc->dma_len)
1169 icvdata = &edesc->link_tbl[edesc->src_nents + 1235 icvdata = &edesc->link_tbl[edesc->src_nents +
1170 edesc->dst_nents + 2]; 1236 edesc->dst_nents + 2];
1171 else 1237 else
1172 icvdata = &edesc->link_tbl[0]; 1238 icvdata = &edesc->link_tbl[0];
1173 1239
1174 sg = sg_last(req->src, edesc->src_nents ? : 1); 1240 sg = sg_last(req->src, edesc->src_nents ? : 1);
1175 1241
1176 memcpy(icvdata, (char *)sg_virt(sg) + sg->length - ctx->authsize, 1242 memcpy(icvdata, (char *)sg_virt(sg) + sg->length - ctx->authsize,
1177 ctx->authsize); 1243 ctx->authsize);
1178 1244
1179 return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_decrypt_swauth_done); 1245 return ipsec_esp(edesc, req, NULL, 0, ipsec_esp_decrypt_swauth_done);
1180 }
1181} 1246}
1182 1247
1183static int aead_authenc_givencrypt( 1248static int aead_givencrypt(struct aead_givcrypt_request *req)
1184 struct aead_givcrypt_request *req)
1185{ 1249{
1186 struct aead_request *areq = &req->areq; 1250 struct aead_request *areq = &req->areq;
1187 struct crypto_aead *authenc = crypto_aead_reqtfm(areq); 1251 struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
1188 struct talitos_ctx *ctx = crypto_aead_ctx(authenc); 1252 struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
1189 struct ipsec_esp_edesc *edesc; 1253 struct talitos_edesc *edesc;
1190 1254
1191 /* allocate extended descriptor */ 1255 /* allocate extended descriptor */
1192 edesc = ipsec_esp_edesc_alloc(areq, 0); 1256 edesc = aead_edesc_alloc(areq, 0);
1193 if (IS_ERR(edesc)) 1257 if (IS_ERR(edesc))
1194 return PTR_ERR(edesc); 1258 return PTR_ERR(edesc);
1195 1259
@@ -1204,31 +1268,228 @@ static int aead_authenc_givencrypt(
1204 ipsec_esp_encrypt_done); 1268 ipsec_esp_encrypt_done);
1205} 1269}
1206 1270
1271static int ablkcipher_setkey(struct crypto_ablkcipher *cipher,
1272 const u8 *key, unsigned int keylen)
1273{
1274 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1275 struct ablkcipher_alg *alg = crypto_ablkcipher_alg(cipher);
1276
1277 if (keylen > TALITOS_MAX_KEY_SIZE)
1278 goto badkey;
1279
1280 if (keylen < alg->min_keysize || keylen > alg->max_keysize)
1281 goto badkey;
1282
1283 memcpy(&ctx->key, key, keylen);
1284 ctx->keylen = keylen;
1285
1286 return 0;
1287
1288badkey:
1289 crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
1290 return -EINVAL;
1291}
1292
1293static void common_nonsnoop_unmap(struct device *dev,
1294 struct talitos_edesc *edesc,
1295 struct ablkcipher_request *areq)
1296{
1297 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[5], DMA_FROM_DEVICE);
1298 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[2], DMA_TO_DEVICE);
1299 unmap_single_talitos_ptr(dev, &edesc->desc.ptr[1], DMA_TO_DEVICE);
1300
1301 talitos_sg_unmap(dev, edesc, areq->src, areq->dst);
1302
1303 if (edesc->dma_len)
1304 dma_unmap_single(dev, edesc->dma_link_tbl, edesc->dma_len,
1305 DMA_BIDIRECTIONAL);
1306}
1307
1308static void ablkcipher_done(struct device *dev,
1309 struct talitos_desc *desc, void *context,
1310 int err)
1311{
1312 struct ablkcipher_request *areq = context;
1313 struct talitos_edesc *edesc;
1314
1315 edesc = container_of(desc, struct talitos_edesc, desc);
1316
1317 common_nonsnoop_unmap(dev, edesc, areq);
1318
1319 kfree(edesc);
1320
1321 areq->base.complete(&areq->base, err);
1322}
1323
1324static int common_nonsnoop(struct talitos_edesc *edesc,
1325 struct ablkcipher_request *areq,
1326 u8 *giv,
1327 void (*callback) (struct device *dev,
1328 struct talitos_desc *desc,
1329 void *context, int error))
1330{
1331 struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1332 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1333 struct device *dev = ctx->dev;
1334 struct talitos_desc *desc = &edesc->desc;
1335 unsigned int cryptlen = areq->nbytes;
1336 unsigned int ivsize;
1337 int sg_count, ret;
1338
1339 /* first DWORD empty */
1340 desc->ptr[0].len = 0;
1341 desc->ptr[0].ptr = 0;
1342 desc->ptr[0].j_extent = 0;
1343
1344 /* cipher iv */
1345 ivsize = crypto_ablkcipher_ivsize(cipher);
1346 map_single_talitos_ptr(dev, &desc->ptr[1], ivsize, giv ?: areq->info, 0,
1347 DMA_TO_DEVICE);
1348
1349 /* cipher key */
1350 map_single_talitos_ptr(dev, &desc->ptr[2], ctx->keylen,
1351 (char *)&ctx->key, 0, DMA_TO_DEVICE);
1352
1353 /*
1354 * cipher in
1355 */
1356 desc->ptr[3].len = cpu_to_be16(cryptlen);
1357 desc->ptr[3].j_extent = 0;
1358
1359 sg_count = talitos_map_sg(dev, areq->src, edesc->src_nents ? : 1,
1360 (areq->src == areq->dst) ? DMA_BIDIRECTIONAL
1361 : DMA_TO_DEVICE,
1362 edesc->src_is_chained);
1363
1364 if (sg_count == 1) {
1365 desc->ptr[3].ptr = cpu_to_be32(sg_dma_address(areq->src));
1366 } else {
1367 sg_count = sg_to_link_tbl(areq->src, sg_count, cryptlen,
1368 &edesc->link_tbl[0]);
1369 if (sg_count > 1) {
1370 desc->ptr[3].j_extent |= DESC_PTR_LNKTBL_JUMP;
1371 desc->ptr[3].ptr = cpu_to_be32(edesc->dma_link_tbl);
1372 dma_sync_single_for_device(dev, edesc->dma_link_tbl,
1373 edesc->dma_len,
1374 DMA_BIDIRECTIONAL);
1375 } else {
1376 /* Only one segment now, so no link tbl needed */
1377 desc->ptr[3].ptr = cpu_to_be32(sg_dma_address(areq->
1378 src));
1379 }
1380 }
1381
1382 /* cipher out */
1383 desc->ptr[4].len = cpu_to_be16(cryptlen);
1384 desc->ptr[4].j_extent = 0;
1385
1386 if (areq->src != areq->dst)
1387 sg_count = talitos_map_sg(dev, areq->dst,
1388 edesc->dst_nents ? : 1,
1389 DMA_FROM_DEVICE,
1390 edesc->dst_is_chained);
1391
1392 if (sg_count == 1) {
1393 desc->ptr[4].ptr = cpu_to_be32(sg_dma_address(areq->dst));
1394 } else {
1395 struct talitos_ptr *link_tbl_ptr =
1396 &edesc->link_tbl[edesc->src_nents + 1];
1397
1398 desc->ptr[4].j_extent |= DESC_PTR_LNKTBL_JUMP;
1399 desc->ptr[4].ptr = cpu_to_be32((struct talitos_ptr *)
1400 edesc->dma_link_tbl +
1401 edesc->src_nents + 1);
1402 sg_count = sg_to_link_tbl(areq->dst, sg_count, cryptlen,
1403 link_tbl_ptr);
1404 dma_sync_single_for_device(ctx->dev, edesc->dma_link_tbl,
1405 edesc->dma_len, DMA_BIDIRECTIONAL);
1406 }
1407
1408 /* iv out */
1409 map_single_talitos_ptr(dev, &desc->ptr[5], ivsize, ctx->iv, 0,
1410 DMA_FROM_DEVICE);
1411
1412 /* last DWORD empty */
1413 desc->ptr[6].len = 0;
1414 desc->ptr[6].ptr = 0;
1415 desc->ptr[6].j_extent = 0;
1416
1417 ret = talitos_submit(dev, desc, callback, areq);
1418 if (ret != -EINPROGRESS) {
1419 common_nonsnoop_unmap(dev, edesc, areq);
1420 kfree(edesc);
1421 }
1422 return ret;
1423}
1424
1425static struct talitos_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request *
1426 areq)
1427{
1428 struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1429 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1430
1431 return talitos_edesc_alloc(ctx->dev, areq->src, areq->dst, areq->nbytes,
1432 0, 0, areq->base.flags);
1433}
1434
1435static int ablkcipher_encrypt(struct ablkcipher_request *areq)
1436{
1437 struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1438 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1439 struct talitos_edesc *edesc;
1440
1441 /* allocate extended descriptor */
1442 edesc = ablkcipher_edesc_alloc(areq);
1443 if (IS_ERR(edesc))
1444 return PTR_ERR(edesc);
1445
1446 /* set encrypt */
1447 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_MODE0_ENCRYPT;
1448
1449 return common_nonsnoop(edesc, areq, NULL, ablkcipher_done);
1450}
1451
1452static int ablkcipher_decrypt(struct ablkcipher_request *areq)
1453{
1454 struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1455 struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1456 struct talitos_edesc *edesc;
1457
1458 /* allocate extended descriptor */
1459 edesc = ablkcipher_edesc_alloc(areq);
1460 if (IS_ERR(edesc))
1461 return PTR_ERR(edesc);
1462
1463 edesc->desc.hdr = ctx->desc_hdr_template | DESC_HDR_DIR_INBOUND;
1464
1465 return common_nonsnoop(edesc, areq, NULL, ablkcipher_done);
1466}
1467
1207struct talitos_alg_template { 1468struct talitos_alg_template {
1208 char name[CRYPTO_MAX_ALG_NAME]; 1469 struct crypto_alg alg;
1209 char driver_name[CRYPTO_MAX_ALG_NAME];
1210 unsigned int blocksize;
1211 struct aead_alg aead;
1212 struct device *dev;
1213 __be32 desc_hdr_template; 1470 __be32 desc_hdr_template;
1214}; 1471};
1215 1472
1216static struct talitos_alg_template driver_algs[] = { 1473static struct talitos_alg_template driver_algs[] = {
1217 /* single-pass ipsec_esp descriptor */ 1474 /* AEAD algorithms. These use a single-pass ipsec_esp descriptor */
1218 { 1475 {
1219 .name = "authenc(hmac(sha1),cbc(aes))", 1476 .alg = {
1220 .driver_name = "authenc-hmac-sha1-cbc-aes-talitos", 1477 .cra_name = "authenc(hmac(sha1),cbc(aes))",
1221 .blocksize = AES_BLOCK_SIZE, 1478 .cra_driver_name = "authenc-hmac-sha1-cbc-aes-talitos",
1222 .aead = { 1479 .cra_blocksize = AES_BLOCK_SIZE,
1223 .setkey = aead_authenc_setkey, 1480 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1224 .setauthsize = aead_authenc_setauthsize, 1481 .cra_type = &crypto_aead_type,
1225 .encrypt = aead_authenc_encrypt, 1482 .cra_aead = {
1226 .decrypt = aead_authenc_decrypt, 1483 .setkey = aead_setkey,
1227 .givencrypt = aead_authenc_givencrypt, 1484 .setauthsize = aead_setauthsize,
1228 .geniv = "<built-in>", 1485 .encrypt = aead_encrypt,
1229 .ivsize = AES_BLOCK_SIZE, 1486 .decrypt = aead_decrypt,
1230 .maxauthsize = SHA1_DIGEST_SIZE, 1487 .givencrypt = aead_givencrypt,
1231 }, 1488 .geniv = "<built-in>",
1489 .ivsize = AES_BLOCK_SIZE,
1490 .maxauthsize = SHA1_DIGEST_SIZE,
1491 }
1492 },
1232 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | 1493 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1233 DESC_HDR_SEL0_AESU | 1494 DESC_HDR_SEL0_AESU |
1234 DESC_HDR_MODE0_AESU_CBC | 1495 DESC_HDR_MODE0_AESU_CBC |
@@ -1238,19 +1499,23 @@ static struct talitos_alg_template driver_algs[] = {
1238 DESC_HDR_MODE1_MDEU_SHA1_HMAC, 1499 DESC_HDR_MODE1_MDEU_SHA1_HMAC,
1239 }, 1500 },
1240 { 1501 {
1241 .name = "authenc(hmac(sha1),cbc(des3_ede))", 1502 .alg = {
1242 .driver_name = "authenc-hmac-sha1-cbc-3des-talitos", 1503 .cra_name = "authenc(hmac(sha1),cbc(des3_ede))",
1243 .blocksize = DES3_EDE_BLOCK_SIZE, 1504 .cra_driver_name = "authenc-hmac-sha1-cbc-3des-talitos",
1244 .aead = { 1505 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1245 .setkey = aead_authenc_setkey, 1506 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1246 .setauthsize = aead_authenc_setauthsize, 1507 .cra_type = &crypto_aead_type,
1247 .encrypt = aead_authenc_encrypt, 1508 .cra_aead = {
1248 .decrypt = aead_authenc_decrypt, 1509 .setkey = aead_setkey,
1249 .givencrypt = aead_authenc_givencrypt, 1510 .setauthsize = aead_setauthsize,
1250 .geniv = "<built-in>", 1511 .encrypt = aead_encrypt,
1251 .ivsize = DES3_EDE_BLOCK_SIZE, 1512 .decrypt = aead_decrypt,
1252 .maxauthsize = SHA1_DIGEST_SIZE, 1513 .givencrypt = aead_givencrypt,
1253 }, 1514 .geniv = "<built-in>",
1515 .ivsize = DES3_EDE_BLOCK_SIZE,
1516 .maxauthsize = SHA1_DIGEST_SIZE,
1517 }
1518 },
1254 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | 1519 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1255 DESC_HDR_SEL0_DEU | 1520 DESC_HDR_SEL0_DEU |
1256 DESC_HDR_MODE0_DEU_CBC | 1521 DESC_HDR_MODE0_DEU_CBC |
@@ -1261,19 +1526,23 @@ static struct talitos_alg_template driver_algs[] = {
1261 DESC_HDR_MODE1_MDEU_SHA1_HMAC, 1526 DESC_HDR_MODE1_MDEU_SHA1_HMAC,
1262 }, 1527 },
1263 { 1528 {
1264 .name = "authenc(hmac(sha256),cbc(aes))", 1529 .alg = {
1265 .driver_name = "authenc-hmac-sha256-cbc-aes-talitos", 1530 .cra_name = "authenc(hmac(sha256),cbc(aes))",
1266 .blocksize = AES_BLOCK_SIZE, 1531 .cra_driver_name = "authenc-hmac-sha256-cbc-aes-talitos",
1267 .aead = { 1532 .cra_blocksize = AES_BLOCK_SIZE,
1268 .setkey = aead_authenc_setkey, 1533 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1269 .setauthsize = aead_authenc_setauthsize, 1534 .cra_type = &crypto_aead_type,
1270 .encrypt = aead_authenc_encrypt, 1535 .cra_aead = {
1271 .decrypt = aead_authenc_decrypt, 1536 .setkey = aead_setkey,
1272 .givencrypt = aead_authenc_givencrypt, 1537 .setauthsize = aead_setauthsize,
1273 .geniv = "<built-in>", 1538 .encrypt = aead_encrypt,
1274 .ivsize = AES_BLOCK_SIZE, 1539 .decrypt = aead_decrypt,
1275 .maxauthsize = SHA256_DIGEST_SIZE, 1540 .givencrypt = aead_givencrypt,
1276 }, 1541 .geniv = "<built-in>",
1542 .ivsize = AES_BLOCK_SIZE,
1543 .maxauthsize = SHA256_DIGEST_SIZE,
1544 }
1545 },
1277 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | 1546 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1278 DESC_HDR_SEL0_AESU | 1547 DESC_HDR_SEL0_AESU |
1279 DESC_HDR_MODE0_AESU_CBC | 1548 DESC_HDR_MODE0_AESU_CBC |
@@ -1283,19 +1552,23 @@ static struct talitos_alg_template driver_algs[] = {
1283 DESC_HDR_MODE1_MDEU_SHA256_HMAC, 1552 DESC_HDR_MODE1_MDEU_SHA256_HMAC,
1284 }, 1553 },
1285 { 1554 {
1286 .name = "authenc(hmac(sha256),cbc(des3_ede))", 1555 .alg = {
1287 .driver_name = "authenc-hmac-sha256-cbc-3des-talitos", 1556 .cra_name = "authenc(hmac(sha256),cbc(des3_ede))",
1288 .blocksize = DES3_EDE_BLOCK_SIZE, 1557 .cra_driver_name = "authenc-hmac-sha256-cbc-3des-talitos",
1289 .aead = { 1558 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1290 .setkey = aead_authenc_setkey, 1559 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1291 .setauthsize = aead_authenc_setauthsize, 1560 .cra_type = &crypto_aead_type,
1292 .encrypt = aead_authenc_encrypt, 1561 .cra_aead = {
1293 .decrypt = aead_authenc_decrypt, 1562 .setkey = aead_setkey,
1294 .givencrypt = aead_authenc_givencrypt, 1563 .setauthsize = aead_setauthsize,
1295 .geniv = "<built-in>", 1564 .encrypt = aead_encrypt,
1296 .ivsize = DES3_EDE_BLOCK_SIZE, 1565 .decrypt = aead_decrypt,
1297 .maxauthsize = SHA256_DIGEST_SIZE, 1566 .givencrypt = aead_givencrypt,
1298 }, 1567 .geniv = "<built-in>",
1568 .ivsize = DES3_EDE_BLOCK_SIZE,
1569 .maxauthsize = SHA256_DIGEST_SIZE,
1570 }
1571 },
1299 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | 1572 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1300 DESC_HDR_SEL0_DEU | 1573 DESC_HDR_SEL0_DEU |
1301 DESC_HDR_MODE0_DEU_CBC | 1574 DESC_HDR_MODE0_DEU_CBC |
@@ -1306,19 +1579,23 @@ static struct talitos_alg_template driver_algs[] = {
1306 DESC_HDR_MODE1_MDEU_SHA256_HMAC, 1579 DESC_HDR_MODE1_MDEU_SHA256_HMAC,
1307 }, 1580 },
1308 { 1581 {
1309 .name = "authenc(hmac(md5),cbc(aes))", 1582 .alg = {
1310 .driver_name = "authenc-hmac-md5-cbc-aes-talitos", 1583 .cra_name = "authenc(hmac(md5),cbc(aes))",
1311 .blocksize = AES_BLOCK_SIZE, 1584 .cra_driver_name = "authenc-hmac-md5-cbc-aes-talitos",
1312 .aead = { 1585 .cra_blocksize = AES_BLOCK_SIZE,
1313 .setkey = aead_authenc_setkey, 1586 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1314 .setauthsize = aead_authenc_setauthsize, 1587 .cra_type = &crypto_aead_type,
1315 .encrypt = aead_authenc_encrypt, 1588 .cra_aead = {
1316 .decrypt = aead_authenc_decrypt, 1589 .setkey = aead_setkey,
1317 .givencrypt = aead_authenc_givencrypt, 1590 .setauthsize = aead_setauthsize,
1318 .geniv = "<built-in>", 1591 .encrypt = aead_encrypt,
1319 .ivsize = AES_BLOCK_SIZE, 1592 .decrypt = aead_decrypt,
1320 .maxauthsize = MD5_DIGEST_SIZE, 1593 .givencrypt = aead_givencrypt,
1321 }, 1594 .geniv = "<built-in>",
1595 .ivsize = AES_BLOCK_SIZE,
1596 .maxauthsize = MD5_DIGEST_SIZE,
1597 }
1598 },
1322 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | 1599 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1323 DESC_HDR_SEL0_AESU | 1600 DESC_HDR_SEL0_AESU |
1324 DESC_HDR_MODE0_AESU_CBC | 1601 DESC_HDR_MODE0_AESU_CBC |
@@ -1328,19 +1605,23 @@ static struct talitos_alg_template driver_algs[] = {
1328 DESC_HDR_MODE1_MDEU_MD5_HMAC, 1605 DESC_HDR_MODE1_MDEU_MD5_HMAC,
1329 }, 1606 },
1330 { 1607 {
1331 .name = "authenc(hmac(md5),cbc(des3_ede))", 1608 .alg = {
1332 .driver_name = "authenc-hmac-md5-cbc-3des-talitos", 1609 .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
1333 .blocksize = DES3_EDE_BLOCK_SIZE, 1610 .cra_driver_name = "authenc-hmac-md5-cbc-3des-talitos",
1334 .aead = { 1611 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1335 .setkey = aead_authenc_setkey, 1612 .cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC,
1336 .setauthsize = aead_authenc_setauthsize, 1613 .cra_type = &crypto_aead_type,
1337 .encrypt = aead_authenc_encrypt, 1614 .cra_aead = {
1338 .decrypt = aead_authenc_decrypt, 1615 .setkey = aead_setkey,
1339 .givencrypt = aead_authenc_givencrypt, 1616 .setauthsize = aead_setauthsize,
1340 .geniv = "<built-in>", 1617 .encrypt = aead_encrypt,
1341 .ivsize = DES3_EDE_BLOCK_SIZE, 1618 .decrypt = aead_decrypt,
1342 .maxauthsize = MD5_DIGEST_SIZE, 1619 .givencrypt = aead_givencrypt,
1343 }, 1620 .geniv = "<built-in>",
1621 .ivsize = DES3_EDE_BLOCK_SIZE,
1622 .maxauthsize = MD5_DIGEST_SIZE,
1623 }
1624 },
1344 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP | 1625 .desc_hdr_template = DESC_HDR_TYPE_IPSEC_ESP |
1345 DESC_HDR_SEL0_DEU | 1626 DESC_HDR_SEL0_DEU |
1346 DESC_HDR_MODE0_DEU_CBC | 1627 DESC_HDR_MODE0_DEU_CBC |
@@ -1349,6 +1630,52 @@ static struct talitos_alg_template driver_algs[] = {
1349 DESC_HDR_MODE1_MDEU_INIT | 1630 DESC_HDR_MODE1_MDEU_INIT |
1350 DESC_HDR_MODE1_MDEU_PAD | 1631 DESC_HDR_MODE1_MDEU_PAD |
1351 DESC_HDR_MODE1_MDEU_MD5_HMAC, 1632 DESC_HDR_MODE1_MDEU_MD5_HMAC,
1633 },
1634 /* ABLKCIPHER algorithms. */
1635 {
1636 .alg = {
1637 .cra_name = "cbc(aes)",
1638 .cra_driver_name = "cbc-aes-talitos",
1639 .cra_blocksize = AES_BLOCK_SIZE,
1640 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1641 CRYPTO_ALG_ASYNC,
1642 .cra_type = &crypto_ablkcipher_type,
1643 .cra_ablkcipher = {
1644 .setkey = ablkcipher_setkey,
1645 .encrypt = ablkcipher_encrypt,
1646 .decrypt = ablkcipher_decrypt,
1647 .geniv = "eseqiv",
1648 .min_keysize = AES_MIN_KEY_SIZE,
1649 .max_keysize = AES_MAX_KEY_SIZE,
1650 .ivsize = AES_BLOCK_SIZE,
1651 }
1652 },
1653 .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
1654 DESC_HDR_SEL0_AESU |
1655 DESC_HDR_MODE0_AESU_CBC,
1656 },
1657 {
1658 .alg = {
1659 .cra_name = "cbc(des3_ede)",
1660 .cra_driver_name = "cbc-3des-talitos",
1661 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1662 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1663 CRYPTO_ALG_ASYNC,
1664 .cra_type = &crypto_ablkcipher_type,
1665 .cra_ablkcipher = {
1666 .setkey = ablkcipher_setkey,
1667 .encrypt = ablkcipher_encrypt,
1668 .decrypt = ablkcipher_decrypt,
1669 .geniv = "eseqiv",
1670 .min_keysize = DES3_EDE_KEY_SIZE,
1671 .max_keysize = DES3_EDE_KEY_SIZE,
1672 .ivsize = DES3_EDE_BLOCK_SIZE,
1673 }
1674 },
1675 .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
1676 DESC_HDR_SEL0_DEU |
1677 DESC_HDR_MODE0_DEU_CBC |
1678 DESC_HDR_MODE0_DEU_3DES,
1352 } 1679 }
1353}; 1680};
1354 1681
@@ -1362,12 +1689,14 @@ struct talitos_crypto_alg {
1362static int talitos_cra_init(struct crypto_tfm *tfm) 1689static int talitos_cra_init(struct crypto_tfm *tfm)
1363{ 1690{
1364 struct crypto_alg *alg = tfm->__crt_alg; 1691 struct crypto_alg *alg = tfm->__crt_alg;
1365 struct talitos_crypto_alg *talitos_alg = 1692 struct talitos_crypto_alg *talitos_alg;
1366 container_of(alg, struct talitos_crypto_alg, crypto_alg);
1367 struct talitos_ctx *ctx = crypto_tfm_ctx(tfm); 1693 struct talitos_ctx *ctx = crypto_tfm_ctx(tfm);
1368 1694
1695 talitos_alg = container_of(alg, struct talitos_crypto_alg, crypto_alg);
1696
1369 /* update context with ptr to dev */ 1697 /* update context with ptr to dev */
1370 ctx->dev = talitos_alg->dev; 1698 ctx->dev = talitos_alg->dev;
1699
1371 /* copy descriptor header template value */ 1700 /* copy descriptor header template value */
1372 ctx->desc_hdr_template = talitos_alg->desc_hdr_template; 1701 ctx->desc_hdr_template = talitos_alg->desc_hdr_template;
1373 1702
@@ -1453,19 +1782,13 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
1453 return ERR_PTR(-ENOMEM); 1782 return ERR_PTR(-ENOMEM);
1454 1783
1455 alg = &t_alg->crypto_alg; 1784 alg = &t_alg->crypto_alg;
1785 *alg = template->alg;
1456 1786
1457 snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name);
1458 snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
1459 template->driver_name);
1460 alg->cra_module = THIS_MODULE; 1787 alg->cra_module = THIS_MODULE;
1461 alg->cra_init = talitos_cra_init; 1788 alg->cra_init = talitos_cra_init;
1462 alg->cra_priority = TALITOS_CRA_PRIORITY; 1789 alg->cra_priority = TALITOS_CRA_PRIORITY;
1463 alg->cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC;
1464 alg->cra_blocksize = template->blocksize;
1465 alg->cra_alignmask = 0; 1790 alg->cra_alignmask = 0;
1466 alg->cra_type = &crypto_aead_type;
1467 alg->cra_ctxsize = sizeof(struct talitos_ctx); 1791 alg->cra_ctxsize = sizeof(struct talitos_ctx);
1468 alg->cra_u.aead = template->aead;
1469 1792
1470 t_alg->desc_hdr_template = template->desc_hdr_template; 1793 t_alg->desc_hdr_template = template->desc_hdr_template;
1471 t_alg->dev = dev; 1794 t_alg->dev = dev;