From: Eric Biggers <ebigg...@google.com>

Use struct assignment instead of memcpy() in lib/crypto/chacha.c where
appropriate.  No functional change.

Signed-off-by: Eric Biggers <ebigg...@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


Reply via email to