Wikipedia / Mathematics of cyclic redundancy checks
Wikipedia / Mathematics of cyclic redundancy checks
The cyclic redundancy check (CRC) is a check of the remainder after division in the ring of polynomials over GF(2) (the finite field of integers modulo 2). That is, the set of polynomials where each coefficient is either zero or one, and arithmetic operations wrap around.
Any string of bits can be interpreted as the coefficients of a polynomial of this sort, and a message has a valid CRC if it is divisible by (i.e. is a multiple of) an agreed-on generator polynomial., see Polynomial arithmetic modulo 2 below for more details). CRCs are convenient and popular because they have good error-detection properties and such a multiple may be easily constructed from any message polynomial-bit remainder polynomial is the degree of the generator polynomial.
.
Formulation
In general, computation of CRC corresponds to Euclidean division of polynomials over GF(2):
is of no interest. Using modulo operation, it can be stated that
(the codeword as
are correct.
to a value reconstructed from the received message, but hardware implementations invariably find the full-length division described above to be simpler.
In practice CRC calculations most closely resemble long division in binary, except that the subtractions involved do not borrow from more significant digits, and thus become exclusive or operations.
A CRC is a checksum in a strict mathematical sense, as it can be expressed as the weighted modulo-2 sum of per-bit syndromess, but that word is generally reserved more specifically for sums computed using larger moduli, such as 10, 256, or 65535.
CRCs can also be used as part of error-correcting codes, which allow not only the detection of transmission errors, but the reconstruction of the correct message. These codes are based on closely related mathematical principles.
Polynomial arithmetic modulo 2
Since the coefficients are constrained to a single bit, any math operation on CRC polynomials must map the coefficients of the result to either zero or one. For example, in addition:
is equivalent to zero in the above equation because addition of coefficients is performed modulo 2:
Polynomial addition modulo 2 is the same as bitwise XOR. Since XOR is the inverse of itself, polynominal subtraction modulo 2 is the same as bitwise XOR too.
Multiplication is similar (a carry-less product):
. We would find that
In other words,
with a remainder of −1, which, since it is odd, has a last bit of 1.
represents the original message bits 111.
Variations
There are several standard variations on CRCs, any or all of which may be used with any CRC polynomial. Implementation variations such as endianness, and do not impact the properties of the algorithm.
The remainder on division does not need to be zero. Although all of the preceding text is written in terms of divisibility by the generator polynomial, any is used, but, for example, the asynchronous transfer mode This does not make CRC checking any more difficult, you just have to know the expected pattern.
The long division may begin with a non-zero remainder.-bit shift register.
which does not change its value, and thus does not change its divisibility by the generator polynomial. By adding a fixed pattern to the first bits of a message, such extra zero bits can be detected.
, and therefore the extra bit will be detected.
ones.
These inversions are extremely common but not universally performed, even in the case of the CRC-32 or CRC-16-CCITT polynomials. They are almost always included when sending variable-length messages, but often omitted when communicating fixed-length messages, as the problem of added zero bits is less likely to arise.
Reversed representations and reciprocal polynomials
Polynomial representations
coefficient.
This bit string may then be converted to a binary number using one of two conventions:
(which is always 1) as the least significant bit.
(which is always 1) as the most significant bit.
The msbit-first form is often referred to in the literature as the normal representation, while the lsbit-first is called the reversed happens to be zero, the forms can be distinguished at a glance by seeing which end has the bit set.
For example, the degree-16 CCITT polynomial in the forms described (bits inside square brackets are included in the word representation; bits outside are implied 1 bits; vertical bars designate nibble boundaries):
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 coefficient
1 [0 0 0 1 |0 0 0 0 |0 0 1 0 |0 0 0 1] Normal
[ 1 | 0 | 2 | 1 ] Nibbles of Normal
0x1021
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[1 0 0 0 |0 1 0 0 |0 0 0 0 |1 0 0 0] 1 Reverse
[ 8 | 4 | 0 | 8 ] Nibbles of Reverse
0x8408
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 [0 0 0 0 |1 0 0 0 |0 0 0 1 |0 0 0 1] Reciprocal
[ 0 | 8 | 1 | 1 ] Nibbles of Reciprocal
0x0811
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Reverse reciprocal
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Koopman
[1 0 0 0 |1 0 0 0 |0 0 0 1 |0 0 0 0] 1
[ 8 | 8 | 1 | 0 ] Nibbles
0x8810is omitted and understood to be 1.
.
.
The msbit-first form is often referred to in the literature as the normal representation, while the lsbit-first is called the reversed happens to be zero, the forms can be distinguished at a glance by seeing which end has the bit set.
To further confuse the matter, the paper by P. Koopman and T. Chakravarty coefficient. This "Koopman" representation has the advantage that the degree can be determined from the hexadecimal form and the coefficients are easy to read off in left-to-right order. However, it is not used anywhere else and is not recommended due to the risk of confusion.
Reciprocal polynomials
The most interesting property of reciprocal polynomials, when used in CRCs, is that they have exactly the same error-detecting strength as the polynomials they are reciprocals of. The reciprocal of a polynomial generates the same codewords, only bit reversed bits of the original codeword. But the reciprocal polynomial is not the same as the original polynomial, and the CRCs generated using it are not the same (even modulo bit reversal) as those generated by the original polynomial.
Error detection strength
is the symmetric difference of the received message codeword and the correct message codeword. An error will go undetected by a CRC algorithm if and only if the error polynomial is divisible by the CRC polynomial.
Because a CRC is based on division, no polynomial can detect errors consisting of a string of zeroes prepended to the data, or of missing leading zeroes. However, see .
.
All two bit errors separated by a distance less than the order of the primitive polynomial which is a factor of the generator polynomial is the polynomial's order or exponent. The polynomials with the largest order are called primitive polynomials.
. This is equivalent to the polynomial having an even number of terms with non-zero coefficients. have an odd number of non-zero coefficients.
All burst errors term.
, then
polynomial with a zero appended. It is just a waste of a bit.)
).
Bitfilters
Analysis using bitfilters allows one to very efficiently determine the properties of a given generator polynomial. The results are the following:
). The exception to this result is a bit pattern the same as that of the generator polynomial.
All uneven bit errors are detected by generator polynomials with even number of terms.
; however, these generator polynomials (with odd number of terms) do not discover all odd number of errors, so they should be avoided. A list of the corresponding generators with even number of terms can be found in the link mentioned at the beginning of this section.
All single bit errors within the bitfilter period mentioned above (for even terms in the generator polynomial) can be identified uniquely by their residual. So CRC method can be used to correct single-bit errors as well (within those limits, e.g. 32,767 bits with optimal generator polynomials of degree 16). Since all odd errors leave an odd residual, all even an even residual, 1-bit errors and 2-bit errors can be distinguished. However, like other SECDED techniques, CRCs cannot always distinguish between 1-bit errors and 3-bit errors. When 3 or more bit errors occur in a block, CRC bit error correction will be erroneous itself and produce more errors.
See also
References
External links
— lists CRC polynomials giving best Hamming distances.