Re: [PATCH v3 2/2] crypto: adiantum - Use the ChaCha library

From: Eric Biggers

Date: Tue Dec 01 2026 - 21:30:19 EST


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