Пример #1
0
        public override void PerformTest()
        {
            // test keyed test vectors:

            Blake2bDigest blake2bkeyed = new Blake2bDigest(Hex.Decode(keyedTestVectors[0][1]));

            for (int tv = 0; tv < keyedTestVectors.Length; tv++)
            {
                byte[] input = Hex.Decode(keyedTestVectors[tv][0]);
                blake2bkeyed.Reset();

                blake2bkeyed.BlockUpdate(input, 0, input.Length);
                byte[] keyedHash = new byte[64];
                blake2bkeyed.DoFinal(keyedHash, 0);

                if (!Arrays.AreEqual(Hex.Decode(keyedTestVectors[tv][2]), keyedHash))
                {
                    Fail("BLAKE2b mismatch on test vector ",
                         keyedTestVectors[tv][2],
                         Hex.ToHexString(keyedHash));
                }

                offsetTest(blake2bkeyed, input, keyedHash);
            }

            Blake2bDigest blake2bunkeyed = new Blake2bDigest();

            // test unkeyed test vectors:
            for (int i = 0; i < unkeyedTestVectors.Length; i++)
            {
                // blake2bunkeyed.update(
                // unkeyedTestVectors[i][1].getBytes("UTF-8"));
                // test update(byte b)
                byte[] unkeyedInput = Encoding.UTF8.GetBytes(unkeyedTestVectors[i][1]);
                for (int j = 0; j < unkeyedInput.Length; j++)
                {
                    blake2bunkeyed.Update(unkeyedInput[j]);
                }

                byte[] unkeyedHash = new byte[64];
                blake2bunkeyed.DoFinal(unkeyedHash, 0);
                blake2bunkeyed.Reset();

                if (!Arrays.AreEqual(Hex.Decode(unkeyedTestVectors[i][0]),
                                     unkeyedHash))
                {
                    Fail("BLAKE2b mismatch on test vector ",
                         unkeyedTestVectors[i][0],
                         Hex.ToHexString(unkeyedHash));
                }
            }

            cloneTest();
            resetTest();
        }
Пример #2
0
        public override void PerformTest()
        {
            // test keyed test vectors:

            Blake2bDigest blake2bkeyed = new Blake2bDigest(Hex.Decode(keyedTestVectors[0, 1]));

            for (int tv = 0; tv < keyedTestVectors.GetLength(0); tv++)
            {
                byte[] input = Hex.Decode(keyedTestVectors[tv, 0]);
                blake2bkeyed.Reset();

                blake2bkeyed.BlockUpdate(input, 0, input.Length);
                byte[] keyedHash = new byte[64];
                blake2bkeyed.DoFinal(keyedHash, 0);

                if (!Arrays.AreEqual(Hex.Decode(keyedTestVectors[tv, 2]), keyedHash))
                {
                    Fail("BLAKE2b mismatch on test vector ", keyedTestVectors[tv, 2], Hex.ToHexString(keyedHash));
                }

                offsetTest(blake2bkeyed, input, keyedHash);
            }

            Blake2bDigest blake2bunkeyed = new Blake2bDigest();

            // test unkeyed test vectors:
            for (int i = 0; i < unkeyedTestVectors.GetLength(0); i++)
            {
                // test update(byte b)
                byte[] unkeyedInput = Encoding.UTF8.GetBytes(unkeyedTestVectors[i, 1]);
                for (int j = 0; j < unkeyedInput.Length; j++)
                {
                    blake2bunkeyed.Update(unkeyedInput[j]);
                }

                byte[] unkeyedHash = new byte[64];
                blake2bunkeyed.DoFinal(unkeyedHash, 0);
                blake2bunkeyed.Reset();

                if (!Arrays.AreEqual(Hex.Decode(unkeyedTestVectors[i, 0]), unkeyedHash))
                {
                    Fail("BLAKE2b mismatch on test vector ", unkeyedTestVectors[i, 0], Hex.ToHexString(unkeyedHash));
                }
            }

            CloneTest();
            ResetTest();
            DoTestNullKeyVsUnkeyed();
            DoTestLengthConstruction();
        }