diff --git a/core/java/src/net/i2p/crypto/SHA256Generator.java b/core/java/src/net/i2p/crypto/SHA256Generator.java index 162b9d0c16c6645cce76e6f869d80662383c3031..217147f7b5037394ebf3d7ad61aea267d97f7dec 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() {