Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7efe4076 authored by Johannes Goetzfried's avatar Johannes Goetzfried Committed by Herbert Xu
Browse files

crypto: serpent - add x86_64/avx assembler implementation



This patch adds a x86_64/avx assembler implementation of the Serpent block
cipher. The implementation is very similar to the sse2 implementation and
processes eight blocks in parallel. Because of the new non-destructive three
operand syntax all move-instructions can be removed and therefore a little
performance increase is provided.

Patch has been tested with tcrypt and automated filesystem tests.

Tcrypt benchmark results:

Intel Core i5-2500 CPU (fam:6, model:42, step:7)

serpent-avx-x86_64 vs. serpent-sse2-x86_64
128bit key:                                             (lrw:256bit)    (xts:256bit)
size    ecb-enc ecb-dec cbc-enc cbc-dec ctr-enc ctr-dec lrw-enc lrw-dec xts-enc xts-dec
16B     1.03x   1.01x   1.01x   1.01x   1.00x   1.00x   1.00x   1.00x   1.00x   1.01x
64B     1.00x   1.00x   1.00x   1.00x   1.00x   0.99x   1.00x   1.01x   1.00x   1.00x
256B    1.05x   1.03x   1.00x   1.02x   1.05x   1.06x   1.05x   1.02x   1.05x   1.02x
1024B   1.05x   1.02x   1.00x   1.02x   1.05x   1.06x   1.05x   1.03x   1.05x   1.02x
8192B   1.05x   1.02x   1.00x   1.02x   1.06x   1.06x   1.04x   1.03x   1.04x   1.02x

256bit key:                                             (lrw:384bit)    (xts:512bit)
size    ecb-enc ecb-dec cbc-enc cbc-dec ctr-enc ctr-dec lrw-enc lrw-dec xts-enc xts-dec
16B     1.01x   1.00x   1.01x   1.01x   1.00x   1.00x   0.99x   1.03x   1.01x   1.01x
64B     1.00x   1.00x   1.00x   1.00x   1.00x   1.00x   1.00x   1.01x   1.00x   1.02x
256B    1.05x   1.02x   1.00x   1.02x   1.05x   1.02x   1.04x   1.05x   1.05x   1.02x
1024B   1.06x   1.02x   1.00x   1.02x   1.07x   1.06x   1.05x   1.04x   1.05x   1.02x
8192B   1.05x   1.02x   1.00x   1.02x   1.06x   1.06x   1.04x   1.05x   1.05x   1.02x

serpent-avx-x86_64 vs aes-asm (8kB block):
         128bit  256bit
ecb-enc  1.26x   1.73x
ecb-dec  1.20x   1.64x
cbc-enc  0.33x   0.45x
cbc-dec  1.24x   1.67x
ctr-enc  1.32x   1.76x
ctr-dec  1.32x   1.76x
lrw-enc  1.20x   1.60x
lrw-dec  1.15x   1.54x
xts-enc  1.22x   1.64x
xts-dec  1.17x   1.57x

