public static void HashWithWrongKey() { var a = new Blake2b(); using (var k = new Key(new Ed25519())) { Assert.Throws <ArgumentException>("key", () => a.Hash(k, ReadOnlySpan <byte> .Empty)); } }
public static void HashWithMaxSpanSuccess() { var a = new Blake2b(); using (var k = new Key(a)) { a.Hash(k, ReadOnlySpan <byte> .Empty, new byte[a.MaxHashSize]); } }
public static void HashWithSpanTooLarge() { var a = new Blake2b(); using (var k = new Key(a)) { Assert.Throws <ArgumentException>("hash", () => a.Hash(k, ReadOnlySpan <byte> .Empty, new byte[a.MaxHashSize + 1])); } }
public static void HashWithSizeTooSmall() { var a = new Blake2b(); using (var k = new Key(a)) { Assert.Throws <ArgumentOutOfRangeException>("hashSize", () => a.Hash(k, ReadOnlySpan <byte> .Empty, a.MinHashSize - 1)); } }
public static void Test(string msg, string hash) { var a = new Blake2b(); var expected = hash.DecodeHex(); var actual = a.Hash(msg.DecodeHex(), expected.Length); Assert.Equal(expected, actual); }
/// <summary> /// Helper to validate a BLAKE2 hash. /// </summary> /// <param name="data">Data to hash.</param> /// <param name="key">Key to hash.</param> /// <param name="expectedHash">Expected value.</param> private void CheckHash(byte[] data, byte[] key, byte[] expectedHash) { ulong[][] blocks = Blake2b.GetDataBlocks(data, key); byte[] hash = Blake2b.Hash(blocks, data.Length, (byte)key.Length, 64); for (int i = 0; i < 64; i++) { Assert.AreEqual(expectedHash[i], hash[i], $"hash byte #{i}"); } }
public static void HashWithMaxSizeSuccess() { var a = new Blake2b(); using (var k = new Key(a)) { var b = a.Hash(k, ReadOnlySpan <byte> .Empty, a.MaxHashSize); Assert.NotNull(b); Assert.Equal(a.MaxHashSize, b.Length); } }
public static void HashWithNullKey() { var a = new Blake2b(); Assert.Throws <ArgumentNullException>("key", () => a.Hash(null, ReadOnlySpan <byte> .Empty)); }