1 | // ***************************************************************************** |
---|
2 | // Copyright (C) 2014, UChicago Argonne, LLC |
---|
3 | // All Rights Reserved |
---|
4 | // High-Performance CRC64 Library |
---|
5 | // Developer: Hal Finkel, LCF Division |
---|
6 | // |
---|
7 | // OPEN SOURCE LICENSE |
---|
8 | // |
---|
9 | // Redistribution and use in source and binary forms, with or without |
---|
10 | // modification, are permitted provided that the following conditions are met: |
---|
11 | // |
---|
12 | // 1. Redistributions of source code must retain the above copyright notice, this |
---|
13 | // list of conditions and the following disclaimer. Software changes, |
---|
14 | // modifications, or derivative works, should be noted with comments and the |
---|
15 | // author and organization's name. |
---|
16 | // |
---|
17 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
18 | // this list of conditions and the following disclaimer in the documentation |
---|
19 | // and/or other materials provided with the distribution. |
---|
20 | // |
---|
21 | // 3. Neither the names of UChicago Argonne, LLC or the Department of Energy nor |
---|
22 | // the names of its contributors may be used to endorse or promote products |
---|
23 | // derived from this software without specific prior written permission. |
---|
24 | // |
---|
25 | // 4. The software and the end-user documentation included with the |
---|
26 | // redistribution, if any, must include the following acknowledgment: |
---|
27 | // |
---|
28 | // "This product includes software produced by UChicago Argonne, LLC under |
---|
29 | // Contract No. DE-AC02-06CH11357 with the Department of Energy." |
---|
30 | // |
---|
31 | // ***************************************************************************** |
---|
32 | // DISCLAIMER |
---|
33 | // |
---|
34 | // THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND. |
---|
35 | // |
---|
36 | // NEITHER THE UNITED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT OF |
---|
37 | // ENERGY, NOR UCHICAGO ARGONNE, LLC, NOR ANY OF THEIR EMPLOYEES, MAKES ANY |
---|
38 | // WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY |
---|
39 | // FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, DATA, |
---|
40 | // APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT |
---|
41 | // INFRINGE PRIVATELY OWNED RIGHTS. |
---|
42 | // |
---|
43 | // ***************************************************************************** |
---|
44 | |
---|
45 | #ifndef CRC64_H |
---|
46 | #define CRC64_H |
---|
47 | |
---|
48 | #include <stdlib.h> |
---|
49 | #include <stdint.h> |
---|
50 | |
---|
51 | /* |
---|
52 | * These functions compute the CRC-64 checksum on a block of data |
---|
53 | * and provide a way to combine the checksums on two blocks of data. |
---|
54 | * For more information, see: |
---|
55 | * http://en.wikipedia.org/wiki/Computation_of_CRC |
---|
56 | * http://checksumcrc.blogspot.com/2011/12/should-you-use-crc-or-checksum.html |
---|
57 | * http://crcutil.googlecode.com/files/crc-doc.1.0.pdf |
---|
58 | * http://www.ross.net/crc/download/crc_v3.txt |
---|
59 | * This implementation uses the ECMA-182 polynomial with -1 initialization, and |
---|
60 | * computes the bit-reversed CRC. |
---|
61 | */ |
---|
62 | |
---|
63 | #ifdef __cplusplus |
---|
64 | extern "C" { |
---|
65 | #endif |
---|
66 | |
---|
67 | /* |
---|
68 | * Calculate the CRC64 of the provided buffer using the slow reference |
---|
69 | * implementation (in serial). |
---|
70 | */ |
---|
71 | uint64_t crc64_slow(const void *input, size_t nbytes); |
---|
72 | |
---|
73 | /* |
---|
74 | * Calculate the CRC64 of the provided buffer (in serial). |
---|
75 | */ |
---|
76 | uint64_t crc64(const void *input, size_t nbytes); |
---|
77 | |
---|
78 | /* |
---|
79 | * Calculate the CRC64 of the provided buffer, in parallel if possible. |
---|
80 | */ |
---|
81 | uint64_t crc64_omp(const void *input, size_t nbytes); |
---|
82 | |
---|
83 | /* |
---|
84 | * Calculate the 'check bytes' for the provided CRC64. If these bytes are |
---|
85 | * appended to the original buffer, then the new total CRC64 should be -1. |
---|
86 | */ |
---|
87 | void crc64_invert(uint64_t cs, void *check_bytes); |
---|
88 | |
---|
89 | /* |
---|
90 | * Given the CRC64 of the first part of a buffer, and the CRC64 and length of |
---|
91 | * the second part of a buffer, calculate the CRC64 of the complete buffer. |
---|
92 | */ |
---|
93 | uint64_t crc64_combine(uint64_t cs1, uint64_t cs2, size_t nbytes2); |
---|
94 | |
---|
95 | #ifdef __cplusplus |
---|
96 | } |
---|
97 | #endif |
---|
98 | |
---|
99 | #endif // CRC64_H |
---|
100 | |
---|