LEBytes() and ToUInt32Array now are private members of ScryptHash256
authorCryptoManiac <balthazar@yandex.ru>
Thu, 27 Aug 2015 06:09:00 +0000 (09:09 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Thu, 27 Aug 2015 06:09:00 +0000 (09:09 +0300)
Novacoin/Interop.cs
Novacoin/ScryptHash256.cs

index e3e4e6d..49481c9 100644 (file)
@@ -39,8 +39,16 @@ namespace Novacoin
         }
     }
 
+    /// <summary>
+    /// Miscellaneous functions
+    /// </summary>
     public class Interop
     {
+        /// <summary>
+        /// Reverse byte array
+        /// </summary>
+        /// <param name="source">Source array</param>
+        /// <returns>Result array</returns>
         public static byte[] ReverseBytes(byte[] source)
         {
             var b = new byte[source.Length];
@@ -52,22 +60,6 @@ namespace Novacoin
             return b;
         }
 
-        public static byte[] LEBytes(uint[] values)
-        {
-            var result = new byte[values.Length * sizeof(uint)];
-            Buffer.BlockCopy(values, 0, result, 0, result.Length);
-
-            return result;
-        }
-
-        public static uint[] ToUInt32Array(byte[] bytes)
-        {
-            var result = new uint[bytes.Length / sizeof(uint)];
-            Buffer.BlockCopy(bytes, 0, result, 0, bytes.Length);
-
-            return result;
-        }
-
         public static byte[] HexToArray(string hex)
         {
             int nChars = hex.Length;
@@ -90,5 +82,10 @@ namespace Novacoin
             }
             return sb.ToString();
         }
+
+        public static int GetTime()
+        {
+            return (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
+        }
     }
 }
index 4f95926..cb39dd8 100644 (file)
@@ -45,7 +45,7 @@ namespace Novacoin
             var V = new uint[(131072 + 63) / sizeof(uint)];
 
             var keyBytes1 = CryptoUtils.PBKDF2_Sha256(128, (byte[])inputBytes, (byte[])inputBytes, 1);
-            var X = Interop.ToUInt32Array(keyBytes1);
+            var X = ToUInt32Array(keyBytes1);
 
             for (var i = 0; i < 1024; i++)
             {
@@ -65,7 +65,7 @@ namespace Novacoin
                 xor_salsa8(ref X, 16, ref X, 0);
             }
 
-            var xBytes = Interop.LEBytes(X);
+            var xBytes = LEBytes(X);
             var keyBytes2 = CryptoUtils.PBKDF2_Sha256(32, (byte[])inputBytes, xBytes, 1);
 
             return new ScryptHash256(keyBytes2);
@@ -141,5 +141,32 @@ namespace Novacoin
             B[indexB + 14] += x14;
             B[indexB + 15] += x15;
         }
+
+        /// <summary>
+        /// Convert array of unsigned integers to array of bytes.
+        /// </summary>
+        /// <param name="values">Array of unsigned integer values.</param>
+        /// <returns>Byte array</returns>
+        private static byte[] LEBytes(uint[] values)
+        {
+            var result = new byte[values.Length * sizeof(uint)];
+            Buffer.BlockCopy(values, 0, result, 0, result.Length);
+
+            return result;
+        }
+
+        /// <summary>
+        /// Convert byte array to array of unsigned integers.
+        /// </summary>
+        /// <param name="bytes">Byte array.</param>
+        /// <returns>Array of integers</returns>
+        private static uint[] ToUInt32Array(byte[] bytes)
+        {
+            var result = new uint[bytes.Length / sizeof(uint)];
+            Buffer.BlockCopy(bytes, 0, result, 0, bytes.Length);
+
+            return result;
+        }
+
     }
 }