From aa9e0904955015a880b8bb3ecc29c03f56043fe1 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 19 Sep 2018 04:02:01 +0200 Subject: chacha20: prefer crypto_xor_cpy to avoid memmove Suggested-by: Eric Biggers --- src/crypto/zinc/chacha20/chacha20.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/crypto/zinc/chacha20/chacha20.c') 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); } } -- cgit v1.2.3-59-g8ed1b