From: Eric Biggers <ebiggers@kernel.org>
To: Laveesh Bansal <laveeshb@laveeshbansal.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] crypto: adiantum - Use the ChaCha library for the stream cipher
Date: Mon, 30 Nov 2026 19:40:12 +0000 [thread overview]
Message-ID: <20261130194012.GA16775@google.com> (raw)
In-Reply-To: <20261130055539.8278-4-laveeshb@laveeshbansal.com>
On Sun, Nov 29, 2026 at 09:55:39PM -0800, Laveesh Bansal wrote:
> adiantum_crypt() runs the XChaCha step through a child crypto_skcipher.
> That needs a spawn, a child tfm and a request sized for the child.
>
> Call chacha_crypt() directly instead and remove the child. The library
> works on plain buffers, so adiantum walks the source and destination
> scatterlists itself.
>
> Suggested-by: Eric Biggers <ebiggers@kernel.org>
> Signed-off-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
> ---
> Notes:
>
> I tested this patch in the same environments as patch 2.
>
> I also ran a test module that splits src and dst at random offsets -
> in place and out of place - and compares the result with a plain
> buffer. They match. This one I did on arm64 and x86_64.
>
> Another one I ran is the tcrypt adiantum speed test;
> I did this on arm64 in a KVM guest with debug options off.
> I did not find any slowness in performance when compared
> with results on base + setkey + aeslib. I can share specific test
> results if anybody is interested.
>
> crypto/Kconfig | 3 +-
> crypto/adiantum.c | 164 ++++++++++++++++++++--------------------------
> 2 files changed, 74 insertions(+), 93 deletions(-)
>
> diff --git a/crypto/Kconfig b/crypto/Kconfig
> index 7cac0141a73cb..93996d1240380 100644
> --- a/crypto/Kconfig
> +++ b/crypto/Kconfig
> @@ -578,7 +578,8 @@ menu "Length-preserving ciphers and modes"
>
> config CRYPTO_ADIANTUM
> tristate "Adiantum"
> - select CRYPTO_CHACHA20
> + select CRYPTO_LIB_CHACHA
> + select CRYPTO_SKCIPHER
> select CRYPTO_LIB_AES
> select CRYPTO_LIB_NH
> select CRYPTO_LIB_POLY1305
> diff --git a/crypto/adiantum.c b/crypto/adiantum.c
> index f53d6d5f56fb9..2358f61e88ce9 100644
> --- a/crypto/adiantum.c
> +++ b/crypto/adiantum.c
> @@ -41,13 +41,11 @@
> #define TWEAK_SIZE 32
>
> struct adiantum_instance_ctx {
> - struct crypto_skcipher_spawn streamcipher_spawn;
> int nrounds;
> };
Now that there are no inner algorithms ("spawns") left, it doesn't make
sense for this to be a template anymore. This file should instead just
register two crypto_skcipher algorithms,
"adiantum(xchacha12,aes)" (driver name "adiantum(xchacha12-lib,aes-lib)"), and
"adiantum(xchacha20,aes)" (driver name "adiantum(xchacha20-lib,aes-lib)").
> +static void adiantum_stream_xor(struct chacha_state *state, int nrounds,
> + struct scatterlist *src,
> + struct scatterlist *dst, unsigned int len)
> +{
> + struct scatter_walk swalk, dwalk;
> +
> + scatterwalk_start(&swalk, src);
> + scatterwalk_start(&dwalk, dst);
> + while (len) {
> + unsigned int n = min(scatterwalk_clamp(&swalk, len),
> + scatterwalk_clamp(&dwalk, len));
> +
> + /*
> + * The ChaCha counter advances in whole blocks, so every
> + * step except the last must be a whole number of blocks.
> + */
> + if (n < len)
> + n = round_down(n, CHACHA_BLOCK_SIZE);
> + if (n) {
> + scatterwalk_map(&swalk);
> + scatterwalk_map(&dwalk);
> + chacha_crypt(state, dwalk.addr, swalk.addr, n, nrounds);
> + scatterwalk_done_dst(&dwalk, n);
> + scatterwalk_done_src(&swalk, n);
> + } else {
> + u8 buf[CHACHA_BLOCK_SIZE];
> +
> + n = min(len, CHACHA_BLOCK_SIZE);
> + memcpy_from_scatterwalk(buf, &swalk, n);
> + chacha_crypt(state, buf, buf, n, nrounds);
> + memcpy_to_scatterwalk(&dwalk, buf, n);
> + }
> + len -= n;
This is not correct, since for in-place operations with CONFIG_HIGHMEM=y
the same memory is being mapped multiple times. The in-place case
either needs to be handled directly, like crypto/aes.c does, or
skcipher_walk should be used which handles this.
(Also, 'buf' is not being zeroized when it goes out of scope.)
- Eric
prev parent reply other threads:[~2026-11-30 19:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 5:55 [PATCH 0/3] crypto: adiantum - Use the ChaCha library Laveesh Bansal
2026-11-30 5:55 ` [PATCH 1/3] crypto: testmgr - Add Adiantum vectors with a partial last ChaCha block Laveesh Bansal
2026-11-30 5:55 ` [PATCH 2/3] crypto: adiantum - Derive the subkeys with the ChaCha library Laveesh Bansal
2026-11-30 19:43 ` Eric Biggers
2026-11-30 5:55 ` [PATCH 3/3] crypto: adiantum - Use the ChaCha library for the stream cipher Laveesh Bansal
2026-11-30 19:40 ` Eric Biggers [this message]
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=20261130194012.GA16775@google.com \
--to=ebiggers@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=laveeshb@laveeshbansal.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®