CRC-32C (Castagnoli) for C++ and .NET

.NET tutorial

After downloading the library, your can use the CRC-32C namespace:

using Crc32C;

You will get access to class Crc32CAlgorithm that implements HashAlgorithm 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!

Project CRC-32C for C++ and .NET
Version 1.0.5
CRC type CRC-32C (Castagnoli)
Polynomial 0x1EDC6F41 / 0x82F63B78
CRC features configurable initial value, chainable, no pre/post-processing, continuous bit order
Optimizations Intel CRC32 instruction (x3) in hardware
Sliced table-driven software fallback
Performance 20 GB/s in hardware
2 GB/s in software
NuGet Crc32C (C++), Crc32C.NET (.NET)
Download crc32c-hw- (C++ and .NET)
Source code crc32c-hw and Crc32C.NET on Bitbucket
License BSD license, zlib license
Credits Robert Važan, Mark Adler