Use BouncyCastle hashing functions
[NovacoinLibrary.git] / Novacoin / SHA1.cs
index 9d31cfa..7ef1755 100644 (file)
@@ -17,7 +17,7 @@
 
 using System.Collections.Generic;
 using System.Linq;
-using System.Security.Cryptography;
+using Org.BouncyCastle.Crypto.Digests;
 
 namespace Novacoin
 {
@@ -29,24 +29,25 @@ namespace Novacoin
         /// <summary>
         /// Computes RIPEMD160 hash using managed library
         /// </summary>
-        private static readonly SHA1Managed _hasher1 = new SHA1Managed();
+        private static Sha1Digest _hasher1 = new Sha1Digest();
 
         // 32 bytes
         public override int hashSize
         {
-            get { return 20; }
+            get { return _hasher1.GetDigestSize(); }
         }
 
         public SHA1() : base() { }
         public SHA1(byte[] bytes, int offset = 0) : base(bytes, offset) { }
-        public SHA1(IEnumerable<byte> bytes, int skip = 0) : base(bytes, skip) { }
         public SHA1(SHA1 h) : base(h) { }
 
 
-        public static SHA1 Compute1(IEnumerable<byte> inputBytes)
+        public static SHA1 Compute1(byte[] inputBytes)
         {
-            var dataBytes = inputBytes.ToArray();
-            var digest1 = _hasher1.ComputeHash(dataBytes, 0, dataBytes.Length);
+            var digest1 = new byte[_hasher1.GetDigestSize()];
+
+            _hasher1.BlockUpdate(inputBytes, 0, inputBytes.Length);
+            _hasher1.DoFinal(digest1, 0);
 
             return new SHA1(digest1);
         }