public void Test_02_1600_bits()
        {
            SHA3_384 H = new SHA3_384();
            int      i = 0;

            H.NewState += (sender, e) =>
            {
                string Expected = States1600Bits[i++].Replace(" ", string.Empty);
                string Actual   = Hashes.BinaryToString(H.GetState()).ToUpper();
                Assert.AreEqual(Expected, Actual);
            };

            byte[] Input = new byte[200];
            int    j;

            for (j = 0; j < 200; j++)
            {
                Input[j] = 0xa3;
            }

            byte[] Digest = H.ComputeVariable(Input);
            string s      = Hashes.BinaryToString(Digest);

            Assert.AreEqual("1881de2ca7e41ef95dc4732b8f5f002b189cc1e42b74168ed1732649ce1dbcdd76197a31fd55ee989f2d7050dd473e8f", s);
            Assert.AreEqual(States1600Bits.Length, i);
        }
        public void Test_04_Performance()
        {
            byte[]   Data = new byte[80 * 1024 * 1024];
            SHA3_384 H    = new SHA3_384();

            H.ComputeVariable(Data);
        }
Beispiel #3
0
        public void Test_03_SHA3_384()
        {
            SHA3_384 H = new SHA3_384();

            byte[] Digest = H.ComputeVariable(new MemoryStream(new byte[0]));
            string s      = Hashes.BinaryToString(Digest);

            Assert.AreEqual("0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004", s);
        }
Beispiel #4
0
        /// <summary>
        /// Evaluates the function on a scalar argument.
        /// </summary>
        /// <param name="Argument">Function argument.</param>
        /// <param name="Variables">Variables collection.</param>
        /// <returns>Function result.</returns>
        public override IElement EvaluateScalar(IElement Argument, Variables Variables)
        {
            if (!(Argument.AssociatedObjectValue is byte[] Bin))
            {
                throw new ScriptRuntimeException("Binary data expected.", this);
            }

            SHA3_384 H = new SHA3_384();

            return(new ObjectValue(H.ComputeVariable(Bin)));
        }
        public void Test_03_1600_bits_Stream()
        {
            SHA3_384 H = new SHA3_384();

            byte[] Input = new byte[200];
            int    j;

            for (j = 0; j < 200; j++)
            {
                Input[j] = 0xa3;
            }

            byte[] Digest = H.ComputeVariable(new MemoryStream(Input));
            string s      = Hashes.BinaryToString(Digest);

            Assert.AreEqual("1881de2ca7e41ef95dc4732b8f5f002b189cc1e42b74168ed1732649ce1dbcdd76197a31fd55ee989f2d7050dd473e8f", s);
        }
        public void Test_01_0_bits()
        {
            SHA3_384 H = new SHA3_384();
            int      i = 0;

            H.NewState += (sender, e) =>
            {
                string Expected = States0Bits[i++].Replace(" ", string.Empty);
                string Actual   = Hashes.BinaryToString(H.GetState()).ToUpper();
                Assert.AreEqual(Expected, Actual);
            };

            byte[] Digest = H.ComputeVariable(new byte[0]);
            string s      = Hashes.BinaryToString(Digest);

            Assert.AreEqual("0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004", s);
            Assert.AreEqual(States0Bits.Length, i);
        }
Beispiel #7
0
 public void ConvertToUpperCasing()
 {
     if (!string.IsNullOrEmpty(MD5))
     {
         MD5 = MD5.ToUpper();
     }
     if (!string.IsNullOrEmpty(SHA1))
     {
         SHA1 = SHA1.ToUpper();
     }
     if (!string.IsNullOrEmpty(SHA256))
     {
         SHA256 = SHA256.ToUpper();
     }
     if (!string.IsNullOrEmpty(SHA384))
     {
         SHA384 = SHA384.ToUpper();
     }
     if (!string.IsNullOrEmpty(SHA512))
     {
         SHA512 = SHA512.ToUpper();
     }
     if (!string.IsNullOrEmpty(CRC32))
     {
         CRC32 = CRC32.ToUpper();
     }
     if (!string.IsNullOrEmpty(RIPEMD160))
     {
         RIPEMD160 = RIPEMD160.ToUpper();
     }
     if (!string.IsNullOrEmpty(SHA3_256))
     {
         SHA3_256 = SHA3_256.ToUpper();
     }
     if (!string.IsNullOrEmpty(SHA3_384))
     {
         SHA3_384 = SHA3_384.ToUpper();
     }
     if (!string.IsNullOrEmpty(SHA3_512))
     {
         SHA3_512 = SHA3_512.ToUpper();
     }
 }
Beispiel #8
0
        static void Main(string[] args)
        {
            TestCases tc = new TestCases();

            for (int i = 0; i < 2; i++)
            {
                byte[] result = SHA3_224.ComputeHash(tc.SHA3_224[i].Input);
                if (CompareArrays(result, tc.SHA3_224[i].Result))
                {
                    Console.WriteLine("SHA3_224 TEST " + i + "           -PASS-");
                }
                else
                {
                    Console.WriteLine("SHA3_224 TEST " + i + "           *FAIL!*");
                }
                result = SHA3_256.ComputeHash(tc.SHA3_256[i].Input);
                if (CompareArrays(result, tc.SHA3_256[i].Result))
                {
                    Console.WriteLine("SHA3_256 TEST " + i + "           -PASS-");
                }
                else
                {
                    Console.WriteLine("SHA3_256 TEST " + i + "           *FAIL!*");
                }
                result = SHA3_384.ComputeHash(tc.SHA3_384[i].Input);
                if (CompareArrays(result, tc.SHA3_384[i].Result))
                {
                    Console.WriteLine("SHA3_384 TEST " + i + "           -PASS-");
                }
                else
                {
                    Console.WriteLine("SHA3_384 TEST " + i + "           *FAIL!*");
                }
                result = SHA3_512.ComputeHash(tc.SHA3_512[i].Input);
                if (CompareArrays(result, tc.SHA3_512[i].Result))
                {
                    Console.WriteLine("SHA3_512 TEST " + i + "           -PASS-");
                }
                else
                {
                    Console.WriteLine("SHA3_512 TEST " + i + "           *FAIL!*");
                }
                result = SHAKE128.ComputeHash(tc.SHAKE128[i].Input, tc.SHAKE128[i].Result.Length);
                if (CompareArrays(result, tc.SHAKE128[i].Result))
                {
                    Console.WriteLine("SHAKE128 TEST " + i + "           -PASS-");
                }
                else
                {
                    Console.WriteLine("SHAKE128 TEST " + i + "           *FAIL!*");
                }
                result = SHAKE256.ComputeHash(tc.SHAKE256[i].Input, tc.SHAKE256[i].Result.Length);
                if (CompareArrays(result, tc.SHAKE256[i].Result))
                {
                    Console.WriteLine("SHAKE256 TEST " + i + "           -PASS-");
                }
                else
                {
                    Console.WriteLine("SHAKE256 TEST " + i + "           *FAIL!*");
                }
            }

            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
        }