예제 #1
0
        public void Hash64_InvalidKeyLength_Throws(int keyLength)
        {
            var invalidKey = new byte[keyLength];
            var buffer     = new byte[0];

            Assert.Throws <ArgumentException>(() => SipHash24.Hash64(buffer, invalidKey));
        }
예제 #2
0
 public void Hash64Async_BigEndian_Throws()
 {
     Bits.IsBigEndian = true;
     Assert.ThrowsAsync <NotSupportedException>(async() =>
                                                await SipHash24.Hash64Async(new MemoryStream(new byte[0]), new byte[16]));
     Bits.IsBigEndian = false;
 }
예제 #3
0
 public void Hash64_Stream_InvalidKeyLength_Throws()
 {
     using (var stream = new MemoryStream(new byte[0]))
     {
         Assert.Throws <ArgumentException>(() => SipHash24.Hash64(stream, new byte[15]));
     }
 }
예제 #4
0
 public void Hash64Async_InvalidKeyLength_Throws()
 {
     using (var stream = new MemoryStream(new byte[0]))
     {
         Assert.ThrowsAsync <ArgumentException>(async() =>
                                                await SipHash24.Hash64Async(stream, new byte[15]));
     }
 }
예제 #5
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]));
        }
예제 #6
0
 public void Hash64_Binary_TestVectors()
 {
     for (int i = 0; i < vectors.Length; ++i)
     {
         var buffer         = getBuffer(i);
         var result         = SipHash24.Hash64(buffer, key);
         var expectedResult = vectors[i];
         Debug.WriteLine("testing iteration #" + i);
         Assert.AreEqual(expectedResult, result);
     }
 }
예제 #7
0
 public void Hash64_Stream_TestVectors()
 {
     for (int i = 0; i < vectors.Length; ++i)
     {
         var buffer = getBuffer(i);
         using var stream = new MemoryStream(buffer);
         var result         = SipHash24.Hash64(stream, key);
         var expectedResult = vectors[i];
         Debug.WriteLine("testing iteration #" + i);
         Assert.AreEqual(expectedResult, result);
     }
 }
예제 #8
0
        public async Task Hash64Async_TestVectors()
        {
            for (int i = 0; i < vectors.Length; ++i)
            {
                var buffer = getBuffer(i);
                using var stream = new MemoryStream(buffer);
                ulong result = await SipHash24.Hash64Async(stream, key);

                ulong expectedResult = vectors[i];
                Assert.AreEqual(expectedResult, result);
            }
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #11
0
 public void Hash64Async_BigEndian_Throws()
 {
     Assert.ThrowsAsync <NotSupportedException>(() =>
                                                SipHash24.Hash64Async(new MemoryStream(new byte[0]), new byte[16]));
 }
예제 #12
0
 public void Hash64_BinaryBigEndian_Throws()
 {
     Assert.Throws <NotSupportedException>(() => SipHash24.Hash64(new byte[0], new byte[16]));
 }
예제 #13
0
 public void Hash64_StreamBigEndian_Throws()
 {
     Bits.IsBigEndian = true;
     Assert.Throws <NotSupportedException>(() => SipHash24.Hash64(new MemoryStream(new byte[0]), new byte[16]));
     Bits.IsBigEndian = false;
 }
예제 #14
0
 public void Hash64_BinaryBigEndian_Throws()
 {
     Bits.IsBigEndian = true;
     Assert.Throws <NotSupportedException>(() => SipHash24.Hash64(new byte[0], new byte[16]));
     Bits.IsBigEndian = false;
 }