private static ulong SipHash(ulong k0, ulong k1, byte[] data) { var hasher = new Hashes.SipHasher(k0, k1); hasher.Write(data); return(hasher.Finalize()); }
private static ulong SipHash(byte[] key, byte[] data) { var k0 = BitConverter.ToUInt64(key, 0); var k1 = BitConverter.ToUInt64(key, 8); var hasher = new Hashes.SipHasher(k0, k1); hasher.Write(data); return(hasher.Finalize()); }
public void siphash() { var hasher = new Hashes.SipHasher(0x0706050403020100UL, 0x0F0E0D0C0B0A0908UL); Assert.Equal(0x726fdb47dd0e0e31UL, hasher.Finalize()); var t0 = new byte[] { 0 }; hasher.Write(t0); Assert.Equal(0x74f839c593dc67fdUL, hasher.Finalize()); var t1 = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; hasher.Write(t1); Assert.Equal(0x93f5f5799a932462UL, hasher.Finalize()); hasher.Write(0x0F0E0D0C0B0A0908UL); Assert.Equal(0x3f2acc7f57c29bdbUL, hasher.Finalize()); var t2 = new byte[] { 16, 17 }; hasher.Write(t2); Assert.Equal(0x4bc1b3f0968dd39cUL, hasher.Finalize()); var t3 = new byte[] { 18, 19, 20, 21, 22, 23, 24, 25, 26 }; hasher.Write(t3); Assert.Equal(0x2f2e6163076bcfadUL, hasher.Finalize()); var t4 = new byte[] { 27, 28, 29, 30, 31 }; hasher.Write(t4); Assert.Equal(0x7127512f72f27cceUL, hasher.Finalize()); hasher.Write(0x2726252423222120UL); Assert.Equal(0x0e3ea96b5304a7d0UL, hasher.Finalize()); hasher.Write(0x2F2E2D2C2B2A2928UL); Assert.Equal(0xe612a3cb9ecba951UL, hasher.Finalize()); Assert.Equal(0x7127512f72f27cceUL, Hashes.SipHash(0x0706050403020100UL, 0x0F0E0D0C0B0A0908UL, new uint256("1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100"))); // Check test vectors from spec, one byte at a time var hasher2 = new Hashes.SipHasher(0x0706050403020100UL, 0x0F0E0D0C0B0A0908UL); for (byte x = 0; x < siphash_4_2_testvec.Length; ++x) { Assert.Equal(hasher2.Finalize(), siphash_4_2_testvec[x]); hasher2.Write(new byte[] { x }); } // Check test vectors from spec, eight bytes at a time var hasher3 = new Hashes.SipHasher(0x0706050403020100UL, 0x0F0E0D0C0B0A0908UL); for (int x = 0; x < siphash_4_2_testvec.Length; x += 8) { Assert.Equal(hasher3.Finalize(), siphash_4_2_testvec[x]); hasher3.Write(uint64_t(x) | (uint64_t(x + 1) << 8) | (uint64_t(x + 2) << 16) | (uint64_t(x + 3) << 24) | (uint64_t(x + 4) << 32) | (uint64_t(x + 5) << 40) | (uint64_t(x + 6) << 48) | (uint64_t(x + 7) << 56)); } }