crc.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <title>Boost CRC Library Documentation</title>
  6. </head>
  7. <body text="black" bgcolor="white" link="blue" vlink="purple" alink="red">
  8. <h1><img src="../../boost.png" alt="boost.png (6897 bytes)"
  9. align="middle" width="277" height="86">Header <cite>&lt;<a
  10. href="../../boost/crc.hpp">boost/crc.hpp</a>&gt;</cite></h1>
  11. <p>The header <cite>&lt;<a
  12. href="../../boost/crc.hpp">boost/crc.hpp</a>&gt;</cite> supplies two
  13. class templates in namespace <code>boost</code>. These templates define
  14. objects that can compute the <dfn>CRC</dfn>, or cyclic redundancy code
  15. (or check), of a given stream of data. The header also supplies
  16. function templates to compute a CRC in one step.</p>
  17. <h2><a name="contents">Contents</a></h2>
  18. <ol>
  19. <li><a href="#contents">Contents</a></li>
  20. <li><a href="#header">Header Synopsis</a></li>
  21. <li><a href="#rationale">Rationale</a></li>
  22. <li><a href="#background">Background</a>
  23. <ul>
  24. <li><a href="#parameters">CRC Parameters</a></li>
  25. </ul></li>
  26. <li><a href="#crc_basic">Theoretical CRC Computer</a></li>
  27. <li><a href="#crc_optimal">Optimized CRC Computer</a></li>
  28. <li><a href="#usage">Computer Usage</a></li>
  29. <li><a href="#crc_func">CRC Function</a></li>
  30. <li><a href="#a_crc_func">Augmented-CRC Function</a></li>
  31. <li><a href="#crc_ex">Pre-Defined CRC Samples</a></li>
  32. <li><a href="#references">References</a></li>
  33. <li><a href="#credits">Credits</a>
  34. <ul>
  35. <li><a href="#contributors">Contributors</a></li>
  36. <li><a href="#acknowledgements">Acknowledgements</a></li>
  37. <li><a href="#history">History</a></li>
  38. </ul></li>
  39. </ol>
  40. <h2><a name="header">Header Synopsis</a></h2>
  41. <blockquote><pre>#include &lt;boost/integer.hpp&gt; <i>// for boost::uint_t</i>
  42. #include &lt;cstddef&gt; <i>// for std::size_t</i>
  43. namespace boost
  44. {
  45. template &lt; std::size_t Bits &gt;
  46. class crc_basic;
  47. template &lt; std::size_t Bits, <em>impl_def</em> TruncPoly = 0u,
  48. <em>impl_def</em> InitRem = 0u,
  49. <em>impl_def</em> FinalXor = 0u, bool ReflectIn = false,
  50. bool ReflectRem = false &gt;
  51. class crc_optimal;
  52. template &lt; std::size_t Bits, <em>impl_def</em> TruncPoly,
  53. <em>impl_def</em> InitRem, <em>impl_def</em> FinalXor,
  54. bool ReflectIn, bool ReflectRem &gt;
  55. typename uint_t&lt;Bits&gt;::fast crc( void const *buffer,
  56. std::size_t byte_count );
  57. template &lt; std::size_t Bits, <em>impl_def</em> TruncPoly &gt;
  58. typename uint_t&lt;Bits&gt;::fast augmented_crc( void const *buffer,
  59. std::size_t byte_count,
  60. typename uint_t&lt;Bits&gt;::fast initial_remainder = 0u );
  61. typedef crc_optimal&lt;16, 0x8005, 0, 0, true, true&gt; crc_16_type;
  62. typedef crc_optimal&lt;16, 0x1021, 0xFFFF, 0, false, false&gt; crc_ccitt_type;
  63. typedef crc_optimal&lt;16, 0x8408, 0, 0, true, true&gt; crc_xmodem_type;
  64. typedef crc_optimal&lt;32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true&gt;
  65. crc_32_type;
  66. }
  67. </pre></blockquote>
  68. <p>The implementation-defined type <var>impl_def</var> stands for the
  69. quickest-to-manipulate built-in unsigned integral type that can
  70. represent at least <var>Bits</var> bits.</p>
  71. <h2><a name="rationale">Rationale</a></h2>
  72. <p>A common error detection technique, especially with electronic
  73. communications, is an appended checksum. The transmitter sends its data
  74. bits, followed by the bits of the checksum. The checksum is based on
  75. operations done on the data bit stream. The receiver applies the same
  76. operations on the bits it gets, and then gets the checksum. If the
  77. computed checksum doesn't match the received checksum, then an error
  78. ocurred in the transmission. There is the slight chance that the error
  79. is only in the checksum, and an actually-correct data stream is
  80. rejected. There is also the chance of an error occurring that does not
  81. change the checksum, making that error invisible. CRC is a common
  82. checksum type, used for error detection for hardware interfaces and
  83. encoding formats.</p>
  84. <h2><a name="background">Background</a></h2>
  85. <p>CRCs work by computing the remainder of a modulo-2 polynominal
  86. division. The message is treated as the (binary) coefficents of a long
  87. polynominal for the dividend, with the earlier bits of the message fed
  88. first as the polynominal's highest coefficents. A particular CRC
  89. algorithm has another polynominal associated with it to be used as the
  90. divisor. The quotient is ignored. The remainder of the division
  91. considered the checksum. However, the division uses modulo-2 rules (no
  92. carries) for the coefficents.</p>
  93. <p>See <cite><a href="http://www.ross.net/crc/crcpaper.html">A
  94. Painless Guide to CRC Error Detection Algorithms</a></cite> for complete
  95. information. A clearer guide is at the <a
  96. href="http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code">CRC
  97. Implementation Code in C</a> web page.</p>
  98. <h3><a name="parameters">CRC Parameters</a></h3>
  99. <dl>
  100. <dt>Truncated polynominal
  101. <dd>The divisor polynominal has a degree one bit larger than the
  102. checksum (remainder) size. That highest bit is always one, so
  103. it is ignored when describing a particular CRC type. Excluding
  104. this bit makes the divisor fit in the same data type as the
  105. checksum.
  106. <dt>Initial remainder
  107. <dd>The interim CRC remainder changes as each bit is processed.
  108. Usually, the interim remainder starts at zero, but some CRCs use
  109. a different initial value to avoid &quot;blind spots.&quot; A
  110. blind spot is when a common sequence of message bits does not
  111. change certain interim remainder values.
  112. <dt>Final XOR value
  113. <dd>A CRC remainder can be combined with a defined value, <i>via</i>
  114. a bitwise exclusive-or operation, before being returned to the
  115. user. The value is usually zero, meaning the interim remainder
  116. is returned unchanged. The other common value is an all-ones
  117. value, meaning that the bitwise complement of the interim
  118. remainder is returned.
  119. <dt>Reflected input
  120. <dd>A message's bits are usually fed a byte at a time, with the
  121. highest bits of the byte treated as the higher bits of the
  122. dividend polynominal. Some CRCs reflect the bits (about the
  123. byte's center, so the first and last bits are switched,
  124. <i>etc.</i>) before feeding.
  125. <dt>Reflected (remainder) output
  126. <dd>Some CRCs return the reflection of the interim remainder (taking
  127. place <em>before</em> the final XOR value stage).
  128. </dl>
  129. <h2><a name="crc_basic">Theoretical CRC Computer</a></h2>
  130. <blockquote><pre>template &lt; std::size_t Bits &gt;
  131. class boost::crc_basic
  132. {
  133. public:
  134. // Type
  135. typedef <em>implementation_defined</em> value_type;
  136. // Constant reflecting template parameter
  137. static std::size_t const bit_count = Bits;
  138. // Constructor
  139. explicit crc_basic( value_type truncated_polynominal,
  140. value_type initial_remainder = 0, value_type final_xor_value = 0,
  141. bool reflect_input = false, bool reflect_remainder = false );
  142. // Internal Operations
  143. value_type get_truncated_polynominal() const;
  144. value_type get_initial_remainder() const;
  145. value_type get_final_xor_value() const;
  146. bool get_reflect_input() const;
  147. bool get_reflect_remainder() const;
  148. value_type get_interim_remainder() const;
  149. void reset( value_type new_rem );
  150. void reset();
  151. // External Operations
  152. void process_bit( bool bit );
  153. void process_bits( unsigned char bits, std::size_t bit_count );
  154. void process_byte( unsigned char byte );
  155. void process_block( void const *bytes_begin, void const *bytes_end );
  156. void process_bytes( void const *buffer, std::size_t byte_count );
  157. value_type checksum() const;
  158. };
  159. </pre></blockquote>
  160. <p>The <code>value_type</code> is the smallest built-in type that can
  161. hold the specified (by <code>Bits</code>) number of bits. This should
  162. be <code>boost::uint_t&lt;Bits&gt;::least</code>, see the <a
  163. href="../integer/doc/html/boost_integer/integer.html">documentation for integer type
  164. selection</a> for details.</p>
  165. <p>This implementation is slow since it computes its CRC the same way as
  166. in theory, bit by bit. No optimizations are performed. It wastes space
  167. since most of the CRC parameters are specified at run-time as
  168. constructor parameters.</p>
  169. <h2><a name="crc_optimal">Optimized CRC Computer</a></h2>
  170. <blockquote><pre>template &lt; std::size_t Bits, <em>impl_def</em> TruncPoly,
  171. <em>impl_def</em> InitRem, <em>impl_def</em> FinalXor,
  172. bool ReflectIn, bool ReflectRem &gt;
  173. class boost::crc_optimal
  174. {
  175. public:
  176. // Type
  177. typedef <em>implementation_defined</em> value_type;
  178. // Constants reflecting template parameters
  179. static std::size_t const bit_count = Bits;
  180. static value_type const truncated_polynominal = TruncPoly;
  181. static value_type const initial_remainder = InitRem;
  182. static value_type const final_xor_value = FinalXor;
  183. static bool const reflect_input = ReflectIn;
  184. static bool const reflect_remainder = ReflectRem;
  185. // Constructor
  186. explicit crc_optimal( value_type init_rem = InitRem );
  187. // Internal Operations
  188. value_type get_truncated_polynominal() const;
  189. value_type get_initial_remainder() const;
  190. value_type get_final_xor_value() const;
  191. bool get_reflect_input() const;
  192. bool get_reflect_remainder() const;
  193. value_type get_interim_remainder() const;
  194. void reset( value_type new_rem = InitRem );
  195. // External Operations
  196. void process_byte( unsigned char byte );
  197. void process_block( void const *bytes_begin, void const *bytes_end );
  198. void process_bytes( void const *buffer, std::size_t byte_count );
  199. value_type checksum() const;
  200. // Operators
  201. void operator ()( unsigned char byte );
  202. value_type operator ()() const;
  203. };
  204. </pre></blockquote>
  205. <p>The <code>value_type</code> is the quickest-to-manipulate built-in
  206. type that can hold at least the specified (by <code>Bits</code>) number
  207. of bits. This should be <code>boost::uint_t&lt;Bits&gt;::fast</code>.
  208. See the <a href="../integer/doc/html/boost_integer/integer.html">integer type selection
  209. documentation</a> for details. The <code>TruncPoly</code>,
  210. <code>InitRem</code>, and <code>FinalXor</code> template parameters also
  211. are of this type.</p>
  212. <p>This implementation is fast since it uses as many optimizations as
  213. practical. All of the CRC parameters are specified at compile-time as
  214. template parameters. No individual bits are considered; only whole
  215. bytes are passed. A table of interim CRC values versus byte values is
  216. pre-computed when the first object using a particular bit size,
  217. truncated polynominal, and input reflection state is processed.</p>
  218. <h2><a name="usage">Computer Usage</a></h2>
  219. <p>The two class templates have different policies on where the CRC's
  220. parameters go. Both class templates use the number of bits in the CRC
  221. as the first template parameter. The theoretical computer class
  222. template has the bit count as its only template parameter, all the other
  223. CRC parameters are entered through the constructor. The optimized
  224. computer class template obtains all its CRC parameters as template
  225. parameters, and instantiated objects are usually
  226. default-constructed.</p>
  227. <p>The CRC parameters can be inspected at run-time with the following
  228. member functions: <code>get_truncated_polynominal</code>,
  229. <code>get_initial_remainder</code>, <code>get_final_xor_value</code>,
  230. <code>get_reflect_input</code>, and <code>get_reflect_remainder</code>.
  231. The fast computer also provides compile-time constants for its CRC
  232. parameters.</p>
  233. <p>The <code>get_interim_remainder</code> member function returns the
  234. internal state of the CRC remainder. It represents the unreflected
  235. remainder of the last division. Saving an interim remainder allows the
  236. freezing of CRC processing, as long as the other CRC parameters and the
  237. current position of the bit stream are saved. Restarting a frozen
  238. stream involves constructing a new computer with the most of the old
  239. computer's parameters. The only change is to use the frozen remainder
  240. as the new computer's initial remainder. Then the interrupted bit
  241. stream can be fed as if nothing happened. The fast CRC computer has a
  242. special constructor that takes one argument, an interim remainder, for
  243. this purpose (overriding the initial remainder CRC parameter).</p>
  244. <p>The <code>reset</code> member functions reset the internal state of
  245. the CRC remainder to the given value. If no value is given, then the
  246. internal remainder is set to the initial remainder value when the object
  247. was created. The remainder must be unreflected. When a CRC calculation
  248. is finished, calling <code>reset</code> lets the object be reused for a
  249. new session.</p>
  250. <p>After any construction, both CRC computers work the same way.
  251. Feeding new data to a computer is in a seperate operation(s) from
  252. extracting the current CRC value from the computer. The following table
  253. lists the feeding and extracting operations.</p>
  254. <table cellpadding="5" border="1">
  255. <caption>Regular CRC Operations</caption>
  256. <tr>
  257. <th>Operation</th>
  258. <th>Description</th>
  259. </tr>
  260. <tr>
  261. <td><code>void process_bit( bool bit );</code></td>
  262. <td>Feeds the single <var>bit</var> to the computer, updating
  263. the interim CRC. It is only defined for the slow CRC
  264. computer.</td>
  265. </tr>
  266. <tr>
  267. <td><code>void process_bits( unsigned char bits, std::size_t
  268. bit_count );</code></td>
  269. <td>Acts as applying <code>process_bit</code> to the lowest
  270. <var>bit_count</var> bits given in <var>bits</var>, most
  271. significant relevant bit first. The results are undefined
  272. if <var>bit_count</var> exceeds the number of bits per byte.
  273. It is only defined for the slow CRC computer.</td>
  274. </tr>
  275. <tr>
  276. <td><code>void process_byte( unsigned char byte );</code></td>
  277. <td>Acts as applying <code>process_bit</code> to the all the
  278. bits in <var>byte</var>. If reflection is not desired, the
  279. bits are fed from the most to least significant. The bits
  280. are fed in the opposite order if reflection is desired.</td>
  281. </tr>
  282. <tr>
  283. <td><code>void process_block( void const *bytes_begin, void
  284. const *bytes_end );</code></td>
  285. <td>Acts as applying <code>process_byte</code> to each byte in
  286. the given memory block. This memory block starts at
  287. <var>bytes_begin</var> and finishes before
  288. <var>bytes_end</var>. The bytes are processed in that
  289. order.</td>
  290. </tr>
  291. <tr>
  292. <td><code>void process_bytes( void const *buffer, std::size_t
  293. byte_count );</code></td>
  294. <td>Acts as applying <code>process_byte</code> to each byte in
  295. the given memory block. This memory block starts at
  296. <var>buffer</var> and lasts for <var>byte_count</var> bytes.
  297. The bytes are processed in ascending order.</td>
  298. </tr>
  299. <tr>
  300. <td><code>value_type checksum() const;</code></td>
  301. <td>Returns the CRC checksum of the data passed in so far,
  302. possibly after applying the remainder-reflection and
  303. exclusive-or operations.</td>
  304. </tr>
  305. <tr>
  306. <td><code>void operator ()( unsigned char byte );</code></td>
  307. <td>Calls <code>process_byte</code>. This member function lets
  308. its object act as a (stateful) function object. It is only
  309. defined for the fast CRC computer.</td>
  310. </tr>
  311. <tr>
  312. <td><code>value_type operator ()() const;</code></td>
  313. <td>Calls <code>checksum</code>. This member function lets
  314. its object act as a generator function object. It is only
  315. defined for the fast CRC computer.</td>
  316. </tr>
  317. </table>
  318. <p>You can use them like this:</p>
  319. <blockquote><pre>#include &lt;boost/crc.hpp&gt; <i>// for boost::crc_basic, boost::crc_optimal</i>
  320. #include &lt;boost/cstdint.hpp&gt; <i>// for boost::uint16_t</i>
  321. #include &lt;algorithm&gt; <i>// for std::for_each</i>
  322. #include &lt;cassert&gt; <i>// for assert</i>
  323. #include &lt;cstddef&gt; <i>// for std::size_t</i>
  324. #include &lt;iostream&gt; <i>// for std::cout</i>
  325. #include &lt;ostream&gt; <i>// for std::endl</i>
  326. // Main function
  327. int
  328. main ()
  329. {
  330. // This is "123456789" in ASCII
  331. unsigned char const data[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  332. 0x38, 0x39 };
  333. std::size_t const data_len = sizeof( data ) / sizeof( data[0] );
  334. // The expected CRC for the given data
  335. boost::uint16_t const expected = 0x29B1;
  336. // Simulate CRC-CCITT
  337. boost::crc_basic&lt;16&gt; crc_ccitt1( 0x1021, 0xFFFF, 0, false, false );
  338. crc_ccitt1.process_bytes( data, data_len );
  339. assert( crc_ccitt1.checksum() == expected );
  340. // Repeat with the optimal version (assuming a 16-bit type exists)
  341. boost::crc_optimal&lt;16, 0x1021, 0xFFFF, 0, false, false&gt; crc_ccitt2;
  342. crc_ccitt2 = std::for_each( data, data + data_len, crc_ccitt2 );
  343. assert( crc_ccitt2() == expected );
  344. std::cout &lt;&lt; "All tests passed." &lt;&lt; std::endl;
  345. return 0;
  346. }
  347. </pre></blockquote>
  348. <h2><a name="crc_func">CRC Function</a></h2>
  349. <blockquote><pre>template &lt; std::size_t Bits, <em>impl_def</em> TruncPoly,
  350. <em>impl_def</em> InitRem, <em>impl_def</em> FinalXor,
  351. bool ReflectIn, bool ReflectRem &gt;
  352. typename boost::uint_t&lt;Bits&gt;::fast
  353. boost::crc( void const *buffer, std::size_t byte_count );
  354. </pre></blockquote>
  355. <p>The <code>boost::crc</code> function template computes the CRC of a
  356. given data block. The data block starts at the address given by
  357. <var>buffer</var> and lasts for <var>byte_count</var> bytes. The CRC
  358. parameters are passed through template arguments, identical to the
  359. optimized CRC computer (<a href="#crc_optimal">see above</a>). In fact,
  360. such a computer is used to implement this function.</p>
  361. <h2><a name="a_crc_func">Augmented-CRC Function</a></h2>
  362. <blockquote><pre>template &lt; std::size_t Bits, <em>impl_def</em> TruncPoly &gt;
  363. typename boost::uint_t&lt;Bits&gt;::fast
  364. boost::augmented_crc( void const *buffer, std::size_t byte_count,
  365. typename boost::uint_t&lt;Bits&gt;::fast initial_remainder = 0u );
  366. </pre></blockquote>
  367. <p>All the other CRC-computing function or class templates work assuming
  368. that the division steps start immediately on the first message bits.
  369. The <code>boost::augmented_crc</code> function template has a
  370. different division order. Instead of combining (<i>via</i> bitwise
  371. exclusive-or) the current message bit with the highest bit of a separate
  372. remainder, these templates shift a new message bit into the low bit of a
  373. remainder register as the highest bit is shifted out. The new method
  374. means that the bits in the inital remainder value are processed before
  375. any of the actual message bits are processed. To compensate, the real
  376. CRC can only be extracted after feeding enough zero bits (the same count
  377. as the register size) after the message bits.</p>
  378. <p>The template parameters of the function template are
  379. the CRC's bit size (<code>Bits</code>) and the truncated polynominal
  380. (<code>TruncPoly</code>). The function parameters are the starting address of
  381. the data block to be worked on (<var>buffer</var>), the number of bytes in that
  382. data block (<var>byte_count</var>), and the incoming value of the remainder
  383. (<var>initial_remainder</var>). That last parameter defaults to zero if it is
  384. ommitted.</p>
  385. <p>This function template is useful if the bytes of the CRC directly
  386. follow the message's bytes. First, set the bytes of where the CRC will
  387. go to zero. Then use <code>augmented_crc</code> over the augmented
  388. message, <i>i.e.</i> the message bytes and the appended CRC bytes. Then
  389. assign the result to the CRC. To later check a received message, either
  390. use <code>augmented_crc</code> (with the same parameters as
  391. transmission, of course) on the received <em>unaugmented</em> message
  392. and check if the result equals the CRC, or use
  393. <code>augmented_crc</code> on the received <em>augmented</em> message
  394. and check if the result equals zero. Note that the CRC has to be stored
  395. with the more-significant bytes first (big-endian).</p>
  396. <p>Interruptions in the CRC data can be handled by feeding the result of
  397. <code>augmented_crc</code> of the previous data block as the
  398. <var>initial_remainder</var> when calling <code>augmented_crc</code> on
  399. the next data block. Remember that the actual CRC can only be
  400. determined after feeding the augmented bytes. Since this method uses
  401. modulo-2 polynominal division at its most raw, neither final XOR values
  402. nor reflection can be used.</p>
  403. <p>Note that for the same CRC system, the initial remainder for
  404. augmented message method will be different than for the unaugmented
  405. message method. The main exception is zero; if the augmented-CRC
  406. algorithm uses a zero initial remainder, the equivalent unaugmented-CRC
  407. algorithm will also use a zero initial remainder. Given an initial
  408. remainder for a augmented-CRC algorithm, the result from processing just
  409. zero-valued CRC bytes without any message bytes is the equivalent inital
  410. remainder for the unaugmented-CRC algorithm. An example follows:</p>
  411. <blockquote><pre>#include &lt;boost/crc.hpp&gt; <i>// for boost::crc_basic, boost::augmented_crc</i>
  412. #include &lt;boost/cstdint.hpp&gt; <i>// for boost::uint16_t</i>
  413. #include &lt;cassert&gt; <i>// for assert</i>
  414. #include &lt;iostream&gt; <i>// for std::cout</i>
  415. #include &lt;ostream&gt; <i>// for std::endl</i>
  416. // Main function
  417. int
  418. main ()
  419. {
  420. using boost::uint16_t;
  421. using boost::augmented_crc;
  422. uint16_t data[6] = { 2, 4, 31, 67, 98, 0 };
  423. uint16_t const init_rem = 0x123;
  424. uint16_t crc1 = augmented_crc&lt;16, 0x8005&gt;( data, sizeof(data), init_rem );
  425. uint16_t const zero = 0;
  426. uint16_t const new_init_rem = augmented_crc&lt;16, 0x8005&gt;( &amp;zero, sizeof(zero) );
  427. boost::crc_basic&lt;16&gt; crc2( 0x8005, new_init_rem );
  428. crc2.process_block( data, &amp;data[5] ); // don't include CRC
  429. assert( crc2.checksum() == crc1 );
  430. std::cout &lt;&lt; "All tests passed." &lt;&lt; std::endl;
  431. return 0;
  432. }
  433. </pre></blockquote>
  434. <h2><a name="crc_ex">Pre-Defined CRC Samples</a></h2>
  435. <p>Four sample CRC types are given, representing several common CRC
  436. algorithms. For example, computations from <code>boost::crc_32_type</code>
  437. can be used for implementing the PKZip standard. Note that, in general, this
  438. library is concerned with CRC implementation, and not with determining
  439. &quot;good&quot; sets of CRC parameters.</p>
  440. <table cellpadding="5" border="1">
  441. <caption>Common CRCs</caption>
  442. <tr>
  443. <th>Algorithm</th>
  444. <th>Example Protocols</th>
  445. </tr>
  446. <tr>
  447. <td><code>crc_16_type</code></td>
  448. <td>BISYNCH, ARC</td>
  449. </tr>
  450. <tr>
  451. <td><code>crc_ccitt_type</code></td>
  452. <td>designated by CCITT (Comit&eacute; Consultatif International
  453. T&eacute;l&eacute;graphique et T&eacute;l&eacute;phonique)</td>
  454. </tr>
  455. <tr>
  456. <td><code>crc_xmodem_type</code></td>
  457. <td>XMODEM</td>
  458. </tr>
  459. <tr>
  460. <td><code>crc_32_type</code></td>
  461. <td>PKZip, AUTODIN II, Ethernet, FDDI</td>
  462. </tr>
  463. </table>
  464. <hr>
  465. <h2><a name="references">References</a></h2>
  466. <ul>
  467. <li>The CRC header itself: <cite><a href="../../boost/crc.hpp">crc.hpp</a></cite>
  468. <li>Some test code: <cite><a href="test/crc_test.cpp">crc_test.cpp</a></cite>
  469. <li>Some example code: <cite><a href="crc_example.cpp">crc_example.cpp</a></cite>
  470. </ul>
  471. <h2><a name="credits">Credits</a></h2>
  472. <h3><a name="contributors">Contributors</a></h3>
  473. <dl>
  474. <dt>Michael Barr (<a
  475. href="mailto:mbarr@netrino.com">mbarr@netrino.com</a>)
  476. <dd>Wrote <a
  477. href="http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code">CRC
  478. Implementation Code in C</a>, a less-confusing guide to implementing CRC
  479. algorithms. (Originally published as &quot;Slow and Steady
  480. Never Lost the Race&quot; in the January 2000 issue of <cite><a
  481. href="http://www.embedded.com/">Embedded Systems
  482. Programming</a></cite>, pages 37&ndash;46. The web version used to be
  483. known as <cite><a href="http://www.netrino.com/Connecting/2000-01/">Easier
  484. Said Than Done</a></cite>.)
  485. <dt>Daryle Walker
  486. <dd>Started the library and contributed the theoretical and optimal
  487. CRC computation class templates and the CRC computing function
  488. template. Contributed <cite><a
  489. href="test/crc_test.cpp">crc_test.cpp</a></cite> and <cite><a
  490. href="crc_example.cpp">crc_example.cpp</a></cite>.
  491. <dt>Ross N. Williams
  492. <dd>Wrote <cite><a href="http://www.ross.net/crc/crcpaper.html">A
  493. Painless Guide to CRC Error Detection Algorithms</a></cite>, a
  494. definitive source of CRC information.
  495. </dl>
  496. <h3><a name="acknowledgements">Acknowledgements</a></h3>
  497. <p>For giving advice on compiler/C++ compliance, implementation,
  498. interface, algorithms, and bug reports:</p>
  499. <ul>
  500. <li>Darin Adler</li>
  501. <li>Beman Dawes</li>
  502. <li>Doug Gregor</li>
  503. <li>John Maddock</li>
  504. <li>Joe Mariadassou</li>
  505. <li>Jens Maurer</li>
  506. <li>Vladimir Prus</li>
  507. <li>Joel Young</li>
  508. </ul>
  509. <h3><a name="history">History</a></h3>
  510. <dl>
  511. <dt>18 Dec 2011, Daryle Walker
  512. <dd>Folded the two versions of <code>boost::augmented_crc</code> together.
  513. <dt>15 Jun 2003, Daryle Walker
  514. <dd>Added example program.
  515. <dt>14 May 2001, Daryle Walker
  516. <dd>Initial version.
  517. </dl>
  518. <hr>
  519. <p>Revised: 18 December 2011</p>
  520. <p>Copyright 2001, 2003, 2011 Daryle Walker. Use, modification, and distribution
  521. are subject to the Boost Software License, Version 1.0. (See accompanying
  522. file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at
  523. &lt;<a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>&gt;.)</p>
  524. </body>
  525. </html>