Beispiel #1
0
        public void HashTest()
        {
            HashNode node = new HashNode();

            node.Hash = TestVectors.h("ABCDEF");
            CustomAssert.AreEqual(TestVectors.h("ABCDEF"), node.Hash);
        }
Beispiel #2
0
        public void Constructor3Test()
        {
            HashNode node = new HashNode(TestVectors.h("ABCDEF"), 1, 2);

            CustomAssert.AreEqual(TestVectors.h("ABCDEF"), node.Hash);
            Assert.AreEqual(1, node.RangeStart);
            Assert.AreEqual(2, node.RangeEnd);
        }
Beispiel #3
0
        public void RootTest()
        {
            HashTree tree = new HashTree(new Tiger(TigerParameters.GetParameters(TigerStandard.Tiger192BitVersion1)), 1024);

            byte[] topHash = tree.ComputeHash(TestVectors.Battery.MillionAs);
            CustomAssert.AreEqual(TestVectors.h("511F341A7C14145FCBA4A55A9CCAF743DAC0EEF270010973"), tree.Root.Hash);
            Assert.AreEqual(0, tree.Root.RangeStart);
            Assert.AreEqual(999999, tree.Root.RangeEnd);
        }
        public void EnsureInputUnchangedTest(string name, Type expectedType)
        {
            System.Security.Cryptography.HashAlgorithm hasher = HashAlgorithm.Create(name);
            byte[] originalInput = (byte[])TestVectors.Battery.NumericRepeated.Clone();
            byte[] input         = (byte[])TestVectors.Battery.NumericRepeated.Clone();

            byte[] output = hasher.ComputeHash(input);
            CustomAssert.AreEqual(originalInput, input);
        }
        public void Constructor4Test()
        {
            HashChain chain = new HashChain(new Crc(CrcParameters.GetParameters(CrcStandard.Crc32Bit)), TestVectors.Battery.NumericRepeated, 0, 10, 5);

            for (int i = 0; i < NumericCrc32VectorChain.Length; i++)
            {
                CustomAssert.AreEqual(NumericCrc32VectorChain[i], chain[i]);
            }
        }
Beispiel #6
0
        public void TestVector(HashAlgorithm hasher, byte[] input, byte[] expectedOutput)
        {
            byte[] result = hasher.ComputeHash(input);

            CustomAssert.AreEqual(
                expectedOutput,
                result,
                string.Format("{0} on {1} should have produced {2} but instead got {3}", hasher, Conversions.ByteToHexadecimal(input), Conversions.ByteToHexadecimal(expectedOutput), Conversions.ByteToHexadecimal(result))
                );
        }
        public void ConstructorDoubleTest()
        {
            byte[] key  = TestVectors.s("1234567890");
            Hmac   hmac = new Hmac(new MD5(), key);
            MD5    md   = new MD5();

            Assert.AreEqual(md.GetType(), hmac.HashAlgorithm.GetType());
            Assert.AreEqual(md.HashSize, hmac.HashAlgorithm.HashSize);
            CustomAssert.AreEqual(key, hmac.Key);
        }
        public void ReusableTest(string name, Type expectedType)
        {
            System.Security.Cryptography.HashAlgorithm hashRepeater = HashAlgorithm.Create(name);
            System.Security.Cryptography.HashAlgorithm hashFresh    = null;

            for (int i = 0; i < TestVectors.Battery.All.Length - 1; i++)
            {
                hashFresh = HashAlgorithm.Create(name);
                CustomAssert.AreEqual(hashFresh.ComputeHash(TestVectors.Battery.All[i]), hashRepeater.ComputeHash(TestVectors.Battery.All[i]));
            }
        }
        public void Constructor5Test()
        {
            HashTreeNode node = new HashTreeNode(TestVectors.h("ABCDEF"), 1, 2);

            CustomAssert.AreEqual(TestVectors.h("ABCDEF"), node.Hash);
            Assert.IsNull(node.Parent);
            Assert.IsNull(node.Left);
            Assert.IsNull(node.Right);
            Assert.AreEqual(1, node.RangeStart);
            Assert.AreEqual(2, node.RangeEnd);
        }
        public void ReusableInputArrayTest(string name, Type expectedType)
        {
            System.Security.Cryptography.HashAlgorithm hashRepeater = HashAlgorithm.Create(name);
            System.Security.Cryptography.HashAlgorithm hashFresh    = null;
            byte[] input = (byte[])TestVectors.Battery.NumericRepeated.Clone();

            for (int i = 0; i < input.Length; i += 10)
            {
                hashFresh = HashAlgorithm.Create(name);
                CustomAssert.AreEqual(hashFresh.ComputeHash(TestVectors.Battery.Numeric), hashRepeater.ComputeHash(input, i, 10));
            }
        }
        public void Enumerator1Test()
        {
            HashChain chain = new HashChain(new Crc(CrcParameters.GetParameters(CrcStandard.Crc32Bit)), TestVectors.Battery.Numeric);

            int i = 0;

            foreach (byte[] hash in chain)
            {
                CustomAssert.AreEqual(NumericCrc32VectorChain[i], hash);
                i++;
            }
        }
        public void TestVector(BlockHashAlgorithm hasher, byte[] key, byte[] input, byte[] expectedOutput)
        {
            Hmac hmac = new Hmac(hasher, key);

            byte[] result = hmac.ComputeHash(input);

            CustomAssert.AreEqual(
                expectedOutput,
                result,
                string.Format("{0}({1}) on {2} should have produced {3} but instead got {4}", hmac, Conversions.ByteToHexadecimal(key), Conversions.ByteToHexadecimal(input), Conversions.ByteToHexadecimal(expectedOutput), Conversions.ByteToHexadecimal(result))
                );
        }
