From 0c90162e20ea8e5e07715d652282dfac49240cd3 Mon Sep 17 00:00:00 2001 From: dev <dev@robertfoss.se> Date: Sat, 4 Apr 2015 02:27:24 +0000 Subject: [PATCH] Copy directly into buffer without intermediate buffer --- core/java/src/net/i2p/crypto/SHA256Generator.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/java/src/net/i2p/crypto/SHA256Generator.java b/core/java/src/net/i2p/crypto/SHA256Generator.java index 162b9d0c16..217147f7b5 100644 --- a/core/java/src/net/i2p/crypto/SHA256Generator.java +++ b/core/java/src/net/i2p/crypto/SHA256Generator.java @@ -2,6 +2,7 @@ package net.i2p.crypto; import gnu.crypto.hash.Sha256Standalone; +import java.security.DigestException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.concurrent.LinkedBlockingQueue; @@ -20,6 +21,7 @@ public final class SHA256Generator { private final LinkedBlockingQueue<MessageDigest> _digests; private static final boolean _useGnu; + static { boolean useGnu = false; try { @@ -53,13 +55,13 @@ public final class SHA256Generator { /** * Calculate the hash and cache the result. + * @param source what to hash */ public final Hash calculateHash(byte[] source, int start, int len) { MessageDigest digest = acquire(); digest.update(source, start, len); byte rv[] = digest.digest(); release(digest); - //return new Hash(rv); return Hash.create(rv); } @@ -71,9 +73,12 @@ public final class SHA256Generator { public final void calculateHash(byte[] source, int start, int len, byte out[], int outOffset) { MessageDigest digest = acquire(); digest.update(source, start, len); - byte rv[] = digest.digest(); + try { + digest.digest(out, outOffset, Hash.HASH_LENGTH); + } catch (DigestException e) { + throw new RuntimeException(e); + } release(digest); - System.arraycopy(rv, 0, out, outOffset, rv.length); } private MessageDigest acquire() { -- GitLab