From f302ecfb119b4a0909652258d648b14c2353629c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 5 Feb 2013 01:29:20 +0100 Subject: optimise keccak-f and rotate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- java/SHA3.java | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'java') diff --git a/java/SHA3.java b/java/SHA3.java index bb1daf9..abf2ebc 100644 --- a/java/SHA3.java +++ b/java/SHA3.java @@ -132,8 +132,8 @@ public class SHA3 */ private static long rotate(long x, int n) { - long m = n % SHA3.w; - return ((x >>> (SHA3.w - m)) + (x << m)) & SHA3.wmod; + long m; + return ((x >>> (SHA3.w - (m = n % SHA3.w))) + (x << m)) & SHA3.wmod; } @@ -307,32 +307,8 @@ public class SHA3 private static void keccakF(long[] A) { if (SHA3.nr == 24) - { - SHA3.keccakFRound(A, 0x0000000000000001L); - SHA3.keccakFRound(A, 0x0000000000008082L); - SHA3.keccakFRound(A, 0x800000000000808AL); - SHA3.keccakFRound(A, 0x8000000080008000L); - SHA3.keccakFRound(A, 0x000000000000808BL); - SHA3.keccakFRound(A, 0x0000000080000001L); - SHA3.keccakFRound(A, 0x8000000080008081L); - SHA3.keccakFRound(A, 0x8000000000008009L); - SHA3.keccakFRound(A, 0x000000000000008AL); - SHA3.keccakFRound(A, 0x0000000000000088L); - SHA3.keccakFRound(A, 0x0000000080008009L); - SHA3.keccakFRound(A, 0x000000008000000AL); - SHA3.keccakFRound(A, 0x000000008000808BL); - SHA3.keccakFRound(A, 0x800000000000008BL); - SHA3.keccakFRound(A, 0x8000000000008089L); - SHA3.keccakFRound(A, 0x8000000000008003L); - SHA3.keccakFRound(A, 0x8000000000008002L); - SHA3.keccakFRound(A, 0x8000000000000080L); - SHA3.keccakFRound(A, 0x000000000000800AL); - SHA3.keccakFRound(A, 0x800000008000000AL); - SHA3.keccakFRound(A, 0x8000000080008081L); - SHA3.keccakFRound(A, 0x8000000000008080L); - SHA3.keccakFRound(A, 0x0000000080000001L); - SHA3.keccakFRound(A, 0x8000000080008008L); - } + for (int i = 0; i < SHA3.nr; i++) + SHA3.keccakFRound(A, SHA3.RC[i]); else for (int i = 0; i < SHA3.nr; i++) SHA3.keccakFRound(A, SHA3.RC[i] & SHA3.wmod); -- cgit v1.2.3-70-g09d2