コード例 #1
0
ファイル: LedgerHeader.cs プロジェクト: fs0c131y/BitfiSources
        public Hash256 Hash()
        {
            var hasher = new Sha512((uint)HashPrefix.LedgerMaster);

            ToBytes(hasher);
            return(new Hash256(hasher.Finish256()));
        }
コード例 #2
0
        public Hash256 CreateHash()
        {
            var half = new Sha512(Prefix().Bytes());

            ToBytesSink(half);
            return(new Hash256(half.Finish256()));
        }
コード例 #3
0
        private byte[] Hash(string message)
        {
            var sha512 = new Sha512();
            var bytes  = Encoding.ASCII.GetBytes(message);

            sha512.Add(bytes);
            return(sha512.Finish256());
        }
コード例 #4
0
        /// <param name="seedBytes"> - a bytes sequence of arbitrary length which will be hashed </param>
        /// <param name="discriminator"> - nullable optional uint32 to hash </param>
        /// <returns> a number between [1, order -1] suitable as a private key
        ///  </returns>
        public static BigInteger ComputeScalar(byte[] seedBytes, uint?discriminator)
        {
            BigInteger key = null;

            for (uint i = 0; i <= 0xFFFFFFFFL; i++)
            {
                var sha512 = new Sha512(seedBytes);
                if (discriminator != null)
                {
                    sha512.AddU32(discriminator.Value);
                }
                sha512.AddU32(i);
                byte[] keyBytes = sha512.Finish256();
                key = Misc.UBigInt(keyBytes);
                if (key.CompareTo(BigInteger.Zero) == 1 &&
                    key.CompareTo(Secp256K1.Order()) == -1)
                {
                    break;
                }
            }
            return(key);
        }