public void EmptyString_384()
        {
            Groestl groestl = new Groestl();

            groestl.btvrs = 384;
            groestl.input = "";
            string expected = "ac353c1095ace21439251007862d6c62f829ddbe6de4f78e68d310a9205a736d8b11d99bffe448f57a1cfa2934f044a5";

            groestl.Execute();

            StringBuilder sb = new StringBuilder();

            foreach (var _byte in groestl.OutputData)
            {
                string res = Convert.ToString(Convert.ToInt16(_byte), 16);
                if (res.Length == 1)
                {
                    res = "0" + res;
                }
                sb.Append(res);
            }
            string actual = sb.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void Groestl_Hash_Should_Match()
        {
            var hasher = new Groestl();
            var result = hasher.Digest(testValue).ToHexString();

            Assert.Equal("e14c0b9b145f2df8ebf37c81a4982a87e174a8b46c7e5ca9326d10997e02e133", result);
        }
        public void Test_From_Wiki_256()
        {
            Groestl groestl = new Groestl();

            groestl.btvrs = 256;
            groestl.input = "The quick brown fox jumps over the lazy dog";
            string expected = "8c7ad62eb26a21297bc39c2d7293b4bd4d3399fa8afab29e970471739e28b301";

            groestl.Execute();

            StringBuilder sb = new StringBuilder();

            foreach (var _byte in groestl.OutputData)
            {
                string res = Convert.ToString(Convert.ToInt16(_byte), 16);
                if (res.Length == 1)
                {
                    res = "0" + res;
                }
                sb.Append(res);
            }
            string actual = sb.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void EmptyString_256()
        {
            Groestl groestl = new Groestl();

            groestl.btvrs = 256;
            groestl.input = "";
            string expected = "1a52d11d550039be16107f9c58db9ebcc417f16f736adb2502567119f0083467";

            groestl.Execute();

            StringBuilder sb = new StringBuilder();

            foreach (var _byte in groestl.OutputData)
            {
                string res = Convert.ToString(Convert.ToInt16(_byte), 16);
                if (res.Length == 1)
                {
                    res = "0" + res;
                }
                sb.Append(res);
            }
            string actual = sb.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void Test_From_Wiki_256_2()
        {
            Groestl groestl = new Groestl();

            groestl.btvrs = 256;
            groestl.input = "The quick brown fox jumps over the lazy dog.";
            string expected = "f48290b1bcacee406a0429b993adb8fb3d065f4b09cbcdb464a631d4a0080aaf";

            groestl.Execute();

            StringBuilder sb = new StringBuilder();

            foreach (var _byte in groestl.OutputData)
            {
                string res = Convert.ToString(Convert.ToInt16(_byte), 16);
                if (res.Length == 1)
                {
                    res = "0" + res;
                }
                sb.Append(res);
            }
            string actual = sb.ToString();

            Assert.AreEqual(expected, actual);
        }
        public void EmptyString_224()
        {
            Groestl groestl = new Groestl();

            groestl.btvrs = 224;
            groestl.input = "";
            string expected = "f2e180fb5947be964cd584e22e496242c6a329c577fc4ce8c36d34c3";

            groestl.Execute();

            StringBuilder sb = new StringBuilder();

            foreach (var _byte in groestl.OutputData)
            {
                string res = Convert.ToString(Convert.ToInt16(_byte), 16);
                if (res.Length == 1)
                {
                    res = "0" + res;
                }
                sb.Append(res);
            }
            string actual = sb.ToString();

            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        // Test encryption
        static void TestCryptography()
        {
            IHashProvider p;

            // Generate a random set of bytes
            byte[] Bytes = SecureRandom.Bytes(32);

            // Write bytes to console
            Console.WriteLine($"Randomly generated bytes: {Encoding.ByteArrayToHexString(Bytes)}");

            // Keccak the generated bytes
            byte[] KeccakBytes = Keccak.keccak(Bytes);

            // Write keccak bytes to console
            Console.WriteLine($"Keccak: {Encoding.ByteArrayToHexString(KeccakBytes)}");

            // Blake256 the generated bytes
            p = new Blake();
            byte[] BlakeBytes = p.Hash(Bytes);

            // Write blake256 bytes to console
            Console.WriteLine($"Blake: {Encoding.ByteArrayToHexString(BlakeBytes)}");

            // Skein the generated bytes
            p = new Skein();
            byte[] SkeinBytes = p.Hash(Bytes);

            // Write skein bytes to console
            Console.WriteLine($"Skein: {Encoding.ByteArrayToHexString(SkeinBytes)}");

            // Groestl the generated bytes
            p = new Groestl();
            byte[] GroestlBytes = p.Hash(Bytes);

            // Write groestl bytes to console
            Console.WriteLine($"Groestl: {Encoding.ByteArrayToHexString(GroestlBytes)}");

            // JH the generated bytes
            p = new JH();
            byte[] JHBytes = p.Hash(Bytes);

            // Write JH bytes to console
            Console.WriteLine($"JH: {Encoding.ByteArrayToHexString(JHBytes)}");

            // Base58 the generated bytes
            string Base58String = Base58.Encode(Bytes);

            // Write base58 bytes to console
            Console.WriteLine($"Base58: {Base58String}");
            Console.WriteLine();
        }
Beispiel #8
0
        /* CryptoNight Step 5: Apply Keccak to the state again, and then
         * use the resulting data to select which of four finalizer
         * hash functions to apply to the data (Blake, Groestl, JH,
         * or Skein). Use this hash to squeeze the state array down
         * to the final 32 byte hash output.
         */
        public static byte[] HashFinalState(CNState cnState)
        {
            /* Get the state buffer as an array of ulongs rather than bytes */
            ulong[] hashState = cnState.GetHashState();

            Keccak.Keccakf(hashState, 24);

            /* Set the state buffer from the coerced hash state */
            cnState.SetHashState(hashState);

            /* Get the actual state buffer finally */
            byte[] state = cnState.GetState();

            /* Choose the final hashing function to use based on the value of
             * state[0] */
            switch (state[0] % 4)
            {
            case 0:
            {
                return(Blake.Hash(state));
            }

            case 1:
            {
                return(Groestl.Hash(state));
            }

            case 2:
            {
                return(JH.Hash(state));
            }

            default:
            {
                return(Skein.Hash(state));
            }
            }
        }
        public void Groestl_Hash_Should_Throw_On_Null_Input()
        {
            var hasher = new Groestl();

            Assert.Throws <ArgumentNullException>(() => hasher.Digest(null));
        }
Beispiel #10
0
        public static ICryptoHash Create(CryptoHashName hash)
        {
            switch (hash)
            {
            case CryptoHashName.Sha256:
                return(Sha2.Create(256));

            case CryptoHashName.Sha224:
                return(Sha2.Create(224));

            case CryptoHashName.Sha512:
                return(Sha2.Create(512));

            case CryptoHashName.Sha384:
                return(Sha2.Create(384));

            case CryptoHashName.Blake256:
                return(Blake.Create(256));

            case CryptoHashName.Blake224:
                return(Blake.Create(224));

            case CryptoHashName.Blake512:
                return(Blake.Create(512));

            case CryptoHashName.Blake384:
                return(Blake.Create(384));

            case CryptoHashName.Groestl256:
                return(Groestl.Create(256));

            case CryptoHashName.Groestl224:
                return(Groestl.Create(224));

            case CryptoHashName.Groestl512:
                return(Groestl.Create(512));

            case CryptoHashName.Groestl384:
                return(Groestl.Create(384));

            case CryptoHashName.JH256:
                return(JH.Create(256));

            case CryptoHashName.JH224:
                return(JH.Create(224));

            case CryptoHashName.JH512:
                return(JH.Create(512));

            case CryptoHashName.JH384:
                return(JH.Create(384));

            case CryptoHashName.Skein256:
                return(Skein.Create(256));

            case CryptoHashName.Skein224:
                return(Skein.Create(224));

            case CryptoHashName.Skein512:
                return(Skein.Create(512));

            case CryptoHashName.Skein384:
                return(Skein.Create(384));

            case CryptoHashName.QmhHuk256:
                return(QmhHuk.Create(256));

            case CryptoHashName.QmhHuk224:
                return(QmhHuk.Create(224));

            case CryptoHashName.QmhHuk512:
                return(QmhHuk.Create(512));

            case CryptoHashName.QmhHuk384:
                return(QmhHuk.Create(384));

            default:
                throw new ArgumentException();
            }
        }