From patchwork Mon May 5 18:18:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 887624 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F3F626F46F; Mon, 5 May 2025 18:19:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469164; cv=none; b=TtAMRXFfkXdY8xjIaunTdULMwMR1uqKDqO2fcF7Ew6lbV+EmQp9US71sQiEwRwk/goCidiMzIuHhOfTfwltNNWKPkc8sof7oIPBKB/Crnncc/8afuJ+dW4SoGJ4fmiuYq/Bh3K+qkb8vopdfcyAkwKWERx4BzlZwK8NYUP8l4Lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746469164; c=relaxed/simple; bh=b/9JYhuN7J7zBR7ary1s1WvggcmHZ7V9W2w6tJgLRtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hFInGnphNeiTFw/MsKURA2nMFKmqWqjLTtemwDft6VcxsnBMf0Qwx1S1FEsdXYqG2K7EVyg8SgbE4W/KB6cF70SgFhu7i59eqSw1hd4XcymtdAELIvsnjCbEf0LUlYntDnFFahWtT9c3CTgh3fnx07HDPohptMWulaRzau4bcIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pDa53t6D; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pDa53t6D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E8EEC4CEEE; Mon, 5 May 2025 18:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746469163; bh=b/9JYhuN7J7zBR7ary1s1WvggcmHZ7V9W2w6tJgLRtw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pDa53t6DCjWYM/LmZqGF9bnJJ573ftIBSUQsp8IeHuT5N7tEcbBprRacM6EAolgWa KnM4f1Ecr4wsjUKSjvQrsrEOI61Z1Nenrn/tYHyD0VxpliwIloUv60+380sygQKeFn FxwIMuAGqXJ/SCu+mhdkAvNtZ/VV+Hpcs9PRhT0j3hKSDgORzS83PV0rP1IGISbSpL aTZfyBqlR/WkgLr3KGW3DlBmln+QJkH1npbWh+vtLcej0hH78R6O4qdEbRHUlUrbSw ke0NPkusn8yL0Rp2/trfxhRJ3n8yZzmTAV2C0r7cHVP5MRtIDrFszeZGaEVvf/LP32 dPGvxobHLcyGg== From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-bcachefs@vger.kernel.org, "Jason A . Donenfeld " , Theodore Ts'o Subject: [PATCH 2/4] crypto: lib/chacha - use struct assignment to copy state Date: Mon, 5 May 2025 11:18:22 -0700 Message-ID: <20250505181824.647138-3-ebiggers@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250505181824.647138-1-ebiggers@kernel.org> References: <20250505181824.647138-1-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Eric Biggers Use struct assignment instead of memcpy() in lib/crypto/chacha.c where appropriate. No functional change. Signed-off-by: Eric Biggers --- lib/crypto/chacha.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/crypto/chacha.c b/lib/crypto/chacha.c index a7f5eb091839..ae50e441f9fb 100644 --- a/lib/crypto/chacha.c +++ b/lib/crypto/chacha.c @@ -74,15 +74,13 @@ static void chacha_permute(struct chacha_state *state, int nrounds) * The caller has already converted the endianness of the input. This function * also handles incrementing the block counter in the input matrix. */ void chacha_block_generic(struct chacha_state *state, u8 *stream, int nrounds) { - struct chacha_state permuted_state; + struct chacha_state permuted_state = *state; int i; - memcpy(permuted_state.x, state->x, 64); - chacha_permute(&permuted_state, nrounds); for (i = 0; i < ARRAY_SIZE(state->x); i++) put_unaligned_le32(permuted_state.x[i] + state->x[i], &stream[i * sizeof(u32)]); @@ -103,13 +101,11 @@ EXPORT_SYMBOL(chacha_block_generic); * of the state. It should not be used for streaming directly. */ void hchacha_block_generic(const struct chacha_state *state, u32 *stream, int nrounds) { - struct chacha_state permuted_state; - - memcpy(permuted_state.x, state->x, 64); + struct chacha_state permuted_state = *state; chacha_permute(&permuted_state, nrounds); memcpy(&stream[0], &permuted_state.x[0], 16); memcpy(&stream[4], &permuted_state.x[12], 16);