summaryrefslogtreecommitdiffhomepage
path: root/src/crypto/zinc/chacha20/chacha20.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-09-19 04:02:01 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-09-20 00:57:59 +0200
commitcc2113b5b27c7ee45711df05c49a7d05bd0a934e (patch)
tree8aae932419bbc43aabbcb39fda208fe37c19c9cf /src/crypto/zinc/chacha20/chacha20.c
parentafdd509ad206e0a3858118ac4c26fbc709af3562 (diff)
chacha20: prefer crypto_xor_cpy to avoid memmove
Suggested-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/zinc/chacha20/chacha20.c')
-rw-r--r--src/crypto/zinc/chacha20/chacha20.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/crypto/zinc/chacha20/chacha20.c b/src/crypto/zinc/chacha20/chacha20.c
index a7c7adc..72e24da 100644
--- a/src/crypto/zinc/chacha20/chacha20.c
+++ b/src/crypto/zinc/chacha20/chacha20.c
@@ -105,18 +105,16 @@ static void chacha20_generic(u8 *out, const u8 *in, u32 len, const u32 key[8],
counter[0], counter[1], counter[2], counter[3]
};
- if (out != in)
- memmove(out, in, len);
-
while (len >= CHACHA20_BLOCK_SIZE) {
chacha20_block_generic(buf, x);
- crypto_xor(out, (u8 *)buf, CHACHA20_BLOCK_SIZE);
+ crypto_xor_cpy(out, in, (u8 *)buf, CHACHA20_BLOCK_SIZE);
len -= CHACHA20_BLOCK_SIZE;
out += CHACHA20_BLOCK_SIZE;
+ in += CHACHA20_BLOCK_SIZE;
}
if (len) {
chacha20_block_generic(buf, x);
- crypto_xor(out, (u8 *)buf, len);
+ crypto_xor_cpy(out, in, (u8 *)buf, len);
}
}