Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: linux-crypto@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>,
	David Miller <davem@davemloft.net>,
	"Jason A . Donenfeld" <Jason@zx2c4.com>,
	Samuel Neves <sneves@dei.uc.pt>, Arnd Bergmann <arnd@arndb.de>,
	Andy Lutomirski <luto@kernel.org>,
	Martin Willi <martin@strongswan.org>,
	Rene van Dorst <opensource@vdorst.com>
Subject: Re: [PATCH v3 07/29] crypto: arm/chacha - remove dependency on generic ChaCha driver
Date: Thu, 10 Oct 2019 23:12:38 -0700	[thread overview]
Message-ID: <20191011061238.GD23882@sol.localdomain> (raw)
In-Reply-To: <20191007164610.6881-8-ard.biesheuvel@linaro.org>

On Mon, Oct 07, 2019 at 06:45:48PM +0200, Ard Biesheuvel wrote:
> diff --git a/arch/arm/crypto/chacha-scalar-core.S b/arch/arm/crypto/chacha-scalar-core.S
> index 2140319b64a0..0970ae107590 100644
> --- a/arch/arm/crypto/chacha-scalar-core.S
> +++ b/arch/arm/crypto/chacha-scalar-core.S
> @@ -41,14 +41,6 @@
>  	X14	.req	r12
>  	X15	.req	r14
>  
> -.Lexpand_32byte_k:
> -	// "expand 32-byte k"
> -	.word	0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
> -
> -#ifdef __thumb2__
> -#  define adrl adr
> -#endif
> -
>  .macro __rev		out, in,  t0, t1, t2
>  .if __LINUX_ARM_ARCH__ >= 6
>  	rev		\out, \in
> @@ -391,61 +383,65 @@
>  .endm	// _chacha
>  
>  /*
> - * void chacha20_arm(u8 *out, const u8 *in, size_t len, const u32 key[8],
> - *		     const u32 iv[4]);
> + * void chacha_doarm(u8 *dst, const u8 *src, unsigned int bytes,
> + *		     u32 *state, int nrounds);
>   */
> -ENTRY(chacha20_arm)
> +ENTRY(chacha_doarm)
>  	cmp		r2, #0			// len == 0?
>  	reteq		lr
>  
> +	ldr		ip, [sp]
> +	cmp		ip, #12
> +
>  	push		{r0-r2,r4-r11,lr}
>  
>  	// Push state x0-x15 onto stack.
>  	// Also store an extra copy of x10-x11 just before the state.
>  
> -	ldr		r4, [sp, #48]		// iv
> -	mov		r0, sp
> -	sub		sp, #80
> -
> -	// iv: x12-x15
> -	ldm		r4, {X12,X13,X14,X15}
> -	stmdb		r0!, {X12,X13,X14,X15}
> +	add		X12, r3, #48
> +	ldm		X12, {X12,X13,X14,X15}
> +	push		{X12,X13,X14,X15}
> +	sub		sp, sp, #64
>  
> -	// key: x4-x11
> -	__ldrd		X8_X10, X9_X11, r3, 24
> +	__ldrd		X8_X10, X9_X11, r3, 40
>  	__strd		X8_X10, X9_X11, sp, 8
> -	stmdb		r0!, {X8_X10, X9_X11}
> -	ldm		r3, {X4-X9_X11}
> -	stmdb		r0!, {X4-X9_X11}
> -
> -	// constants: x0-x3
> -	adrl		X3, .Lexpand_32byte_k
> -	ldm		X3, {X0-X3}
> +	__strd		X8_X10, X9_X11, sp, 56
> +	ldm		r3, {X0-X9_X11}
>  	__strd		X0, X1, sp, 16
>  	__strd		X2, X3, sp, 24
> +	__strd		X4, X5, sp, 32
> +	__strd		X6, X7, sp, 40
> +	__strd		X8_X10, X9_X11, sp, 48
>  
> +	beq		1f
>  	_chacha		20
>  
> -	add		sp, #76
> +0:	add		sp, #76
>  	pop		{r4-r11, pc}
> -ENDPROC(chacha20_arm)
> +
> +1:	_chacha		12
> +	b		0b
> +ENDPROC(chacha_doarm)
>  
>  /*
> - * void hchacha20_arm(const u32 state[16], u32 out[8]);
> + * void hchacha_block_arm(const u32 state[16], u32 out[8], int nrounds);
>   */
> -ENTRY(hchacha20_arm)
> +ENTRY(hchacha_block_arm)
>  	push		{r1,r4-r11,lr}
>  
> +	cmp		r2, #12			// ChaCha12 ?
> +
>  	mov		r14, r0
>  	ldmia		r14!, {r0-r11}		// load x0-x11
>  	push		{r10-r11}		// store x10-x11 to stack
>  	ldm		r14, {r10-r12,r14}	// load x12-x15
>  	sub		sp, #8
>  
> +	beq		1f
>  	_chacha_permute	20
>  
>  	// Skip over (unused0-unused1, x10-x11)
> -	add		sp, #16
> +0:	add		sp, #16
>  
>  	// Fix up rotations of x12-x15
>  	ror		X12, X12, #drot
> @@ -458,4 +454,7 @@ ENTRY(hchacha20_arm)
>  	stm		r4, {X0,X1,X2,X3,X12,X13,X14,X15}
>  
>  	pop		{r4-r11,pc}
> -ENDPROC(hchacha20_arm)
> +
> +1:	_chacha_permute	12
> +	b		0b
> +ENDPROC(hchacha_block_arm)
> -- 

FYI, I've also had a version of this code supporting both the 12 and 20-round
variants sitting around here:
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/commit/?h=chacha-arm-scalar&id=fc51d8012742f591da3204b327a865f6109d472a
I'll take a closer look at this later, but you might want to take a quick look
at what I did, just in case I happened to do anything in a better way.

- Eric

  reply	other threads:[~2019-10-11  6:12 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-07 16:45 [PATCH v3 00/29] crypto: crypto API library interfaces for WireGuard Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 01/29] crypto: chacha - move existing library code into lib/crypto Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 02/29] crypto: x86/chacha - depend on generic chacha library instead of crypto driver Ard Biesheuvel
