Linux cryptographic layer development
 help / color / mirror / Atom feed
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 v3 2/2] crypto: adiantum - Use the ChaCha library
Date: Wed, 2 Dec 2026 02:30:13 +0000	[thread overview]
Message-ID: <20261202023013.GC2427638@google.com> (raw)
In-Reply-To: <20261201080825.56171-3-laveeshb@laveeshbansal.com>

On Tue, Dec 01, 2026 at 12:08:25AM -0800, Laveesh Bansal wrote:
> diff --git a/crypto/adiantum.c b/crypto/adiantum.c
> index 5e16d2c4699b6..a78bf9f8d6145 100644
> --- a/crypto/adiantum.c
> +++ b/crypto/adiantum.c

Maybe add <linux/unaligned.h> for the new use of get_unaligned_le32(),
rather than relying on a transitive inclusion.

> +/* The IV is the 24-byte nonce followed by the 8-byte stream position. */
> +static void adiantum_xchacha_init(struct chacha_state *state,
> +				  const u32 key[CHACHA_KEY_WORDS], int nrounds,
> +				  const u8 iv[XCHACHA_IV_SIZE])

Both callers use a starting stream position of 0.  The
'iv = nonce || stream_pos' packing is an unnecessary holdover from
crypto_skcipher.  Perhaps simplify this to take just the 24-byte nonce,
and make it assume that the starting stream position is 0?

>  /*
>   * Given the XChaCha stream key K_S, derive the block cipher key K_E and the
> @@ -96,34 +101,26 @@ struct adiantum_request_ctx {
>   * get indirectly by encrypting a buffer containing all 0's.
>   */
>  static int adiantum_setkey(struct crypto_skcipher *tfm, const u8 *key,
> -			   unsigned int keylen)
> +			   unsigned int keylen, int nrounds)

keylen is never actually used.  Now that this function is no longer
installed directly as skcipher_alg::setkey, it would make sense for it
to take 'const u8 key[CHACHA_KEY_SIZE]' and no keylen.

> +			u8 buf[CHACHA_BLOCK_SIZE];

Should add __aligned(sizeof(long)), like lib/crypto/chacha.c has.

>  	if (round_up(stream_len, CHACHA_BLOCK_SIZE) <= req->cryptlen)
>  		stream_len = round_up(stream_len, CHACHA_BLOCK_SIZE);
>  
> -	skcipher_request_set_tfm(&rctx->u.streamcipher_req, tctx->streamcipher);
> -	skcipher_request_set_crypt(&rctx->u.streamcipher_req, req->src,
> -				   req->dst, stream_len, &rbuf);
> -	skcipher_request_set_callback(&rctx->u.streamcipher_req,
> -				      req->base.flags, NULL, NULL);
> -	err = crypto_skcipher_encrypt(&rctx->u.streamcipher_req);
> -	if (err)
> -		return err;
> +	if (bulk_len) {
> +		adiantum_xchacha_init(&state, tctx->stream_key, tctx->nrounds,
> +				      rbuf.bytes);
> +		adiantum_stream_xor(&state, tctx->nrounds, src, dst,
> +				    stream_len);
> +		chacha_zeroize_state(&state);
> +	}

The calculation of stream_len should be moved into the new if statement.

- Eric

      reply	other threads:[~2026-12-02  2:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:08 [PATCH v3 0/2] crypto: adiantum - Use the ChaCha library Laveesh Bansal
2026-12-01  8:08 ` [PATCH v3 1/2] crypto: testmgr - Add Adiantum vectors with a partial last ChaCha block Laveesh Bansal
2026-12-02  2:21   ` Eric Biggers
2026-12-01  8:08 ` [PATCH v3 2/2] crypto: adiantum - Use the ChaCha library Laveesh Bansal
2026-12-02  2:30   ` 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=20261202023013.GC2427638@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