aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-02-04 13:29:14 +0100
committerMattias Andrée <maandree@operamail.com>2013-02-04 13:29:14 +0100
commit448a60aef468166b9d50f2a7b2429c62f4467a97 (patch)
tree3d4ae0408c90fe88f9d29d1259c41f2b0d7afbea
parentrepair py (S was transposed...) (diff)
downloadsha3sum-448a60aef468166b9d50f2a7b2429c62f4467a97.tar.gz
sha3sum-448a60aef468166b9d50f2a7b2429c62f4467a97.tar.bz2
sha3sum-448a60aef468166b9d50f2a7b2429c62f4467a97.tar.xz
m
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--SHA3.java152
-rw-r--r--sha3sum.java6
-rwxr-xr-xsha3sum.py8
3 files changed, 106 insertions, 60 deletions
diff --git a/SHA3.java b/SHA3.java
index d1a1b0f..8db88c4 100644
--- a/SHA3.java
+++ b/SHA3.java
@@ -125,7 +125,7 @@ public class SHA3
private static long rotate(long x, int n)
{
long m = n % SHA3.w;
- return (x >>> (SHA3.w - m)) + (x << m);
+ return ((x >>> (SHA3.w - m)) + (x << m)) & SHA3.wmod;
}
@@ -138,7 +138,7 @@ public class SHA3
*/
private static long rotate64(long x, int n)
{
- return (x >> (SHA3.w - n)) + (x << n);
+ return (x >>> (SHA3.w - n)) + (x << n);
}
@@ -411,13 +411,13 @@ public class SHA3
/**
- * Initalise Keccak sponge
+ * Initialise Keccak sponge
*
* @param r The bitrate
* @param c The capacity
* @param n The output size
*/
- public static void initalise(int r, int c, int n)
+ public static void initialise(int r, int c, int n)
{
SHA3.r = r;
SHA3.c = c;
@@ -426,7 +426,7 @@ public class SHA3
SHA3.w = SHA3.b / 25;
SHA3.l = SHA3.lb(SHA3.w);
SHA3.nr = 12 + (SHA3.l << 1);
- SHA3.wmod = (1 << SHA3.w) - 1;
+ SHA3.wmod = (1L << SHA3.w) - 1L;
SHA3.S = new long[25];
SHA3.M = new byte[(SHA3.r * SHA3.b) >> 2];
SHA3.mptr = 0;
@@ -456,7 +456,7 @@ public class SHA3
int ww = SHA3.w >> 3;
if (SHA3.mptr + msglen > SHA3.M.length)
- System.arraycopy(SHA3.M, 0, SHA3.M = new byte[SHA3.M.length << 1], 0, SHA3.mptr);
+ System.arraycopy(SHA3.M, 0, SHA3.M = new byte[(SHA3.M.length + msglen) << 1], 0, SHA3.mptr);
System.arraycopy(msg, 0, SHA3.M, SHA3.mptr, msglen);
SHA3.mptr += msglen;
int len = SHA3.mptr;
@@ -469,38 +469,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[ 1] ^= SHA3.toLane64(message, rr, i + 8);
- SHA3.S[ 2] ^= SHA3.toLane64(message, rr, i + 16);
- SHA3.S[ 3] ^= SHA3.toLane64(message, rr, i + 24);
- SHA3.S[ 4] ^= SHA3.toLane64(message, rr, i + 32);
- SHA3.S[ 5] ^= SHA3.toLane64(message, rr, i + 40);
+ 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[ 7] ^= SHA3.toLane64(message, rr, i + 56);
- SHA3.S[ 8] ^= SHA3.toLane64(message, rr, i + 64);
- SHA3.S[ 9] ^= SHA3.toLane64(message, rr, i + 72);
- SHA3.S[10] ^= SHA3.toLane64(message, rr, i + 80);
- SHA3.S[11] ^= SHA3.toLane64(message, rr, i + 88);
- SHA3.S[12] ^= SHA3.toLane64(message, rr, i + 96);
- SHA3.S[13] ^= SHA3.toLane64(message, rr, i + 104);
- SHA3.S[14] ^= SHA3.toLane64(message, rr, i + 112);
- SHA3.S[15] ^= SHA3.toLane64(message, rr, i + 120);
- SHA3.S[16] ^= SHA3.toLane64(message, rr, i + 128);
- SHA3.S[17] ^= SHA3.toLane64(message, rr, i + 136);
- SHA3.S[18] ^= SHA3.toLane64(message, rr, i + 144);
- SHA3.S[19] ^= SHA3.toLane64(message, rr, i + 152);
- SHA3.S[20] ^= SHA3.toLane64(message, rr, i + 160);
- SHA3.S[21] ^= SHA3.toLane64(message, rr, i + 168);
- SHA3.S[22] ^= SHA3.toLane64(message, rr, i + 176);
- SHA3.S[23] ^= SHA3.toLane64(message, rr, i + 184);
+ 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.keccakF(SHA3.S);
}
else
for (int i = 0; i < len; i += rr)
{
- for (int j = 0; j < 25; j++)
- SHA3.S[j] ^= SHA3.toLane(message, rr, ww, i + j * ww);
+ 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.keccakF(SHA3.S);
}
}
@@ -558,37 +581,60 @@ public class SHA3
for (int i = 0; i < len; i += rr)
{
SHA3.S[ 0] ^= SHA3.toLane64(message, rr, i + 0);
- SHA3.S[ 1] ^= SHA3.toLane64(message, rr, i + 8);
- SHA3.S[ 2] ^= SHA3.toLane64(message, rr, i + 16);
- SHA3.S[ 3] ^= SHA3.toLane64(message, rr, i + 24);
- SHA3.S[ 4] ^= SHA3.toLane64(message, rr, i + 32);
- SHA3.S[ 5] ^= SHA3.toLane64(message, rr, i + 40);
+ 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[ 7] ^= SHA3.toLane64(message, rr, i + 56);
- SHA3.S[ 8] ^= SHA3.toLane64(message, rr, i + 64);
- SHA3.S[ 9] ^= SHA3.toLane64(message, rr, i + 72);
- SHA3.S[10] ^= SHA3.toLane64(message, rr, i + 80);
- SHA3.S[11] ^= SHA3.toLane64(message, rr, i + 88);
+ 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[13] ^= SHA3.toLane64(message, rr, i + 104);
- SHA3.S[14] ^= SHA3.toLane64(message, rr, i + 112);
- SHA3.S[15] ^= SHA3.toLane64(message, rr, i + 120);
- SHA3.S[16] ^= SHA3.toLane64(message, rr, i + 128);
- SHA3.S[17] ^= SHA3.toLane64(message, rr, i + 136);
+ 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[19] ^= SHA3.toLane64(message, rr, i + 152);
- SHA3.S[20] ^= SHA3.toLane64(message, rr, i + 160);
- SHA3.S[21] ^= SHA3.toLane64(message, rr, i + 168);
- SHA3.S[22] ^= SHA3.toLane64(message, rr, i + 176);
- SHA3.S[23] ^= SHA3.toLane64(message, rr, i + 184);
+ 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.keccakF(SHA3.S);
}
else
for (int i = 0; i < len; i += rr)
{
- for (int j = 0; j < 25; j++)
- SHA3.S[j] ^= SHA3.toLane(message, rr, ww, i + j * ww);
+ 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.keccakF(SHA3.S);
}
diff --git a/sha3sum.java b/sha3sum.java
index 430ca13..2baf1e5 100644
--- a/sha3sum.java
+++ b/sha3sum.java
@@ -36,7 +36,7 @@ public class sha3sum
*/
public static void main(String... argv) throws IOException
{
- String cmd, _cmd = cmd = ""; //FIXME
+ String cmd, _cmd = cmd = ""; //FIXME /proc/self/cmdline split ^@ [0]
if (cmd.indexOf('/') >= 0)
cmd = cmd.substring(cmd.lastIndexOf('/') + 1);
if (cmd.endsWith(".jar"))
@@ -200,7 +200,7 @@ public class sha3sum
try
{
file = new FileInputStream(fn);
- SHA3.initalise(r, c, o);
+ SHA3.initialise(r, c, o);
int blksize = 4096; /** XXX os.stat(os.path.realpath(fn)).st_size; **/
byte[] chunk = new byte[blksize];
for (;;)
@@ -213,7 +213,7 @@ public class sha3sum
byte[] bs = SHA3.digest();
for (int _ = 1; _ < i; _++)
{
- SHA3.initalise(r, c, o);
+ SHA3.initialise(r, c, o);
bs = SHA3.digest(bs);
}
if (binary)
diff --git a/sha3sum.py b/sha3sum.py
index 872edce..c508254 100755
--- a/sha3sum.py
+++ b/sha3sum.py
@@ -349,9 +349,9 @@ class SHA3:
@staticmethod
- def initalise(r, c, n):
+ def initialise(r, c, n):
'''
- Initalise Keccak sponge
+ Initialise Keccak sponge
@param r:int The bitrate
@param c:int The capacity
@@ -697,7 +697,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
rc = ''
fn = '/dev/stdin' if filename is None else filename
with open(fn, 'rb') as file:
- SHA3.initalise(r, c, o)
+ SHA3.initialise(r, c, o)
blksize = os.stat(os.path.realpath(fn)).st_size
while True:
chunk = file.read(blksize)
@@ -706,7 +706,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
SHA3.update(chunk)
bs = SHA3.digest(file.read())
for _ in range(1, i):
- SHA3.initalise(r, c, o)
+ SHA3.initialise(r, c, o)
bs = SHA3.digest(bs)
if binary:
if filename is None: