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=1796322822; b=18SGV4WBNPnzM5hok8AdSxGBQmTWpzxnsrhbjCDE0zwAAUuUYJvgORhWE7XHvxR+WSmP tglBVKpvUmf6FQD5jlqe3JxxUqoS3vLa6EYjvw4/e/xQtX5ApVry9ONjpUS9eqlCczlWk oHjhekEXfRmKX+nvGe0qTJ+kBnThFrkvChgh9akUaYl4uRkKShlMlux4ZZA0GeMJw+f86 EiF0dv0boI4An7HlVKmxa9dkmLAKku+LIEQCroqZv2x/7A3fphh7XG4Kr4ratrikIHJyO +ceYzJp/RsAsslWkY/PxSBUb/L7E9zUeSohnEXj6uPU3lswM7TUmQZ6l+4GTxOF5VBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796322822; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=J5cqOjyP/vqGnbKVtn7LqFjVukrufOAMwDDT1sp5gzc=; b=HJ/VJuYhWv1EQdzyTOTn1dCBJLE1JiGeCjy7z3FN0Miwlp9LpnqN18ZR9tmv7Nu6V50p pv2MJYLfdrTRaIXdjQnpPzCCVE2DTQUGl/NZ98L0t15lTpQGmYDCpYUSfAq6155g0otkY Ijfn0FOeEfXMn0p6hT8S6fH9UzOqIg/VSCrlHNSd283TMe1P3d5e4yhFuS6n/5Eae9IyL wqBU9CBfgjyURjdjGTz/xmDuToiAMkTkrtDQR6NzF4206ddO8Sw9iTmgYxZp7qPY4jEV6 b3HONBaGuSeGsEyr7KjeWYPmZkrtl53gTqxI55pt6e1WXya0lHylcvoR35zJPdrjjbg== 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=ROwYJHZJ; 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 7EC00606A32C; Thu, 3 Dec 2026 18:33:42 +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=ROwYJHZJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0A101F00898; Thu, 3 Dec 2026 18:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796322822; bh=J5cqOjyP/vqGnbKVtn7LqFjVukrufOAMwDDT1sp5gzc=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=ROwYJHZJRI1le2cEo7vC3yRKdffjI/ejFpfE5DE0e/CWHKHg3MdeiYPZraIMrHN+8 vyOS8f3Rc+E7hK2YNLxf192vk970XgVCIzvKqxgzU5eGcDwJJddtgi3+eFyAhkal3g FuxlKgaLBil7+F2aD7pY3Q3rXj1uhq9MEk74yEtCjrkezMfIgbSTlXsTW2PXwKZ7B9 e05n7rjy3C0txJLLG1P8FoiCq2RNxHMZgRcbDivrzcXBp44X0jsB5E8hhfWvztOgFf IV/NAfoqaOZsrnC+P6XIv1/0TFevUIKIVP6YSkQyA4udBH97VejIBpSHatrJ/fbJQk 3ZW28cDZbNLlg== Date: Thu, 3 Dec 2026 10:33:40 -0800 From: Eric Biggers To: sashiko-reviews@lists.linux.dev Cc: Laveesh Bansal , Herbert Xu , "Jason A. Donenfeld" , Ard Biesheuvel , "David S. Miller" , linux-crypto@vger.kernel.org Subject: Re: [PATCH] crypto: chacha - Consolidate XChaCha initialization Message-ID: <20261203183340.GB2267@sol> References: <20261203161849.85971-1-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: On Thu, Dec 03, 2026 at 04:36:56PM +0000, sashiko-bot@kernel.org wrote: > > +static inline void xchacha_init(struct chacha_state *state, > > + const u32 key[at_least CHACHA_KEY_WORDS], > > + const u8 nonce[at_least XCHACHA_NONCE_SIZE], > > + int nrounds) > > +{ > > + u32 subkey[HCHACHA_OUT_WORDS]; > > + u8 iv[CHACHA_IV_SIZE] = {}; > > + > > + /* Compute the subkey given the original key and first 128 nonce bits */ > > + chacha_init(state, key, nonce); > > + hchacha_block(state, subkey, nrounds); > > + > > + memcpy(&iv[8], nonce + 16, 8); > > + chacha_init(state, subkey, iv); > > + > > + memzero_explicit(subkey, sizeof(subkey)); > > +} > > [Severity: Low] > Should xchacha_init() also zeroize iv with memzero_explicit() before > returning? > > Previously, xchacha_init() in lib/crypto/chacha20poly1305.c cleared its > stack iv buffer with memzero_explicit(iv, sizeof(iv)). Leaving iv > uncleared here leaves the upper 8 nonce bytes on the stack on every > xchacha20poly1305_encrypt() or xchacha20poly1305_decrypt() call. We can avoid the 'iv' buffer by replacing the second chacha_init() with the following instead: memcpy(&state->x[4], subkey, sizeof(subkey)); state->x[12] = 0; state->x[13] = 0; state->x[14] = get_unaligned_le32(nonce + 16); state->x[15] = get_unaligned_le32(nonce + 20); state->x[0..3] still contain the constants from the first init. - Eric