1 | // Author: Hal Finkel |
---|
2 | |
---|
3 | #ifndef CRC64_H |
---|
4 | #define CRC64_H |
---|
5 | |
---|
6 | #include <stdlib.h> |
---|
7 | #include <stdint.h> |
---|
8 | |
---|
9 | /* |
---|
10 | * These functions compute the CRC-64 checksum on a block of data |
---|
11 | * and provide a way to combine the checksums on two blocks of data. |
---|
12 | * For more information, see: |
---|
13 | * http://en.wikipedia.org/wiki/Computation_of_CRC |
---|
14 | * http://checksumcrc.blogspot.com/2011/12/should-you-use-crc-or-checksum.html |
---|
15 | * http://crcutil.googlecode.com/files/crc-doc.1.0.pdf |
---|
16 | * http://www.ross.net/crc/download/crc_v3.txt |
---|
17 | * This implementation uses the ECMA-182 polynomial with -1 initialization, and |
---|
18 | * computes the bit-reversed CRC. |
---|
19 | */ |
---|
20 | |
---|
21 | #ifdef __cplusplus |
---|
22 | extern "C" { |
---|
23 | #endif |
---|
24 | |
---|
25 | /* |
---|
26 | * Calculate the CRC64 of the provided buffer using the slow reference |
---|
27 | * implementation (in serial). |
---|
28 | */ |
---|
29 | uint64_t crc64_slow(const void *input, size_t nbytes); |
---|
30 | |
---|
31 | /* |
---|
32 | * Calculate the CRC64 of the provided buffer (in serial). |
---|
33 | */ |
---|
34 | uint64_t crc64(const void *input, size_t nbytes); |
---|
35 | |
---|
36 | /* |
---|
37 | * Calculate the CRC64 of the provided buffer, in parallel if possible. |
---|
38 | */ |
---|
39 | uint64_t crc64_omp(const void *input, size_t nbytes); |
---|
40 | |
---|
41 | /* |
---|
42 | * Calculate the 'check bytes' for the provided CRC64. If these bytes are |
---|
43 | * appended to the original buffer, then the new total CRC64 should be -1. |
---|
44 | */ |
---|
45 | void crc64_invert(uint64_t cs, void *buffer); |
---|
46 | |
---|
47 | /* |
---|
48 | * Given the CRC64 of the first part of a buffer, and the CRC64 and length of |
---|
49 | * the second part of a buffer, calculate the CRC64 of the complete buffer. |
---|
50 | */ |
---|
51 | uint64_t crc64_combine(uint64_t cs1, uint64_t cs2, size_t nbytes2); |
---|
52 | |
---|
53 | #ifdef __cplusplus |
---|
54 | } |
---|
55 | #endif |
---|
56 | |
---|
57 | #endif // CRC64_H |
---|
58 | |
---|