X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=Novacoin%2FSHA256.cs;h=4ceda483127047224a200625e946331a82af7649;hb=0fe762d6eee8a8a23033f813217c1675a34f2d6a;hp=953eaf4b6dc822342bf6898c992b84b04f372385;hpb=0aa2d5cb7cdb5813440e7afcdbe6014e9b8deeee;p=NovacoinLibrary.git diff --git a/Novacoin/SHA256.cs b/Novacoin/SHA256.cs index 953eaf4..4ceda48 100644 --- a/Novacoin/SHA256.cs +++ b/Novacoin/SHA256.cs @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -using System.Linq; -using System.Collections.Generic; +using Org.BouncyCastle.Crypto.Digests; namespace Novacoin { @@ -26,22 +25,25 @@ namespace Novacoin /// public class SHA256 : Hash { + private static Sha256Digest _hasher256 = new Sha256Digest(); + // 32 bytes public override int hashSize { - get { return 32; } + get { return _hasher256.GetDigestSize(); } } public SHA256() : base() { } public SHA256(byte[] bytes, int offset = 0) : base(bytes, offset) { } - public SHA256(IEnumerable bytes, int skip = 0) : base(bytes, skip) { } public SHA256(SHA256 h) : base(h) { } - public static SHA256 Compute256(IEnumerable inputBytes) + public static SHA256 Compute256(byte[] inputBytes) { - var dataBytes = inputBytes.ToArray(); - var digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length); + var digest1 = new byte[_hasher256.GetDigestSize()]; + + _hasher256.BlockUpdate(inputBytes, 0, inputBytes.Length); + _hasher256.DoFinal(digest1, 0); return new SHA256(digest1); }