From d36944946ecda0a48c885702fc4b0b20618ecd16 Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Sat, 15 Feb 2020 00:27:25 +0100 Subject: [PATCH] Removed modulo operation in SHA-512 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/optional/monocypher-ed25519.c b/src/optional/monocypher-ed25519.c index f6b4628..fe844ce 100644 --- a/src/optional/monocypher-ed25519.c +++ b/src/optional/monocypher-ed25519.c @@ -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)); } -- 2.47.3