Skip to contentSkip to conversation

crypto: cast5/cast6 - move lookup tables to shared module

PATCH In review Jussi Kivilinna 3 participants 5 messages Nov 13, 2012 – Dec 6, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: cast5/cast6 - move lookup tables to shared module

CAST5 and CAST6 both use same lookup tables, which can be moved shared module 'cast_common'.

---
 arch/x86/crypto/cast5-avx-x86_64-asm_64.S |   16 +-
 arch/x86/crypto/cast6-avx-x86_64-asm_64.S |   16 +-
 crypto/Kconfig                            |   10 +
 crypto/Makefile                           |    1 
 crypto/cast5_generic.c                    |  277 ----------------------------
 crypto/cast6_generic.c                    |  280 ----------------------------
 crypto/cast_common.c                      |  290 +++++++++++++++++++++++++++++
 include/crypto/cast5.h                    |    6 -
 include/crypto/cast6.h                    |    6 -
 include/crypto/cast_common.h              |    9 +
 10 files changed, 336 insertions(+), 575 deletions(-)
 create mode 100644 crypto/cast_common.c
 create mode 100644 include/crypto/cast_common.h
arch/x86/crypto/cast5-avx-x86_64-asm_64.S +8 -8
index 12478e4..15b00ac 100644
@@ -25,10 +25,10 @@
 
 .file "cast5-avx-x86_64-asm_64.S"
 
-.extern cast5_s1
-.extern cast5_s2
-.extern cast5_s3
-.extern cast5_s4
+.extern cast_s1
+.extern cast_s2
+.extern cast_s3
+.extern cast_s4
 
 /* structure of crypto context */
 #define km	0
@@ -36,10 +36,10 @@
 #define rr	((16*4)+16)
 
 /* s-boxes */
-#define s1	cast5_s1
-#define s2	cast5_s2
-#define s3	cast5_s3
-#define s4	cast5_s4
+#define s1	cast_s1
+#define s2	cast_s2
+#define s3	cast_s3
+#define s4	cast_s4
 
 /**********************************************************************
   16-way AVX cast5
arch/x86/crypto/cast6-avx-x86_64-asm_64.S +8 -8
index 83a5381..2569d0d 100644
@@ -27,20 +27,20 @@
 
 .file "cast6-avx-x86_64-asm_64.S"
 
-.extern cast6_s1
-.extern cast6_s2
-.extern cast6_s3
-.extern cast6_s4
+.extern cast_s1
+.extern cast_s2
+.extern cast_s3
+.extern cast_s4
 
 /* structure of crypto context */
 #define km	0
 #define kr	(12*4*4)
 
 /* s-boxes */
