예제 #1
0
        public static void TestOneMillionBytes()
        {
            var message = Enumerable.Repeat((byte)0, 1000000).ToArray();

            using (var hash = new SipHash(SpecificationKey))
                AssertEqual(hash.ComputeHash(message), 0x28205108397aa742UL);
        }
예제 #2
0
        public static void TestSevenBytes()
        {
            var message = Encoding.UTF8.GetBytes("SipHash");

            using (var hash = new SipHash(SpecificationKey))
                AssertEqual(hash.ComputeHash(message), 0x8325093242a96f60UL);
        }
예제 #3
0
        public static void TestEightBytes()
        {
            var message = Encoding.UTF8.GetBytes("12345678");

            using (var hash = new SipHash(SpecificationKey))
                AssertEqual(hash.ComputeHash(message), 0x2130609caea37ebUL);
        }
예제 #4
0
        public static void TestSixBytes()
        {
            var message = Encoding.UTF8.GetBytes("abcdef");

            using (var hash = new SipHash(SpecificationKey))
                AssertEqual(hash.ComputeHash(message), 0x2a6e77e733c7c05dUL);
        }
예제 #5
0
        public static void TestSingleByte()
        {
            var message = new byte[] { 0x61 };

            using (var hash = new SipHash(SpecificationKey))
                AssertEqual(hash.ComputeHash(message), 0x2ba3e8e9a71148caUL);
        }
예제 #6
0
        public static void TestEmptyMessage()
        {
            var message = new byte[0];

            using (var hash = new SipHash(SpecificationKey))
                AssertEqual(hash.ComputeHash(message), 0x726fdb47dd0e0e31UL);
        }
예제 #7
0
 public string CalculateHash(string message, string littleEndianKey)
 {
     var messageBytes = Encoding.ASCII.GetBytes(message);
     var byteKey = BigInteger.Parse(littleEndianKey, NumberStyles.HexNumber).ToByteArray();
     var hasher = new SipHash(byteKey);
     var hash = hasher.ComputeHash(messageBytes);
     var stringHash = BitConverter.ToUInt64(hash, 0).ToString("X");
     return PadHash(stringHash);
 }
예제 #8
0
        internal SipState(byte[] key, int compressionRounds, int finalizationRounds)
        {
            SipHash.ValidateArguments(key, compressionRounds, finalizationRounds);

            var k0 = BitConverter.ToUInt64(key, 0);
            var k1 = BitConverter.ToUInt64(key, 8);

            // "somepseudorandomlychosenbytes".  See §4
            _v[0] = 0x736f6d6570736575UL ^ k0;
            _v[1] = 0x646f72616e646f6dUL ^ k1;
            _v[2] = 0x6c7967656e657261UL ^ k0;
            _v[3] = 0x7465646279746573UL ^ k1;

            CompressionRounds  = compressionRounds;
            FinalizationRounds = finalizationRounds;
        }
예제 #9
0
 public static void TestBlockHash(int blockSize)
 {
     using (var hash = new SipHash(SpecificationKey))
         AssertEqual(BlockHash(hash, SpecificationMessage, 0, blockSize), 0xa129ca6149be45e5UL);
 }
예제 #10
0
        /***
         * Tests adapted from https://github.com/emboss/siphash-java/blob/master/test/com/github/emboss/siphash/SipHashTest.java
         * Thanks to Martin Boßlet for these, which allowed me to quickly verify (presumable) correct functionality.
         ***/

        public static void TestSpecification()
        {
            using (var hash = new SipHash(SpecificationKey))
                AssertEqual(hash.ComputeHash(SpecificationMessage), 0xa129ca6149be45e5UL);
        }