/**
         * which generates the p , q and a values from the given parameters,
         * returning the Gost3410Parameters object.
         */
        public Gost3410Parameters GenerateParameters()
        {
            BigInteger [] pq = new BigInteger[2];
            BigInteger    q = null, p = null, a = null;

            int  x0, c;
            long x0L, cL;

            if (typeproc == 1)
            {
                x0 = init_random.NextInt();
                c  = init_random.NextInt();

                switch (size)
                {
                case 512:
                    procedure_A(x0, c, pq, 512);
                    break;

                case 1024:
                    procedure_B(x0, c, pq);
                    break;

                default:
                    throw new ArgumentException("Ooops! key size 512 or 1024 bit.");
                }
                p = pq[0];  q = pq[1];
                a = procedure_C(p, q);
                //System.out.println("p:"+p.toString(16)+"\n"+"q:"+q.toString(16)+"\n"+"a:"+a.toString(16));
                //System.out.println("p:"+p+"\n"+"q:"+q+"\n"+"a:"+a);
                return(new Gost3410Parameters(p, q, a, new Gost3410ValidationParameters(x0, c)));
            }
            else
            {
                x0L = init_random.NextLong();
                cL  = init_random.NextLong();

                switch (size)
                {
                case 512:
                    procedure_Aa(x0L, cL, pq, 512);
                    break;

                case 1024:
                    procedure_Bb(x0L, cL, pq);
                    break;

                default:
                    throw new InvalidOperationException("Ooops! key size 512 or 1024 bit.");
                }
                p = pq[0];  q = pq[1];
                a = procedure_C(p, q);
                //System.out.println("p:"+p.toString(16)+"\n"+"q:"+q.toString(16)+"\n"+"a:"+a.toString(16));
                //System.out.println("p:"+p+"\n"+"q:"+q+"\n"+"a:"+a);
                return(new Gost3410Parameters(p, q, a, new Gost3410ValidationParameters(x0L, cL)));
            }
        }
Esempio n. 2
0
        public Gost3410Parameters GenerateParameters()
        {
            //IL_0074: Unknown result type (might be due to invalid IL or missing references)
            //IL_00f8: Unknown result type (might be due to invalid IL or missing references)
            BigInteger[] array       = new BigInteger[2];
            BigInteger   bigInteger  = null;
            BigInteger   bigInteger2 = null;
            BigInteger   bigInteger3 = null;

            if (typeproc == 1)
            {
                int x = init_random.NextInt();
                int c = init_random.NextInt();
                switch (size)
                {
                case 512:
                    procedure_A(x, c, array, 512);
                    break;

                case 1024:
                    procedure_B(x, c, array);
                    break;

                default:
                    throw new ArgumentException("Ooops! key size 512 or 1024 bit.");
                }
                bigInteger2 = array[0];
                bigInteger  = array[1];
                bigInteger3 = procedure_C(bigInteger2, bigInteger);
                return(new Gost3410Parameters(bigInteger2, bigInteger, bigInteger3, new Gost3410ValidationParameters(x, c)));
            }
            long num  = init_random.NextLong();
            long num2 = init_random.NextLong();

            switch (size)
            {
            case 512:
                procedure_Aa(num, num2, array, 512);
                break;

            case 1024:
                procedure_Bb(num, num2, array);
                break;

            default:
                throw new InvalidOperationException("Ooops! key size 512 or 1024 bit.");
            }
            bigInteger2 = array[0];
            bigInteger  = array[1];
            bigInteger3 = procedure_C(bigInteger2, bigInteger);
            return(new Gost3410Parameters(bigInteger2, bigInteger, bigInteger3, new Gost3410ValidationParameters(num, num2)));
        }
Esempio n. 3
0
        /** Generates a nonce (a random number used once). */
        public static long generateNonce()
        {
            long nonce = RANDOM.NextLong();

            knownNonces.Add(nonce);
            return(nonce);
        }
Esempio n. 4
0
        private static Path GeneratePath(String prefix, String suffix, Path dir)
        {
            long n = Random.NextLong();

            n = (n == Long.MinValue) ? 0 : System.Math.Abs(n);
            Path name = dir.FileSystem.getPath(prefix + Convert.ToString(n) + suffix);

            // the generated name should be a simple file name
            if (name.Parent != null)
            {
                throw new IllegalArgumentException("Invalid prefix or suffix");
            }
            return(dir.Resolve(name));
        }