Beispiel #13
0
        public void UnevenInputTest(byte[] expectedHash, byte[][] inputChunks)
        {
            MD5 hasher = new MD5();

            for (int i = 0; i < inputChunks.Length - 1; i++)
            {
                hasher.TransformBlock(inputChunks[i], 0, inputChunks[i].Length, null, 0);
            }
            hasher.TransformFinalBlock(inputChunks[inputChunks.Length - 1], 0, inputChunks[inputChunks.Length - 1].Length);

            CustomAssert.AreEqual(expectedHash, hasher.Hash);
        }
        public void Constructor2BTest()
        {
            HashList list = new HashList(new MD5(), 10);

            CustomAssert.AreEqual(AlphanumericMD5TopHash, list.ComputeHash(TestVectors.Battery.Alphanumeric));

            for (int i = 0; i < AlphanumericMD5VectorList.Length; i++)
            {
                CustomAssert.AreEqual(AlphanumericMD5VectorList[i], list[i].Hash);
            }

            Assert.AreEqual(10, list.BlockSize);
        }
        public void Constructor2Test()
        {
            HashList list = new HashList(new Crc(CrcParameters.GetParameters(CrcStandard.Crc32Bit)), 10);

            CustomAssert.AreEqual(AlphanumericCrc32TopHash, list.ComputeHash(TestVectors.Battery.Alphanumeric));

            for (int i = 0; i < AlphanumericCrc32VectorList.Length; i++)
            {
                CustomAssert.AreEqual(AlphanumericCrc32VectorList[i], list[i].Hash);
            }

            Assert.AreEqual(10, list.BlockSize);
        }
        public void Enumerator3Test()
        {
            HashChain chain = new HashChain(new Crc(CrcParameters.GetParameters(CrcStandard.Crc32Bit)), TestVectors.Battery.Numeric);

            IEnumerator e = ((IEnumerable)chain).GetEnumerator();
            int         i = 0;

            while (e.MoveNext())
            {
                CustomAssert.AreEqual(NumericCrc32VectorChain[i], (byte[])e.Current);
                i++;
            }
        }
        public void Enumerator1Test()
        {
            HashList list = new HashList(new Crc(CrcParameters.GetParameters(CrcStandard.Crc32Bit)), 10);

            list.ComputeHash(TestVectors.Battery.Alphanumeric);

            int i = 0;

            foreach (HashNode node in list)
            {
                CustomAssert.AreEqual(AlphanumericCrc32VectorList[i], node.Hash);
                i++;
            }
        }
        public void Enumerator3Test()
        {
            HashList list = new HashList(new Crc(CrcParameters.GetParameters(CrcStandard.Crc32Bit)), 10);

            list.ComputeHash(TestVectors.Battery.Alphanumeric);

            IEnumerator e = ((IEnumerable)list).GetEnumerator();
            int         i = 0;

            while (e.MoveNext())
            {
                CustomAssert.AreEqual(AlphanumericCrc32VectorList[i], ((HashNode)e.Current).Hash);
                i++;
            }
        }
        public void DefaultConstructorTest()
        {
            MultiHash hasher = new MultiHash();

            CustomAssert.AreEqual(new byte[0], hasher.ComputeHash(new byte[0]));
        }
Beispiel #20
0
        public void TigerTreeVectorTest(byte[] input, byte[] expectedOutput)
        {
            HashTree tree = new HashTree(new Tiger(TigerParameters.GetParameters(TigerStandard.Tiger192BitVersion1)), 1024);

            CustomAssert.AreEqual(expectedOutput, tree.ComputeHash(input));
        }