From 61555d45676473e77c11f8da97301e2d2b865871 Mon Sep 17 00:00:00 2001 From: Alain Mosnier Date: Sun, 4 Aug 2019 14:20:53 +0200 Subject: [PATCH] While I'm at it, squeeze out a little more performance by changing some integer regular arithmetic to bitwise operations. I'm not sure that would make any difference if I used optimized compilation, but it might still make a difference on some old compilers. It seems to make a difference on gcc without optimization on my Linux machine (and, of course, it does not break the tests). Before: real 1m6,707s user 1m6,035s sys 0m0,672s After: real 1m6,352s user 1m5,672s sys 0m0,680s --- sha-256.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sha-256.c b/sha-256.c index a79bdfb..cd923ea 100644 --- a/sha-256.c +++ b/sha-256.c @@ -187,7 +187,7 @@ void calc_sha_256(uint8_t hash[32], const void * input, size_t len) } const uint32_t s1 = right_rot(ah[4], 6) ^ right_rot(ah[4], 11) ^ right_rot(ah[4], 25); const uint32_t ch = (ah[4] & ah[5]) ^ (~ah[4] & ah[6]); - const uint32_t temp1 = ah[7] + s1 + ch + k[i * 16 + j] + w[j]; + const uint32_t temp1 = ah[7] + s1 + ch + k[i << 4 | j] + w[j]; const uint32_t s0 = right_rot(ah[0], 2) ^ right_rot(ah[0], 13) ^ right_rot(ah[0], 22); const uint32_t maj = (ah[0] & ah[1]) ^ (ah[0] & ah[2]) ^ (ah[1] & ah[2]); const uint32_t temp2 = s0 + maj;