diff options
Diffstat (limited to '')
-rw-r--r-- | pure-java/SHA3.java | 210 |
1 files changed, 106 insertions, 104 deletions
diff --git a/pure-java/SHA3.java b/pure-java/SHA3.java index 5cacc5f..b7d60b5 100644 --- a/pure-java/SHA3.java +++ b/pure-java/SHA3.java @@ -273,15 +273,16 @@ public class SHA3 * Convert a chunk of byte:s to a word * * @param message The message + * @param msgoff The number of times to loop has run times the bitrate * @param rr Bitrate in bytes * @param ww Word size in bytes * @param off The offset in the message * @return Lane */ - private static long toLane(byte[] message, int rr, int ww, int off) + private static long toLane(byte[] message, int msgoff, int rr, int ww, int off) { long rc = 0; - int n = Math.min(message.length, rr); + int n = Math.min(message.length, rr) + msgoff; for (int i = off + ww - 1; i >= off; i--) rc = (rc << 8) | ((i < n) ? (long)(message[i] & 255) : 0L); return rc; @@ -292,13 +293,14 @@ public class SHA3 * Convert a chunk of byte:s to a 64-bit word * * @param message The message + * @param msgoff The number of times to loop has run times the bitrate * @param rr Bitrate in bytes * @param off The offset in the message * @return Lane */ - private static long toLane64(byte[] message, int rr, int off) + private static long toLane64(byte[] message, int msgoff, int rr, int off) { - int n = Math.min(message.length, rr); + int n = Math.min(message.length, rr) + msgoff; return ((off + 7 < n) ? ((long)(message[off + 7] & 255) << 56) : 0L) | ((off + 6 < n) ? ((long)(message[off + 6] & 255) << 48) : 0L) | ((off + 5 < n) ? ((long)(message[off + 5] & 255) << 40) : 0L) | @@ -404,61 +406,61 @@ public class SHA3 if (ww == 8) for (int i = 0; i < len; i += rr) { - SHA3.S[ 0] ^= SHA3.toLane64(message, rr, i + 0); - SHA3.S[ 5] ^= SHA3.toLane64(message, rr, i + 8); - SHA3.S[10] ^= SHA3.toLane64(message, rr, i + 16); - SHA3.S[15] ^= SHA3.toLane64(message, rr, i + 24); - SHA3.S[20] ^= SHA3.toLane64(message, rr, i + 32); - SHA3.S[ 1] ^= SHA3.toLane64(message, rr, i + 40); - SHA3.S[ 6] ^= SHA3.toLane64(message, rr, i + 48); - SHA3.S[11] ^= SHA3.toLane64(message, rr, i + 56); - SHA3.S[16] ^= SHA3.toLane64(message, rr, i + 64); - SHA3.S[21] ^= SHA3.toLane64(message, rr, i + 72); - SHA3.S[ 2] ^= SHA3.toLane64(message, rr, i + 80); - SHA3.S[ 7] ^= SHA3.toLane64(message, rr, i + 88); - SHA3.S[12] ^= SHA3.toLane64(message, rr, i + 96); - SHA3.S[17] ^= SHA3.toLane64(message, rr, i + 104); - SHA3.S[22] ^= SHA3.toLane64(message, rr, i + 112); - SHA3.S[ 3] ^= SHA3.toLane64(message, rr, i + 120); - SHA3.S[ 8] ^= SHA3.toLane64(message, rr, i + 128); - SHA3.S[13] ^= SHA3.toLane64(message, rr, i + 136); - SHA3.S[18] ^= SHA3.toLane64(message, rr, i + 144); - SHA3.S[23] ^= SHA3.toLane64(message, rr, i + 152); - SHA3.S[ 4] ^= SHA3.toLane64(message, rr, i + 160); - SHA3.S[ 9] ^= SHA3.toLane64(message, rr, i + 168); - SHA3.S[14] ^= SHA3.toLane64(message, rr, i + 176); - SHA3.S[19] ^= SHA3.toLane64(message, rr, i + 184); - SHA3.S[24] ^= SHA3.toLane64(message, rr, i + 192); + SHA3.S[ 0] ^= SHA3.toLane64(message, i, rr, i + 0); + SHA3.S[ 5] ^= SHA3.toLane64(message, i, rr, i + 8); + SHA3.S[10] ^= SHA3.toLane64(message, i, rr, i + 16); + SHA3.S[15] ^= SHA3.toLane64(message, i, rr, i + 24); + SHA3.S[20] ^= SHA3.toLane64(message, i, rr, i + 32); + SHA3.S[ 1] ^= SHA3.toLane64(message, i, rr, i + 40); + SHA3.S[ 6] ^= SHA3.toLane64(message, i, rr, i + 48); + SHA3.S[11] ^= SHA3.toLane64(message, i, rr, i + 56); + SHA3.S[16] ^= SHA3.toLane64(message, i, rr, i + 64); + SHA3.S[21] ^= SHA3.toLane64(message, i, rr, i + 72); + SHA3.S[ 2] ^= SHA3.toLane64(message, i, rr, i + 80); + SHA3.S[ 7] ^= SHA3.toLane64(message, i, rr, i + 88); + SHA3.S[12] ^= SHA3.toLane64(message, i, rr, i + 96); + SHA3.S[17] ^= SHA3.toLane64(message, i, rr, i + 104); + SHA3.S[22] ^= SHA3.toLane64(message, i, rr, i + 112); + SHA3.S[ 3] ^= SHA3.toLane64(message, i, rr, i + 120); + SHA3.S[ 8] ^= SHA3.toLane64(message, i, rr, i + 128); + SHA3.S[13] ^= SHA3.toLane64(message, i, rr, i + 136); + SHA3.S[18] ^= SHA3.toLane64(message, i, rr, i + 144); + SHA3.S[23] ^= SHA3.toLane64(message, i, rr, i + 152); + SHA3.S[ 4] ^= SHA3.toLane64(message, i, rr, i + 160); + SHA3.S[ 9] ^= SHA3.toLane64(message, i, rr, i + 168); + SHA3.S[14] ^= SHA3.toLane64(message, i, rr, i + 176); + SHA3.S[19] ^= SHA3.toLane64(message, i, rr, i + 184); + SHA3.S[24] ^= SHA3.toLane64(message, i, rr, i + 192); SHA3.keccakF(SHA3.S); } else for (int i = 0; i < len; i += rr) { - SHA3.S[ 0] ^= SHA3.toLane(message, rr, ww, i + 0 ); - SHA3.S[ 5] ^= SHA3.toLane(message, rr, ww, i + w); - SHA3.S[10] ^= SHA3.toLane(message, rr, ww, i + 2 * w); - SHA3.S[15] ^= SHA3.toLane(message, rr, ww, i + 3 * w); - SHA3.S[20] ^= SHA3.toLane(message, rr, ww, i + 4 * w); - SHA3.S[ 1] ^= SHA3.toLane(message, rr, ww, i + 5 * w); - SHA3.S[ 6] ^= SHA3.toLane(message, rr, ww, i + 6 * w); - SHA3.S[11] ^= SHA3.toLane(message, rr, ww, i + 7 * w); - SHA3.S[16] ^= SHA3.toLane(message, rr, ww, i + 8 * w); - SHA3.S[21] ^= SHA3.toLane(message, rr, ww, i + 9 * w); - SHA3.S[ 2] ^= SHA3.toLane(message, rr, ww, i + 10 * w); - SHA3.S[ 7] ^= SHA3.toLane(message, rr, ww, i + 11 * w); - SHA3.S[12] ^= SHA3.toLane(message, rr, ww, i + 12 * w); - SHA3.S[17] ^= SHA3.toLane(message, rr, ww, i + 13 * w); - SHA3.S[22] ^= SHA3.toLane(message, rr, ww, i + 14 * w); - SHA3.S[ 3] ^= SHA3.toLane(message, rr, ww, i + 15 * w); - SHA3.S[ 8] ^= SHA3.toLane(message, rr, ww, i + 16 * w); - SHA3.S[13] ^= SHA3.toLane(message, rr, ww, i + 17 * w); - SHA3.S[18] ^= SHA3.toLane(message, rr, ww, i + 18 * w); - SHA3.S[23] ^= SHA3.toLane(message, rr, ww, i + 19 * w); - SHA3.S[ 4] ^= SHA3.toLane(message, rr, ww, i + 20 * w); - SHA3.S[ 9] ^= SHA3.toLane(message, rr, ww, i + 21 * w); - SHA3.S[14] ^= SHA3.toLane(message, rr, ww, i + 22 * w); - SHA3.S[19] ^= SHA3.toLane(message, rr, ww, i + 23 * w); - SHA3.S[24] ^= SHA3.toLane(message, rr, ww, i + 24 * w); + SHA3.S[ 0] ^= SHA3.toLane(message, i, rr, ww, i + 0 ); + SHA3.S[ 5] ^= SHA3.toLane(message, i, rr, ww, i + w); + SHA3.S[10] ^= SHA3.toLane(message, i, rr, ww, i + 2 * w); + SHA3.S[15] ^= SHA3.toLane(message, i, rr, ww, i + 3 * w); + SHA3.S[20] ^= SHA3.toLane(message, i, rr, ww, i + 4 * w); + SHA3.S[ 1] ^= SHA3.toLane(message, i, rr, ww, i + 5 * w); + SHA3.S[ 6] ^= SHA3.toLane(message, i, rr, ww, i + 6 * w); + SHA3.S[11] ^= SHA3.toLane(message, i, rr, ww, i + 7 * w); + SHA3.S[16] ^= SHA3.toLane(message, i, rr, ww, i + 8 * w); + SHA3.S[21] ^= SHA3.toLane(message, i, rr, ww, i + 9 * w); + SHA3.S[ 2] ^= SHA3.toLane(message, i, rr, ww, i + 10 * w); + SHA3.S[ 7] ^= SHA3.toLane(message, i, rr, ww, i + 11 * w); + SHA3.S[12] ^= SHA3.toLane(message, i, rr, ww, i + 12 * w); + SHA3.S[17] ^= SHA3.toLane(message, i, rr, ww, i + 13 * w); + SHA3.S[22] ^= SHA3.toLane(message, i, rr, ww, i + 14 * w); + SHA3.S[ 3] ^= SHA3.toLane(message, i, rr, ww, i + 15 * w); + SHA3.S[ 8] ^= SHA3.toLane(message, i, rr, ww, i + 16 * w); + SHA3.S[13] ^= SHA3.toLane(message, i, rr, ww, i + 17 * w); + SHA3.S[18] ^= SHA3.toLane(message, i, rr, ww, i + 18 * w); + SHA3.S[23] ^= SHA3.toLane(message, i, rr, ww, i + 19 * w); + SHA3.S[ 4] ^= SHA3.toLane(message, i, rr, ww, i + 20 * w); + SHA3.S[ 9] ^= SHA3.toLane(message, i, rr, ww, i + 21 * w); + SHA3.S[14] ^= SHA3.toLane(message, i, rr, ww, i + 22 * w); + SHA3.S[19] ^= SHA3.toLane(message, i, rr, ww, i + 23 * w); + SHA3.S[24] ^= SHA3.toLane(message, i, rr, ww, i + 24 * w); SHA3.keccakF(SHA3.S); } } @@ -556,61 +558,61 @@ public class SHA3 if (ww == 8) for (int i = 0; i < len; i += rr) { - SHA3.S[ 0] ^= SHA3.toLane64(message, rr, i + 0); - SHA3.S[ 5] ^= SHA3.toLane64(message, rr, i + 8); - SHA3.S[10] ^= SHA3.toLane64(message, rr, i + 16); - SHA3.S[15] ^= SHA3.toLane64(message, rr, i + 24); - SHA3.S[20] ^= SHA3.toLane64(message, rr, i + 32); - SHA3.S[ 1] ^= SHA3.toLane64(message, rr, i + 40); - SHA3.S[ 6] ^= SHA3.toLane64(message, rr, i + 48); - SHA3.S[11] ^= SHA3.toLane64(message, rr, i + 56); - SHA3.S[16] ^= SHA3.toLane64(message, rr, i + 64); - SHA3.S[21] ^= SHA3.toLane64(message, rr, i + 72); - SHA3.S[ 2] ^= SHA3.toLane64(message, rr, i + 80); - SHA3.S[ 7] ^= SHA3.toLane64(message, rr, i + 88); - SHA3.S[12] ^= SHA3.toLane64(message, rr, i + 96); - SHA3.S[17] ^= SHA3.toLane64(message, rr, i + 104); - SHA3.S[22] ^= SHA3.toLane64(message, rr, i + 112); - SHA3.S[ 3] ^= SHA3.toLane64(message, rr, i + 120); - SHA3.S[ 8] ^= SHA3.toLane64(message, rr, i + 128); - SHA3.S[13] ^= SHA3.toLane64(message, rr, i + 136); - SHA3.S[18] ^= SHA3.toLane64(message, rr, i + 144); - SHA3.S[23] ^= SHA3.toLane64(message, rr, i + 152); - SHA3.S[ 4] ^= SHA3.toLane64(message, rr, i + 160); - SHA3.S[ 9] ^= SHA3.toLane64(message, rr, i + 168); - SHA3.S[14] ^= SHA3.toLane64(message, rr, i + 176); - SHA3.S[19] ^= SHA3.toLane64(message, rr, i + 184); - SHA3.S[24] ^= SHA3.toLane64(message, rr, i + 192); + SHA3.S[ 0] ^= SHA3.toLane64(message, i, rr, i + 0); + SHA3.S[ 5] ^= SHA3.toLane64(message, i, rr, i + 8); + SHA3.S[10] ^= SHA3.toLane64(message, i, rr, i + 16); + SHA3.S[15] ^= SHA3.toLane64(message, i, rr, i + 24); + SHA3.S[20] ^= SHA3.toLane64(message, i, rr, i + 32); + SHA3.S[ 1] ^= SHA3.toLane64(message, i, rr, i + 40); + SHA3.S[ 6] ^= SHA3.toLane64(message, i, rr, i + 48); + SHA3.S[11] ^= SHA3.toLane64(message, i, rr, i + 56); + SHA3.S[16] ^= SHA3.toLane64(message, i, rr, i + 64); + SHA3.S[21] ^= SHA3.toLane64(message, i, rr, i + 72); + SHA3.S[ 2] ^= SHA3.toLane64(message, i, rr, i + 80); + SHA3.S[ 7] ^= SHA3.toLane64(message, i, rr, i + 88); + SHA3.S[12] ^= SHA3.toLane64(message, i, rr, i + 96); + SHA3.S[17] ^= SHA3.toLane64(message, i, rr, i + 104); + SHA3.S[22] ^= SHA3.toLane64(message, i, rr, i + 112); + SHA3.S[ 3] ^= SHA3.toLane64(message, i, rr, i + 120); + SHA3.S[ 8] ^= SHA3.toLane64(message, i, rr, i + 128); + SHA3.S[13] ^= SHA3.toLane64(message, i, rr, i + 136); + SHA3.S[18] ^= SHA3.toLane64(message, i, rr, i + 144); + SHA3.S[23] ^= SHA3.toLane64(message, i, rr, i + 152); + SHA3.S[ 4] ^= SHA3.toLane64(message, i, rr, i + 160); + SHA3.S[ 9] ^= SHA3.toLane64(message, i, rr, i + 168); + SHA3.S[14] ^= SHA3.toLane64(message, i, rr, i + 176); + SHA3.S[19] ^= SHA3.toLane64(message, i, rr, i + 184); + SHA3.S[24] ^= SHA3.toLane64(message, i, rr, i + 192); SHA3.keccakF(SHA3.S); } else for (int i = 0; i < len; i += rr) { - SHA3.S[ 0] ^= SHA3.toLane(message, rr, ww, i + 0 ); - SHA3.S[ 5] ^= SHA3.toLane(message, rr, ww, i + w); - SHA3.S[10] ^= SHA3.toLane(message, rr, ww, i + 2 * w); - SHA3.S[15] ^= SHA3.toLane(message, rr, ww, i + 3 * w); - SHA3.S[20] ^= SHA3.toLane(message, rr, ww, i + 4 * w); - SHA3.S[ 1] ^= SHA3.toLane(message, rr, ww, i + 5 * w); - SHA3.S[ 6] ^= SHA3.toLane(message, rr, ww, i + 6 * w); - SHA3.S[11] ^= SHA3.toLane(message, rr, ww, i + 7 * w); - SHA3.S[16] ^= SHA3.toLane(message, rr, ww, i + 8 * w); - SHA3.S[21] ^= SHA3.toLane(message, rr, ww, i + 9 * w); - SHA3.S[ 2] ^= SHA3.toLane(message, rr, ww, i + 10 * w); - SHA3.S[ 7] ^= SHA3.toLane(message, rr, ww, i + 11 * w); - SHA3.S[12] ^= SHA3.toLane(message, rr, ww, i + 12 * w); - SHA3.S[17] ^= SHA3.toLane(message, rr, ww, i + 13 * w); - SHA3.S[22] ^= SHA3.toLane(message, rr, ww, i + 14 * w); - SHA3.S[ 3] ^= SHA3.toLane(message, rr, ww, i + 15 * w); - SHA3.S[ 8] ^= SHA3.toLane(message, rr, ww, i + 16 * w); - SHA3.S[13] ^= SHA3.toLane(message, rr, ww, i + 17 * w); - SHA3.S[18] ^= SHA3.toLane(message, rr, ww, i + 18 * w); - SHA3.S[23] ^= SHA3.toLane(message, rr, ww, i + 19 * w); - SHA3.S[ 4] ^= SHA3.toLane(message, rr, ww, i + 20 * w); - SHA3.S[ 9] ^= SHA3.toLane(message, rr, ww, i + 21 * w); - SHA3.S[14] ^= SHA3.toLane(message, rr, ww, i + 22 * w); - SHA3.S[19] ^= SHA3.toLane(message, rr, ww, i + 23 * w); - SHA3.S[24] ^= SHA3.toLane(message, rr, ww, i + 24 * w); + SHA3.S[ 0] ^= SHA3.toLane(message, i, rr, ww, i + 0 ); + SHA3.S[ 5] ^= SHA3.toLane(message, i, rr, ww, i + w); + SHA3.S[10] ^= SHA3.toLane(message, i, rr, ww, i + 2 * w); + SHA3.S[15] ^= SHA3.toLane(message, i, rr, ww, i + 3 * w); + SHA3.S[20] ^= SHA3.toLane(message, i, rr, ww, i + 4 * w); + SHA3.S[ 1] ^= SHA3.toLane(message, i, rr, ww, i + 5 * w); + SHA3.S[ 6] ^= SHA3.toLane(message, i, rr, ww, i + 6 * w); + SHA3.S[11] ^= SHA3.toLane(message, i, rr, ww, i + 7 * w); + SHA3.S[16] ^= SHA3.toLane(message, i, rr, ww, i + 8 * w); + SHA3.S[21] ^= SHA3.toLane(message, i, rr, ww, i + 9 * w); + SHA3.S[ 2] ^= SHA3.toLane(message, i, rr, ww, i + 10 * w); + SHA3.S[ 7] ^= SHA3.toLane(message, i, rr, ww, i + 11 * w); + SHA3.S[12] ^= SHA3.toLane(message, i, rr, ww, i + 12 * w); + SHA3.S[17] ^= SHA3.toLane(message, i, rr, ww, i + 13 * w); + SHA3.S[22] ^= SHA3.toLane(message, i, rr, ww, i + 14 * w); + SHA3.S[ 3] ^= SHA3.toLane(message, i, rr, ww, i + 15 * w); + SHA3.S[ 8] ^= SHA3.toLane(message, i, rr, ww, i + 16 * w); + SHA3.S[13] ^= SHA3.toLane(message, i, rr, ww, i + 17 * w); + SHA3.S[18] ^= SHA3.toLane(message, i, rr, ww, i + 18 * w); + SHA3.S[23] ^= SHA3.toLane(message, i, rr, ww, i + 19 * w); + SHA3.S[ 4] ^= SHA3.toLane(message, i, rr, ww, i + 20 * w); + SHA3.S[ 9] ^= SHA3.toLane(message, i, rr, ww, i + 21 * w); + SHA3.S[14] ^= SHA3.toLane(message, i, rr, ww, i + 22 * w); + SHA3.S[19] ^= SHA3.toLane(message, i, rr, ww, i + 23 * w); + SHA3.S[24] ^= SHA3.toLane(message, i, rr, ww, i + 24 * w); SHA3.keccakF(SHA3.S); } |