Full name: Checksum versus cyclic redundancy check.
Definition
A checksum is a short value computed from data by simple arithmetic, such as the sum of its bytes, and stored or sent with the data so that a receiver can recompute it and detect accidental changes. A cyclic redundancy check (CRC) is a check value computed as the remainder when the data, read as a polynomial whose coefficients are its bits, is divided by a fixed generator polynomial. Neither uses a secret key, so anyone can compute either. A CRC detects classes of errors that a sum misses.
The idea
Bits go wrong. Electrical noise flips bits on a cable, interference corrupts radio packets, and worn flash memory §6.6 returns a value different from the one written. A receiver wants to notice. The sender adds a few redundant bits computed from the data, and the receiver recomputes them; a mismatch means the data changed. A simple sum is cheap but blind to some errors: it cannot tell the bytes 01 02 from 02 01. A CRC mixes every bit into the result by polynomial division. Hardware computes it with a short shift register, a row of one-bit cells whose contents move one place at each step, and a few exclusive-or (XOR) gates. A CRC catches every short burst of errors, the typical result of a noise spike.
Both designs answer one threat: random errors that do not adapt to the check. An attacker is a different threat. An attacker chooses the new data, knows the public algorithm §14.1, and computes the matching check value. A checksum is like the page count written on a document: it reveals a lost page, but a forger simply writes the new count. Showing who wrote the data needs a value that only the real sender can compute, which needs a secret, such as the key of a message authentication code §5.7.
How it works
Checksums. The simplest checksum adds all bytes and keeps the sum modulo 256, the remainder after division by 256, so that it fits in one byte. The Internet checksum, described in RFC 1071 [459] and carried in the headers of several core Internet protocols, adds 16-bit words in ones’ complement arithmetic, in which a carry out of the top bit is added back in at the bottom, and sends the complement of the sum. Fletcher’s checksum and Adler-32 also keep a second running sum, the sum of the first sum’s successive values, which makes each byte’s contribution depend on its position and so detects reordering.
CRCs. A CRC is defined by a generator polynomial of degree , written as bits that begin with a 1.
Read the message bits as the coefficients of a polynomial, highest power first: the bits
1101are .Do all coefficient arithmetic modulo 2. Addition and subtraction are then the same operation, bitwise XOR (exclusive or: the result bit is 1 when the two bits differ), with no carries and no borrows.
Append zero bits to the message, which multiplies its polynomial by .
Divide by long division: wherever the leftmost remaining bit is 1, XOR the generator’s bits into the bits that start there.
The last bits that remain form the remainder, the CRC. The sender transmits the message followed by the CRC.
The receiver divides the whole received bit string by in the same way. A remainder of zero means no detected error; any other remainder means the data changed.
Deployed CRCs add conventions to this basic division: a starting value for the remainder, bit reflection, which processes each byte from its least significant bit, and a final XOR. The CRC-32 of IEEE 802.3, the Ethernet standard [460], uses the generator 0x04C11DB7, starts with all ones, reflects input and output, and inverts the result. Its CRC of the 9 ASCII characters 123456789 is 0xCBF43926, the standard check value that confirms an implementation follows all of these conventions.
Worked example
Checksum. For the bytes 01 02, the 8-bit sum is . For 02 01 it is as well, so swapping the bytes goes undetected. An attacker who changes 01 02 to 05 02 simply sends the new sum , and the receiver’s check passes.
CRC. Take the message 1101 and the generator 1011, which is , of degree . Append three zeros to get 1101000. Divide, writing every step in 7 bits; each line places the generator under the leftmost remaining 1:
1101000XOR1011000=0110000
0110000XOR0101100=0011100
0011100XOR0010110=0001010
0001010XOR0001011=0000001
The last 3 bits, 001, are the CRC, and the sender transmits 1101001. Dividing 1101001 in the same way leaves 000, so the receiver accepts it.
Noise flips the fourth bit from the left, and the receiver gets 1100001. Division gives 1100001 XOR 1011000 = 0111001, then XOR 0101100 gives 0010101, then XOR 0010110 gives 0000011. The remainder 011 is not zero, so the error is detected.
An attacker who wants the receiver to accept the message 1110 divides 1110000 by 1011: 1110000 XOR 1011000 = 0101000, then XOR 0101100 gives 0000100. The CRC is 100, the attacker sends 1110100, and the receiver’s division leaves 000. The check passes, because the attacker computed it exactly as the sender would.
Stated precisely
Let be the message polynomial and the generator, of degree . The CRC is the remainder , and the transmitted polynomial is divisible by , because adding the remainder modulo 2 is the same as subtracting it. Flipped bits are described by an error polynomial , with a 1 at every flipped position, and the receiver sees . The error goes undetected exactly when divides . Four consequences follow.
Every single flipped bit, , is detected when has at least two terms.
Every burst, meaning a set of flipped bits that all lie within consecutive positions, is detected when contains the constant term 1.
Every odd number of flipped bits is detected when divides .
A random error pattern longer than bits goes undetected with probability about .
A CRC is linear over XOR. Write for bitwise XOR. For a CRC with starting value zero and no final XOR, and for any two messages and of equal length, . With a starting value and a final XOR, as in CRC-32, , where is the all-zero message of the same length. An attacker who XORs a chosen pattern into a message therefore knows the change to its CRC, , without knowing the message.
For authentication §1.6 the contrast is exact. With a public function and no secret, an attacker who replaces a message by sends and is accepted with probability 1. With a secure message authentication code of bits and a secret key, an attacker without the key has a forgery probability §5.13, the chance that one attempt is accepted, of about .
Limits and common mistakes
No secret, no authentication. A checksum or CRC shows only that the data and the check value agree. It says nothing about who computed them.
Encrypting a CRC does not fix it. WEP (Wired Equivalent Privacy), the original Wi-Fi security protocol, appended a CRC-32 to each packet and encrypted both with the stream cipher RC4 (Rivest Cipher 4), which encrypts by XOR with a key-dependent byte sequence. Because both the CRC and the encryption are linear over XOR, an attacker could flip chosen bits of an encrypted packet and correct the encrypted CRC without the key; Borisov, Goldberg and Wagner showed this in 2001 [461]. A CRC with a secret starting value fails for the same reason: the change does not depend on the starting value, so the attacker computes it with any starting value, such as zero.
An unkeyed cryptographic hash §5.1 does not authenticate either. A cryptographic hash function such as SHA-256 §5.2 (Secure Hash Algorithm with a 256-bit output) makes it infeasible to find two inputs with the same hash, but an attacker who replaces the data also replaces the hash. A hash authenticates data only when the hash itself arrives over an authenticated path.
Guarantees depend on the error model and the message length. The guarantees above hold for errors as the model describes them. How many flipped bits a given polynomial always detects falls as messages grow longer, so a CRC is chosen for a maximum message length. A CRC’s width is not a security level §7.33.
Conventions must match. Two programs that both say CRC-32 can still disagree on the starting value, the reflection, the final XOR, or the byte order §4.21 in which the CRC is appended. Bit reflection is not the same thing as endianness, the byte order of a number in memory. Test every implementation against the check value of 123456789.
Detection is not correction, and coverage starts where the check is computed. A checksum or CRC only reports that data changed; recovering the data needs an error-correcting code or a retransmission §7.36. Data corrupted in memory before its CRC was computed travels with a valid CRC.
A CRC still has a place next to a message authentication code. A CRC is the right tool against noise, and it is cheap, so a link can reject corrupted frames quickly while a message authentication code protects against the attacker from end to end.
Questions answered
Why can neither mechanism authenticate a malicious sender?
Neither a checksum nor a CRC (cyclic redundancy check) can authenticate a malicious sender, because both are public functions of the data alone: they use no secret, so whoever changes the data can compute the correct check value for the new data, and the receiver’s check passes. For example, with an 8-bit sum, an attacker who changes the bytes 01 02 to 05 02 sends the new sum 7 in place of 3. A matching value shows only that the data and the check value agree, which rules out most accidental corruption; it does not show who produced them. A CRC is weaker still against an attacker, because it is linear over XOR (exclusive or): an attacker can flip chosen bits and correct the CRC without seeing the data, which is how the encrypted CRC of WEP (Wired Equivalent Privacy), the original Wi-Fi security protocol, was defeated. Authenticating the sender needs something that only the legitimate sender can compute: a message authentication code (MAC) made with a shared secret key, or a digital signature §5.14 made with a private key. A CRC can stay alongside either one for its own job of detecting noise.
Related entries: Message authentication code (MAC) (§5.7), Cryptographic hash function (§5.1), Endianness (§4.21), Digital signature (§5.14), Authenticated encryption (AEAD) (§5.16), Bit operations: truth tables, masks, shifts, and rotations (§4.50). Further reading: [459, 460, 461].