Example #1
0
        public void Advance(int count)
        {
            _currentByteIndex += count;

            while (_currentByteIndex >= _byteIndexProcessedUpTo + _blockSizeBytes)
            {
                var block = _buffer.AsSpan(_byteIndexProcessedUpTo, _blockSizeBytes);

                _hashFunction.AddCompleteBlock(block);

                _byteIndexProcessedUpTo += _blockSizeBytes;
            }
        }
Example #2
0
        private static byte[] GenerateHashImpl(
            ReadOnlySpan <byte> bytes,
            IHashFunction hashFunction)
        {
            var blockSizeBytes = hashFunction.BlockSizeBytes;
            var blockCount     = bytes.Length / blockSizeBytes;
            var remainder      = bytes.Length % blockSizeBytes;

            for (var blockIndex = 0; blockIndex < blockCount; blockIndex++)
            {
                var start = blockIndex * blockSizeBytes;
                var block = bytes.Slice(start, blockSizeBytes);
                hashFunction.AddCompleteBlock(block);
            }

            if (remainder > 0)
            {
                hashFunction.AddRemainder(bytes.Slice(bytes.Length - remainder));
            }

            return(hashFunction.GetFinalHashValue());
        }