From: Eric Biggers <ebiggers@kernel.org>
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 " <Jason@zx2c4.com>,
Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 2/4] crypto: lib/chacha - use struct assignment to copy state
Date: Mon, 5 May 2025 11:18:22 -0700 [thread overview]
Message-ID: <20250505181824.647138-3-ebiggers@kernel.org> (raw)
In-Reply-To: <20250505181824.647138-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
Use struct assignment instead of memcpy() in lib/crypto/chacha.c where
appropriate. No functional change.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
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);
--
2.49.0
WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
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 " <Jason@zx2c4.com>,
Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 2/4] crypto: lib/chacha - use struct assignment to copy state
Date: Mon, 5 May 2025 11:18:22 -0700 [thread overview]
Message-ID: <20250505181824.647138-3-ebiggers@kernel.org> (raw)
In-Reply-To: <20250505181824.647138-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
Use struct assignment instead of memcpy() in lib/crypto/chacha.c where
appropriate. No functional change.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
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);
--
2.49.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-05-05 18:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 18:18 [PATCH 0/4] crypto: lib/chacha - improve type safety Eric Biggers
2025-05-05 18:18 ` Eric Biggers
2025-05-05 18:18 ` [PATCH 1/4] crypto: lib/chacha - strongly type the ChaCha state Eric Biggers
2025-05-05 18:18 ` Eric Biggers
2025-05-06 16:09 ` Kent Overstreet
2025-05-06 16:09 ` Kent Overstreet
2025-05-05 18:18 ` Eric Biggers [this message]
2025-05-05 18:18 ` [PATCH 2/4] crypto: lib/chacha - use struct assignment to copy state Eric Biggers
2025-05-05 18:18 ` [PATCH 3/4] crypto: lib/chacha - add strongly-typed state zeroization Eric Biggers
2025-05-05 18:18 ` Eric Biggers
2025-05-05 18:18 ` [PATCH 4/4] crypto: lib/chacha - add array bounds to function prototypes Eric Biggers
2025-05-05 18:18 ` Eric Biggers
2025-05-12 5:45 ` [PATCH 0/4] crypto: lib/chacha - improve type safety Herbert Xu
2025-05-12 5:45 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250505181824.647138-3-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-bcachefs@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.