コード例 #1
0
        public void ComputeHash_ExceptionTest()
        {
            SipHash24 hash = new SipHash24();

            Assert.Throws <ArgumentNullException>(() => hash.ComputeHash(null, new byte[0]));
            Assert.Throws <ArgumentNullException>(() => hash.ComputeHash(new byte[0], null));
            Assert.Throws <ArgumentOutOfRangeException>(() => hash.ComputeHash(new byte[0], new byte[0]));
        }
コード例 #2
0
        public void ComputeHashTest()
        {
            // From last page of https://131002.net/siphash/siphash.pdf
            SipHash24 hash = new SipHash24();

            byte[] key  = Enumerable.Range(0, 16).Select(x => (byte)x).ToArray();
            byte[] data = Enumerable.Range(0, 15).Select(x => (byte)x).ToArray();

            ulong actual   = hash.ComputeHash(key, data);
            ulong expected = 0xa129ca6149be45e5UL;

            Assert.Equal(expected, actual);
        }
コード例 #3
0
        public void ComputeHash_AllCasesTest(byte[] hashBa, int len)
        {
            // Tests from: https://github.com/veorq/SipHash/blob/bab35c64d10f63587a3693a71200620f0ee03cc4/vectors.h#L3-L196
            // How its used: https://github.com/veorq/SipHash/blob/bab35c64d10f63587a3693a71200620f0ee03cc4/test.c#L69
            SipHash24 hash = new SipHash24();

            byte[] key  = Enumerable.Range(0, 16).Select(x => (byte)x).ToArray();
            byte[] data = Enumerable.Range(0, len).Select(x => (byte)x).ToArray();

            ulong actual   = hash.ComputeHash(key, data);
            ulong expected = (ulong)hashBa[0] |
                             (ulong)hashBa[1] << 8 |
                             (ulong)hashBa[2] << 16 |
                             (ulong)hashBa[3] << 24 |
                             (ulong)hashBa[4] << 32 |
                             (ulong)hashBa[5] << 40 |
                             (ulong)hashBa[6] << 48 |
                             (ulong)hashBa[7] << 56;

            Assert.Equal(expected, actual);
        }