]> git.codecow.com Git - Monocypher.git/commitdiff
Optimised Poly1305 loading code
authorLoup Vaillant <loup@loup-vaillant.fr>
Fri, 22 Mar 2019 20:52:30 +0000 (21:52 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Fri, 22 Mar 2019 20:52:30 +0000 (21:52 +0100)
By actually *rolling* the loading code.  I haven't looked at the
assembly, but I suspect the loop is easier for the compiler to
vectorise.

This results in a 5% speed increase on my machine (Intel i5 Skylake
laptop, gcc 7.3.0).

This fix was made possible by @Sadoon-AlBader on GitHub, who submitted
pull request #118

src/monocypher.c

index 55a0d4c55d214c141925698d4a9decaf9abeee0c..efa04f3ba33ba254beccf77b3e655c7cd6575eb7 100644 (file)
@@ -388,10 +388,9 @@ void crypto_poly1305_update(crypto_poly1305_ctx *ctx,
     // Process the message block by block
     size_t nb_blocks = message_size >> 4;
     FOR (i, 0, nb_blocks) {
-        ctx->c[0] = load32_le(message +  0);
-        ctx->c[1] = load32_le(message +  4);
-        ctx->c[2] = load32_le(message +  8);
-        ctx->c[3] = load32_le(message + 12);
+        FOR (i, 0, 4) {
+            ctx->c[i] = load32_le(message +  i*4);
+        }
         poly_block(ctx);
         message += 16;
     }