From c08d3c300b11adc9ac02d90e59c7306ea6c0bcd3 Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Sat, 24 Feb 2018 15:46:49 +0100 Subject: [PATCH] Strength reduction for Chacha20 The performance gain is tiny, but measurable. --- src/monocypher.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/monocypher.c b/src/monocypher.c index 5fee4de..a792b38 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -236,15 +236,16 @@ void crypto_chacha20_encrypt(crypto_chacha_ctx *ctx, if (plain_text != 0) { FOR (j, 0, 16) { u32 plain = load32_le(plain_text); - store32_le(cipher_text + j * 4, ctx->pool[j] ^ plain); - plain_text += 4; + store32_le(cipher_text, ctx->pool[j] ^ plain); + plain_text += 4; + cipher_text += 4; } } else { FOR (j, 0, 16) { - store32_le(cipher_text + j * 4, ctx->pool[j]); + store32_le(cipher_text, ctx->pool[j]); + cipher_text += 4; } } - cipher_text += 64; ctx->pool_idx = 64; } -- 2.47.3