Exemple #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);
        }
Exemple #2
0
        public static void TestSevenBytes()
        {
            var message = Encoding.UTF8.GetBytes("SipHash");

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

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

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

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

            using (var hash = new SipHash(SpecificationKey))
                AssertEqual(hash.ComputeHash(message), 0x726fdb47dd0e0e31UL);
        }
 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);
 }
Exemple #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;
        }
Exemple #9
0
 public static void TestBlockHash(int blockSize)
 {
     using (var hash = new SipHash(SpecificationKey))
         AssertEqual(BlockHash(hash, SpecificationMessage, 0, blockSize), 0xa129ca6149be45e5UL);
 }
Exemple #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);
        }