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=1796067614; b=cJ/jlJ6fVUlUr66CzQsb+xvEmihv7dx3t7zsokOQxUQ82zE6ehavUQiNogeDFNYGmOCg b1CCQtDRKoO331Pr8XReCp4v7dvEaj6zMOeMlzQ60Lxl6bOpcHkiTYFjCxTVSchvxLo7O FcP5YIEbPOrfilGPgOylfH3ZUENuwIXdYrVSr7O1HAgjQx/7NzD9fGqwfCVC9YXLfpQLK RnHQkDIYwBpl5xi/rDy9HNMXaWr/ylmKuy0BZID37VBrQF1XFFRv2/m+3R4io5hNT6Muh 0brFodn3JLGXkC/vWGFbEugo2iCeOlKqBoq5E1rGT3axlXsdJ0gr1G40SiJcVw09PZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796067614; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=FPNgvlHJCP+2O8dcnxe5gTY1/JshixfMwnsF3XCnDSY=; b=qu9AK7ed0JJFhLjPhKILdQbwZg7IMdV2VW/xd0QZpRqyx/nfxhF1IG0kVGqDk/tK5A60 tyYUIIMHN2V4LWIr9ZfOxudQBIClYHNI7cE0599S2rhx+rPNHR0p7HT57ebTh1ENJgDF5 twplBybwECo8Lo292vtc+uYweQyGp7z30o9vmPVBGc3q2ZiLRFUouwNr2DL+3lh4I7nw4 ose1mKRqzlDjwZ6i8qDtN92b+OOOgY/7RP7PTKb3v0fsnrKwtT4Rbo5kMauiiq0AW02Z3 npvIrYJQVNMfcAIAoyo4nCF6u0Xc3W38bEbB/KE+vW953BT/pQm96P9GlW74Gic7dIg== 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=KTj05syA; 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 CF4F1606A320; Mon, 30 Nov 2026 19:40:14 +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=KTj05syA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B5581F000C1; Mon, 30 Nov 2026 19:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796067614; bh=FPNgvlHJCP+2O8dcnxe5gTY1/JshixfMwnsF3XCnDSY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=KTj05syA+wMn870Ng9zSXXbklA4cF3E1uHPzh4/2YpkzDZDpc4ngULmk3aC9sb8xX 5a3eGlKq3ZaNiFlsOs9EUyRLM6XgQ1MuH0Ff6nFcVJhpWIhoeCVmv0ikcVEJErBMl4 3PxH57CI/Ey1LbEyT+5b6VIX2Vf01zkLSbFQQGNLbVDMdMSzCwCelHuH+RcBilF792 5DcDR88dx2b0sB4UyVWs91xGxKfJheZhp94iqRWD9KpKLn0sgx6gydjOc8yzhxOEz7 TTF076hO54zuzoOUvCjO1aqimRR7g64JtKQP/Y7R6z6YKjpPqDmsEZHVP1FcLWCGJG DwpENDpXtdt5g== Date: Mon, 30 Nov 2026 19:40:12 +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 3/3] crypto: adiantum - Use the ChaCha library for the stream cipher Message-ID: <20261130194012.GA16775@google.com> References: <20261130055539.8278-1-laveeshb@laveeshbansal.com> <20261130055539.8278-4-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: <20261130055539.8278-4-laveeshb@laveeshbansal.com> On Sun, Nov 29, 2026 at 09:55:39PM -0800, Laveesh Bansal wrote: > adiantum_crypt() runs the XChaCha step through a child crypto_skcipher. > That needs a spawn, a child tfm and a request sized for the child. > > Call chacha_crypt() directly instead and remove the child. The library > works on plain buffers, so adiantum walks the source and destination > scatterlists itself. > > Suggested-by: Eric Biggers > Signed-off-by: Laveesh Bansal > --- > Notes: > > I tested this patch in the same environments as patch 2. > > I also ran a test module that splits src and dst at random offsets - > in place and out of place - and compares the result with a plain > buffer. They match. This one I did on arm64 and x86_64. > > Another one I ran is the tcrypt adiantum speed test; > I did this on arm64 in a KVM guest with debug options off. > I did not find any slowness in performance when compared > with results on base + setkey + aeslib. I can share specific test > results if anybody is interested. > > crypto/Kconfig | 3 +- > crypto/adiantum.c | 164 ++++++++++++++++++++-------------------------- > 2 files changed, 74 insertions(+), 93 deletions(-) > > diff --git a/crypto/Kconfig b/crypto/Kconfig > index 7cac0141a73cb..93996d1240380 100644 > --- a/crypto/Kconfig > +++ b/crypto/Kconfig > @@ -578,7 +578,8 @@ menu "Length-preserving ciphers and modes" > > 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 > diff --git a/crypto/adiantum.c b/crypto/adiantum.c > index f53d6d5f56fb9..2358f61e88ce9 100644 > --- a/crypto/adiantum.c > +++ b/crypto/adiantum.c > @@ -41,13 +41,11 @@ > #define TWEAK_SIZE 32 > > struct adiantum_instance_ctx { > - struct crypto_skcipher_spawn streamcipher_spawn; > int nrounds; > }; Now that there are no inner algorithms ("spawns") left, it doesn't make sense for this to be a template anymore. This file should instead just register two crypto_skcipher algorithms, "adiantum(xchacha12,aes)" (driver name "adiantum(xchacha12-lib,aes-lib)"), and "adiantum(xchacha20,aes)" (driver name "adiantum(xchacha20-lib,aes-lib)"). > +static void adiantum_stream_xor(struct chacha_state *state, int nrounds, > + struct scatterlist *src, > + struct scatterlist *dst, unsigned int len) > +{ > + struct scatter_walk swalk, dwalk; > + > + scatterwalk_start(&swalk, src); > + scatterwalk_start(&dwalk, dst); > + while (len) { > + unsigned int n = min(scatterwalk_clamp(&swalk, len), > + scatterwalk_clamp(&dwalk, len)); > + > + /* > + * The ChaCha counter advances in whole blocks, so every > + * step except the last must be a whole number of blocks. > + */ > + if (n < len) > + n = round_down(n, CHACHA_BLOCK_SIZE); > + if (n) { > + scatterwalk_map(&swalk); > + scatterwalk_map(&dwalk); > + chacha_crypt(state, dwalk.addr, swalk.addr, n, nrounds); > + scatterwalk_done_dst(&dwalk, n); > + scatterwalk_done_src(&swalk, n); > + } else { > + u8 buf[CHACHA_BLOCK_SIZE]; > + > + n = min(len, CHACHA_BLOCK_SIZE); > + memcpy_from_scatterwalk(buf, &swalk, n); > + chacha_crypt(state, buf, buf, n, nrounds); > + memcpy_to_scatterwalk(&dwalk, buf, n); > + } > + len -= n; This is not correct, since for in-place operations with CONFIG_HIGHMEM=y the same memory is being mapped multiple times. The in-place case either needs to be handled directly, like crypto/aes.c does, or skcipher_walk should be used which handles this. (Also, 'buf' is not being zeroized when it goes out of scope.) - Eric