Professional Documents
Culture Documents
Checksum algorithms based solely on addition the packet--for example, the received checksum
are easy to implement and can be executed bits do not accurately describe the received
efficiently on any microcontroller. However, message bits--it may either discard the packet
many common types of transmission errors and request a retransmission (error detection)
cannot be detected when such simple or attempt to repair the damage on its own
checksums are used. This article describes a (error correction). If packet repairs are to be
stronger type of checksum, commonly known as attempted, the checksum is said to be an error
a CRC. correcting code.
A cyclic redundancy check (CRC) is based on The key to repairing corrupted packets is a
division instead of addition. The error detection stronger checksum algorithm. Specifically,
capabilities of a CRC make it a much stronger what's needed is a checksum algorithm that
checksum and, therefore, often worth the price distributes the set of valid bit sequences
of additional computational complexity. randomly and evenly across the entire set of
possible bit sequences. For example, if the
Additive checksums are error detection codes minimum number of bits that must change to
as opposed to error correction codes. A turn any one valid packet into some other valid
mismatch in the checksum will tell you there's packet is seven, then any packet with three or
been an error but not where or how to fix it. In fewer bit inversions can be corrected
implementation terms, there's not much automatically by the receiver. (If four bit errors
difference between an error detection code and occur during transmission, the packet will seem
an error correction code. In both cases, you closer to some other valid packet with only
take the message you want to send, compute three errors in it.) In this case, error correction
some mathematical function over its bits can only be done for up to three bit errors,
(usually called a checksum), and append the while error detection can be done for up to six.
resulting bits to the message during
transmission. This spreading of the valid packets across the
space of possible packets can be measured by
Error Correction the Hamming distance, which is the number of
bit positions in which any two equal-length
The difference between error detection and packets differ. In other words, it's the number
error correction lies primarily in what happens of bit errors that must occur if one of those
next. If the receiving system detects an error in packets is to be incorrectly received as the
other. A simple example is the case of the two Binary Long Division
binary strings 1001001 and 1011010, which are
separated by a Hamming distance of three. (To It turns out that once you start to focus on
see which bits must be changed, simply XOR the maximizing the "minimum Hamming distance
two strings together and note the bit positions across the entire set of valid packets," it
that are set. In our example, the result is becomes obvious that simple checksum
0010011.) algorithms based on binary addition don't have
the necessary properties. A change in one of
The beauty of all this is that the mere presence the message bits does not affect enough of the
of an error detection or correction code within checksum bits during addition. Fortunately, you
a packet means that not all of the possible don't have to develop a better checksum
packets are valid. Figure 1 shows what a packet algorithm on your own. Researchers figured out
looks like after a checksum has been appended long ago that modulo-2 binary division is the
to it. Since the checksum bits contain redundant simplest mathematical operation that provides
information (they are completely a function of the necessary properties for a strong checksum.
the message bits that precede them), not all of
the 2(m+c) possible packets are valid packets. In All of the CRC formulas you will encounter are
fact, the stronger the checksum algorithm used, simply checksum algorithms based on modulo-2
the greater the number of invalid packets will binary division. Though some differences exist
be. in the specifics across different CRC formulas,
the basic mathematical process is always the
same:
As is the case with other types of checksums, • A message with any one bit in error
the width of the CRC plays an important role in • A message with any two bits in error
the error detection capabilities of the (no matter how far apart, which
algorithm. Ignoring special types of errors that column, and so on)
are always detected by a particular checksum • A message with any odd number of bits
algorithm, the percentage of detectable errors in error (no matter where they are)
is limited strictly by the width of a checksum. A • A message with an error burst as wide
checksum of c bits can only take one of 2c as the checksum itself
unique values. Since the number of possible
messages is significantly larger than that, the The first class of detectable error is also
potential exists for two or more messages to detected by an addition-based checksum, or
have an identical checksum. If one of those even a simple parity bit. However, the middle
messages is somehow transformed into one of two classes of errors represent much stronger
the others during transmission, the checksum detection capabilities than those other types of
will appear correct and the receiver will checksum. The fourth class of detectable error
unknowingly accept a bad message. The chance sounds at first to be similar to a class of errors
of this happening is directly related to the width detected by addition-based checksums, but in
of the checksum. Specifically, the chance of the case of CRCs, any odd number of bit errors
such an error is 1/2c. Therefore, the probability will be detected. So the set of error bursts too
of any random error being detected is 1-1/2c. wide to detect is now limited to those with an
even number of bit errors. All other types of
To repeat, the probability of detecting any errors fall into the relatively high 1-1/2c
random error increases as the width of the probability of detection.
checksum increases. Specifically, a 16-bit
checksum will detect 99.9985% of all errors.
Ethernet, SLIP, and PPP
This is far better than the 99.6094% detection
rate of an eight-bit checksum, but not nearly as
Ethernet, like most physical layer protocols,
good as the 99.9999% detection rate of a 32-bit
employs a CRC rather than an additive
checksum. All of this applies to both CRCs and
checksum. Specifically, it employs the CRC-32
addition-based checksums. What really sets
algorithm. The likelihood of an error in a packet
CRCs apart, however, is the number of special
sent over Ethernet being undetected is,
cases that can be detected 100% of the time.
therefore, extremely low. Many types of
For example, I pointed out last month that two
common transmission errors are detected 100%
opposite bit inversions (one bit becoming 0, the
of the time, with the less likely ones detected
other becoming 1) in the same column of an
99.9999% of the time. Even if an error would
addition would cause the error to be
somehow manage to get through at the
undetected. Well, that's not the case with a
Ethernet layer, it would probably be detected at
CRC.
the IP layer checksum (if the error is in the IP
header) or in the TCP or UDP layer checksum
By using one of the mathematically well-
above that. After all the chances of two or more
understood generator polynomials like those in
different checksum algorithms not detecting
Table 1 to calculate a checksum, it's possible to
the same error is extremely remote.
state that the following types of errors will be
detected without fail: