Skip to contentSkip to conversation

crypto: arm64/ARM: NEON accelerated ChaCha20

PATCH Superseded Ard Biesheuvel 3 participants 10 messages Dec 8, 2016 – Dec 28, 2016

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover crypto: arm64/ARM: NEON accelerated ChaCha20

Another port of existing x86 SSE code to NEON, again both for arm64 and ARM.

ChaCha20 is a stream cipher described in RFC 7539, and is intended to be an efficient software implementable 'standby cipher', in case AES cannot be used.

This NEON implementation is almost 2x as fast as the generic C code (measured on Cortex-A57 using the arm64 version)

I'm aware that blkciphers are deprecated in favor of skciphers, but this code (like the x86 version) uses the init and setkey routines of the generic version, so it is probably better to port all implementations at once.

Ard Biesheuvel (2):
crypto: arm64/chacha20 - implement NEON version based on SSE3 code
crypto: arm/chacha20 - implement NEON version based on SSE3 code

 arch/arm/crypto/Kconfig                |   6 +
 arch/arm/crypto/Makefile               |   2 +
 arch/arm/crypto/chacha20-neon-core.S   | 524 ++++++++++++++++++++
 arch/arm/crypto/chacha20-neon-glue.c   | 136 +++++
 arch/arm64/crypto/Kconfig              |   6 +
 arch/arm64/crypto/Makefile             |   3 +
 arch/arm64/crypto/chacha20-neon-core.S | 480 ++++++++++++++++++
 arch/arm64/crypto/chacha20-neon-glue.c | 131 +++++
 8 files changed, 1288 insertions(+)
 create mode 100644 arch/arm/crypto/chacha20-neon-core.S
 create mode 100644 arch/arm/crypto/chacha20-neon-glue.c
 create mode 100644 arch/arm64/crypto/chacha20-neon-core.S
 create mode 100644 arch/arm64/crypto/chacha20-neon-glue.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 crypto: arm64/chacha20 - implement NEON version based on SSE3 code

This is a straight port to arm64/NEON of the x86 SSE3 implementation of the ChaCha20 stream cipher.

---
 arch/arm64/crypto/Kconfig              |   6 +
 arch/arm64/crypto/Makefile             |   3 +
 arch/arm64/crypto/chacha20-neon-core.S | 480 ++++++++++++++++++++
 arch/arm64/crypto/chacha20-neon-glue.c | 131 ++++++
 4 files changed, 620 insertions(+)
arch/arm64/crypto/Kconfig +6 -0
index 450a85df041a..0bf0f531f539 100644
@@ -72,4 +72,10 @@ config CRYPTO_CRC32_ARM64
 	depends on ARM64
 	select CRYPTO_HASH
 
+config CRYPTO_CHACHA20_NEON
+	tristate "NEON accelerated ChaCha20 symmetric cipher"
+	depends on KERNEL_MODE_NEON
+	select CRYPTO_BLKCIPHER
+	select CRYPTO_CHACHA20
+
 endif
arch/arm64/crypto/Makefile +3 -0
index aa8888d7b744..9d2826c5fccf 100644
@@ -41,6 +41,9 @@ sha256-arm64-y := sha256-glue.o sha256-core.o
 obj-$(CONFIG_CRYPTO_SHA512_ARM64) += sha512-arm64.o
 sha512-arm64-y := sha512-glue.o sha512-core.o
 
+obj-$(CONFIG_CRYPTO_CHACHA20_NEON) += chacha20-neon.o
+chacha20-neon-y := chacha20-neon-core.o chacha20-neon-glue.o
+
 AFLAGS_aes-ce.o		:= -DINTERLEAVE=4
 AFLAGS_aes-neon.o	:= -DINTERLEAVE=4
 
arch/arm64/crypto/chacha20-neon-core.S new file +480 -0

480 lines not on this page · raw message

arch/arm64/crypto/chacha20-neon-glue.c new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/2 crypto: arm/chacha20 - implement NEON version based on SSE3 code

In reply to Ard Biesheuvel

This is a straight port to ARM/NEON of the x86 SSE3 implementation of the ChaCha20 stream cipher.

---
 arch/arm/crypto/Kconfig              |   6 +
 arch/arm/crypto/Makefile             |   2 +
 arch/arm/crypto/chacha20-neon-core.S | 524 ++++++++++++++++++++
 arch/arm/crypto/chacha20-neon-glue.c | 136 +++++
 4 files changed, 668 insertions(+)
arch/arm/crypto/Kconfig +6 -0
index 13f1b4c289d4..2f3339f015d3 100644
@@ -130,4 +130,10 @@ config CRYPTO_CRC32_ARM_CE
 	depends on KERNEL_MODE_NEON && CRC32
 	select CRYPTO_HASH
 
+config CRYPTO_CHACHA20_NEON
+	tristate "NEON accelerated ChaCha20 symmetric cipher"
+	depends on KERNEL_MODE_NEON
+	select CRYPTO_BLKCIPHER
+	select CRYPTO_CHACHA20
+
 endif
arch/arm/crypto/Makefile +2 -0
index b578a1820ab1..8d74e55eacd4 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_CRYPTO_SHA1_ARM) += sha1-arm.o
 obj-$(CONFIG_CRYPTO_SHA1_ARM_NEON) += sha1-arm-neon.o
 obj-$(CONFIG_CRYPTO_SHA256_ARM) += sha256-arm.o
 obj-$(CONFIG_CRYPTO_SHA512_ARM) += sha512-arm.o
+obj-$(CONFIG_CRYPTO_CHACHA20_NEON) += chacha20-neon.o
 
 ce-obj-$(CONFIG_CRYPTO_AES_ARM_CE) += aes-arm-ce.o
 ce-obj-$(CONFIG_CRYPTO_SHA1_ARM_CE) += sha1-arm-ce.o
@@ -40,6 +41,7 @@ aes-arm-ce-y	:= aes-ce-core.o aes-ce-glue.o
 ghash-arm-ce-y	:= ghash-ce-core.o ghash-ce-glue.o
 crct10dif-arm-ce-y	:= crct10dif-ce-core.o crct10dif-ce-glue.o
 crc32-arm-ce-y:= crc32-ce-core.o crc32-ce-glue.o
+chacha20-neon-y := chacha20-neon-core.o chacha20-neon-glue.o
 
 quiet_cmd_perl = PERL    $@
       cmd_perl = $(PERL) $(<) > $(@)
arch/arm/crypto/chacha20-neon-core.S new file +524 -0

524 lines not on this page · raw message

arch/arm/crypto/chacha20-neon-glue.c new file +136 -0

136 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#3 lore raw

cover crypto: arm64/ARM: NEON accelerated ChaCha20

In reply to Ard Biesheuvel
Quoted 9 lines · Ard Biesheuvel

Another port of existing x86 SSE code to NEON, again both for arm64 and ARM.

ChaCha20 is a stream cipher described in RFC 7539, and is intended to be an efficient software implementable 'standby cipher', in case AES cannot be used.

This NEON implementation is almost 2x as fast as the generic C code (measured on Cortex-A57 using the arm64 version)

Quoted 7 lines

I'm aware that blkciphers are deprecated in favor of skciphers, but this code (like the x86 version) uses the init and setkey routines of the generic version, so it is probably better to port all implementations at once.

Ard Biesheuvel (2):
crypto: arm64/chacha20 - implement NEON version based on SSE3 code
crypto: arm/chacha20 - implement NEON version based on SSE3 code

Both patches 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
#4 lore raw

cover crypto: arm64/ARM: NEON accelerated ChaCha20

Quoted 18 lines · Herbert Xu
Quoted 15 lines · Ard Biesheuvel

Another port of existing x86 SSE code to NEON, again both for arm64 and ARM.

ChaCha20 is a stream cipher described in RFC 7539, and is intended to be an efficient software implementable 'standby cipher', in case AES cannot be used.

This NEON implementation is almost 2x as fast as the generic C code (measured on Cortex-A57 using the arm64 version)

I'm aware that blkciphers are deprecated in favor of skciphers, but this code (like the x86 version) uses the init and setkey routines of the generic version, so it is probably better to port all implementations at once.

Quoted 5 lines
Quoted 3 lines

Ard Biesheuvel (2):
crypto: arm64/chacha20 - implement NEON version based on SSE3 code
crypto: arm/chacha20 - implement NEON version based on SSE3 code

Both patches applied. Thanks.

You just nacked the v2 of this series (due to the chunksize/walksize) and i rewrote them as skciphers as well

Quoted 4 lines
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
maintainer
#5 lore raw

cover crypto: arm64/ARM: NEON accelerated ChaCha20

Quoted 2 lines · Ard Biesheuvel

You just nacked the v2 of this series (due to the chunksize/walksize) and i rewrote them as skciphers as well

Sorry. Would you like me to revert or just send a new series on top of this?

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
#6 lore raw

cover crypto: arm64/ARM: NEON accelerated ChaCha20

Quoted 10 lines · Herbert Xu
Quoted 4 lines · Ard Biesheuvel

You just nacked the v2 of this series (due to the chunksize/walksize) and i rewrote them as skciphers as well

Sorry. Would you like me to revert or just send a new series on top of this?

No worries. If you can, please drop them entirely, or revert them otherwise. I will resend after the holidays

Quoted 5 lines

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
maintainer
#7 lore raw

cover crypto: arm64/ARM: NEON accelerated ChaCha20

Quoted 5 lines · Ard Biesheuvel
Quoted 5 lines · Herbert Xu
Quoted 3 lines · Ard Biesheuvel
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

You just nacked the v2 of this series (due to the chunksize/walksize) and i rewrote them as skciphers as well

Sorry. Would you like me to revert or just send a new series on top of this?

No worries. If you can, please drop them entirely, or revert them otherwise. I will resend after the holidays

OK I will revert. 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
#8 lore raw
In reply to Ard Biesheuvel
Quoted 3 lines

ChaCha20 is a stream cipher described in RFC 7539, and is intended to be an efficient software implementable 'standby cipher', in case AES cannot be used.

That's not quite correct.

The IETF changed the algorithm a bit, and its not compatible with Bernstein's ChaCha. They probably should have differentiated the name to avoid this sort of confusion.

You can find Bernstein's specification for ChaCha at
https://cr.yp.to/chacha.html, and the test vectors for Bernstein's specification at
http://tools.ietf.org/html/draft-strombergson-chacha-test-vectors.

Jeff

#9 lore raw
Quoted 6 lines · Jeffrey Walton
Quoted 3 lines

ChaCha20 is a stream cipher described in RFC 7539, and is intended to be an efficient software implementable 'standby cipher', in case AES cannot be used.

That's not quite correct.

Quoted 9 lines

The IETF changed the algorithm a bit, and its not compatible with Bernstein's ChaCha. They probably should have differentiated the name to avoid this sort of confusion.

You can find Bernstein's specification for ChaCha at
https://cr.yp.to/chacha.html, and the test vectors for Bernstein's specification at
http://tools.ietf.org/html/draft-strombergson-chacha-test-vectors.

Thanks for the clarification. However, this should not affect the content of the patches: they simply reimplement in ARM SIMD what the kernel already knows as "chacha20", which is the IETF derivative rather than djb's original. I will mention this in the cover letter of the next respin (given that I need to respin these anyway)