Skip to contentSkip to conversation

Add MIPS-assembler version of twofish crypto algorithm

PATCH New David Kuehling 1 participant 1 message Nov 18, 2011

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

PATCH v2 1/1 Add MIPS-assembler version of twofish crypto algorithm

Second version of the patch, cleaned up as discussed a few weeks back:
use register defines from asm/regdef.h, removed most of the #ifdef'ery. Did not yet add MIPS32r2 instructions for rotation, endianess-conversion, I'll leave that for a later time when I have access to such hardware and the time to test the additional code.

For N64-ABI I verified that this produces the same binary code as the earlier patch. For O32 I merely tested that it still compiles and checked the disassembly.

Original comment:

This patch adds a MIPS assembler version of the twofish cipher algorithm. x86(_64) had an assembler version of twofish for some time now, giving it an "unfair" advantage against the not so common architectures.

The code wast put through various tests and benchmarks in a user-space testbench, testing its correctness (also via qemu) for 32bit vs. 64bit and big vs. little endian MIPS.

http://mosquito.dyndns.tv/freesvn/trunk/linux/twofish-mips/

Also the same code backported to a 2.6.39 kernel (64bit) has been working flawlessly on my loongson-2f machine (with a twofish dm-crypt root) for a few weeks now.

Performance gain for the pure crypto code in 32-bit mode is about 15% on both Ingenic Xburst and Loongson-2f. With 64-bit it is 24-29%, as the C code suffers from 32->64 bit type conversions inserted by gcc. The code uses less unrolling than the C version, and should be smaller by at least a factor of 8. Full results in file Benchres.txt at the SVN URL given above.

---
 arch/mips/Kbuild                    |    2 +
 arch/mips/crypto/Makefile           |    7 +
 arch/mips/crypto/twofish-mips-asm.S |  332 +++++++++++++++++++++++++++++++++++
 arch/mips/crypto/twofish_glue.c     |   97 ++++++++++
 arch/mips/kernel/asm-offsets.c      |    8 +
 crypto/Kconfig                      |   16 ++
 6 files changed, 462 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/crypto/Makefile
 create mode 100644 arch/mips/crypto/twofish-mips-asm.S
 create mode 100644 arch/mips/crypto/twofish_glue.c
arch/mips/Kbuild +2 -0
index 7dd65cf..fc88443 100644
@@ -17,3 +17,5 @@ obj- := $(platform-)
 obj-y += kernel/
 obj-y += mm/
 obj-y += math-emu/
+
+obj-y += crypto/
arch/mips/crypto/Makefile new file +7 -0
new file mode 100644
index 0000000..6069354
@@ -0,0 +1,7 @@
+#
+# Arch-specific CryptoAPI modules.
+#
+
+obj-$(CONFIG_CRYPTO_TWOFISH_MIPS) += twofish-mips.o
+
+twofish-mips-y := twofish-mips-asm.o twofish_glue.o
arch/mips/crypto/twofish-mips-asm.S new file +331 -0

331 lines not on this page · raw message

arch/mips/crypto/twofish_glue.c new file +97 -0

97 lines not on this page · raw message

arch/mips/kernel/asm-offsets.c +8 -0
index 6b30fb2..9d91a6d 100644
@@ -15,6 +15,7 @@
 #include <linux/interrupt.h>
 #include <linux/kbuild.h>
 #include <linux/suspend.h>
+#include <linux/crypto.h>
 #include <asm/ptrace.h>
 #include <asm/processor.h>
 
@@ -339,3 +340,10 @@ void output_pbe_defines(void)
 	BLANK();
 }
 #endif
+
+void output_crypto_defines(void)
+{
+	COMMENT(" Linux crypto API offsets. ");
+	OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
+	BLANK();
+}
crypto/Kconfig +16 -0
index 527a857..4586715 100644
@@ -856,6 +856,22 @@ config CRYPTO_TWOFISH_X86_64_3WAY
 	  See also:
 	  <http://www.schneier.com/twofish.html>
 
+config CRYPTO_TWOFISH_MIPS
+	tristate "Twofish cipher algorithm (MIPS)"
+	depends on MIPS
+	select CRYPTO_ALGAPI
+	select CRYPTO_TWOFISH_COMMON
+	help
+	  Twofish cipher algorithm (MIPS).
+
+	  Twofish was submitted as an AES (Advanced Encryption Standard)
+	  candidate cipher by researchers at CounterPane Systems.  It is a
+	  16 round block cipher supporting key sizes of 128, 192, and 256
+	  bits.
+
+	  See also:
+	  <http://www.schneier.com/twofish.html>
+
 comment "Compression"
 
 config CRYPTO_DEFLATE
Signature · 1 line
1.7.5.4