.N .NET Landscape

Crc32.NET

Utilities & Core Helpers
github.com/force-net/Crc32.NET

Fast version of Crc32 algorithm for .NET

GitHub stars
204
Forks
52
Open issues
8
NuGet downloads
39,403,240
latest 2.1.0
License
MIT
Language
C#
Last push
6 days ago
18 Oct 2026
Created
19 Jun 2016

Crc32.NET

Optimized and fast managed implementation of Crc32 & Crc32C (Castagnoly) algorithms for .NET and .NET Core.

At this time, Microsoft released https://www.nuget.org/packages/System.IO.Hashing/ package with support of CRC32, so this package is for compatibility purposes. But it still really fast.

Installation through Nuget:

> Install-Package Crc32.NET

Version 1.1.0 Remarks

Initially, this library only support Crc32 checksum, but I found, that there are lack of .NET Core libraries for Crc32 calculation. So, I've added Crc32C (Castagnoli) managed implementation in this library. Other Crc32 variants (like Crc32Q or Crc32K) seems to be unpopular to implement it here.

So, if you need to use Crc32C for .NET Core, you can use this library. But if you only use 'big' .NET frameworks, it is better to use Crc32C.NET for Crc32C? because it has fast native implementation.

Version 1.2.0 Remarks

CRC algorithms has interesting feature: if we calculate it for some data and write result CRC data to end of source data, then calculate data with this CRC we'll receive a constant number. This number is 0x2144DF1C for CRC32 and 0x48674BC7 for CRC32C.

This feature can be used for more convenient CRC usage, e.g. validation of correctness is a simple comparison with constant. There are no requirement to decode CRC value from input array and compare it with calculated data.

So in 1.2.0 version, I've added 2 methods (with overloads) to use this feature:

var inputArray = new byte[realDataLength + 4];

// write real data to inputArray
Crc32Algorithm.ComputeAndWriteToEnd(inputArray); // last 4 bytes contains CRC

// transferring data or writing reading, and checking as final operation
if (!Crc32Algorithm.IsValidWithCrcAtEnd(inputArray))
{
    throw new InvalidOperationException("Data was tampered");
}

In other words, you should pass some input buffer to calculation function and it will write CRC data at last 4 bytes. After that, when you need validation, you should pass this buffer to validation function and it will return is data correct.

Version 2.0.0 Remarks

After long pause, project was updated to next major version. Changes:

  • Removed support for .net2.0 and .netstandard1.3
  • Added support for .net6.0
  • For core version ReadOnlySpan versions was added
  • Optimized CRC32 version for .net6.0
  • Intrinsic for CRC32C version for .net6.0

So, results now:

Algorithm framework Speed
CRC32(C) .net4.0 1090 MB/s
CRC32 .net6.0 1378 MB/s
CRC32C .net6.0 18128 MB/s

Other libraries were not checked now, it also can be already optimized.

Version 2.1.0 Remarks

  • CRC32 for .net6.0 now uses pclmulqdq to improve speed if supported and uses cast to uint if unsupported. It is SSE2 command, so, it should be supported at any modern cpu. for ARM binary primitives used also. Speed not checked

So, difference between old and new version:

Algorithm framework Speed
CRC32 at 2.0.0 .net6.0 1378 MB/s
CRC32 at 2.1.0 no pclmulqdq .net6.0 1560 MB/s
CRC32 at 2.1.0 supports pclmulqdq .net6.0 2772 MB/s

Idea of code from https://www.nuget.org/packages/System.IO.Hashing/

This is "maintenance" release with optimizations and new frameworks, but it not checked carefully and can be optimized more.

Description

This library is port of Crc32C.NET by Robert Važan but for Crc32 algorithm. Also, this library contains optimizations for managed code, so, it really faster than other Crc32 implementations.

If you do not not catch the difference, it is C (Castagnoli). I recommend to use Crc32C, not usual CRC32, because it can be faster (up to 20GB/s with native CPU implementation) and slightly better in error detection. But if you need exactly Crc32, this library is the best choice.

Performance (not checked for new versions of other packages)

This library has code, which is optimized for .NET (implementation is not dumb copy-paste from google), as result, it is really fast in comparison with other implemenations.

Library Speed
CH.Crc32 by Cliff Hammerschmidt 117 MB/s
Crc32 by Dario Griffo 401 MB/s
Klinkby.Checksum by Mads Breusch Klinkby 400 MB/s
Data.HashFunction.CRC by Brandon Dahler 206 MB/s
Dexiom.QuickCrc32 by Jonathan Paré 364 MB/s
K4os.Hash.Crc by Milosz Krajewski 399 MB/s
This library 2772 MB/s

Some notes

I thought about making a pull request to Crc32 library, but it seems, this library was abandoned. Anyway, I implement my library to be fully compatible with Crc32 library. And you can switch from Crc32 library to this.

Api interface was taken from Crc32C.NET library. It is very handy for using in applications.

License

MIT license