Alternate privkey generation method, disabled for now
authorCryptoManiac <balthazar@yandex.ru>
Thu, 27 Aug 2015 06:11:02 +0000 (09:11 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Thu, 27 Aug 2015 06:11:02 +0000 (09:11 +0300)
Novacoin/CKeyPair.cs
NovacoinTest/Program.cs

index f5deeed..b1845d1 100644 (file)
@@ -18,6 +18,9 @@
 
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Generators;
+
+using System.Security.Cryptography;
+
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Security;
@@ -30,12 +33,15 @@ namespace Novacoin
     public class CKeyPair : CKey
     {
         private ECPrivateKeyParameters _Private;
+        private RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
 
         /// <summary>
         /// Initialize new CKeyPair instance with random secret.
         /// </summary>
-        public CKeyPair(bool Compressed=true)
+        public CKeyPair(bool Compressed = true)
         {
+
+
             var genParams = new ECKeyGenerationParameters(domain, new SecureRandom());
             var generator = new ECKeyPairGenerator("ECDSA");
             generator.Init(genParams);
@@ -44,6 +50,29 @@ namespace Novacoin
             _Private = (ECPrivateKeyParameters)ecKeyPair.Private;
             _Public = (ECPublicKeyParameters)ecKeyPair.Public;
 
+            /*
+              BigInteger D;
+              var buffer1 = new byte[32];
+              var buffer2 = new byte[32];
+
+              do
+              {
+                  rng.GetBytes(buffer1);
+                  rng.GetNonZeroBytes(buffer2);
+
+                  D = new BigInteger(Hash256.ComputeRaw256(ref buffer1, ref buffer2));
+
+                  if (D.BitLength < 249)
+                      System.Console.WriteLine(D.BitLength);
+              }
+              while (D.SignValue == -1);
+
+              var Q = curve.G.Multiply(D);
+
+              _Private = new ECPrivateKeyParameters(D, domain);
+              _Public = new ECPublicKeyParameters(Q, domain);
+            */
+
             if (Compressed)
             {
                 _Public = Compress(_Public);
index 708747d..5fa85c0 100644 (file)
@@ -248,10 +248,11 @@ namespace NovacoinTest
 
             // Initialization of key store
 
-            Console.Write("Initialization of key store...");
+            Console.WriteLine("Initialization of key store...");
+            watch = Stopwatch.StartNew();
             var keyStore = new CKeyStore();
 
-            Console.WriteLine("Adding and querying new key pair");
+            Console.WriteLine("Initialization done in {0} ms, adding and querying new key pair.", watch.ElapsedMilliseconds);
             var kp1 = new CKeyPair();
             keyStore.AddKey(kp1);