After downloading the library, your can use the CRC-32C namespace:
You will get access to class
Crc32CAlgorithm that implements
with all its features:
/// <summary> /// Implementation of CRC-32C (Castagnoli) with polynomial 0x1EDC6F41. /// It can detect errors more reliably than the older CRC-32-IEEE. /// This class will use CRC32 instruction on recent Intel processors /// if it is available. Otherwise it will transparently fall back to /// a very fast software implementation. Besides standard /// HashAlgorithm methods, this class supports several convenient /// static methods returning the CRC as UInt32. /// </summary> public class Crc32CAlgorithm : HashAlgorithm
And here are the handy static methods mentioned in the class documentation. They map directly to the underlying native library.
public static uint Compute(byte input); public static uint Compute(byte input, int offset, int length); public static uint Append(uint initial, byte input); public static uint Append(uint initial, byte input, int offset, int length);
You can then compute CRC-32C of a buffer with the following C# code:
uint crc = Crc32CAlgorithm.Compute(array);
You can also submit smaller section of a buffer:
uint crc = Crc32CAlgorithm.Compute(array, 0, 10000);
If you would like to chain multiple buffers, you can do it like this:
uint intermediate = Crc32CAlgorithm.Compute(array, 0, 3000); uint crc = Crc32CAlgorithm.Append(intermediate, array, 3000, 7000);
You can of course call Append as many times as you wish.
You can add pre/post-processing of the CRC value depending on requirements of your application. Enjoy!