コード例 #1
0
        private static bool checkDuplexModByHash(SHA3 sha3)
        {
            byte[] m1 = new byte[72 * 8 - 1];
            byte[] m2 = new byte[72 * 8 - 1];
            byte[] m  = new byte[m1.Length + m2.Length + 1];

            var rnd = new Random(98732796);

            for (int i = 0; i < m.Length; i++)
            {
                if (m.Length - i == 72)
                {
                    m[i] = 0x81;
                }
                else
                {
                    m[i] = (byte)rnd.Next(0, 255);
                }
            }

            rnd = new Random(98732796);
            for (int i = 0, j = 0, k = 0; i < m.Length - 1; i++)
            {
                if (i % 144 >= 72 || k >= m2.Length)
                {
                    m1[j++] = (byte)rnd.Next(0, 255);
                }
                else
                {
                    m2[k++] = (byte)rnd.Next(0, 255);
                }
            }

            byte[] hash  = sha3.getHash512(m);
            byte[] gamma = sha3.getDuplexMod(m1, m2);
            byte[] tmp   = new byte[64];
            BytesBuilder.CopyTo(gamma, tmp, 0, -1, 72 * 7);

            bool errorFlag = false;

            for (int i = 0; i < hash.Length; i++)
            {
                if (hash[i] != tmp[i])
                {
                    errorFlag = true;
                }
            }

            if (errorFlag)
            {
                Console.WriteLine("DuplexMod and hash unequal, duplexMod is incorrect");
            }
            else
            {
                Console.WriteLine("Well. DuplexMod and hash equal, duplexMod is correct.");
            }

            return(!errorFlag);
        }
コード例 #2
0
        private static bool checkDuplexByHash(SHA3 sha3)
        {
            byte[] keyAndMessage = new byte[72 * 8 - 1];

            var rnd = new Random(98732796);

            for (int i = 0; i < 64; i++)
            {
                keyAndMessage[i] = (byte)rnd.Next(0, 255);
            }

            keyAndMessage[64] = 0x01;
            keyAndMessage[71] = 0x80;

            for (int i = 72; i < keyAndMessage.Length; i++)
            {
                keyAndMessage[i] = (byte)rnd.Next(0, 255);
            }

            byte[] hash  = sha3.getHash512(keyAndMessage);
            byte[] gamma = sha3.getDuplex(keyAndMessage);

            bool errorFlag = false;

            for (int i = 0; i < hash.Length; i++)
            {
                if (hash[i] != gamma[gamma.Length - 72 + i])
                {
                    errorFlag = true;
                }
            }

            if (errorFlag)
            {
                Console.WriteLine("Duplex and hash unequal, duplex is incorrect");
            }
            else
            {
                Console.WriteLine("Well. Duplex and hash equal, duplex is correct.");
            }

            return(!errorFlag);
        }
コード例 #3
0
        private static bool checkGammaByHash(SHA3 sha3)
        {
            byte[] keyAndMessage = new byte[72 * 8 - 1];
            byte[] key           = new byte[64];
            byte[] message       = new byte[72 * 7 - 1];

            var rnd = new Random(98732796);

            for (int i = 0; i < 64; i++)
            {
                keyAndMessage[i] = (byte)rnd.Next(0, 255);
            }

            keyAndMessage[64] = 0x01;
            keyAndMessage[71] = 0x80;

            for (int i = 72; i < keyAndMessage.Length; i++)
            {
                keyAndMessage[i] = (byte)rnd.Next(0, 255);
            }

            rnd = new Random(98732796);
            for (int i = 0; i < 64; i++)
            {
                key[i] = (byte)rnd.Next(0, 255);
            }
            for (int i = 0; i < message.Length; i++)
            {
                message[i] = (byte)rnd.Next(0, 255);
            }

            byte[] hash = sha3.getHash512(keyAndMessage);
            sha3.prepareGamma(key, message);
            byte[] gamma = sha3.getGamma(64, true);

            bool errorFlag = false;

            for (int i = 0; i < hash.Length; i++)
            {
                if (hash[i] != gamma[i])
                {
                    errorFlag = true;
                }
            }

            if (hash.Length != gamma.Length)
            {
                errorFlag = true;
            }

            if (errorFlag)
            {
                Console.WriteLine("Gamma and hash unequal, gamma is incorrect");
            }
            else
            {
                Console.WriteLine("Well. Gamma and hash equal, gamma is correct.");
            }

            return(!errorFlag);
        }