aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-02-05 02:08:20 +0100
committerMattias Andrée <maandree@operamail.com>2013-02-05 02:08:20 +0100
commitf00288a76da730087009a9f9810a7f332d64c862 (patch)
tree4496bfb555c980e2c08cd2b6d1bd15410d18e928 /java
parentoptimise first part of the theta step (diff)
downloadsha3sum-f00288a76da730087009a9f9810a7f332d64c862.tar.gz
sha3sum-f00288a76da730087009a9f9810a7f332d64c862.tar.bz2
sha3sum-f00288a76da730087009a9f9810a7f332d64c862.tar.xz
java optimised
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--java/SHA3.java80
1 files changed, 34 insertions, 46 deletions
diff --git a/java/SHA3.java b/java/SHA3.java
index f71b355..5b4796e 100644
--- a/java/SHA3.java
+++ b/java/SHA3.java
@@ -176,85 +176,73 @@ public class SHA3
for (int i = 0, j = 0; i < 5; i++, j += 5)
SHA3.C[i] = (A[j] ^ A[j + 1]) ^ (A[j + 2] ^ A[j + 3]) ^ A[j + 4];
+ long da, db, dc, dd, de;
+
if (SHA3.w == 64)
{
- /* θ step (step 2 of 3) */
- long da = SHA3.C[4] ^ SHA3.rotate64(SHA3.C[1], 1);
- long db = SHA3.C[0] ^ SHA3.rotate64(SHA3.C[2], 1);
- long dc = SHA3.C[1] ^ SHA3.rotate64(SHA3.C[3], 1);
- long dd = SHA3.C[2] ^ SHA3.rotate64(SHA3.C[4], 1);
- long de = SHA3.C[3] ^ SHA3.rotate64(SHA3.C[0], 1);
-
- /* ρ and π steps, with last part of θ */
- SHA3.B[0] = A[0] ^ da;
- SHA3.B[1] = SHA3.rotate64(A[15] ^ dd, 28);
- SHA3.B[2] = SHA3.rotate64(A[5] ^ db, 1);
- SHA3.B[3] = SHA3.rotate64(A[20] ^ de, 27);
- SHA3.B[4] = SHA3.rotate64(A[10] ^ dc, 62);
+ /* ρ and π steps, with last two part of θ */
+ SHA3.B[0] = A[ 0] ^ (da = SHA3.C[4] ^ SHA3.rotate64(SHA3.C[1], 1));
+ SHA3.B[1] = SHA3.rotate64(A[15] ^ (dd = SHA3.C[2] ^ SHA3.rotate64(SHA3.C[4], 1)), 28);
+ SHA3.B[2] = SHA3.rotate64(A[ 5] ^ (db = SHA3.C[0] ^ SHA3.rotate64(SHA3.C[2], 1)), 1);
+ SHA3.B[3] = SHA3.rotate64(A[20] ^ (de = SHA3.C[3] ^ SHA3.rotate64(SHA3.C[0], 1)), 27);
+ SHA3.B[4] = SHA3.rotate64(A[10] ^ (dc = SHA3.C[1] ^ SHA3.rotate64(SHA3.C[3], 1)), 62);
- SHA3.B[5] = SHA3.rotate64(A[6] ^ db, 44);
+ SHA3.B[5] = SHA3.rotate64(A[ 6] ^ db, 44);
SHA3.B[6] = SHA3.rotate64(A[21] ^ de, 20);
- SHA3.B[7] = SHA3.rotate64(A[11] ^ dc, 6);
- SHA3.B[8] = SHA3.rotate64(A[1] ^ da, 36);
+ SHA3.B[7] = SHA3.rotate64(A[11] ^ dc, 6);
+ SHA3.B[8] = SHA3.rotate64(A[ 1] ^ da, 36);
SHA3.B[9] = SHA3.rotate64(A[16] ^ dd, 55);
SHA3.B[10] = SHA3.rotate64(A[12] ^ dc, 43);
- SHA3.B[11] = SHA3.rotate64(A[2] ^ da, 3);
+ SHA3.B[11] = SHA3.rotate64(A[ 2] ^ da, 3);
SHA3.B[12] = SHA3.rotate64(A[17] ^ dd, 25);
- SHA3.B[13] = SHA3.rotate64(A[7] ^ db, 10);
+ SHA3.B[13] = SHA3.rotate64(A[ 7] ^ db, 10);
SHA3.B[14] = SHA3.rotate64(A[22] ^ de, 39);
SHA3.B[15] = SHA3.rotate64(A[18] ^ dd, 21);
- SHA3.B[16] = SHA3.rotate64(A[8] ^ db, 45);
- SHA3.B[17] = SHA3.rotate64(A[23] ^ de, 8);
+ SHA3.B[16] = SHA3.rotate64(A[ 8] ^ db, 45);
+ SHA3.B[17] = SHA3.rotate64(A[23] ^ de, 8);
SHA3.B[18] = SHA3.rotate64(A[13] ^ dc, 15);
- SHA3.B[19] = SHA3.rotate64(A[3] ^ da, 41);
+ SHA3.B[19] = SHA3.rotate64(A[ 3] ^ da, 41);
SHA3.B[20] = SHA3.rotate64(A[24] ^ de, 14);
SHA3.B[21] = SHA3.rotate64(A[14] ^ dc, 61);
- SHA3.B[22] = SHA3.rotate64(A[4] ^ da, 18);
+ SHA3.B[22] = SHA3.rotate64(A[ 4] ^ da, 18);
SHA3.B[23] = SHA3.rotate64(A[19] ^ dd, 56);
- SHA3.B[24] = SHA3.rotate64(A[9] ^ db, 2);
+ SHA3.B[24] = SHA3.rotate64(A[ 9] ^ db, 2);
}
else
{
- /* θ step (step 2 of 3) */
- long da = SHA3.C[4] ^ SHA3.rotate(SHA3.C[1], 1);
- long db = SHA3.C[0] ^ SHA3.rotate(SHA3.C[2], 1);
- long dc = SHA3.C[1] ^ SHA3.rotate(SHA3.C[3], 1);
- long dd = SHA3.C[2] ^ SHA3.rotate(SHA3.C[4], 1);
- long de = SHA3.C[3] ^ SHA3.rotate(SHA3.C[0], 1);
-
- /*ρ and π steps, with last part of θ */
- SHA3.B[0] = A[0] ^ da;
- SHA3.B[1] = SHA3.rotate(A[15] ^ dd, 28);
- SHA3.B[2] = SHA3.rotate(A[5] ^ db, 1);
- SHA3.B[3] = SHA3.rotate(A[20] ^ de, 27);
- SHA3.B[4] = SHA3.rotate(A[10] ^ dc, 62);
+ /* ρ and π steps, with last two part of θ */
+ SHA3.B[0] = A[ 0] ^ (da = SHA3.C[4] ^ SHA3.rotate(SHA3.C[1], 1));
+ SHA3.B[1] = SHA3.rotate(A[15] ^ (dd = SHA3.C[2] ^ SHA3.rotate(SHA3.C[4], 1)), 28);
+ SHA3.B[2] = SHA3.rotate(A[ 5] ^ (db = SHA3.C[0] ^ SHA3.rotate(SHA3.C[2], 1)), 1);
+ SHA3.B[3] = SHA3.rotate(A[20] ^ (de = SHA3.C[3] ^ SHA3.rotate(SHA3.C[0], 1)), 27);
+ SHA3.B[4] = SHA3.rotate(A[10] ^ (dc = SHA3.C[1] ^ SHA3.rotate(SHA3.C[3], 1)), 62);
- SHA3.B[5] = SHA3.rotate(A[6] ^ db, 44);
+ SHA3.B[5] = SHA3.rotate(A[ 6] ^ db, 44);
SHA3.B[6] = SHA3.rotate(A[21] ^ de, 20);
- SHA3.B[7] = SHA3.rotate(A[11] ^ dc, 6);
- SHA3.B[8] = SHA3.rotate(A[1] ^ da, 36);
+ SHA3.B[7] = SHA3.rotate(A[11] ^ dc, 6);
+ SHA3.B[8] = SHA3.rotate(A[ 1] ^ da, 36);
SHA3.B[9] = SHA3.rotate(A[16] ^ dd, 55);
SHA3.B[10] = SHA3.rotate(A[12] ^ dc, 43);
- SHA3.B[11] = SHA3.rotate(A[2] ^ da, 3);
+ SHA3.B[11] = SHA3.rotate(A[ 2] ^ da, 3);
SHA3.B[12] = SHA3.rotate(A[17] ^ dd, 25);
- SHA3.B[13] = SHA3.rotate(A[7] ^ db, 10);
+ SHA3.B[13] = SHA3.rotate(A[ 7] ^ db, 10);
SHA3.B[14] = SHA3.rotate(A[22] ^ de, 39);
SHA3.B[15] = SHA3.rotate(A[18] ^ dd, 21);
- SHA3.B[16] = SHA3.rotate(A[8] ^ db, 45);
- SHA3.B[17] = SHA3.rotate(A[23] ^ de, 8);
+ SHA3.B[16] = SHA3.rotate(A[ 8] ^ db, 45);
+ SHA3.B[17] = SHA3.rotate(A[23] ^ de, 8);
SHA3.B[18] = SHA3.rotate(A[13] ^ dc, 15);
- SHA3.B[19] = SHA3.rotate(A[3] ^ da, 41);
+ SHA3.B[19] = SHA3.rotate(A[ 3] ^ da, 41);
SHA3.B[20] = SHA3.rotate(A[24] ^ de, 14);
SHA3.B[21] = SHA3.rotate(A[14] ^ dc, 61);
- SHA3.B[22] = SHA3.rotate(A[4] ^ da, 18);
+ SHA3.B[22] = SHA3.rotate(A[ 4] ^ da, 18);
SHA3.B[23] = SHA3.rotate(A[19] ^ dd, 56);
- SHA3.B[24] = SHA3.rotate(A[9] ^ db, 2);
+ SHA3.B[24] = SHA3.rotate(A[ 9] ^ db, 2);
}
/* ξ step */