]> git.codecow.com Git - Monocypher.git/commitdiff
Strength reduction for Chacha20
authorLoup Vaillant <loup@loup-vaillant.fr>
Sat, 24 Feb 2018 14:46:49 +0000 (15:46 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Sat, 24 Feb 2018 14:47:53 +0000 (15:47 +0100)
The performance gain is tiny, but measurable.

src/monocypher.c

index 5fee4dee6117bd8ea098531ecba90c610495a20f..a792b38976f74ab20b0b41b9b636d7a63b41c5ef 100644 (file)
@@ -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;
     }