From: sashiko-bot@kernel.org
To: "Laveesh Bansal" <laveeshb@laveeshbansal.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"Eric Biggers" <ebiggers@kernel.org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
"Ard Biesheuvel" <ardb@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
linux-crypto@vger.kernel.org
Subject: Re: [PATCH] crypto: chacha - Consolidate XChaCha initialization
Date: Thu, 03 Dec 2026 16:36:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-248206@kernel.org> (raw)
In-Reply-To: <20261203161849.85971-1-laveeshb@laveeshbansal.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] crypto: chacha - xchacha_init() leaves stack iv buffer
unzeroized
--
commit cb60a2e5b6777695110805ae396df4d61a659318
Author: Laveesh Bansal <laveeshb@laveeshbansal.com>
crypto: chacha - Consolidate XChaCha initialization
This commit adds a shared xchacha_init() helper to include/crypto/chacha.h
and replaces the duplicated XChaCha initialization code in
crypto/adiantum.c, crypto/chacha.c, and lib/crypto/chacha20poly1305.c.
> diff --git a/include/crypto/chacha.h b/include/crypto/chacha.h
> index bacf253781d52..10071d7b03043 100644
> --- a/include/crypto/chacha.h
> +++ b/include/crypto/chacha.h
[ ... ]
> @@ -85,6 +86,28 @@ static inline void chacha_init(struct chacha_state *state,
> state->x[15] = get_unaligned_le32(iv + 12);
> }
>
> +/*
> + * Initialize @state for XChaCha with the given key and 192-bit nonce,
> + * starting at stream position 0.
> + */
> +static inline void xchacha_init(struct chacha_state *state,
> + const u32 key[at_least CHACHA_KEY_WORDS],
> + const u8 nonce[at_least XCHACHA_NONCE_SIZE],
> + int nrounds)
> +{
> + u32 subkey[HCHACHA_OUT_WORDS];
> + u8 iv[CHACHA_IV_SIZE] = {};
> +
> + /* Compute the subkey given the original key and first 128 nonce bits */
> + chacha_init(state, key, nonce);
> + hchacha_block(state, subkey, nrounds);
> +
> + memcpy(&iv[8], nonce + 16, 8);
> + chacha_init(state, subkey, iv);
> +
> + memzero_explicit(subkey, sizeof(subkey));
> +}
[Severity: Low]
Should xchacha_init() also zeroize iv with memzero_explicit() before
returning?
Previously, xchacha_init() in lib/crypto/chacha20poly1305.c cleared its
stack iv buffer with memzero_explicit(iv, sizeof(iv)). Leaving iv
uncleared here leaves the upper 8 nonce bytes on the stack on every
xchacha20poly1305_encrypt() or xchacha20poly1305_decrypt() call.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203161849.85971-1-laveeshb@laveeshbansal.com?part=1
prev parent reply other threads:[~2026-12-03 16:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:18 [PATCH] crypto: chacha - Consolidate XChaCha initialization Laveesh Bansal
2026-12-03 16:36 ` sashiko-bot [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=sashiko-outbox-248206@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Jason@zx2c4.com \
--cc=ardb@kernel.org \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=laveeshb@laveeshbansal.com \
--cc=linux-crypto@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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