aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-02-04 05:03:27 +0100
committerMattias Andrée <maandree@operamail.com>2013-02-04 05:03:27 +0100
commit320221a3dc479ab59acafeba5f6467ca4920afc3 (patch)
treea515bb62c489d49526c5eeaa5a12dfb37392012e
parentthe java lib compiles (diff)
downloadsha3sum-320221a3dc479ab59acafeba5f6467ca4920afc3.tar.gz
sha3sum-320221a3dc479ab59acafeba5f6467ca4920afc3.tar.bz2
sha3sum-320221a3dc479ab59acafeba5f6467ca4920afc3.tar.xz
support for slaxed chunks
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--SHA3.java38
1 files changed, 31 insertions, 7 deletions
diff --git a/SHA3.java b/SHA3.java
index 46e09e1..3064d8a 100644
--- a/SHA3.java
+++ b/SHA3.java
@@ -440,13 +440,25 @@ public class SHA3
*/
private static void update(byte[] msg)
{
+ update(msg, msg.length);
+ }
+
+
+ /**
+ * Absorb the more of the message message to the Keccak sponge
+ *
+ * @param msg The partial message
+ * @param msglen The length of the partial message
+ */
+ private static void update(byte[] msg, int msglen)
+ {
int rr = SHA3.r >> 3;
int ww = SHA3.w >> 3;
- if (SHA3.mptr + msg.length > SHA3.M.length)
+ 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(msg, 0, SHA3.M, SHA3.mptr, msg.length);
- SHA3.mptr += msg.length;
+ System.arraycopy(msg, 0, SHA3.M, SHA3.mptr, msglen);
+ SHA3.mptr += msglen;
int len = SHA3.mptr;
len -= len % ((SHA3.r * SHA3.b) >> 3);
byte[] message;
@@ -510,15 +522,27 @@ public class SHA3
*/
private static byte[] digest(byte[] msg)
{
+ return digest(msg, msg.length);
+ }
+
+
+ /**
+ * Absorb the last part of the message and squeeze the Keccak sponge
+ *
+ * @param msg The rest of the message
+ * @param msglen The length of the partial message
+ */
+ private static byte[] digest(byte[] msg, int msglen)
+ {
byte[] message;
- if ((msg == null) || (msg.length == 0))
+ if ((msg == null) || (msglen == 0))
message = SHA3.pad10star1(SHA3.M, SHA3.mptr, SHA3.r);
else
{
- if (SHA3.mptr + msg.length > SHA3.M.length)
+ 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(msg, 0, SHA3.M, SHA3.mptr, msg.length);
- message = SHA3.pad10star1(SHA3.M, SHA3.mptr + msg.length, SHA3.r);
+ System.arraycopy(msg, 0, SHA3.M, SHA3.mptr, msglen);
+ message = SHA3.pad10star1(SHA3.M, SHA3.mptr + msglen, SHA3.r);
}
SHA3.M = null;
int len = message.length;