Esempio n. 1
0
        private void ResetTest()
        {
            // Generate a non-zero key
            byte[] key = new byte[32];
            for (byte i = 0; i < key.Length; i++)
            {
                key[i] = i;
            }
            // Generate some non-zero input longer than the key
            byte[] input = new byte[key.Length + 1];
            for (byte i = 0; i < input.Length; i++)
            {
                input[i] = i;
            }
            // Hash the input
            Blake2bDigest digest = new Blake2bDigest(key);

            digest.BlockUpdate(input, 0, input.Length);
            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);
            // Using a second instance, hash the input without calling doFinal()
            Blake2bDigest digest1 = new Blake2bDigest(key);

            digest1.BlockUpdate(input, 0, input.Length);
            // Reset the second instance and hash the input again
            digest1.Reset();
            digest1.BlockUpdate(input, 0, input.Length);
            byte[] hash1 = new byte[digest.GetDigestSize()];
            digest1.DoFinal(hash1, 0);
            // The hashes should be identical
            if (!Arrays.AreEqual(hash, hash1))
            {
                Fail("state was not reset");
            }
        }
Esempio n. 2
0
        public static byte[] Hash(byte[] input)
        {
            Blake2bDigest digest = new Blake2bDigest(256);

            digest.BlockUpdate(input, 0, input.Length);
            byte[] hash = new byte[digest.GetDigestSize()];
            digest.DoFinal(hash, 0);
            return(hash);
        }
Esempio n. 3
0
        public static byte[] Hash(byte[] bytes, int bitLength)
        {
            var digest = new Blake2bDigest(bitLength);
            var output = new byte[digest.GetDigestSize()];

            digest.BlockUpdate(bytes, 0, bytes.Length);
            digest.DoFinal(output, 0);

            return(output);
        }
Esempio n. 4
0
        public static byte[] Blake2b(byte[] data)
        {
            Blake2bDigest black2b = new Blake2bDigest(32 * 8);

            black2b.BlockUpdate(data, 0, data.Length);
            var hashed = new byte[black2b.GetDigestSize()];

            black2b.DoFinal(hashed, 0);
            return(hashed);
        }
Esempio n. 5
0
        public uint256 GetHash()
        {
            var blake2b = new Blake2bDigest(null, 32, null, _personalization);
            var hash    = new byte[blake2b.GetDigestSize()];

            blake2b.BlockUpdate(((MemoryStream)Inner).ToArrayEfficient(), 0, (int)Inner.Length);
            blake2b.DoFinal(hash, 0);

            return(new uint256(hash));
        }
Esempio n. 6
0
        public override byte[] ComputeHash(byte[] input, int offset, int count)
        {
            var blake2b = new Blake2bDigest(DigestSize);
            var result  = new byte[blake2b.GetDigestSize()];

            blake2b.BlockUpdate(input, offset, count);
            blake2b.DoFinal(result, 0);

            return(result);
        }
Esempio n. 7
0
        protected static byte[] ComputeHash(byte[] message, int bits)
        {
            var digest = new Blake2bDigest(bits);
            var output = new byte[digest.GetDigestSize()];

            byte[] msg = message ?? new byte[0];
            digest.BlockUpdate(msg, 0, msg.Length);
            digest.DoFinal(output, 0);

            return(output);
        }
Esempio n. 8
0
        public static byte[] Compute(byte[] input, int offset, int count, int digestSize)
        {
            var blake2b = new Blake2bDigest(digestSize);

            var result = new byte[blake2b.GetDigestSize()];

            blake2b.BlockUpdate(input, offset, count);
            blake2b.DoFinal(result, 0);

            return(result);
        }
Esempio n. 9
0
        private void CheckClone(Blake2bDigest blake2bCloneSource, byte[] expected)
        {
            byte[] message = Hex.Decode(keyedTestVectors[3, 0]);

            blake2bCloneSource.BlockUpdate(message, 0, message.Length);

            byte[] hash = new byte[blake2bCloneSource.GetDigestSize()];

            Blake2bDigest digClone = new Blake2bDigest(blake2bCloneSource);

            blake2bCloneSource.DoFinal(hash, 0);
            if (!AreEqual(expected, hash))
            {
                Fail("clone source not correct");
            }

            digClone.DoFinal(hash, 0);
            if (!AreEqual(expected, hash))
            {
                Fail("clone not correct");
            }
        }