Esempio n. 5
0
 /// <summary>
 /// Generates a unique object identifier.
 ///
 /// <para>If the system property <code>java.rmi.server.randomIDs</code>
 /// is defined to equal the string <code>"true"</code> (case insensitive),
 /// then this constructor will use a cryptographically
 /// strong random number generator to choose the object number of the
 /// returned <code>ObjID</code>.
 /// </para>
 /// </summary>
 public ObjID()
 {
     /*
      * If generating random object numbers, create a new UID to
      * ensure uniqueness; otherwise, use a shared UID because
      * sequential object numbers already ensure uniqueness.
      */
     if (UseRandomIDs())
     {
         Space  = new UID();
         ObjNum = SecureRandom.NextLong();
     }
     else
     {
         Space  = MySpace;
         ObjNum = NextObjNum.AndIncrement;
     }
 }
Esempio n. 6
0
        /// <summary>Regression test for IV calculation, see HADOOP-11343</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestCalculateIV()
        {
            JceAesCtrCryptoCodec codec = new JceAesCtrCryptoCodec();

            codec.SetConf(conf);
            SecureRandom sr = new SecureRandom();

            byte[] initIV     = new byte[16];
            byte[] Iv         = new byte[16];
            long   iterations = 1000;
            long   counter    = 10000;

            // Overflow test, IV: 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff
            for (int i = 0; i < 8; i++)
            {
                initIV[8 + i] = unchecked ((byte)unchecked ((int)(0xff)));
            }
            for (long j = 0; j < counter; j++)
            {
                AssertIVCalculation(codec, initIV, j, Iv);
            }
            // Random IV and counter sequence test
            for (long i_1 = 0; i_1 < iterations; i_1++)
            {
                sr.NextBytes(initIV);
                for (long j_1 = 0; j_1 < counter; j_1++)
                {
                    AssertIVCalculation(codec, initIV, j_1, Iv);
                }
            }
            // Random IV and random counter test
            for (long i_2 = 0; i_2 < iterations; i_2++)
            {
                sr.NextBytes(initIV);
                for (long j_1 = 0; j_1 < counter; j_1++)
                {
                    long c = sr.NextLong();
                    AssertIVCalculation(codec, initIV, c, Iv);
                }
            }
        }
        /// <summary>
        /// Creates a new random key pair, using a user-provided string to add entropy to the
        /// SecureRandom generator provided by the .NET Framework.
        /// </summary>
        public static KeyPair Create(string usersalt, bool compressed = false, byte addressType = 0)
        {
            if (usersalt == null)
            {
                usersalt = "ok, whatever";
            }
            usersalt += DateTime.UtcNow.Ticks.ToString();

            SecureRandom sr = new SecureRandom();

            /// Random sr = new Random();

            byte[] poop = Util.ComputeSha256(usersalt + nonce.ToString());
            nonce++;

            byte[] newkey = new byte[32];

            for (int i = 0; i < 32; i++)
            {
                long x = sr.NextLong() & long.MaxValue;
                /// long x = sr.Next() & long.MaxValue;
                x        += poop[i];
                newkey[i] = (byte)(x & 0xff);
            }

            /*
             * ///!!! можно просто передать массив байтов ниже
             * for (int i = 0; i < 32; i++)
             * {
             * // newkey[i] = (byte)(255 & 0xff);  ///!!! выдал рабочий ключ 5Km2kuu7vtFDPpxywn4u3NLu8iSdrqhxWT8tUKjeEXs2f9yxoWz
             * ///с адресом 12M4QznuNZH2BRVbLK8SKvNqGTPJpCpST7 , но создать кошелек с этими данными не получается
             * //  newkey[i] = (byte)(33 & 0xff);
             * byte x= (byte)sr.Next(1, 256);
             * newkey[i] = (byte)(x & 0xff);
             * }
             */
            return(new KeyPair(newkey, compressed: compressed, addressType: addressType));
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new random key pair, using a user-provided string to add entropy to the
        /// SecureRandom generator provided by the .NET Framework.
        /// </summary>
        public static KeyPair Create(string usersalt, bool compressed = false, byte addressType = 55)
        {
            if (usersalt == null)
            {
                usersalt = "ok, whatever";
            }
            usersalt += DateTime.UtcNow.Ticks.ToString();

            SecureRandom sr = new SecureRandom();

            byte[] poop = Util.ComputeSha256(usersalt + nonce.ToString());
            nonce++;

            byte[] newkey = new byte[32];

            for (int i = 0; i < 32; i++)
            {
                long x = sr.NextLong() & long.MaxValue;
                x        += poop[i];
                newkey[i] = (byte)(x & 0xff);
            }
            return(new KeyPair(newkey, compressed: compressed, addressType: addressType));
        }
        /// <summary>
        /// Create an intermediate from a passphrase or intermediate code
        /// </summary>
        public Bip38Intermediate(string fromstring, Interpretation interpretation, int startingSequenceNumber = 0)
        {
            if (interpretation == Interpretation.IntermediateCode)
            {
                createFromCode(fromstring);
            }
            else
            {
                _ownerentropy = new byte[8];

                // Get 8 random bytes to use as salt
                SecureRandom sr = new SecureRandom();
                sr.NextBytes(_ownerentropy);
                // set lot number between 100000 and 999999, and sequence number to 1
                long x = (sr.NextLong() % 900000L + 100000L) * 4096L + (long)startingSequenceNumber;
                for (int i = 7; i >= 4; i--)
                {
                    _ownerentropy[i] = (byte)(x & 0xFF);
                    x >>= 8;
                }
                createFromPassphrase(fromstring, _ownerentropy, true);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new random key pair with added compatibility for WIF-stupid coins
        /// </summary>
        public static KeyPair CreateX(string usersalt, bool compressed = false, byte addressType = 30, bool isWIFstupid = false)
        { // changed default addressType for DOGE conversion
            if (usersalt == null)
            {
                usersalt = "ok, whatever";
            }
            usersalt += DateTime.UtcNow.Ticks.ToString();

            SecureRandom sr = new SecureRandom();

            byte[] poop = Util.ComputeSha256(usersalt + nonce.ToString());
            nonce++;

            byte[] newkey = new byte[32];

            for (int i = 0; i < 32; i++)
            {
                long x = sr.NextLong() & long.MaxValue;
                x        += poop[i];
                newkey[i] = (byte)(x & 0xff);
            }
            return(new KeyPair(newkey, addressType, isWIFstupid, compressed: compressed));
        }
Esempio n. 11
0
        private string salt = "wefdhwfkhjwefopiwjdfldkdsfjndkljf"; // initial salt replaced at runtime

        private void GenerateAddresses()
        {
            string       b58       = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
            int          b58len    = b58.Length;
            Sha256Digest bcsha256a = new Sha256Digest();
            Sha256Digest bcsha256b = new Sha256Digest();

            string shacode = "";


            SecureRandom sr  = new SecureRandom();
            int          dec = 0;

            List <string> myaddresses = new List <string>();
            Dictionary <string, string> myprivkeys = new Dictionary <string, string>();

            for (int ji = 0; ji < 100000000; ji++)
            {
                byte[] poop = Util.ComputeSha256(salt + ji.ToString());

                byte[] ahash = null;
                do
                {
                    // Get 'S' + 21 random base58 characters, where sha256(result + '?') starts with the byte 00 (1 in 256 possibilities)
                    shacode = "S";
                    for (int i = 0; i < 29; i++)
                    {
                        long x = sr.NextLong() & long.MaxValue;
                        x += poop[i];
                        long x58 = x % b58len;
                        shacode += b58.Substring((int)x58, 1);
                    }
                    string shacodeq = shacode + "?";
                    ahash = Util.ComputeSha256(Encoding.ASCII.GetBytes(shacodeq));

                    if (ahash[0] == 0)
                    {
                        break;
                    }

                    Application.DoEvents();
                } while (true);


                string pubhex  = Util.PrivHexToPubHex(Util.ByteArrayToString(Util.ComputeSha256(shacode)));
                string pubhash = Util.PubHexToPubHash(pubhex);
                string address = Util.PubHashToAddress(pubhash, "Dogecoin");


                pubhex = pubhex.Replace(" ", "");

                lock (LockObject) {
                    using (StreamWriter sw1 = new StreamWriter("privkeys3.txt", true)) {
                        sw1.WriteLine("\"" + address + "\",\"" + shacode + "\",\"" + pubhex + "\"");
                        sw1.Close();
                    }


                    using (StreamWriter sw1 = new StreamWriter("addresses3.txt", true)) {
                        sw1.WriteLine("\"" + address + "\",\"" + pubhex + "\"");
                        sw1.Close();
                    }
                }

                Debug.WriteLine(shacode + "=" + address);

                /*
                 * myaddresses.Add(address);
                 * myprivkeys.Add(address, shacode);
                 * dec++;
                 * if (dec == 1000) {
                 *  dec = 0;
                 *  Application.DoEvents();
                 * }
                 * */
            }
        }
 /// <summary>
 /// Gets the next random <see langword="long"/> from the <see cref="SecureRandom"/>.
 /// </summary>
 /// <returns> The random <see langword="long"/>. </returns>
 public long NextLong() => secureRandom.NextLong();
Esempio n. 13
0
 private string CreateMessageId()
 {
     return(Math.Abs(SecureRandom.NextLong()).ToString());
 }
 public ConnectionSuccessComposer()
 {
     WriteLong(0);
     WriteByte(0);
     WriteLong(SecureRandom.NextLong());
 }