]> git.codecow.com Git - Monocypher.git/commitdiff
Removed modulo operation in SHA-512
authorLoup Vaillant <loup@loup-vaillant.fr>
Fri, 14 Feb 2020 23:27:25 +0000 (00:27 +0100)
committerLoup Vaillant <loup@loup-vaillant.fr>
Fri, 14 Feb 2020 23:27:25 +0000 (00:27 +0100)
While I expect almost all compilers optimise those down to a bit mask in
practice, it can help naive compilers generate better code. The rest of
Monocypher already took this approach, I just forgot about this one.

src/optional/monocypher-ed25519.c

index f6b462861609e8f34a170c52271a76a74464b3f8..fe844ce15443c28a7010d407b89b124885247d8b 100644 (file)
@@ -163,8 +163,8 @@ static void sha512_set_input(crypto_sha512_ctx *ctx, u8 input)
             ctx->input[i] = 0;
         }
     }
-    size_t word = ctx->input_idx / 8;
-    size_t byte = ctx->input_idx % 8;
+    size_t word = ctx->input_idx >> 3;
+    size_t byte = ctx->input_idx &  7;
     ctx->input[word] |= (u64)input << (8 * (7 - byte));
 }