protected override byte[] HashFinal()
        {
            uint len = (uint)Length;

            // pipelining friendly algorithm
            H1 ^= len; H2 ^= len; H3 ^= len; H4 ^= len;

            H1 += (H2 + H3 + H4);
            H2 += H1; H3 += H1; H4 += H1;

            H1 = H1.FMix();
            H2 = H2.FMix();
            H3 = H3.FMix();
            H4 = H4.FMix();

            H1 += (H2 + H3 + H4);
            H2 += H1; H3 += H1; H4 += H1;

            var result = new byte[16];

            unsafe
            {
                fixed(byte *h = result)
                {
                    var r = (uint *)h;

                    r[0] = H1;
                    r[1] = H2;
                    r[2] = H3;
                    r[3] = H4;
                }
            }

            return(result);
        }
Пример #2
0
        protected override byte[] HashFinal()
        {
            uint len = (uint)Length;

            H1 ^= len; H2 ^= len; H3 ^= len; H4 ^= len;

            H1 += (H2 + H3 + H4);
            H2 += H1; H3 += H1; H4 += H1;

            H1 = H1.FMix();
            H2 = H2.FMix();
            H3 = H3.FMix();
            H4 = H4.FMix();

            H1 += (H2 + H3 + H4);
            H2 += H1; H3 += H1; H4 += H1;

            var result = new byte[16];

            Array.Copy(BitConverter.GetBytes(H1), 0, result, 0, 4);
            Array.Copy(BitConverter.GetBytes(H2), 0, result, 4, 4);
            Array.Copy(BitConverter.GetBytes(H3), 0, result, 8, 4);
            Array.Copy(BitConverter.GetBytes(H4), 0, result, 12, 4);

            return(result);
        }
Пример #3
0
        protected override bool TryHashFinal(Span <byte> destination, out int bytesWritten)
        {
            if (destination.Length < 16)
            {
                bytesWritten = 0;
                return(false);
            }

            var len = (uint)Length;

            // pipelining friendly algorithm
            H1 ^= len; H2 ^= len; H3 ^= len; H4 ^= len;

            H1 += (H2 + H3 + H4);
            H2 += H1; H3 += H1; H4 += H1;

            H1 = H1.FMix();
            H2 = H2.FMix();
            H3 = H3.FMix();
            H4 = H4.FMix();

            H1 += (H2 + H3 + H4);
            H2 += H1; H3 += H1; H4 += H1;

            var uintDestination = MemoryMarshal.Cast <byte, uint>(destination);

            uintDestination[0] = H1;
            uintDestination[1] = H2;
            uintDestination[2] = H3;
            uintDestination[3] = H4;
            bytesWritten       = 16;
            return(true);
        }
Пример #4
0
        public override unsafe Memory <byte> FinalizeHash()
        {
            uint len = (uint)Length;

            // pipelining friendly algorithm
            H1 ^= len;
            H2 ^= len;
            H3 ^= len;
            H4 ^= len;

            H1 += (H2 + H3 + H4);
            H2 += H1;
            H3 += H1;
            H4 += H1;

            H1 = H1.FMix();
            H2 = H2.FMix();
            H3 = H3.FMix();
            H4 = H4.FMix();

            H1 += (H2 + H3 + H4);
            H2 += H1;
            H3 += H1;
            H4 += H1;

            var result = new Memory <byte>(new byte[16]);

            using var hMemory = result.Pin();
            var r = (uint *)hMemory.Pointer;

            r[0] = H1;
            r[1] = H2;
            r[2] = H3;
            r[3] = H4;

            return(result);
        }