-#define s1	cast6_s1
-#define s2	cast6_s2
-#define s3	cast6_s3
-#define s4	cast6_s4
+#define s1	cast_s1
+#define s2	cast_s2
+#define s3	cast_s3
+#define s4	cast_s4
 
 /**********************************************************************
   8-way AVX cast6
crypto/Kconfig +10 -0
index c226b2c..4641d95 100644
@@ -841,9 +841,16 @@ config CRYPTO_CAMELLIA_SPARC64
 	  See also:
 	  <https://info.isl.ntt.co.jp/crypt/eng/camellia/index_s.html>
 
+config CRYPTO_CAST_COMMON
+	tristate
+	help
+	  Common parts of the CAST cipher algorithms shared by the
+	  generic c and the assembler implementations.
+
 config CRYPTO_CAST5
 	tristate "CAST5 (CAST-128) cipher algorithm"
 	select CRYPTO_ALGAPI
+	select CRYPTO_CAST_COMMON
 	help
 	  The CAST5 encryption algorithm (synonymous with CAST-128) is
 	  described in RFC2144.
@@ -854,6 +861,7 @@ config CRYPTO_CAST5_AVX_X86_64
 	select CRYPTO_ALGAPI
 	select CRYPTO_CRYPTD
 	select CRYPTO_ABLK_HELPER_X86
+	select CRYPTO_CAST_COMMON
 	select CRYPTO_CAST5
 	help
 	  The CAST5 encryption algorithm (synonymous with CAST-128) is
@@ -865,6 +873,7 @@ config CRYPTO_CAST5_AVX_X86_64
 config CRYPTO_CAST6
 	tristate "CAST6 (CAST-256) cipher algorithm"
 	select CRYPTO_ALGAPI
+	select CRYPTO_CAST_COMMON
 	help
 	  The CAST6 encryption algorithm (synonymous with CAST-256) is
 	  described in RFC2612.
@@ -876,6 +885,7 @@ config CRYPTO_CAST6_AVX_X86_64
 	select CRYPTO_CRYPTD
 	select CRYPTO_ABLK_HELPER_X86
 	select CRYPTO_GLUE_HELPER_X86
+	select CRYPTO_CAST_COMMON
 	select CRYPTO_CAST6
 	select CRYPTO_LRW
 	select CRYPTO_XTS
crypto/Makefile +1 -0
index 8cf61ff..d59dec7 100644
@@ -68,6 +68,7 @@ obj-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o
 obj-$(CONFIG_CRYPTO_SERPENT) += serpent_generic.o
 obj-$(CONFIG_CRYPTO_AES) += aes_generic.o
 obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia_generic.o
+obj-$(CONFIG_CRYPTO_CAST_COMMON) += cast_common.o
 obj-$(CONFIG_CRYPTO_CAST5) += cast5_generic.o
 obj-$(CONFIG_CRYPTO_CAST6) += cast6_generic.o
 obj-$(CONFIG_CRYPTO_ARC4) += arc4.o
crypto/cast5_generic.c +4 -273

289 lines not on this page · raw message

crypto/cast6_generic.c +4 -276

292 lines not on this page · raw message

crypto/cast_common.c new file +290 -0

290 lines not on this page · raw message

include/crypto/cast5.h +1 -5
index 586183a..14fbf39 100644
@@ -3,6 +3,7 @@
 
 #include <linux/types.h>
 #include <linux/crypto.h>
+#include <crypto/cast_common.h>
 
 #define CAST5_BLOCK_SIZE 8
 #define CAST5_MIN_KEY_SIZE 5
@@ -19,9 +20,4 @@ int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen);
 void __cast5_encrypt(struct cast5_ctx *ctx, u8 *dst, const u8 *src);
 void __cast5_decrypt(struct cast5_ctx *ctx, u8 *dst, const u8 *src);
 
-extern const u32 cast5_s1[256];
-extern const u32 cast5_s2[256];
-extern const u32 cast5_s3[256];
-extern const u32 cast5_s4[256];
-
 #endif
include/crypto/cast6.h +1 -5
index 157af6f..32b60eb 100644
@@ -3,6 +3,7 @@
 
 #include <linux/types.h>
 #include <linux/crypto.h>
+#include <crypto/cast_common.h>
 
 #define CAST6_BLOCK_SIZE 16
 #define CAST6_MIN_KEY_SIZE 16
@@ -20,9 +21,4 @@ int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen);
 void __cast6_encrypt(struct cast6_ctx *ctx, u8 *dst, const u8 *src);
 void __cast6_decrypt(struct cast6_ctx *ctx, u8 *dst, const u8 *src);
 
-extern const u32 cast6_s1[256];
-extern const u32 cast6_s2[256];
-extern const u32 cast6_s3[256];
-extern const u32 cast6_s4[256];
-
 #endif
include/crypto/cast_common.h new file +9 -0
new file mode 100644
index 0000000..b7df35c
@@ -0,0 +1,9 @@
+#ifndef _CRYPTO_CAST_COMMON_H
+#define _CRYPTO_CAST_COMMON_H
+
+extern const u32 cast_s1[256];
+extern const u32 cast_s2[256];
+extern const u32 cast_s3[256];
+extern const u32 cast_s4[256];
+
+#endif
#2 lore raw

Quoting David Miller <[email protected]>:

Quoted 11 lines

From: Jussi Kivilinna <[email protected]>
Date: Tue, 13 Nov 2012 11:43:14 +0200

Quoted 4 lines

CAST5 and CAST6 both use same lookup tables, which can be moved shared module 'cast_common'.

Does this work if you make CAST5 modular and CAST6 static, or vice versa?

Yes, dependencies force common module to be built-in/static in both cases and will be build as module only if both cast5 and cast6 are also.

maintainer Acked-by
#3 lore raw

From: Jussi Kivilinna <[email protected]>
Date: Tue, 13 Nov 2012 21:50:20 +0200

Quoted 11 lines

Quoting David Miller <[email protected]>:

Quoted 9 lines

From: Jussi Kivilinna <[email protected]>
Date: Tue, 13 Nov 2012 11:43:14 +0200

Quoted 5 lines

CAST5 and CAST6 both use same lookup tables, which can be moved shared module
'cast_common'.

Quoted 7 lines
Quoted 3 lines

Does this work if you make CAST5 modular and CAST6 static, or vice versa?

Yes, dependencies force common module to be built-in/static in both cases and will be build as module only if both cast5 and cast6 are also.

Fair enough:

maintainer
#4 lore raw
Quoted 18 lines · David Miller

From: Jussi Kivilinna <[email protected]>
Date: Tue, 13 Nov 2012 21:50:20 +0200

Quoted 15 lines

Quoting David Miller <[email protected]>:

Quoted 12 lines

From: Jussi Kivilinna <[email protected]>
Date: Tue, 13 Nov 2012 11:43:14 +0200

Quoted 5 lines

CAST5 and CAST6 both use same lookup tables, which can be moved shared module
'cast_common'.

Does this work if you make CAST5 modular and CAST6 static, or vice versa?

Quoted 7 lines
Quoted 3 lines

Yes, dependencies force common module to be built-in/static in both cases and will be build as module only if both cast5 and cast6 are also.

Fair enough:

Patch applied. Thanks!

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt