/// <summary> /// When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash. /// </summary> /// <param name="array">The input to compute the hash code for.</param> /// <param name="offset">The offset into the byte array from which to begin using data.</param> /// <param name="length">The number of bytes in the byte array to use as data.</param> internal override void HashCoreImplement(byte[] array, int offset, int length) { uint crc = Paramter.RefOutput ? CrcHashAlgorithmHelper.ReverseBits(Paramter.RemainderInitialValue, Paramter.Width) : Paramter.RemainderInitialValue; if (Paramter.RefOutput) { for (int i = offset; i < offset + length; i++) { crc = (Table[(crc ^ array[i]) & 0xFF] ^ (crc >> 8)); crc &= Mask; } } else { int toRight = (HashSize - 8); toRight = toRight < 0 ? 0 : toRight; for (int i = offset; i < offset + length; i++) { crc = (Table[((crc >> toRight) ^ array[i]) & 0xFF] ^ (crc << 8)); crc &= Mask; } } FinalValue = crc; }
/// <summary> /// Generates the specified paramter. /// </summary> /// <param name="paramter">The paramter.</param> /// <returns></returns> internal override uint[] Generate(CrcParamter <uint> paramter) => CrcHashAlgorithmHelper.GenerateTable(paramter.Polynomial, paramter.Width, paramter.RefInput, Mask);
/// <summary> /// When overridden in a derived class, finalizes the hash computation after the last data is processed by the cryptographic stream object. /// </summary> /// <returns> /// The computed hash code. /// </returns> protected override byte[] HashFinal() => CrcHashAlgorithmHelper.ToBigEndianBytes(FinalValue ^ Paramter.XorResultValue);