Jump to content

Cyclic redundancy check

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 24.51.155.22 (talk) at 03:35, 14 October 2004 (Polynomials and Types). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A cyclic redundancy check (CRC) is a type of hash function used to produce a small integer from a large block of data, such as network traffic or computer files, in order to detect errors in transmission or duplication. CRCs are calculated before and after transmission or duplication, and compared to confirm that they are the same. The most widely used CRC calculations are constructed in ways such that certain types of errors, such as those due to noise in transmission channels, are almost always detected.

The essential mathematical operation in the calculation of a CRC is modulo 2 division, and the remainder from the division determines the CRC. CRC's are often referred to as "checksums," but such designations are not accurate since, technically, a checksum is calculated through addition, not division. The main portion of the algorithm in pseudocode is as follows:

Template:Wikicode

 function crc(bit array bitString[1..len]) {
     shiftRegister := initial value // commonly all 0 bits or all 1 bits
     for i from 1 to len {
         if most significant bit of shiftRegister xor bitString[i] = 1
             shiftregister := (shiftregister left shift 1) xor polynomial
         else
             shiftRegister := shiftregister left shift 1
     }
     return shiftregister
 }

Note: Use of a lookup table containing the CRC's of all 256 possible bytes allows for an eight-fold increase in the speed of the algorithm.

CRC types are often identified by "polynomial," which is the number used as the divisor (given in hexadecimal format). One of the most commonly encountered of the CRC types is that used by (among others) Ethernet, FDDI, PKZIP, WinZip, and PNG. It uses the polynomial 0x04C11DB7, and is known as CRC-32.

Polynomials and Types

CRC-8 x^8 + x^2 + x + 1
CRC-CCITT x^16 + x^12 + x^5 + 1
IBM-CRC-16 x^16 + x^15 + x^2 + 1
802.3-Frames x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1

CRCs and data integrity

While useful for error detection, CRCs cannot be safely relied upon to verify data integrity (that no changes whatsoever have occurred), since it's possible to intentionally change data without modifying its CRC. Cryptographic hash functions can be used to verify data integrity.

See also