From: Eric Biggers <ebiggers@kernel.org>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au,
andre.przywara@arm.com, linux-arm-kernel@lists.infradead.org,
"Jason A . Donenfeld" <Jason@zx2c4.com>
Subject: Re: [PATCH v2] crypto: arm/chacha-neon - optimize for non-block size multiples
Date: Fri, 11 Dec 2020 22:43:33 -0800 [thread overview]
Message-ID: <X9RmlccBrwoY7zXS@sol.localdomain> (raw)
In-Reply-To: <20201103162809.28167-1-ardb@kernel.org>
Hi Ard,
On Tue, Nov 03, 2020 at 05:28:09PM +0100, Ard Biesheuvel wrote:
> @@ -42,24 +42,24 @@ static void chacha_doneon(u32 *state, u8 *dst, const u8 *src,
> {
> u8 buf[CHACHA_BLOCK_SIZE];
>
> - while (bytes >= CHACHA_BLOCK_SIZE * 4) {
> - chacha_4block_xor_neon(state, dst, src, nrounds);
> - bytes -= CHACHA_BLOCK_SIZE * 4;
> - src += CHACHA_BLOCK_SIZE * 4;
> - dst += CHACHA_BLOCK_SIZE * 4;
> - state[12] += 4;
> - }
> - while (bytes >= CHACHA_BLOCK_SIZE) {
> - chacha_block_xor_neon(state, dst, src, nrounds);
> - bytes -= CHACHA_BLOCK_SIZE;
> - src += CHACHA_BLOCK_SIZE;
> - dst += CHACHA_BLOCK_SIZE;
> - state[12]++;
> + while (bytes > CHACHA_BLOCK_SIZE) {
> + unsigned int l = min(bytes, CHACHA_BLOCK_SIZE * 4U);
> +
> + chacha_4block_xor_neon(state, dst, src, nrounds, l);
> + bytes -= l;
> + src += l;
> + dst += l;
> + state[12] += DIV_ROUND_UP(l, CHACHA_BLOCK_SIZE);
> }
> if (bytes) {
> - memcpy(buf, src, bytes);
> - chacha_block_xor_neon(state, buf, buf, nrounds);
> - memcpy(dst, buf, bytes);
> + const u8 *s = src;
> + u8 *d = dst;
> +
> + if (bytes != CHACHA_BLOCK_SIZE)
> + s = d = memcpy(buf, src, bytes);
> + chacha_block_xor_neon(state, d, s, nrounds);
> + if (d != dst)
> + memcpy(dst, buf, bytes);
> }
> }
>
Shouldn't this be incrementing the block counter after chacha_block_xor_neon()?
It might be needed by the library API.
Also, even with that fixed, this patch is causing the self-tests (both the
chacha20poly1305_selftest(), and the crypto API tests for chacha20-neon,
xchacha20-neon, and xchacha12-neon) to fail when I boot a kernel in QEMU. This
doesn't happen on real hardware (Raspberry Pi 2), and I don't see any other bugs
in this patch, so I'm not sure what the problem is. Did you run the self-tests
on every platform you tested this on?
- Eric
next prev parent reply other threads:[~2020-12-12 6:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-03 16:28 [PATCH v2] crypto: arm/chacha-neon - optimize for non-block size multiples Ard Biesheuvel
2020-11-13 5:10 ` Herbert Xu
2020-12-12 6:43 ` Eric Biggers [this message]
2020-12-12 7:24 ` Ard Biesheuvel
2020-12-12 19:48 ` Eric Biggers
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=X9RmlccBrwoY7zXS@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=andre.przywara@arm.com \
--cc=ardb@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
/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