CRC Math

advertisement
A Appendix -- Mathematical Foundations of CRC
A.1 Algorithm
This section describes the simple algorithm whereby the CRC algorithm must compute the
remainder of the division of two polynomials.
The algorithm treats the input data bit streams as binary polynomials. Given the original
data frame, the transmitter generates the checksum for that frame. The checksum is generated
so that the resulting frame (the cascade of the original frame and the checksum), is exactly
divisible by some pre-defined polynomial. This pre-defined polynomial is called the divisor or
the CRC generator polynomial.
Let's define the following:
 M - The original (raw) data frame to be transmitted, before adding the checksum. It is
 k bits long.
 C - The resulting checksum to be added to M. It is r bits long.
 T - The cascading of M and C. This is the resulting frame that will be transmitted. It
 is n = k + r bits long.
 P - The pre-defined CRC generator polynomial. A pattern of r + 1 bits.
The main principle behind the CRC algorithm is that the checksum is generated such that
the remainder of T=P is zero. We observe that
T = M ¤ xr + C
(1)
This is so as by cascading C to M we have shifted M by r bits to the left and then added
C to the result. We want the transmitted frame, T, to be exactly divisible by the pre-defined
polynomial P, so we would have to find a suitable checksum (C) for every raw message (M).
Suppose we divided only M ¤ xr by P, we would get:
(M ¤ xr)=P = Q + R=P
(2)
where Q is the quotient and R is the remainder. We will use this remainder, R, as our
checksum (C). Returning to Eq.(1), we have,
T = M ¤ xr + R
(3)
We will now show that this selection of the checksum makes the transmitted frame (T)
exactly divisible by P:
T=P = (M ¤ xr + R)=P
= (M ¤ xr)=P + R=P
= Q + R=P + R=P
= Q + (R + R)=P
=Q
.
.
.
.
(4)
as any binary number added to itself in a modulo 2 field yields zero.
This also proves that the two techniques of either comparing the transmitted checksum with
the checksum calculated at the receiver or that of just checking for the remainder of T=P to be
zero, are equivalent.
A.2 Summary
In summary, the CRC generation process is:
1. Get the raw frame.
2. Left shift the raw frame by r bits and then divide it by P.
3. The remainder of the last action is the checksum.
4. Append the checksum to the raw frame. The result is the frame to transmit.
And the CRC check process is:
1. Receive the frame.
2. Divide it by P.
3. Check the remainder. If not zero then there is an error in the frame.
Download