/// <exception cref="System.InvalidOperationException">HashSize set to an invalid value.</exception>
        /// <inheritdoc />
        protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
        {
            UInt64[] h = new UInt64[12];
            
            h[0]=h[3]=h[6]=h[9]  = InitVal1;
            h[1]=h[4]=h[7]=h[10] = (HashSize == 128 ? InitVal2 : InitVal1);
            h[2]=h[5]=h[8]=h[11] = 0XDEADBEEFDEADBEEF;


            var remainderData = new byte[96];

            await data.ForEachGroupAsync(96, 
                (dataGroup, position, length) => {
                    Mix(h, dataGroup, position, length);
                },
                (remainder, position, length) => {
                    Array.Copy(remainder, position, remainderData, 0, length);
                    remainderData[95] = (byte) length;
                }).ConfigureAwait(false);

            Mix(h, remainderData, 0, remainderData.Length);
            End(h);


            byte[] hash = null;

            switch (HashSize)
            {
                case 32:
                    hash = BitConverter.GetBytes((UInt32) h[0]);
                    break;

                case 64:
                    hash = BitConverter.GetBytes(h[0]);
                    break;

                case 128:
                    hash = new byte[16];

                    BitConverter.GetBytes(h[0])
                        .CopyTo(hash, 0);

                    BitConverter.GetBytes(h[1])
                        .CopyTo(hash, 8);

                    break;
            }

            return hash;
        }
        /// <exception cref="System.InvalidOperationException">HashSize set to an invalid value.</exception>
        /// <inheritdoc />
        protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
        {
            byte[] hash = null;

            switch (HashSize)
            {
                case 32:
                {        
                    const UInt32 m = unchecked((UInt32) MixConstant);

                    UInt32 h = (UInt32) Seed ^ (UInt32) data.Length;

                    await data.ForEachGroupAsync(4, 
                        (dataGroup, position, length) => {
                            ProcessGroup(ref h, m, dataGroup, position, length);
                        }, 
                        (remainder, position, length) => {
                            ProcessRemainder(ref h, m, remainder, position, length);
                        }).ConfigureAwait(false);

                    // Do a few final mixes of the hash to ensure the last few
                    // bytes are well-incorporated.

                    h ^= h >> 13;
                    h *= m;
                    h ^= h >> 15;

                    hash = BitConverter.GetBytes(h);
                    break;
                }

                case 64:
                { 
                    const UInt64 m = MixConstant;

                    UInt64 h = Seed ^ ((UInt64) data.Length * m);
            
                    await data.ForEachGroupAsync(8, 
                        (dataGroup, position, length) => {
                            ProcessGroup(ref h, m, dataGroup, position, length);
                        },
                        (remainder, position, length) => {
                            ProcessRemainder(ref h, m, remainder, position, length);
                        }).ConfigureAwait(false);
 
                    h ^= h >> 47;
                    h *= m;
                    h ^= h >> 47;

                    hash = BitConverter.GetBytes(h);
                    break;
                }
            }

            return hash;
        }
        /// <inheritdoc />
        protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
        {
            UInt32 a = 0x9e3779b9;
            UInt32 b = 0x9e3779b9;
            UInt32 c = InitVal;

            int dataCount = 0;

            await data.ForEachGroupAsync(12, 
                (dataGroup, position, length) => {
                    ProcessGroup(ref a, ref b, ref c, dataGroup, position, length);

                    dataCount += length;
                }, 
                (remainder, position, length) => {
                    ProcessRemainder(ref a, ref b, ref c, remainder, position, length);

                    dataCount += length;
                }).ConfigureAwait(false);

            c += (UInt32) dataCount;

            Mix(ref a, ref b, ref c);


            return BitConverter.GetBytes(c);
        }
Example #4
0
        /// <exception cref="System.InvalidOperationException">HashSize set to an invalid value.</exception>
        /// <inheritdoc />
        protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
        {
            byte[] hash = null;
            
            switch (HashSize)
            {
                case 32:
                {
                    var h = ((UInt32) InitVal) + _primes32[4];

                    int dataCount = 0;
                    byte[] remainder = null;


                    var initValues = new[] {
                        ((UInt32) InitVal) + _primes32[0] + _primes32[1],
                        ((UInt32) InitVal) + _primes32[1],
                        ((UInt32) InitVal),
                        ((UInt32) InitVal) - _primes32[0]
                    };

                    await data.ForEachGroupAsync(16, 
                        (dataGroup, position, length) => {
                            for (var x = position; x < position + length; x += 16)
                            {
                                for (var y = 0; y < 4; ++y)
                                {
                                    initValues[y] += BitConverter.ToUInt32(dataGroup, x + (y * 4)) * _primes32[1];
                                    initValues[y] = initValues[y].RotateLeft(13);
                                    initValues[y] *= _primes32[0];
                                }
                            }

                            dataCount += length;
                        },
                        (remainderData, position, length) => {
                            remainder = new byte[length];
                            Array.Copy(remainderData, position, remainder, 0, length);

                            dataCount += length;
                        }).ConfigureAwait(false);

                    PostProcess(ref h, initValues, dataCount, remainder);

                    hash = BitConverter.GetBytes(h);
                    break;
                }

                case 64:
                {
                     var h = InitVal + _primes64[4];

                    int dataCount = 0;
                    byte[] remainder = null;

                    var initValues = new[] {
                        InitVal + _primes64[0] + _primes64[1],
                        InitVal + _primes64[1],
                        InitVal,
                        InitVal - _primes64[0]
                    };


                    await data.ForEachGroupAsync(32, 
                        (dataGroup, position, length) => {
                            for (var x = position; x < position + length; x += 32)
                            {
                                for (var y = 0; y < 4; ++y)
                                {
                                    initValues[y] += BitConverter.ToUInt64(dataGroup, x + (y * 8)) * _primes64[1];
                                    initValues[y] = initValues[y].RotateLeft(31);
                                    initValues[y] *= _primes64[0];
                                }
                            }

                            dataCount += length;
                        },
                        (remainderData, position, length) => {
                            remainder = new byte[length];
                            Array.Copy(remainderData, position, remainder, 0, length);

                            dataCount += remainder.Length;
                        }).ConfigureAwait(false);


                    PostProcess(ref h, initValues, dataCount, remainder);

                    hash = BitConverter.GetBytes(h);
                    break;
                }
            }

            return hash;
        }
        /// <exception cref="System.InvalidOperationException">HashSize set to an invalid value.</exception>
        /// <inheritdoc />
        protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
        {
            byte[] hash = null;

            switch (HashSize)
            {
                case 32:
                {
                    UInt32 h1 = Seed;
                    int dataCount = 0;


                    await data.ForEachGroupAsync(4, 
                        (dataGroup, position, length) => {
                            ProcessGroup(ref h1, dataGroup, position, length);

                            dataCount += length;
                        },
                        (remainder, position, length) => {
                            ProcessRemainder(ref h1, remainder, position, length);

                            dataCount += length;
                        }).ConfigureAwait(false);
            

                    h1 ^= (UInt32) dataCount;
                    Mix(ref h1);

                    hash = BitConverter.GetBytes(h1);
                    break;
                }

                case 128:
                {
                    UInt64 h1 = (UInt64) Seed;
                    UInt64 h2 = (UInt64) Seed;

                    int dataCount = 0;

            
                    await data.ForEachGroupAsync(16, 
                        (dataGroup, position, length) => {
                            ProcessGroup(ref h1, ref h2, dataGroup, position, length);

                            dataCount += length;
                        },
                        (remainder, position, length) => {
                            ProcessRemainder(ref h1, ref h2, remainder, position, length);

                            dataCount += length;
                        }).ConfigureAwait(false);


                    h1 ^= (UInt64) dataCount; 
                    h2 ^= (UInt64) dataCount;

                    h1 += h2;
                    h2 += h1;

                    Mix(ref h1);
                    Mix(ref h2);

                    h1 += h2;
                    h2 += h1;


                    hash = new byte[16];

                    BitConverter.GetBytes(h1)
                        .CopyTo(hash, 0);

                    BitConverter.GetBytes(h2)
                        .CopyTo(hash, 8);

                    break;
                }
            }

            return hash;
        }
Example #6
0
		/// <inheritdoc />
		protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
		{
            var internalState = new InternalState(HashSize, _originalKeyLength, _salt, _personalization);


            if (_originalKeyLength > 0)
                ProcessBytes(internalState, _key, 0, _key.Length);

			await data.ForEachGroupAsync(
                BlockSizeBytes,
                (array, start, count) => ProcessBytes(internalState, array, start, count),
                (array, start, count) => ProcessBytes(internalState, array, start, count));

			return Final(HashSize, internalState);
		}
        /// <inheritdoc />
        protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
        {
            UInt32 h = Seed ^ ((UInt32) data.Length * m);

            await data.ForEachGroupAsync(4,
                (dataGroup, position, length) => {
                    ProcessGroup(ref h, dataGroup, position, length);
                },
                (remainder, position, length) => {
                    ProcessRemainder(ref h, remainder, position, length);
                }).ConfigureAwait(false);

            h *= m;
            h ^= h >> 10;
            h *= m;
            h ^= h >> 17;

            return BitConverter.GetBytes(h);
        }
        /// <exception cref="System.InvalidOperationException">HashSize set to an invalid value.</exception>
        /// <inheritdoc />
        protected override async Task<byte[]> ComputeHashAsyncInternal(UnifiedData data)
        {
            UInt32 a = 0xdeadbeef + (UInt32) data.Length + InitVal1;
            UInt32 b = 0xdeadbeef + (UInt32) data.Length + InitVal1;
            UInt32 c = 0xdeadbeef + (UInt32) data.Length + InitVal1;

            if (HashSize == 64)
                c += InitVal2;


            int dataCount = 0;

            await data.ForEachGroupAsync(12, 
                (dataGroup, position, length) => {
                    ProcessGroup(ref a, ref b, ref c, ref dataCount, dataGroup, position, length);
                },
                (remainder, position, length) => {
                    ProcessRemainder(ref a, ref b, ref c, ref dataCount, remainder, position, length);
                }).ConfigureAwait(false);
    
            if (dataCount > 0)
                Final(ref a, ref b, ref c);


            byte[] hash = null;

            switch (HashSize)
            {
                case 32:
                    hash = BitConverter.GetBytes(c);
                    break;

                case 64:
                    hash = BitConverter.GetBytes((((UInt64) b) << 32) | c);
                    break;
            }

            return hash;
        }