Questions tagged [crc32]

A cyclic redundancy check (CRC) is an error-detecting code designed to detect accidental changes to raw computer data, and is commonly used in digital networks. (wiki) A CRC32 algorithm typically takes in a file stream or character array and calculates an unsigned long codeword from the input. One can transmit this codeword and re-calculate it on the receiver end, then compare it to the transmitted one to detect an error.

A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data. Blocks of data entering these systems get a short check value attached, based on the remainder of a polynomial division of their contents; on retrieval the calculation is repeated, and corrective action can be taken against presumed data corruption if the check values do not match. wikipedia

The most commonly used polynomial lengths are:

  • CRC-8: 9 bits
  • CRC-16: 17 bits
  • CRC-32: 33 bits
  • CRC-64: 65 bits

A truly excellent tutorial on CRC's is Ross Williams' "Painless Guide to CRC Detection Algorithms", which can also be found here, here, here, here, and here.

570 questions
140
votes
7 answers

How is a CRC32 checksum calculated?

Maybe I'm just not seeing it, but CRC32 seems either needlessly complicated, or insufficiently explained anywhere I could find on the web. I understand that it is the remainder from a non-carry-based arithmetic division of the message value, divided…
aquanar
  • 1,531
  • 2
  • 11
  • 8
58
votes
9 answers

CRC32 C or C++ implementation

I'm looking for an implementation of CRC32 in C or C++ that is explicitly licensed as being no cost or public domain. The implementation here seems nice, but the only thing it says about the license is "source code", which isn't good enough. I'd…
twk
  • 16,760
  • 23
  • 73
  • 97
50
votes
3 answers

How do I calculate CRC32 of a string

How do I calculate the CRC32 (Cyclic Redundancy Checksum) of a string in .NET?
Nick Berardi
  • 54,393
  • 15
  • 113
  • 135
50
votes
3 answers

Can CRC32 be used as a hash function?

Can CRC32 be used as a hash function? Any drawbacks to this approach? Any tradedeoffs?
Pradyot
  • 2,897
  • 7
  • 41
  • 58
49
votes
7 answers

Data Length vs CRC Length

I've seen 8-bit, 16-bit, and 32-bit CRCs. At what point do I need to jump to a wider CRC? My gut reaction is that it is based on the data length: 1-100 bytes: 8-bit CRC 101 - 1000 bytes: 16-bit CRC 1001 - ??? bytes: 32-bit CRC EDIT: Looking at the…
Robert Deml
  • 12,390
  • 20
  • 65
  • 92
46
votes
6 answers

JavaScript CRC32

I'm looking for a modern JavaScript implementation of CRC32. This implementation, which may have originated from here, and is now here, there and everywhere, is unacceptable because it's slow (500ms/MB), and depends on over 2KB of space delimited…
Adria
  • 8,651
  • 4
  • 37
  • 30
45
votes
3 answers

How to calculate CRC32 with Python to match online results?

I'm trying to calculate/generate the CRC32 hash of some random strings using Python but they do not match the values I generate from online sources. Here is what I'm doing on my PC, >>> import binascii >>>…
chronodekar
  • 2,616
  • 6
  • 31
  • 36
35
votes
4 answers

Implementing SSE 4.2's CRC32C in software

So I have a design which incorporates CRC32C checksums to ensure data hasn't been damaged. I decided to use CRC32C because I can have both a software version and a hardware-accelerated version if the computer the software runs on supports SSE…
LMS
  • 4,117
  • 5
  • 27
  • 37
33
votes
5 answers

Can one construct a "good" hash function using CRC32C as a base?

Given that SSE 4.2 (Intel Core i7 & i5 parts) includes a CRC32 instruction, it seems reasonable to investigate whether one could build a faster general-purpose hash function. According to this only 16 bits of a CRC32 are evenly distributed. So what…
DavidD
  • 361
  • 1
  • 4
  • 5
31
votes
1 answer

How to calculate 32 bit CRC in Ruby on rails?

i want to calculate 32 bit CRC value for 'input field value" in Ruby on rails. need the sample code , please help me anyone.
Jeyavel
  • 2,974
  • 10
  • 38
  • 48
29
votes
4 answers

How to create Uncompressed Zip archive in Java

I am using the Zip utility package of Java and wanted to know how to create a zip file with no compression at all. Setting the level to 0 doesn't help. Is this right? Also, when I used the STORED method, it throws following…
Keya
25
votes
3 answers

Can CRC32(C) ever return to 0?

I'm wondering if CRC32 sum and CRC32C in particular ever return to 0? The simple answer would be "yes" given a large enough data set. However, I was wondering if there is any provisioning in CRC32C standard that would explicitly prevent this from…
dtoux
  • 1,754
  • 3
  • 21
  • 38
22
votes
2 answers

Why does java.util.zip.CRC32.getValue() return a long, not an int?

See the title. The returned value is 32 bits, right? Why not return an int?
Steveo
  • 2,238
  • 1
  • 21
  • 34
20
votes
7 answers

How to calculate crc32 checksum from a string on linux bash

I used crc32 to calculate checksums from strings a long time ago, but I cannot remember how I did it. echo -n "LongString" | crc32 # no output I found a solution [1] to calculate them with Python, but is there not a direct way to calculate that…
oxidworks
  • 1,563
  • 1
  • 14
  • 37
18
votes
2 answers

Python equivalent of unix cksum function

I've been looking for the equivalent python method for the unix cksum command: http://pubs.opengroup.org/onlinepubs/7990989775/xcu/cksum.html $ cksum ./temp.bin 1605138151 712368 ./temp.bin So far I have found the zlib.crc32() function >>> import…
Dan
  • 1,029
  • 9
  • 14
1
2 3
37 38