Skip to contentSkip to conversation

crypto: chacha-generic - use crypto_xor_cpy()

PATCH In review Eric Biggers 2 participants 2 messages Mar 15, 2019 – Mar 22, 2019 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: chacha-generic - use crypto_xor_cpy()

From: Eric Biggers <[email protected]>

In chacha_docrypt(), use crypto_xor_cpy() instead of crypto_xor(). This avoids having to memcpy() the src buffer to the dst buffer.

---
 crypto/chacha_generic.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
crypto/chacha_generic.c +3 -5
index 90ec0ec1b4f7..a7fae9b73ec4 100644
@@ -22,18 +22,16 @@ static void chacha_docrypt(u32 *state, u8 *dst, const u8 *src,
 	/* aligned to potentially speed up crypto_xor() */
 	u8 stream[CHACHA_BLOCK_SIZE] __aligned(sizeof(long));
 
-	if (dst != src)
-		memcpy(dst, src, bytes);
-
 	while (bytes >= CHACHA_BLOCK_SIZE) {
 		chacha_block(state, stream, nrounds);
-		crypto_xor(dst, stream, CHACHA_BLOCK_SIZE);
+		crypto_xor_cpy(dst, src, stream, CHACHA_BLOCK_SIZE);
 		bytes -= CHACHA_BLOCK_SIZE;
 		dst += CHACHA_BLOCK_SIZE;
+		src += CHACHA_BLOCK_SIZE;
 	}
 	if (bytes) {
 		chacha_block(state, stream, nrounds);
-		crypto_xor(dst, stream, bytes);
+		crypto_xor_cpy(dst, src, stream, bytes);
 	}
 }
 
Signature · 1 line
2.21.0
maintainer
#1 lore raw
Quoted 9 lines · Eric Biggers

From: Eric Biggers <[email protected]>

In chacha_docrypt(), use crypto_xor_cpy() instead of crypto_xor(). This avoids having to memcpy() the src buffer to the dst buffer.

---
 crypto/chacha_generic.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt