diff options
Diffstat (limited to '')
-rw-r--r-- | c/sha3.c | 37 | ||||
-rw-r--r-- | c/sha3sum.c | 2 | ||||
-rw-r--r-- | java-c-jni/SHA3.c | 39 | ||||
-rw-r--r-- | pure-java/SHA3.java | 210 | ||||
-rw-r--r-- | vala/sha3sum.vala | 210 |
5 files changed, 265 insertions, 233 deletions
@@ -562,6 +562,8 @@ extern void update(byte* msg, long msglen) long ww = w >> 3; long i, len; byte* message; + byte* _msg; + long nnn; if (mptr + msglen > mlen) { @@ -576,13 +578,14 @@ extern void update(byte* msg, long msglen) message = (byte*)malloc(len); arraycopy(M, 0, message, 0, len); mptr -= len; - revarraycopy(M, len, M, 0, mptr); + revarraycopy(M, nnn = len, M, 0, mptr); + _msg = message; /* Absorbing phase */ if (ww == 8) - for (i = 0; i < len; i += rr) + for (i = 0; i < nnn; i += rr) { - #define __S(Si, OFF) S[Si] ^= toLane64(message, len, rr, i + OFF) + #define __S(Si, OFF) S[Si] ^= toLane64(message + i, len - i, rr, OFF) __S( 0, 0); __S( 5, 8); __S(10, 16); __S(15, 24); __S(20, 32); __S( 1, 40); __S( 6, 48); __S(11, 56); __S(16, 64); __S(21, 72); __S( 2, 80); __S( 7, 88); __S(12, 96); __S(17, 104); __S(22, 112); @@ -590,11 +593,13 @@ extern void update(byte* msg, long msglen) __S( 4, 160); __S( 9, 168); __S(14, 176); __S(19, 184); __S(24, 192); #undef __S keccakF(S); + message += rr; + len -= rr; } else - for (i = 0; i < len; i += rr) + for (i = 0; i < nnn; i += rr) { - #define __S(Si, OFF) S[Si] ^= toLane(message, len, rr, ww, i + OFF * w) + #define __S(Si, OFF) S[Si] ^= toLane(message + i, len - i, rr, ww, OFF * w) __S( 0, 0); __S( 5, 1); __S(10, 2); __S(15, 3); __S(20, 4); __S( 1, 5); __S( 6, 6); __S(11, 7); __S(16, 8); __S(21, 9); __S( 2, 10); __S( 7, 11); __S(12, 12); __S(17, 13); __S(22, 14); @@ -602,9 +607,11 @@ extern void update(byte* msg, long msglen) __S( 4, 20); __S( 9, 21); __S(14, 22); __S(19, 23); __S(24, 24); #undef __S keccakF(S); + message += rr; + len -= rr; } - free(message); + free(_msg); } @@ -619,11 +626,13 @@ extern void update(byte* msg, long msglen) extern byte* digest(byte* msg, long msglen, boolean withReturn) { byte* message; + byte* _msg; byte* rc; long rr = r >> 3, len; long nn = (n + 7) >> 3, olen; long ww = w >> 3, ni; long i, j = 0, ptr = 0, _; + long nnn; if ((msg == null) || (msglen == 0)) message = pad10star1(M, mptr, r, &len); @@ -642,12 +651,14 @@ extern byte* digest(byte* msg, long msglen, boolean withReturn) free(M); M = null; rc = (byte*)malloc((n + 7) >> 3); + _msg = message; + nnn = len; /* Absorbing phase */ if (ww == 8) - for (i = 0; i < len; i += rr) + for (i = 0; i < nnn; i += rr) { - #define __S(Si, OFF) S[Si] ^= toLane64(message, len, rr, i + OFF) + #define __S(Si, OFF) S[Si] ^= toLane64(message, len, rr, OFF) __S( 0, 0); __S( 5, 8); __S(10, 16); __S(15, 24); __S(20, 32); __S( 1, 40); __S( 6, 48); __S(11, 56); __S(16, 64); __S(21, 72); __S( 2, 80); __S( 7, 88); __S(12, 96); __S(17, 104); __S(22, 112); @@ -655,11 +666,13 @@ extern byte* digest(byte* msg, long msglen, boolean withReturn) __S( 4, 160); __S( 9, 168); __S(14, 176); __S(19, 184); __S(24, 192); #undef __S keccakF(S); + message += rr; + len -= rr; } else - for (i = 0; i < len; i += rr) + for (i = 0; i < nnn; i += rr) { - #define __S(Si, OFF) S[Si] ^= toLane(message, len, rr, ww, i + OFF * w) + #define __S(Si, OFF) S[Si] ^= toLane(message, len, rr, ww, OFF * w) __S( 0, 0); __S( 5, 1); __S(10, 2); __S(15, 3); __S(20, 4); __S( 1, 5); __S( 6, 6); __S(11, 7); __S(16, 8); __S(21, 9); __S( 2, 10); __S( 7, 11); __S(12, 12); __S(17, 13); __S(22, 14); @@ -667,9 +680,11 @@ extern byte* digest(byte* msg, long msglen, boolean withReturn) __S( 4, 20); __S( 9, 21); __S(14, 22); __S(19, 23); __S(24, 24); #undef __S keccakF(S); + message += rr; + len -= rr; } - free(message); + free(_msg); /* Squeezing phase */ olen = n; diff --git a/c/sha3sum.c b/c/sha3sum.c index e8d982a..4467a72 100644 --- a/c/sha3sum.c +++ b/c/sha3sum.c @@ -480,7 +480,7 @@ int main(int argc, char** argv) if (_O) { - o = o; + o = O; if (o <= 0) { ERR("the output size must be positive."); diff --git a/java-c-jni/SHA3.c b/java-c-jni/SHA3.c index 827458a..90ba49f 100644 --- a/java-c-jni/SHA3.c +++ b/java-c-jni/SHA3.c @@ -549,8 +549,9 @@ void update(byte* msg, jint msglen) { long rr = r >> 3; long ww = w >> 3; - long i, len; + long i, len, nnn; byte* message; + byte* _msg; if (mptr + msglen > mlen) { @@ -565,13 +566,14 @@ void update(byte* msg, jint msglen) message = (byte*)malloc(len); arraycopy(M, 0, message, 0, len); mptr -= len; - revarraycopy(M, len, M, 0, mptr); + revarraycopy(M, nnn = len, M, 0, mptr); + _msg = message; /* Absorbing phase */ if (ww == 8) - for (i = 0; i < len; i += rr) + for (i = 0; i < nnn; i += rr) { - #define __S(Si, OFF) S[Si] ^= toLane64(message, len, rr, i + OFF) + #define __S(Si, OFF) S[Si] ^= toLane64(message, len, rr, OFF) __S( 0, 0); __S( 5, 8); __S(10, 16); __S(15, 24); __S(20, 32); __S( 1, 40); __S( 6, 48); __S(11, 56); __S(16, 64); __S(21, 72); __S( 2, 80); __S( 7, 88); __S(12, 96); __S(17, 104); __S(22, 112); @@ -579,11 +581,13 @@ void update(byte* msg, jint msglen) __S( 4, 160); __S( 9, 168); __S(14, 176); __S(19, 184); __S(24, 192); #undef __S keccakF(S); + message += rr; + len -= rr; } else - for (i = 0; i < len; i += rr) + for (i = 0; i < nnn; i += rr) { - #define __S(Si, OFF) S[Si] ^= toLane(message, len, rr, ww, i + OFF * w) + #define __S(Si, OFF) S[Si] ^= toLane(message, len, rr, ww, OFF * w) __S( 0, 0); __S( 5, 1); __S(10, 2); __S(15, 3); __S(20, 4); __S( 1, 5); __S( 6, 6); __S(11, 7); __S(16, 8); __S(21, 9); __S( 2, 10); __S( 7, 11); __S(12, 12); __S(17, 13); __S(22, 14); @@ -591,9 +595,11 @@ void update(byte* msg, jint msglen) __S( 4, 20); __S( 9, 21); __S(14, 22); __S(19, 23); __S(24, 24); #undef __S keccakF(S); + message += rr; + len -= rr; } - free(message); + free(_msg); } @@ -607,7 +613,8 @@ byte* digest(byte* msg, jint msglen) { byte* message; byte* rc; - long rr = r >> 3, len; + byte* _msg; + long rr = r >> 3, len, nnn; long nn = (n + 7) >> 3, olen; long ww = w >> 3, ni; long i, j = 0, ptr = 0, _; @@ -629,12 +636,14 @@ byte* digest(byte* msg, jint msglen) free(M); M = null; rc = (byte*)malloc((n + 7) >> 3); + nnn = len; + _msg = message; /* Absorbing phase */ if (ww == 8) - for (i = 0; i < len; i += rr) + for (i = 0; i < nnn; i += rr) { - #define __S(Si, OFF) S[Si] ^= toLane64(message, len, rr, i + OFF) + #define __S(Si, OFF) S[Si] ^= toLane64(message, len, rr, OFF) __S( 0, 0); __S( 5, 8); __S(10, 16); __S(15, 24); __S(20, 32); __S( 1, 40); __S( 6, 48); __S(11, 56); __S(16, 64); __S(21, 72); __S( 2, 80); __S( 7, 88); __S(12, 96); __S(17, 104); __S(22, 112); @@ -642,11 +651,13 @@ byte* digest(byte* msg, jint msglen) __S( 4, 160); __S( 9, 168); __S(14, 176); __S(19, 184); __S(24, 192); #undef __S keccakF(S); + message += rr; + len -= rr; } else - for (i = 0; i < len; i += rr) + for (i = 0; i < nnn; i += rr) { - #define __S(Si, OFF) S[Si] ^= toLane(message, len, rr, ww, i + OFF * w) + #define __S(Si, OFF) S[Si] ^= toLane(message, len, rr, ww, OFF * w) __S( 0, 0); __S( 5, 1); __S(10, 2); __S(15, 3); __S(20, 4); __S( 1, 5); __S( 6, 6); __S(11, 7); __S(16, 8); __S(21, 9); __S( 2, 10); __S( 7, 11); __S(12, 12); __S(17, 13); __S(22, 14); @@ -654,9 +665,11 @@ byte* digest(byte* msg, jint msglen) __S( 4, 20); __S( 9, 21); __S(14, 22); __S(19, 23); __S(24, 24); #undef __S keccakF(S); + message += rr; + len -= rr; } - free(message); + free(_msg); /* Squeezing phase */ olen = n; 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); } diff --git a/vala/sha3sum.vala b/vala/sha3sum.vala index 6aed7b0..b783f9c 100644 --- a/vala/sha3sum.vala +++ b/vala/sha3sum.vala @@ -307,15 +307,16 @@ class SHA3 : Object * Convert a chunk of byte:s to a word * * @param message The message + * @param msgoff The number of times to loop has run times to bitrate * @param rr Bitrate in bytes * @param ww Word size in bytes * @param off The offset in the message * @return Lane */ - private int64 toLane(uint8[] message, int rr, int ww, int off) + private int64 toLane(uint8[] message, int msgoff, int rr, int ww, int off) { int64 rc = 0; - int n = message.length < rr ? message.length : rr; + int n = (message.length < rr ? message.length : rr) + msgoff; for (int i = off + ww - 1; i >= off; i--) rc = (rc << 8) | ((i < n) ? (int64)(message[i] & 255) : 0L); return rc; @@ -326,13 +327,14 @@ class SHA3 : Object * 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 to bitrate * @param rr Bitrate in bytes * @param off The offset in the message * @return Lane */ - private int64 toLane64(uint8[] message, int rr, int off) + private int64 toLane64(uint8[] message, int msgoff, int rr, int off) { - int n = message.length < rr ? message.length : rr; + int n = (message.length < rr ? message.length : rr) + msgoff; return ((off + 7 < n) ? ((int64)(message[off + 7] & 255) << 56) : 0L) | ((off + 6 < n) ? ((int64)(message[off + 6] & 255) << 48) : 0L) | ((off + 5 < n) ? ((int64)(message[off + 5] & 255) << 40) : 0L) | @@ -427,61 +429,61 @@ class SHA3 : Object if (ww == 8) for (int i = 0; i < len; i += rr) { - this.S[ 0] ^= this.toLane64(message, rr, i + 0); - this.S[ 5] ^= this.toLane64(message, rr, i + 8); - this.S[10] ^= this.toLane64(message, rr, i + 16); - this.S[15] ^= this.toLane64(message, rr, i + 24); - this.S[20] ^= this.toLane64(message, rr, i + 32); - this.S[ 1] ^= this.toLane64(message, rr, i + 40); - this.S[ 6] ^= this.toLane64(message, rr, i + 48); - this.S[11] ^= this.toLane64(message, rr, i + 56); - this.S[16] ^= this.toLane64(message, rr, i + 64); - this.S[21] ^= this.toLane64(message, rr, i + 72); - this.S[ 2] ^= this.toLane64(message, rr, i + 80); - this.S[ 7] ^= this.toLane64(message, rr, i + 88); - this.S[12] ^= this.toLane64(message, rr, i + 96); - this.S[17] ^= this.toLane64(message, rr, i + 104); - this.S[22] ^= this.toLane64(message, rr, i + 112); - this.S[ 3] ^= this.toLane64(message, rr, i + 120); - this.S[ 8] ^= this.toLane64(message, rr, i + 128); - this.S[13] ^= this.toLane64(message, rr, i + 136); - this.S[18] ^= this.toLane64(message, rr, i + 144); - this.S[23] ^= this.toLane64(message, rr, i + 152); - this.S[ 4] ^= this.toLane64(message, rr, i + 160); - this.S[ 9] ^= this.toLane64(message, rr, i + 168); - this.S[14] ^= this.toLane64(message, rr, i + 176); - this.S[19] ^= this.toLane64(message, rr, i + 184); - this.S[24] ^= this.toLane64(message, rr, i + 192); + this.S[ 0] ^= this.toLane64(message, i, rr, i + 0); + this.S[ 5] ^= this.toLane64(message, i, rr, i + 8); + this.S[10] ^= this.toLane64(message, i, rr, i + 16); + this.S[15] ^= this.toLane64(message, i, rr, i + 24); + this.S[20] ^= this.toLane64(message, i, rr, i + 32); + this.S[ 1] ^= this.toLane64(message, i, rr, i + 40); + this.S[ 6] ^= this.toLane64(message, i, rr, i + 48); + this.S[11] ^= this.toLane64(message, i, rr, i + 56); + this.S[16] ^= this.toLane64(message, i, rr, i + 64); + this.S[21] ^= this.toLane64(message, i, rr, i + 72); + this.S[ 2] ^= this.toLane64(message, i, rr, i + 80); + this.S[ 7] ^= this.toLane64(message, i, rr, i + 88); + this.S[12] ^= this.toLane64(message, i, rr, i + 96); + this.S[17] ^= this.toLane64(message, i, rr, i + 104); + this.S[22] ^= this.toLane64(message, i, rr, i + 112); + this.S[ 3] ^= this.toLane64(message, i, rr, i + 120); + this.S[ 8] ^= this.toLane64(message, i, rr, i + 128); + this.S[13] ^= this.toLane64(message, i, rr, i + 136); + this.S[18] ^= this.toLane64(message, i, rr, i + 144); + this.S[23] ^= this.toLane64(message, i, rr, i + 152); + this.S[ 4] ^= this.toLane64(message, i, rr, i + 160); + this.S[ 9] ^= this.toLane64(message, i, rr, i + 168); + this.S[14] ^= this.toLane64(message, i, rr, i + 176); + this.S[19] ^= this.toLane64(message, i, rr, i + 184); + this.S[24] ^= this.toLane64(message, i, rr, i + 192); this.keccakF(this.S); } else for (int i = 0; i < len; i += rr) { - this.S[ 0] ^= this.toLane(message, rr, ww, i + 0 ); - this.S[ 5] ^= this.toLane(message, rr, ww, i + w); - this.S[10] ^= this.toLane(message, rr, ww, i + 2 * w); - this.S[15] ^= this.toLane(message, rr, ww, i + 3 * w); - this.S[20] ^= this.toLane(message, rr, ww, i + 4 * w); - this.S[ 1] ^= this.toLane(message, rr, ww, i + 5 * w); - this.S[ 6] ^= this.toLane(message, rr, ww, i + 6 * w); - this.S[11] ^= this.toLane(message, rr, ww, i + 7 * w); - this.S[16] ^= this.toLane(message, rr, ww, i + 8 * w); - this.S[21] ^= this.toLane(message, rr, ww, i + 9 * w); - this.S[ 2] ^= this.toLane(message, rr, ww, i + 10 * w); - this.S[ 7] ^= this.toLane(message, rr, ww, i + 11 * w); - this.S[12] ^= this.toLane(message, rr, ww, i + 12 * w); - this.S[17] ^= this.toLane(message, rr, ww, i + 13 * w); - this.S[22] ^= this.toLane(message, rr, ww, i + 14 * w); - this.S[ 3] ^= this.toLane(message, rr, ww, i + 15 * w); - this.S[ 8] ^= this.toLane(message, rr, ww, i + 16 * w); - this.S[13] ^= this.toLane(message, rr, ww, i + 17 * w); - this.S[18] ^= this.toLane(message, rr, ww, i + 18 * w); - this.S[23] ^= this.toLane(message, rr, ww, i + 19 * w); - this.S[ 4] ^= this.toLane(message, rr, ww, i + 20 * w); - this.S[ 9] ^= this.toLane(message, rr, ww, i + 21 * w); - this.S[14] ^= this.toLane(message, rr, ww, i + 22 * w); - this.S[19] ^= this.toLane(message, rr, ww, i + 23 * w); - this.S[24] ^= this.toLane(message, rr, ww, i + 24 * w); + this.S[ 0] ^= this.toLane(message, i, rr, ww, i + 0 ); + this.S[ 5] ^= this.toLane(message, i, rr, ww, i + w); + this.S[10] ^= this.toLane(message, i, rr, ww, i + 2 * w); + this.S[15] ^= this.toLane(message, i, rr, ww, i + 3 * w); + this.S[20] ^= this.toLane(message, i, rr, ww, i + 4 * w); + this.S[ 1] ^= this.toLane(message, i, rr, ww, i + 5 * w); + this.S[ 6] ^= this.toLane(message, i, rr, ww, i + 6 * w); + this.S[11] ^= this.toLane(message, i, rr, ww, i + 7 * w); + this.S[16] ^= this.toLane(message, i, rr, ww, i + 8 * w); + this.S[21] ^= this.toLane(message, i, rr, ww, i + 9 * w); + this.S[ 2] ^= this.toLane(message, i, rr, ww, i + 10 * w); + this.S[ 7] ^= this.toLane(message, i, rr, ww, i + 11 * w); + this.S[12] ^= this.toLane(message, i, rr, ww, i + 12 * w); + this.S[17] ^= this.toLane(message, i, rr, ww, i + 13 * w); + this.S[22] ^= this.toLane(message, i, rr, ww, i + 14 * w); + this.S[ 3] ^= this.toLane(message, i, rr, ww, i + 15 * w); + this.S[ 8] ^= this.toLane(message, i, rr, ww, i + 16 * w); + this.S[13] ^= this.toLane(message, i, rr, ww, i + 17 * w); + this.S[18] ^= this.toLane(message, i, rr, ww, i + 18 * w); + this.S[23] ^= this.toLane(message, i, rr, ww, i + 19 * w); + this.S[ 4] ^= this.toLane(message, i, rr, ww, i + 20 * w); + this.S[ 9] ^= this.toLane(message, i, rr, ww, i + 21 * w); + this.S[14] ^= this.toLane(message, i, rr, ww, i + 22 * w); + this.S[19] ^= this.toLane(message, i, rr, ww, i + 23 * w); + this.S[24] ^= this.toLane(message, i, rr, ww, i + 24 * w); this.keccakF(this.S); } } @@ -518,61 +520,61 @@ class SHA3 : Object if (ww == 8) for (int i = 0; i < len; i += rr) { - this.S[ 0] ^= this.toLane64(message, rr, i + 0); - this.S[ 5] ^= this.toLane64(message, rr, i + 8); - this.S[10] ^= this.toLane64(message, rr, i + 16); - this.S[15] ^= this.toLane64(message, rr, i + 24); - this.S[20] ^= this.toLane64(message, rr, i + 32); - this.S[ 1] ^= this.toLane64(message, rr, i + 40); - this.S[ 6] ^= this.toLane64(message, rr, i + 48); - this.S[11] ^= this.toLane64(message, rr, i + 56); - this.S[16] ^= this.toLane64(message, rr, i + 64); - this.S[21] ^= this.toLane64(message, rr, i + 72); - this.S[ 2] ^= this.toLane64(message, rr, i + 80); - this.S[ 7] ^= this.toLane64(message, rr, i + 88); - this.S[12] ^= this.toLane64(message, rr, i + 96); - this.S[17] ^= this.toLane64(message, rr, i + 104); - this.S[22] ^= this.toLane64(message, rr, i + 112); - this.S[ 3] ^= this.toLane64(message, rr, i + 120); - this.S[ 8] ^= this.toLane64(message, rr, i + 128); - this.S[13] ^= this.toLane64(message, rr, i + 136); - this.S[18] ^= this.toLane64(message, rr, i + 144); - this.S[23] ^= this.toLane64(message, rr, i + 152); - this.S[ 4] ^= this.toLane64(message, rr, i + 160); - this.S[ 9] ^= this.toLane64(message, rr, i + 168); - this.S[14] ^= this.toLane64(message, rr, i + 176); - this.S[19] ^= this.toLane64(message, rr, i + 184); - this.S[24] ^= this.toLane64(message, rr, i + 192); + this.S[ 0] ^= this.toLane64(message, i, rr, i + 0); + this.S[ 5] ^= this.toLane64(message, i, rr, i + 8); + this.S[10] ^= this.toLane64(message, i, rr, i + 16); + this.S[15] ^= this.toLane64(message, i, rr, i + 24); + this.S[20] ^= this.toLane64(message, i, rr, i + 32); + this.S[ 1] ^= this.toLane64(message, i, rr, i + 40); + this.S[ 6] ^= this.toLane64(message, i, rr, i + 48); + this.S[11] ^= this.toLane64(message, i, rr, i + 56); + this.S[16] ^= this.toLane64(message, i, rr, i + 64); + this.S[21] ^= this.toLane64(message, i, rr, i + 72); + this.S[ 2] ^= this.toLane64(message, i, rr, i + 80); + this.S[ 7] ^= this.toLane64(message, i, rr, i + 88); + this.S[12] ^= this.toLane64(message, i, rr, i + 96); + this.S[17] ^= this.toLane64(message, i, rr, i + 104); + this.S[22] ^= this.toLane64(message, i, rr, i + 112); + this.S[ 3] ^= this.toLane64(message, i, rr, i + 120); + this.S[ 8] ^= this.toLane64(message, i, rr, i + 128); + this.S[13] ^= this.toLane64(message, i, rr, i + 136); + this.S[18] ^= this.toLane64(message, i, rr, i + 144); + this.S[23] ^= this.toLane64(message, i, rr, i + 152); + this.S[ 4] ^= this.toLane64(message, i, rr, i + 160); + this.S[ 9] ^= this.toLane64(message, i, rr, i + 168); + this.S[14] ^= this.toLane64(message, i, rr, i + 176); + this.S[19] ^= this.toLane64(message, i, rr, i + 184); + this.S[24] ^= this.toLane64(message, i, rr, i + 192); this.keccakF(this.S); } else for (int i = 0; i < len; i += rr) { - this.S[ 0] ^= this.toLane(message, rr, ww, i + 0 ); - this.S[ 5] ^= this.toLane(message, rr, ww, i + w); - this.S[10] ^= this.toLane(message, rr, ww, i + 2 * w); - this.S[15] ^= this.toLane(message, rr, ww, i + 3 * w); - this.S[20] ^= this.toLane(message, rr, ww, i + 4 * w); - this.S[ 1] ^= this.toLane(message, rr, ww, i + 5 * w); - this.S[ 6] ^= this.toLane(message, rr, ww, i + 6 * w); - this.S[11] ^= this.toLane(message, rr, ww, i + 7 * w); - this.S[16] ^= this.toLane(message, rr, ww, i + 8 * w); - this.S[21] ^= this.toLane(message, rr, ww, i + 9 * w); - this.S[ 2] ^= this.toLane(message, rr, ww, i + 10 * w); - this.S[ 7] ^= this.toLane(message, rr, ww, i + 11 * w); - this.S[12] ^= this.toLane(message, rr, ww, i + 12 * w); - this.S[17] ^= this.toLane(message, rr, ww, i + 13 * w); - this.S[22] ^= this.toLane(message, rr, ww, i + 14 * w); - this.S[ 3] ^= this.toLane(message, rr, ww, i + 15 * w); - this.S[ 8] ^= this.toLane(message, rr, ww, i + 16 * w); - this.S[13] ^= this.toLane(message, rr, ww, i + 17 * w); - this.S[18] ^= this.toLane(message, rr, ww, i + 18 * w); - this.S[23] ^= this.toLane(message, rr, ww, i + 19 * w); - this.S[ 4] ^= this.toLane(message, rr, ww, i + 20 * w); - this.S[ 9] ^= this.toLane(message, rr, ww, i + 21 * w); - this.S[14] ^= this.toLane(message, rr, ww, i + 22 * w); - this.S[19] ^= this.toLane(message, rr, ww, i + 23 * w); - this.S[24] ^= this.toLane(message, rr, ww, i + 24 * w); + this.S[ 0] ^= this.toLane(message, i, rr, ww, i + 0 ); + this.S[ 5] ^= this.toLane(message, i, rr, ww, i + w); + this.S[10] ^= this.toLane(message, i, rr, ww, i + 2 * w); + this.S[15] ^= this.toLane(message, i, rr, ww, i + 3 * w); + this.S[20] ^= this.toLane(message, i, rr, ww, i + 4 * w); + this.S[ 1] ^= this.toLane(message, i, rr, ww, i + 5 * w); + this.S[ 6] ^= this.toLane(message, i, rr, ww, i + 6 * w); + this.S[11] ^= this.toLane(message, i, rr, ww, i + 7 * w); + this.S[16] ^= this.toLane(message, i, rr, ww, i + 8 * w); + this.S[21] ^= this.toLane(message, i, rr, ww, i + 9 * w); + this.S[ 2] ^= this.toLane(message, i, rr, ww, i + 10 * w); + this.S[ 7] ^= this.toLane(message, i, rr, ww, i + 11 * w); + this.S[12] ^= this.toLane(message, i, rr, ww, i + 12 * w); + this.S[17] ^= this.toLane(message, i, rr, ww, i + 13 * w); + this.S[22] ^= this.toLane(message, i, rr, ww, i + 14 * w); + this.S[ 3] ^= this.toLane(message, i, rr, ww, i + 15 * w); + this.S[ 8] ^= this.toLane(message, i, rr, ww, i + 16 * w); + this.S[13] ^= this.toLane(message, i, rr, ww, i + 17 * w); + this.S[18] ^= this.toLane(message, i, rr, ww, i + 18 * w); + this.S[23] ^= this.toLane(message, i, rr, ww, i + 19 * w); + this.S[ 4] ^= this.toLane(message, i, rr, ww, i + 20 * w); + this.S[ 9] ^= this.toLane(message, i, rr, ww, i + 21 * w); + this.S[14] ^= this.toLane(message, i, rr, ww, i + 22 * w); + this.S[19] ^= this.toLane(message, i, rr, ww, i + 23 * w); + this.S[24] ^= this.toLane(message, i, rr, ww, i + 24 * w); this.keccakF(this.S); } |