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=1796178615; b=ITMvBtx1yFmmc4O9o4YecEiUCl3YaQ/x9937BGFYHMONOf2eLaeTTmq91PrSsnw2HXEN tIpWb6fSdTaIHYEPr04txnhp8PMLjkWMZwkeaJXA17lX/D7z/K+CJeUPxOGS8dDauJ17+ Gb/0YvUGRZcAM3K0/lZ0OYhA5MPpMLo4zqoPRb8SmIcQLpUDtqtoMMh3aPm4ilAdyZL8D U1NJCL/tRsSTg9ZjgmPbFQxGNBCJ1DAsphpGbrJz3PaFzscW03jcsFWPFB5httI/OSFB5 O+1So+wz1Ot1l8ugGC231cOU91HaK1Ol6cjXK0SSzxlB2h/EWT83upios6zCCK9g0YQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796178615; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=vK+Rf18hEATAR5611tvNvWRVWLEy+8oTTlEj/GZ66BA=; b=bMbLaqkfPYtHxMArTOFWKfj34MSgjDmQcslSZamdyEV6oBkgYmeqATS3u5N7JlNDKiNA uJywWaDbbC1es81vEifuLP0HoXb/crU1iIF6aWgej4wH/PhFNI44K3j8fevY3aVQ48r7u 7kzlVekDGk+lk8OGI+7VJPji/5ZMdDK2mo1UW0ZszvLTHmh1cfL3Ftyzp4PDWEeNPiiYt KjqfKF+DBgjuJz4qSdsXHOnUo0w+o3RUaDgRtCjJO3NZP3j4lKg9TAu0FFaLTJvKu2yHM msHnh7BunlPMKsz1bxcfvpMVF16eapSPNtVYxaCySdretCx9DtvOuty/WYZO9tDuYHg== 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=SZNoW0tv; 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 C13D4606A68C; Wed, 2 Dec 2026 02:30:15 +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=SZNoW0tv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BE401F0089A; Wed, 2 Dec 2026 02:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796178615; bh=vK+Rf18hEATAR5611tvNvWRVWLEy+8oTTlEj/GZ66BA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=SZNoW0tvdtbO/flQrkMzVOJykxJqJXvi+t6sm19Q1Zr88KD/EBUKyP2vNX6ndmFtr 0nZKd7X+S4WHVJkR891AWV+lSNPMj+RFZP0mBx0kuLz7olSGHCt+GoMIa06UYIMVag fTlxrgmhO+oDhWRSiF5CXQwFn5z1SGmgIzMELGcn47F02uXIDBO4e8MtuxRaqQjgpe raJxZ6IFa6M6FeFjZjLGTE4RP5EejtEwE/blLMWYFURB8mosJQ4uDYV78CY7xq1AV9 hTO73+qtmgohWi0/fpDRn0HljaqCErb+IcvXZms7z/MBDaFmQIOfBadsdNvl+TWo7n ovK8kfRzIckHA== Date: Wed, 2 Dec 2026 02:30:13 +0000 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 v3 2/2] crypto: adiantum - Use the ChaCha library Message-ID: <20261202023013.GC2427638@google.com> References: <20261201080825.56171-1-laveeshb@laveeshbansal.com> <20261201080825.56171-3-laveeshb@laveeshbansal.com> X-Mailing-List: linux-kernel@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: <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 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