aboutsummaryrefslogtreecommitdiffstats
path: root/java/ConcurrentSHA3.java
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-08-10 20:44:39 +0200
committerMattias Andrée <maandree@operamail.com>2013-08-10 20:44:39 +0200
commit12f9869bb8796f6f261b748890d839aee3cfc0b4 (patch)
treecf0623a001adf01f88da861b988ae968735185e6 /java/ConcurrentSHA3.java
parentpad10star1 returns actual length of message (diff)
downloadsha3sum-12f9869bb8796f6f261b748890d839aee3cfc0b4.tar.gz
sha3sum-12f9869bb8796f6f261b748890d839aee3cfc0b4.tar.bz2
sha3sum-12f9869bb8796f6f261b748890d839aee3cfc0b4.tar.xz
improved memoery management in java version
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--java/ConcurrentSHA3.java10
1 files changed, 6 insertions, 4 deletions
diff --git a/java/ConcurrentSHA3.java b/java/ConcurrentSHA3.java
index 8deae20..00a9082 100644
--- a/java/ConcurrentSHA3.java
+++ b/java/ConcurrentSHA3.java
@@ -106,7 +106,7 @@ public class ConcurrentSHA3
/**
* Message chunk that is being processed
*/
- private byte[] message;
+ private byte[] message = null;
/**
* The current state
@@ -373,8 +373,11 @@ public class ConcurrentSHA3
this.nr = 12 + (this.l << 1);
this.wmod = w == 64 ? -1L : (1L << this.w) - 1L;
this.S = new long[25];
- this.M = new byte[(this.r * this.b) >> 2];
+ if ((this.M == null) || ((this.r * this.b) >> 2 != this.M.length))
+ this.M = new byte[(this.r * this.b) >> 2];
this.mptr = 0;
+ if (this.message == null)
+ this.message = new byte[8 << 10];
}
@@ -405,7 +408,7 @@ public class ConcurrentSHA3
System.arraycopy(msg, 0, this.M, this.mptr, msglen);
int len = this.mptr += msglen;
len -= len % ((this.r * this.b) >> 3);
- System.arraycopy(this.M, 0, this.message = new byte[len], 0, len);
+ System.arraycopy(this.M, 0, (this.message.length < len) ? (this.message = new byte[len]) : this.message, 0, len);
System.arraycopy(this.M, len, this.M, 0, this.mptr -= len);
int n = Math.min(len, rr);
@@ -556,7 +559,6 @@ public class ConcurrentSHA3
System.arraycopy(msg, 0, this.M, this.mptr, msglen);
len = this.pad10star1(this.M, this.mptr + msglen, this.r);
}
- this.M = null;
int rr = this.r >> 3;
int nn = (this.n + 7) >> 3;