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
18
votes
2 answers

Fast CRC algorithm?

I want to create a 32-bit number out of an ASCII-string. CRC32 algorithm is exactly what I'm looking for, but I can't use it because the table it requires is way too huge (it is for an embedded system where resources are VERY rare). So: any…
Elmi
  • 5,899
  • 15
  • 72
  • 143
18
votes
4 answers

Reversing CRC32

I'm looking for a way to reverse a CRC32 checksum. There are solutions around, but they are either badly written, extremely technical and/or in Assembly. Assembly is (currently) beyond my ken, so I'm hoping someone can piece together an…
pat
  • 16,116
  • 5
  • 40
  • 46
17
votes
4 answers

Is it possible to do CRC-32 calculation in splits?

I use this trivial function to calculate the CRC checksum of a given file: long i, j = 0; int k = 0; uint crc = 0xFFFFFFFF; FileInfo file_info = new FileInfo(file); byte[] file_buffer = new byte[32768]; FileStream file_stream = new…
Mik
  • 199
  • 2
  • 5
17
votes
1 answer

How is PNG CRC calculated exactly?

For the past 4 hours I've been studying the CRC algorithm. I'm pretty sure I got the hang of it already. I'm trying to write a png encoder, and I don't wish to use external libraries for the CRC calculation, nor for the png encoding itself. My…
MythicManiac
  • 445
  • 1
  • 4
  • 11
16
votes
6 answers

How to set STM32 to generate standard CRC32

I am trying to generate CRC with STM32L4 hardware modul. I would like to validate fatfs files so basically I have byte arrays. I am using this CRC generator. Unfortunately I cannot figure out how to set STM32L4 to generate the same result. I need…
David Molnar
  • 419
  • 1
  • 6
  • 14
15
votes
4 answers

Ethernet CRC32 calculation - software vs algorithmic result

I'm trying to calculate the Frame Check Sequence (FCS) of an Ethernet packet byte by byte. The polynomial is 0x104C11DB7. I did follow the XOR-SHIFT algorithm seen here http://en.wikipedia.org/wiki/Cyclic_redundancy_check or here…
sebs
  • 4,566
  • 3
  • 19
  • 28
15
votes
2 answers

Calculate a 32-bit CRC lookup table in C/C++

I want to calculate a 32-bit CRC lookup table. One way I tried is by using the following code from this website: #include #include void make_crc_table() { unsigned long POLYNOMIAL = 0x04c11db7; unsigned long WIDTH = 8…
Programmer_D
  • 601
  • 2
  • 15
  • 27
13
votes
0 answers

How to implement CRC32 taking advantage of Intel specific instructions?

Intel has a specific CRC32 instruction available in the SSE4.2 instruction set. How can I take advantage of this instruction to speed up CRC32 calculations?
RubenLaguna
  • 21,435
  • 13
  • 113
  • 151
13
votes
1 answer

Alternative to reinterpret_cast with constexpr functions

Below, you will find a constexpr string literal to CRC32 computation. I had to reinterpret the string literal character from char to unsigned char. Because reinterpret_cast is not available in constexpr function, the workaround is a small utility…
galop1n
  • 8,573
  • 22
  • 36
13
votes
1 answer

CRC32 algorithm/implementation in C without a look up table and with a public license

I am trying to implement a CRC32 algorithm in C that does not use a look up table (I need to use it in a boot loader that doesn't have enough memory available to have one). Is there an available solution to this that has a public license?
Oscar_Mariani
  • 728
  • 3
  • 9
  • 22
12
votes
4 answers

Is CRC32 additive?

On several places I've read that crc32 is additive and so: CRC(A xor B) = CRC(A) xor CRC(B). The above statement was disproven by the following code I wrote: import zlib def crc32(data): return zlib.crc32(data) & 0xffffffff print…
Ryan82
  • 121
  • 1
  • 4
12
votes
1 answer

Basic CRC32 Wikipedia implementation differs from standard CRC32 seen online

I have a basic CRC32 implementation following Wikipedia's Code Fragment:1 sample. I think I have done it right, with the modification of using an n-bit register for the remainderPolynomial instead of n+1 bit usage as per the example. The result I…
Titus
  • 907
  • 8
  • 18
11
votes
3 answers

Calculate/validate bz2 (bzip2) CRC32 in Python

I'm trying to calculate/validate the CRC32 checksums for compressed bzip2 archives. .magic:16 = 'BZ' signature/magic number .version:8 = 'h' for Bzip2 ('H'uffman coding) .hundred_k_blocksize:8 =…
soulseekah
  • 8,770
  • 3
  • 53
  • 58
10
votes
2 answers

CRC32 calculation in Python without using libraries

I have been trying to get my head around CRC32 calculations without much success, the values that I seem to get do not match what I should get. I am aware that Python has libraries that are capable of generating these checksums (namely zlib and…
Cooper
  • 127
  • 1
  • 1
  • 8
10
votes
1 answer

Difference between crc32() implementations of and in C

I am calling two functions on my char* s = "pratik" as: User code: #include int main() { char *s = "pratik"; printf("%x\n",crc32(0x80000000, s, strlen(s))); return 0; } Output: 66fa3c99 Kernel code: #include…
Raunaq Kochar
  • 1,024
  • 3
  • 15
  • 24
1
2
3
37 38