aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorJohannes Goetzfried <Johannes.Goetzfried@informatik.stud.uni-erlangen.de>2012-07-11 13:37:04 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2012-08-01 05:47:29 -0400
commit270b0c6b406a0ae7673ee880d1d7cc6bd6c904de (patch)
treef73fc16f158c1cc3ff13ef6cd1019805ec79b53e /crypto
parent37743cc0d34c4c5cb8520bc27eb2a45141e938fe (diff)
crypto: cast5 - prepare generic module for optimized implementations
Rename cast5 module to cast5_generic to allow autoloading of optimized implementations. Generic functions and s-boxes are exported to be able to use them within optimized implementations. Signed-off-by: Johannes Goetzfried <Johannes.Goetzfried@informatik.stud.uni-erlangen.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/Makefile2
-rw-r--r--crypto/cast5_generic.c (renamed from crypto/cast5.c)79
2 files changed, 47 insertions, 34 deletions
diff --git a/crypto/Makefile b/crypto/Makefile
index 30f33d675330..a56821e5d573 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -68,7 +68,7 @@ obj-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o
68obj-$(CONFIG_CRYPTO_SERPENT) += serpent_generic.o 68obj-$(CONFIG_CRYPTO_SERPENT) += serpent_generic.o
69obj-$(CONFIG_CRYPTO_AES) += aes_generic.o 69obj-$(CONFIG_CRYPTO_AES) += aes_generic.o
70obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia_generic.o 70obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia_generic.o
71obj-$(CONFIG_CRYPTO_CAST5) += cast5.o 71obj-$(CONFIG_CRYPTO_CAST5) += cast5_generic.o
72obj-$(CONFIG_CRYPTO_CAST6) += cast6.o 72obj-$(CONFIG_CRYPTO_CAST6) += cast6.o
73obj-$(CONFIG_CRYPTO_ARC4) += arc4.o 73obj-$(CONFIG_CRYPTO_ARC4) += arc4.o
74obj-$(CONFIG_CRYPTO_TEA) += tea.o 74obj-$(CONFIG_CRYPTO_TEA) += tea.o
diff --git a/crypto/cast5.c b/crypto/cast5_generic.c
index fffcb37dec11..bc525dbd8a4b 100644
--- a/crypto/cast5.c
+++ b/crypto/cast5_generic.c
@@ -4,8 +4,8 @@
4* Derived from GnuPG implementation of cast5. 4* Derived from GnuPG implementation of cast5.
5* 5*
6* Major Changes. 6* Major Changes.
7* Complete conformance to rfc2144. 7* Complete conformance to rfc2144.
8* Supports key size from 40 to 128 bits. 8* Supports key size from 40 to 128 bits.
9* 9*
10* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. 10* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
11* Copyright (C) 2003 Kartikey Mahendra Bhatt <kartik_me@hotmail.com>. 11* Copyright (C) 2003 Kartikey Mahendra Bhatt <kartik_me@hotmail.com>.
@@ -28,19 +28,10 @@
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/types.h> 30#include <linux/types.h>
31#include <crypto/cast5.h>
31 32
32#define CAST5_BLOCK_SIZE 8
33#define CAST5_MIN_KEY_SIZE 5
34#define CAST5_MAX_KEY_SIZE 16
35 33
36struct cast5_ctx { 34const u32 cast5_s1[256] = {
37 u32 Km[16];
38 u8 Kr[16];
39 int rr; /* rr?number of rounds = 16:number of rounds = 12; (rfc 2144) */
40};
41
42
43static const u32 s1[256] = {
44 0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 35 0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f,
45 0x9c004dd3, 0x6003e540, 0xcf9fc949, 36 0x9c004dd3, 0x6003e540, 0xcf9fc949,
46 0xbfd4af27, 0x88bbbdb5, 0xe2034090, 0x98d09675, 0x6e63a0e0, 37 0xbfd4af27, 0x88bbbdb5, 0xe2034090, 0x98d09675, 0x6e63a0e0,
@@ -106,7 +97,8 @@ static const u32 s1[256] = {
106 0x1a69e783, 0x02cc4843, 0xa2f7c579, 0x429ef47d, 0x427b169c, 97 0x1a69e783, 0x02cc4843, 0xa2f7c579, 0x429ef47d, 0x427b169c,
107 0x5ac9f049, 0xdd8f0f00, 0x5c8165bf 98 0x5ac9f049, 0xdd8f0f00, 0x5c8165bf
108}; 99};
109static const u32 s2[256] = { 100EXPORT_SYMBOL_GPL(cast5_s1);
101const u32 cast5_s2[256] = {
110 0x1f201094, 0xef0ba75b, 0x69e3cf7e, 0x393f4380, 0xfe61cf7a, 102 0x1f201094, 0xef0ba75b, 0x69e3cf7e, 0x393f4380, 0xfe61cf7a,
111 0xeec5207a, 0x55889c94, 0x72fc0651, 103 0xeec5207a, 0x55889c94, 0x72fc0651,
112 0xada7ef79, 0x4e1d7235, 0xd55a63ce, 0xde0436ba, 0x99c430ef, 104 0xada7ef79, 0x4e1d7235, 0xd55a63ce, 0xde0436ba, 0x99c430ef,
@@ -172,7 +164,8 @@ static const u32 s2[256] = {
172 0x43d79572, 0x7e6dd07c, 0x06dfdf1e, 0x6c6cc4ef, 0x7160a539, 164 0x43d79572, 0x7e6dd07c, 0x06dfdf1e, 0x6c6cc4ef, 0x7160a539,
173 0x73bfbe70, 0x83877605, 0x4523ecf1 165 0x73bfbe70, 0x83877605, 0x4523ecf1
174}; 166};
175static const u32 s3[256] = { 167EXPORT_SYMBOL_GPL(cast5_s2);
168const u32 cast5_s3[256] = {
176 0x8defc240, 0x25fa5d9f, 0xeb903dbf, 0xe810c907, 0x47607fff, 169 0x8defc240, 0x25fa5d9f, 0xeb903dbf, 0xe810c907, 0x47607fff,
177 0x369fe44b, 0x8c1fc644, 0xaececa90, 170 0x369fe44b, 0x8c1fc644, 0xaececa90,
178 0xbeb1f9bf, 0xeefbcaea, 0xe8cf1950, 0x51df07ae, 0x920e8806, 171 0xbeb1f9bf, 0xeefbcaea, 0xe8cf1950, 0x51df07ae, 0x920e8806,
@@ -238,7 +231,8 @@ static const u32 s3[256] = {
238 0xf7baefd5, 0x4142ed9c, 0xa4315c11, 0x83323ec5, 0xdfef4636, 231 0xf7baefd5, 0x4142ed9c, 0xa4315c11, 0x83323ec5, 0xdfef4636,
239 0xa133c501, 0xe9d3531c, 0xee353783 232 0xa133c501, 0xe9d3531c, 0xee353783
240}; 233};
241static const u32 s4[256] = { 234EXPORT_SYMBOL_GPL(cast5_s3);
235const u32 cast5_s4[256] = {
242 0x9db30420, 0x1fb6e9de, 0xa7be7bef, 0xd273a298, 0x4a4f7bdb, 236 0x9db30420, 0x1fb6e9de, 0xa7be7bef, 0xd273a298, 0x4a4f7bdb,
243 0x64ad8c57, 0x85510443, 0xfa020ed1, 237 0x64ad8c57, 0x85510443, 0xfa020ed1,
244 0x7e287aff, 0xe60fb663, 0x095f35a1, 0x79ebf120, 0xfd059d43, 238 0x7e287aff, 0xe60fb663, 0x095f35a1, 0x79ebf120, 0xfd059d43,
@@ -304,6 +298,7 @@ static const u32 s4[256] = {
304 0x7ae5290c, 0x3cb9536b, 0x851e20fe, 0x9833557e, 0x13ecf0b0, 298 0x7ae5290c, 0x3cb9536b, 0x851e20fe, 0x9833557e, 0x13ecf0b0,
305 0xd3ffb372, 0x3f85c5c1, 0x0aef7ed2 299 0xd3ffb372, 0x3f85c5c1, 0x0aef7ed2
306}; 300};
301EXPORT_SYMBOL_GPL(cast5_s4);
307static const u32 s5[256] = { 302static const u32 s5[256] = {
308 0x7ec90c04, 0x2c6e74b9, 0x9b0e66df, 0xa6337911, 0xb86a7fff, 303 0x7ec90c04, 0x2c6e74b9, 0x9b0e66df, 0xa6337911, 0xb86a7fff,
309 0x1dd358f5, 0x44dd9d44, 0x1731167f, 304 0x1dd358f5, 0x44dd9d44, 0x1731167f,
@@ -569,17 +564,21 @@ static const u32 sb8[256] = {
569 0xeaee6801, 0x8db2a283, 0xea8bf59e 564 0xeaee6801, 0x8db2a283, 0xea8bf59e
570}; 565};
571 566
567#define s1 cast5_s1
568#define s2 cast5_s2
569#define s3 cast5_s3
570#define s4 cast5_s4
571
572#define F1(D, m, r) ((I = ((m) + (D))), (I = rol32(I, (r))), \ 572#define F1(D, m, r) ((I = ((m) + (D))), (I = rol32(I, (r))), \
573 (((s1[I >> 24] ^ s2[(I>>16)&0xff]) - s3[(I>>8)&0xff]) + s4[I&0xff])) 573 (((s1[I >> 24] ^ s2[(I>>16)&0xff]) - s3[(I>>8)&0xff]) + s4[I&0xff]))
574#define F2(D, m, r) ((I = ((m) ^ (D))), (I = rol32(I, (r))), \ 574#define F2(D, m, r) ((I = ((m) ^ (D))), (I = rol32(I, (r))), \
575 (((s1[I >> 24] - s2[(I>>16)&0xff]) + s3[(I>>8)&0xff]) ^ s4[I&0xff])) 575 (((s1[I >> 24] - s2[(I>>16)&0xff]) + s3[(I>>8)&0xff]) ^ s4[I&0xff]))
576#define F3(D, m, r) ((I = ((m) - (D))), (I = rol32(I, (r))), \ 576#define F3(D, m, r) ((I = ((m) - (D))), (I = rol32(I, (r))), \
577 (((s1[I >> 24] + s2[(I>>16)&0xff]) ^ s3[(I>>8)&0xff]) - s4[I&0xff])) 577 (((s1[I >> 24] + s2[(I>>16)&0xff]) ^ s3[(I>>8)&0xff]) - s4[I&0xff]))
578 578
579 579
580static void cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) 580void __cast5_encrypt(struct cast5_ctx *c, u8 *outbuf, const u8 *inbuf)
581{ 581{
582 struct cast5_ctx *c = crypto_tfm_ctx(tfm);
583 const __be32 *src = (const __be32 *)inbuf; 582 const __be32 *src = (const __be32 *)inbuf;
584 __be32 *dst = (__be32 *)outbuf; 583 __be32 *dst = (__be32 *)outbuf;
585 u32 l, r, t; 584 u32 l, r, t;
@@ -628,10 +627,15 @@ static void cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
628 dst[0] = cpu_to_be32(r); 627 dst[0] = cpu_to_be32(r);
629 dst[1] = cpu_to_be32(l); 628 dst[1] = cpu_to_be32(l);
630} 629}
630EXPORT_SYMBOL_GPL(__cast5_encrypt);
631 631
632static void cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) 632static void cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
633{
634 __cast5_encrypt(crypto_tfm_ctx(tfm), outbuf, inbuf);
635}
636
637void __cast5_decrypt(struct cast5_ctx *c, u8 *outbuf, const u8 *inbuf)
633{ 638{
634 struct cast5_ctx *c = crypto_tfm_ctx(tfm);
635 const __be32 *src = (const __be32 *)inbuf; 639 const __be32 *src = (const __be32 *)inbuf;
636 __be32 *dst = (__be32 *)outbuf; 640 __be32 *dst = (__be32 *)outbuf;
637 u32 l, r, t; 641 u32 l, r, t;
@@ -667,6 +671,12 @@ static void cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
667 dst[0] = cpu_to_be32(r); 671 dst[0] = cpu_to_be32(r);
668 dst[1] = cpu_to_be32(l); 672 dst[1] = cpu_to_be32(l);
669} 673}
674EXPORT_SYMBOL_GPL(__cast5_decrypt);
675
676static void cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
677{
678 __cast5_decrypt(crypto_tfm_ctx(tfm), outbuf, inbuf);
679}
670 680
671static void key_schedule(u32 *x, u32 *z, u32 *k) 681static void key_schedule(u32 *x, u32 *z, u32 *k)
672{ 682{
@@ -743,7 +753,7 @@ static void key_schedule(u32 *x, u32 *z, u32 *k)
743} 753}
744 754
745 755
746static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned key_len) 756int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len)
747{ 757{
748 struct cast5_ctx *c = crypto_tfm_ctx(tfm); 758 struct cast5_ctx *c = crypto_tfm_ctx(tfm);
749 int i; 759 int i;
@@ -771,19 +781,22 @@ static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned key_len)
771 c->Kr[i] = k[i] & 0x1f; 781 c->Kr[i] = k[i] & 0x1f;
772 return 0; 782 return 0;
773} 783}
784EXPORT_SYMBOL_GPL(cast5_setkey);
774 785
775static struct crypto_alg alg = { 786static struct crypto_alg alg = {
776 .cra_name = "cast5", 787 .cra_name = "cast5",
777 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 788 .cra_driver_name = "cast5-generic",
778 .cra_blocksize = CAST5_BLOCK_SIZE, 789 .cra_priority = 100,
779 .cra_ctxsize = sizeof(struct cast5_ctx), 790 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
780 .cra_alignmask = 3, 791 .cra_blocksize = CAST5_BLOCK_SIZE,
781 .cra_module = THIS_MODULE, 792 .cra_ctxsize = sizeof(struct cast5_ctx),
782 .cra_u = { 793 .cra_alignmask = 3,
794 .cra_module = THIS_MODULE,
795 .cra_u = {
783 .cipher = { 796 .cipher = {
784 .cia_min_keysize = CAST5_MIN_KEY_SIZE, 797 .cia_min_keysize = CAST5_MIN_KEY_SIZE,
785 .cia_max_keysize = CAST5_MAX_KEY_SIZE, 798 .cia_max_keysize = CAST5_MAX_KEY_SIZE,
786 .cia_setkey = cast5_setkey, 799 .cia_setkey = cast5_setkey,
787 .cia_encrypt = cast5_encrypt, 800 .cia_encrypt = cast5_encrypt,
788 .cia_decrypt = cast5_decrypt 801 .cia_decrypt = cast5_decrypt
789 } 802 }
@@ -805,4 +818,4 @@ module_exit(cast5_mod_fini);
805 818
806MODULE_LICENSE("GPL"); 819MODULE_LICENSE("GPL");
807MODULE_DESCRIPTION("Cast5 Cipher Algorithm"); 820MODULE_DESCRIPTION("Cast5 Cipher Algorithm");
808 821MODULE_ALIAS("cast5");