From fe19b6c4809602ff29fee35bd4640f6f36b73aa6 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Thu, 27 Aug 2015 09:09:00 +0300 Subject: [PATCH] LEBytes() and ToUInt32Array now are private members of ScryptHash256 --- Novacoin/Interop.cs | 29 +++++++++++++---------------- Novacoin/ScryptHash256.cs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Novacoin/Interop.cs b/Novacoin/Interop.cs index e3e4e6d..49481c9 100644 --- a/Novacoin/Interop.cs +++ b/Novacoin/Interop.cs @@ -39,8 +39,16 @@ namespace Novacoin } } + /// + /// Miscellaneous functions + /// public class Interop { + /// + /// Reverse byte array + /// + /// Source array + /// Result array 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; + } } } diff --git a/Novacoin/ScryptHash256.cs b/Novacoin/ScryptHash256.cs index 4f95926..cb39dd8 100644 --- a/Novacoin/ScryptHash256.cs +++ b/Novacoin/ScryptHash256.cs @@ -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; } + + /// + /// Convert array of unsigned integers to array of bytes. + /// + /// Array of unsigned integer values. + /// Byte array + private static byte[] LEBytes(uint[] values) + { + var result = new byte[values.Length * sizeof(uint)]; + Buffer.BlockCopy(values, 0, result, 0, result.Length); + + return result; + } + + /// + /// Convert byte array to array of unsigned integers. + /// + /// Byte array. + /// Array of integers + private static uint[] ToUInt32Array(byte[] bytes) + { + var result = new uint[bytes.Length / sizeof(uint)]; + Buffer.BlockCopy(bytes, 0, result, 0, bytes.Length); + + return result; + } + } } -- 1.7.1