2019-10-11  6:00   ` Eric Biggers
2019-10-15 10:00   ` Martin Willi
2019-10-15 10:12     ` Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 03/29] crypto: x86/chacha - expose SIMD ChaCha routine as library function Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 04/29] crypto: arm64/chacha - depend on generic chacha library instead of crypto driver Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 05/29] crypto: arm64/chacha - expose arm64 ChaCha routine as library function Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 06/29] crypto: arm/chacha - import Eric Biggers's scalar accelerated ChaCha code Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 07/29] crypto: arm/chacha - remove dependency on generic ChaCha driver Ard Biesheuvel
2019-10-11  6:12   ` Eric Biggers [this message]
2019-10-11  6:31   ` Eric Biggers
2019-10-07 16:45 ` [PATCH v3 08/29] crypto: arm/chacha - expose ARM ChaCha routine as library function Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 09/29] crypto: mips/chacha - import 32r2 ChaCha code from Zinc Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 10/29] crypto: mips/chacha - wire up accelerated 32r2 " Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 11/29] crypto: chacha - unexport chacha_generic routines Ard Biesheuvel
2019-10-11  6:04   ` Eric Biggers
2019-10-07 16:45 ` [PATCH v3 12/29] crypto: poly1305 - move core routines into a separate library Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 13/29] crypto: x86/poly1305 - unify Poly1305 state struct with generic code Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 14/29] crypto: poly1305 - expose init/update/final library interface Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 15/29] crypto: x86/poly1305 - depend on generic library not generic shash Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 16/29] crypto: x86/poly1305 - expose existing driver as poly1305 library Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 17/29] crypto: arm64/poly1305 - incorporate OpenSSL/CRYPTOGAMS NEON implementation Ard Biesheuvel
2019-10-07 16:45 ` [PATCH v3 18/29] crypto: arm/poly1305 " Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 19/29] crypto: mips/poly1305 - incorporate OpenSSL/CRYPTOGAMS optimized implementation Ard Biesheuvel
2019-10-07 21:02   ` René van Dorst
2019-10-08  5:55     ` Ard Biesheuvel
2019-10-08 11:38     ` Andy Polyakov
2019-10-08 17:46       ` René van Dorst
2019-10-11 14:14       ` Andy Polyakov
2019-10-11 17:21         ` René van Dorst
2019-10-11 18:49           ` Andy Polyakov
2019-10-11 21:38           ` Arnd Bergmann
2019-10-07 16:46 ` [PATCH v3 20/29] int128: move __uint128_t compiler test to Kconfig Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 21/29] crypto: BLAKE2s - generic C library implementation and selftest Ard Biesheuvel
2019-10-11  6:02   ` Eric Biggers
2019-10-11 16:45     ` Jason A. Donenfeld
2019-10-14 12:53       ` Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 22/29] crypto: BLAKE2s - x86_64 library implementation Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 23/29] crypto: Curve25519 - generic C library implementations and selftest Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 24/29] crypto: lib/curve25519 - work around Clang stack spilling issue Ard Biesheuvel
2019-10-14 14:13   ` Jason A. Donenfeld
2019-10-14 16:07     ` Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 25/29] crypto: Curve25519 - x86_64 library implementation Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 26/29] crypto: arm - import Bernstein and Schwabe's Curve25519 ARM implementation Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 27/29] crypto: arm/Curve25519 - wire up NEON implementation Ard Biesheuvel
2019-10-07 16:46 ` [PATCH v3 28/29] crypto: chacha20poly1305 - import construction and selftest from Zinc Ard Biesheuvel
2019-10-11  6:14   ` Eric Biggers
2019-10-07 16:46 ` [PATCH v3 29/29] crypto: lib/chacha20poly1305 - reimplement crypt_from_sg() routine Ard Biesheuvel
2019-10-14 14:33 ` [PATCH v3 00/29] crypto: crypto API library interfaces for WireGuard Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191011061238.GD23882@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=martin@strongswan.org \
    --cc=opensource@vdorst.com \
    --cc=sneves@dei.uc.pt \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox