diff --git a/README.md b/README.md new file mode 100644 index 0000000..e97af1f --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# CRC-16-IBM +## Synopsis +This code produces a look-up table for quick calculation of a 16-bit CRC. The output is in C-style hexadecimal, to make it easy to cut & paste into code. It also uses this same table to compute the CRC of a (hardcoded) golden packet and verifies it against a reference (naïve) computation. +## CRC Implementation +The CRC polynomial is the [CRC-16-IBM](https://en.wikipedia.org/wiki/Cyclic_redundancy_check#Polynomial_representations_of_cyclic_redundancy_checks "CRC-16-IBM") in the "reversed reciprocal" form. The reference (naïve) CRC implementation does slow, bit-by-bit polynomial division. The table-based CRC implementation uses a LUT to perform the, considerable faster, Sarwate algorithm. Information on both implementations is available on [Wikipedia](https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks). The LUT transforms an 8-bit input to a 16-bit output, which takes relatively little space on most 32-bit microcontrollers, but offers a significant speedup. +## Building + $ mingw32-make crc + gcc -c -o crc.o crc.c -Wall -Wextra -Werror -pedantic + gcc -o crc crc.o -Wall -Wextra -Werror -pedantic + +## Running + $ ./crc + CRC byte lookup table: + 0x0000, 0x7f81, 0xff02, 0x8083, 0x7e01, 0x0180, 0x8103, 0xfe82, + 0xfc02, 0x8383, 0x0300, 0x7c81, 0x8203, 0xfd82, 0x7d01, 0x0280, + 0x7801, 0x0780, 0x8703, 0xf882, 0x0600, 0x7981, 0xf902, 0x8683, + 0x8403, 0xfb82, 0x7b01, 0x0480, 0xfa02, 0x8583, 0x0500, 0x7a81, + 0xf002, 0x8f83, 0x0f00, 0x7081, 0x8e03, 0xf182, 0x7101, 0x0e80, + 0x0c00, 0x7381, 0xf302, 0x8c83, 0x7201, 0x0d80, 0x8d03, 0xf282, + 0x8803, 0xf782, 0x7701, 0x0880, 0xf602, 0x8983, 0x0900, 0x7681, + 0x7401, 0x0b80, 0x8b03, 0xf482, 0x0a00, 0x7581, 0xf502, 0x8a83, + 0x6001, 0x1f80, 0x9f03, 0xe082, 0x1e00, 0x6181, 0xe102, 0x9e83, + 0x9c03, 0xe382, 0x6301, 0x1c80, 0xe202, 0x9d83, 0x1d00, 0x6281, + 0x1800, 0x6781, 0xe702, 0x9883, 0x6601, 0x1980, 0x9903, 0xe682, + 0xe402, 0x9b83, 0x1b00, 0x6481, 0x9a03, 0xe582, 0x6501, 0x1a80, + 0x9003, 0xef82, 0x6f01, 0x1080, 0xee02, 0x9183, 0x1100, 0x6e81, + 0x6c01, 0x1380, 0x9303, 0xec82, 0x1200, 0x6d81, 0xed02, 0x9283, + 0xe802, 0x9783, 0x1700, 0x6881, 0x9603, 0xe982, 0x6901, 0x1680, + 0x1400, 0x6b81, 0xeb02, 0x9483, 0x6a01, 0x1580, 0x9503, 0xea82, + 0xc002, 0xbf83, 0x3f00, 0x4081, 0xbe03, 0xc182, 0x4101, 0x3e80, + 0x3c00, 0x4381, 0xc302, 0xbc83, 0x4201, 0x3d80, 0xbd03, 0xc282, + 0xb803, 0xc782, 0x4701, 0x3880, 0xc602, 0xb983, 0x3900, 0x4681, + 0x4401, 0x3b80, 0xbb03, 0xc482, 0x3a00, 0x4581, 0xc502, 0xba83, + 0x3000, 0x4f81, 0xcf02, 0xb083, 0x4e01, 0x3180, 0xb103, 0xce82, + 0xcc02, 0xb383, 0x3300, 0x4c81, 0xb203, 0xcd82, 0x4d01, 0x3280, + 0x4801, 0x3780, 0xb703, 0xc882, 0x3600, 0x4981, 0xc902, 0xb683, + 0xb403, 0xcb82, 0x4b01, 0x3480, 0xca02, 0xb583, 0x3500, 0x4a81, + 0xa003, 0xdf82, 0x5f01, 0x2080, 0xde02, 0xa183, 0x2100, 0x5e81, + 0x5c01, 0x2380, 0xa303, 0xdc82, 0x2200, 0x5d81, 0xdd02, 0xa283, + 0xd802, 0xa783, 0x2700, 0x5881, 0xa603, 0xd982, 0x5901, 0x2680, + 0x2400, 0x5b81, 0xdb02, 0xa483, 0x5a01, 0x2580, 0xa503, 0xda82, + 0x5001, 0x2f80, 0xaf03, 0xd082, 0x2e00, 0x5181, 0xd102, 0xae83, + 0xac03, 0xd382, 0x5301, 0x2c80, 0xd202, 0xad83, 0x2d00, 0x5281, + 0x2800, 0x5781, 0xd702, 0xa883, 0x5601, 0x2980, 0xa903, 0xd682, + 0xd402, 0xab83, 0x2b00, 0x5481, 0xaa03, 0xd582, 0x5501, 0x2a80 + + Golden Checksum: 0x03e8 + Reference Golden Checksum: 0x03e8 +