Signed-off-by: default avatarJohannes Goetzfried <Johannes.Goetzfried@informatik.stud.uni-erlangen.de>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 4da7de4d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ obj-$(CONFIG_CRYPTO_TWOFISH_X86_64_3WAY) += twofish-x86_64-3way.o
obj-$(CONFIG_CRYPTO_TWOFISH_AVX_X86_64) += twofish-avx-x86_64.o
obj-$(CONFIG_CRYPTO_SALSA20_X86_64) += salsa20-x86_64.o
obj-$(CONFIG_CRYPTO_SERPENT_SSE2_X86_64) += serpent-sse2-x86_64.o
obj-$(CONFIG_CRYPTO_SERPENT_AVX_X86_64) += serpent-avx-x86_64.o
obj-$(CONFIG_CRYPTO_AES_NI_INTEL) += aesni-intel.o
obj-$(CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o

@@ -34,6 +35,7 @@ twofish-x86_64-3way-y := twofish-x86_64-asm_64-3way.o twofish_glue_3way.o
twofish-avx-x86_64-y := twofish-avx-x86_64-asm_64.o twofish_avx_glue.o
salsa20-x86_64-y := salsa20-x86_64-asm_64.o salsa20_glue.o
serpent-sse2-x86_64-y := serpent-sse2-x86_64-asm_64.o serpent_sse2_glue.o
serpent-avx-x86_64-y := serpent-avx-x86_64-asm_64.o serpent_avx_glue.o

aesni-intel-y := aesni-intel_asm.o aesni-intel_glue.o fpu.o
ghash-clmulni-intel-y := ghash-clmulni-intel_asm.o ghash-clmulni-intel_glue.o
+704 −0

File added.

Preview size limit exceeded, changes collapsed.

+949 −0

File added.

Preview size limit exceeded, changes collapsed.

+20 −0
Original line number Diff line number Diff line
@@ -821,6 +821,26 @@ config CRYPTO_SERPENT_SSE2_586
	  See also:
	  <http://www.cl.cam.ac.uk/~rja14/serpent.html>

config CRYPTO_SERPENT_AVX_X86_64
	tristate "Serpent cipher algorithm (x86_64/AVX)"
	depends on X86 && 64BIT
	select CRYPTO_ALGAPI
	select CRYPTO_CRYPTD
	select CRYPTO_SERPENT
	select CRYPTO_LRW
	select CRYPTO_XTS
	help
	  Serpent cipher algorithm, by Anderson, Biham & Knudsen.

	  Keys are allowed to be from 0 to 256 bits in length, in steps
	  of 8 bits.

	  This module provides the Serpent cipher algorithm that processes
	  eight blocks parallel using the AVX instruction set.

	  See also:
	  <http://www.cl.cam.ac.uk/~rja14/serpent.html>

config CRYPTO_TEA
	tristate "TEA, XTEA and XETA cipher algorithms"
	select CRYPTO_ALGAPI
+60 −0
Original line number Diff line number Diff line
@@ -1534,6 +1534,21 @@ static int alg_test_null(const struct alg_test_desc *desc,
/* Please keep this list sorted by algorithm name. */
static const struct alg_test_desc alg_test_descs[] = {
	{
		.alg = "__cbc-serpent-avx",
		.test = alg_test_null,
		.suite = {
			.cipher = {
				.enc = {
					.vecs = NULL,
					.count = 0
				},
				.dec = {
					.vecs = NULL,
					.count = 0
				}
			}
		}
	}, {
		.alg = "__cbc-serpent-sse2",
		.test = alg_test_null,
		.suite = {
@@ -1578,6 +1593,21 @@ static const struct alg_test_desc alg_test_descs[] = {
				}
			}
		}
	}, {
		.alg = "__driver-cbc-serpent-avx",
		.test = alg_test_null,
		.suite = {
			.cipher = {
				.enc = {
					.vecs = NULL,
					.count = 0
				},
				.dec = {
					.vecs = NULL,
					.count = 0
				}
			}
		}
	}, {
		.alg = "__driver-cbc-serpent-sse2",
		.test = alg_test_null,
@@ -1623,6 +1653,21 @@ static const struct alg_test_desc alg_test_descs[] = {
				}
			}
		}
	}, {
		.alg = "__driver-ecb-serpent-avx",
		.test = alg_test_null,
		.suite = {
			.cipher = {
				.enc = {
					.vecs = NULL,
					.count = 0
				},
				.dec = {
					.vecs = NULL,
					.count = 0
				}
			}
		}
	}, {
		.alg = "__driver-ecb-serpent-sse2",
		.test = alg_test_null,
@@ -1835,6 +1880,21 @@ static const struct alg_test_desc alg_test_descs[] = {
				}
			}
		}
	}, {
		.alg = "cryptd(__driver-ecb-serpent-avx)",
		.test = alg_test_null,
		.suite = {
			.cipher = {
				.enc = {
					.vecs = NULL,
					.count = 0
				},
				.dec = {
					.vecs = NULL,
					.count = 0
				}
			}
		}
	}, {
		.alg = "cryptd(__driver-ecb-serpent-sse2)",
		.test = alg_test_null,