]> git.ozlabs.org Git - ccan/blob - ccan/crc32c/crc32c.h
ccan/crc32c: new module for accelerated CRC32 (on x86-64).
[ccan] / ccan / crc32c / crc32c.h
1 /* Licensed under MIT - see LICENSE file for details */
2 #ifndef CCAN_CRC32C_H
3 #define CCAN_CRC32C_H
4 #include <stdint.h>
5 #include <stdlib.h>
6
7 /**
8  * crc32c - Castagnoli 32 bit crc of string of bytes
9  * @start_crc: the initial crc (usually 0)
10  * @buf: pointer to bytes
11  * @size: length of buffer
12  *
13  * If you don't know what crc32 to use, use this one: it's the best.
14  *
15  * @Article{castagnoli-crc,
16  * author =       { Guy Castagnoli and Stefan Braeuer and Martin Herrman},
17  * title =        {{Optimization of Cyclic Redundancy-Check Codes with 24
18  *                 and 32 Parity Bits}},
19  * journal =      IEEE Transactions on Communication,
20  * year =         {1993},
21  * volume =       {41},
22  * number =       {6},
23  * pages =        {},
24  * month =        {June},
25  *}
26  * 32 bit CRC checksum using polynomial
27  * X^32+X^28+X^27+X^26+X^25+X^23+X^22+X^20+X^19+X^18+X^14+X^13+X^11+X^10+X^9+X^8+X^6+X^0.
28  *
29  * You can calculate the CRC of non-contiguous arrays by passing @start_crc
30  * as 0 the first time, and the current crc result from then on.
31  *
32  * Example:
33  *      #include <sys/uio.h>
34  *      ...
35  *      // Check that iovec has the crc we expect (Castagnoli version)
36  *      static bool check_crc(uint32_t expected, const struct iovec *iov, int l)
37  *      {
38  *              uint32_t crc = 0;
39  *              while (l >= 0) {
40  *                      crc = crc32c(crc, iov->iov_base, iov->iov_len);
41  *                      iov++;
42  *              }
43  *              return crc == expected;
44  *      }
45  */
46 uint32_t crc32c(uint32_t start_crc, const void *buf, size_t size);
47
48 #endif /* CCAN_CRC32C_H */