aboutsummaryrefslogtreecommitdiffstats
path: root/pure-java
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-05-03 21:47:49 +0200
committerMattias Andrée <maandree@operamail.com>2013-05-03 21:47:49 +0200
commit3b5d9f3799709cea2834d7d5976c20d242024f91 (patch)
treef31f7c75d0bcafe3074c15f1ff5a7735956b81fe /pure-java
parentm (diff)
downloadsha3sum-3b5d9f3799709cea2834d7d5976c20d242024f91.tar.gz
sha3sum-3b5d9f3799709cea2834d7d5976c20d242024f91.tar.bz2
sha3sum-3b5d9f3799709cea2834d7d5976c20d242024f91.tar.xz
debug stuff + hex input for java
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'pure-java')
-rw-r--r--pure-java/SHA3.java26
-rw-r--r--pure-java/sha3sum.java25
2 files changed, 49 insertions, 2 deletions
diff --git a/pure-java/SHA3.java b/pure-java/SHA3.java
index 2eed163..e859d5b 100644
--- a/pure-java/SHA3.java
+++ b/pure-java/SHA3.java
@@ -492,6 +492,12 @@ public class SHA3
*/
public static byte[] digest(byte[] msg, int msglen)
{
+ /*{ String _;
+ System.out.print("\033[32m");
+ for (int j = 0; j < msglen; j++)
+ System.out.print((_ = "00" + Long.toString(msg[j] & 255, 16)).substring(_.length() - 2));
+ System.out.println("\033[00m");
+ }*/
byte[] message;
if ((msg == null) || (msglen == 0))
message = SHA3.pad10star1(SHA3.M, SHA3.mptr, SHA3.r);
@@ -502,6 +508,12 @@ public class SHA3
System.arraycopy(msg, 0, SHA3.M, SHA3.mptr, msglen);
message = SHA3.pad10star1(SHA3.M, SHA3.mptr + msglen, SHA3.r);
}
+ /*{ String _;
+ System.out.print("\033[33m");
+ for (int j = 0; j < message.length; j++)
+ System.out.print((_ = "00" + Long.toString(message[j] & 255, 16)).substring(_.length() - 2));
+ System.out.println("\033[00m");
+ }*/
SHA3.M = null;
int len = message.length;
byte[] rc = new byte[(SHA3.n + 7) >> 3];
@@ -515,6 +527,13 @@ public class SHA3
if (ww == 8)
for (int i = 0; i < len; i += rr)
{
+ /*if (i == 0)
+ { String _;
+ System.out.print("\033[34m");
+ for (int j = 0; j < 25; j++)
+ System.out.print((_ = "0000000000000000" + Long.toString(SHA3.S[j], 16)).substring(_.length() - 16));
+ System.out.println("\033[00m");
+ }*/
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);
@@ -540,6 +559,13 @@ public class SHA3
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);
+ /*if (i == 0)
+ { String _;
+ System.out.print("\033[35m");
+ for (int j = 0; j < 25; j++)
+ System.out.print((_ = "0000000000000000" + Long.toString(SHA3.S[j], 16)).substring(_.length() - 16));
+ System.out.println("\033[00m");
+ }*/
SHA3.keccakF(SHA3.S);
}
else
diff --git a/pure-java/sha3sum.java b/pure-java/sha3sum.java
index 75f48b0..d8b5d85 100644
--- a/pure-java/sha3sum.java
+++ b/pure-java/sha3sum.java
@@ -67,7 +67,7 @@ public class sha3sum
else if (cmd == "sha3-256sum") o = _o = 256;
else if (cmd == "sha3-384sum") o = _o = 384;
else if (cmd == "sha3-512sum") o = _o = 512;
- boolean binary = false;
+ boolean binary = false, hex = false;
int multi = 0;
String[] files = new String[argv.length + 1];
@@ -111,6 +111,9 @@ public class sha3sum
System.out.println(" -i ITERATIONS");
System.out.println(" --iterations The number of hash iterations to run. (default: " + _i + ")");
System.out.println(" ");
+ System.out.println(" -h");
+ System.out.println(" --hex Read the input in hexadecimal, rather than binary.");
+ System.out.println(" ");
System.out.println(" -b");
System.out.println(" --binary Print the checksum in binary, rather than hexadecimal.");
System.out.println(" ");
@@ -182,6 +185,8 @@ public class sha3sum
binary = true;
else if (arg == "--multi")
multi++;
+ else if (arg == "--hex")
+ hex = true;
else
linger = new String[] { arg, null };
else if (arg.startsWith("-"))
@@ -197,6 +202,11 @@ public class sha3sum
multi++;
arg = arg.substring(1);
}
+ else if (arg.charAt(0) == 'h')
+ {
+ hex = true;
+ arg = arg.substring(1);
+ }
else if (arg.length() == 1)
linger = new String[] { "-" + arg, null };
else
@@ -328,7 +338,18 @@ public class sha3sum
int read = file.read(chunk, 0, blksize);
if (read <= 0)
break;
- SHA3.update(chunk, read);
+ if (hex == false)
+ SHA3.update(chunk, read);
+ else
+ {
+ int n = read << 1;
+ for (int _ = 0; _ < n; _++)
+ {
+ byte a = chunk[_ << 1], b = chunk[(_ << 1) | 1];
+ chunk[_] = (byte)((((a & 15) + (a <= '9' ? 0 : 9)) << 4) | ((b & 15) + (b <= '9' ? 0 : 9)));
+ }
+ SHA3.update(chunk, n);
+ }
}
byte[] bs = SHA3.digest();
if (multi == 0)