aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--README2
-rw-r--r--java/SHA3.java80
2 files changed, 35 insertions, 47 deletions
diff --git a/README b/README
index f74ccae..c6837e5 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
COMPLETE STATUS:
python :: optimised
- java :: not optimised
+ java :: optimised
c :: planned (after java)
nasm :: planned (maybe, after c)
haskell :: planned (maybe)
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 */