From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796102274; b=kg6Xi+J/M+gmedYpDD0+36W3no8mGuHrDSWN/kUbKmrvr6vwBXqSGdHBPmLga056QDJN DAqC1Q9sjtFSqt2Fbg5xBf3dUGzS6xkXFpihI+d6+1pn8+56tXMBqqOkhxrGuyBgNu0FS Ynj4aSemxHMoHX129QRJueZtLe2v4fD879Sluy+oZHmyjJ7DtQjF0dOYp1ZUOK7dE1+z/ SDIXnBX/H4tci4KVnkDjWoC6IOkRfDhAPZXDZMRQzZQhbArxyVd7TISDInvyBCSOL8bgY LUrGyV7kkzPbXlAKPE5o91bvbTUGfMJN7uMUzou9zA9bTBX4gjSTvP8ftak5zBIuGhA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796102274; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=ka9acaNQHhHnLrkgOFoICpqb1yABfPhJZMwBCmUD2+Y=; b=YagXa9Yc4HI0J1Q2nw15j2HrKT87BdzI1esxIJfBSSkxN5oLp2tpah0B/f4hLxfHz4/2 BztTorwTs2Yi0l2b6MrHpGYHcuaYxqGMB39pMDU/Wz5QkJk4F/R3x19lR6FbkT8q/hv49 /8A5JQ4rtjAsSxMxSFrUudB5PcEgrRN+dKFbVeDlgJe444w58oldOa0EItoImpAL8orzd o0lszonACLCsd7hlyan+7RUpKgS0eFZYaonpIpRj9tapeMGea1CQvyezB1lUnWY/wC0wi eHVdyGiGNfpZjW+pyvaHd4fstfP+8AkDnR0dfmlOX/gYn4XmsPk2Jo/N6PQUDAMyCSg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e2YJ8v8R; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBC7D606A31A; Tue, 1 Dec 2026 05:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e2YJ8v8R Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46E991F00893; Tue, 1 Dec 2026 05:17:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796102274; bh=ka9acaNQHhHnLrkgOFoICpqb1yABfPhJZMwBCmUD2+Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=e2YJ8v8RY29/gGmosWfWFbrzk2XY3tIx4jtHThFB8pJ3ZESngz9hYyR4WUE70LRSm Q6BLPKbabvNLxCxUjo/nkbhKlJSZw+zx8Q7YOV/Eayae7mc6L+mTYI/dNxqbguGkZd y0jWEZjmv5LEQYc5tWultwRbg//otJOLvZ3ULY0uoDbKeKRwcPKDy8dOX2f8al8qR2 qpZ0fXtoK40Qz1V2Vt1ThmeeDb1G2zd8QedGep2M8MWL9T1njw5/RR1ID6F7zJl/cd cJ320QFIKWBIu95lufPhLA7DeK2wJml8CdnUoMy/jDZontu5coAc+qyriPos6e68T+ 1wTK0Q+4Trx5g== Date: Mon, 30 Nov 2026 21:17:52 -0800 From: Eric Biggers To: Laveesh Bansal Cc: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] crypto: adiantum - Use the ChaCha library Message-ID: <20261201051752.GB7060@sol> References: <20261201043945.50022-1-laveeshb@laveeshbansal.com> <20261201043945.50022-3-laveeshb@laveeshbansal.com> X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261201043945.50022-3-laveeshb@laveeshbansal.com> Thanks for the patch! On Mon, Nov 30, 2026 at 08:39:45PM -0800, Laveesh Bansal wrote: > 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 > select CRYPTO_LIB_POLY1305_GENERIC > select CRYPTO_MANAGER CRYPTO_MANAGER should be removed too, since it was only needed for template support. Also, please keep the options in alphabetical order. > /* > * Given the XChaCha stream key K_S, derive the block cipher key K_E and the > @@ -99,31 +104,21 @@ static int adiantum_setkey(struct crypto_skcipher *tfm, const u8 *key, > unsigned int keylen) > { > struct adiantum_tfm_ctx *tctx = crypto_skcipher_ctx(tfm); > - SYNC_SKCIPHER_REQUEST_ON_STACK( > - req, (struct crypto_sync_skcipher *)tctx->streamcipher); > u8 poly_keys[2 * POLY1305_BLOCK_SIZE]; > u8 iv[XCHACHA_IV_SIZE] = { 1 }; 'iv' can be made 'static const', now that it no longer is passed to the crypto_skcipher API which requires mutability. > - 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; > + adiantum_xchacha_init(&state, tctx->stream_key, tctx->nrounds, > + rbuf.bytes); > + adiantum_stream_xor(&state, tctx->nrounds, req->src, req->dst, > + stream_len); > + chacha_zeroize_state(&state); This should all be under 'if (bulk_len)', so that if nothing needs to be encrypted with the stream cipher then an unnecessary HChaCha computation isn't done. Also, this uses 'req->src' and 'req->dst' instead of the src and dst local variables used elsewhere in the function. > +static int adiantum_init_tfm(struct crypto_skcipher *tfm, int nrounds) > { > - struct skcipher_instance *inst = skcipher_alg_instance(tfm); > - struct adiantum_instance_ctx *ictx = skcipher_instance_ctx(inst); > struct adiantum_tfm_ctx *tctx = crypto_skcipher_ctx(tfm); > - struct crypto_skcipher *streamcipher; > - > - streamcipher = crypto_spawn_skcipher(&ictx->streamcipher_spawn); > - if (IS_ERR(streamcipher)) > - return PTR_ERR(streamcipher); > - if (WARN_ON(crypto_skcipher_reqsize(streamcipher) > > - MAX_SYNC_SKCIPHER_REQSIZE)) { > - crypto_free_skcipher(streamcipher); > - return -EINVAL; > - } > > - tctx->streamcipher = streamcipher; > - > - BUILD_BUG_ON(offsetofend(struct adiantum_request_ctx, u) != > - sizeof(struct adiantum_request_ctx)); > - crypto_skcipher_set_reqsize( > - tfm, max(sizeof(struct adiantum_request_ctx), > - offsetofend(struct adiantum_request_ctx, > - u.streamcipher_req) + > - crypto_skcipher_reqsize(streamcipher))); > + tctx->nrounds = nrounds; > + crypto_skcipher_set_reqsize(tfm, sizeof(struct nhpoly1305_ctx)); > return 0; Instead of crypto_skcipher_set_reqsize(), just set .base.cra_reqsize in the struct skcipher_alg. That would leave setting tctx->nrounds as the only thing here. It would be a bit simpler to handle that in setkey instead. > +#define ADIANTUM_ALG(rounds) \ > + { \ > + .base.cra_name = "adiantum(xchacha" #rounds ",aes)", \ > + .base.cra_driver_name = \ > + "adiantum(xchacha" #rounds "-lib,aes-lib)", \ > + .base.cra_priority = 300, \ > + .base.cra_blocksize = AES_BLOCK_SIZE, \ > + .base.cra_ctxsize = sizeof(struct adiantum_tfm_ctx), \ > + .base.cra_module = THIS_MODULE, \ > + .setkey = adiantum_setkey, \ > + .encrypt = adiantum_encrypt, \ > + .decrypt = adiantum_decrypt, \ > + .init = adiantum_init_xchacha##rounds##_tfm, \ > + .min_keysize = CHACHA_KEY_SIZE, \ > + .max_keysize = CHACHA_KEY_SIZE, \ > + .ivsize = TWEAK_SIZE, \ Since there are only two of these, I think I'd prefer that they each just be written out explicitly. Especially since the above proposal would generate the strings using concatenation, making them difficult to find in searches. - Eric