Files
ternfs-XTXMarkets/cpp/crc32c/crc32c.h
T
Francesco Mazzoli 5bff9b8fae Many, many changes -- tests pass, but FUSE is currently not present
The main thing that's added is full RS support, but a lot of things
were rejigged along the way. The tests are still a bit lacking,
and will be augmented in future commits.
2023-03-03 16:42:22 +00:00

43 lines
1.3 KiB
C

// Computes the CRC32C (C = "Castagnoli" polynomial, also used in iSCSI)
//
// As usual, the CRC is initialized with -1, and xor'd with -1 at the end.
// Since we provide `crc32c` so that the CRC can be computed incrementally,
// we just invert the crc at the beginning and at the end.
//
// See <https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks#CRC_variants>.
#ifndef EGGS_CRC32C
#define EGGS_CRC32C
#include <stdint.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
// Initialize crc with 0.
uint32_t crc32c(uint32_t crc, const char* buf, size_t len);
// Computes the CRC32C of the XOR between two equally long
// strings, given their crcs and their length.
uint32_t crc32c_xor(uint32_t crc1, uint32_t crc2, size_t len);
// Computes the CRC32C of the concatenation of two strings, given
// their crcs and the length of the second string.
uint32_t crc32c_append(uint32_t crc1, uint32_t crc2, size_t len2);
// Computes the CRC32C that you'd get by doing
//
// char* zero_bytes = (char*)malloc(zeros);
// memset(zero_bytes, 0, zeros);
// crc = crc32c(crc, zero_bytes, zeros);
//
// `zeros` can be negative, in which case this "undoes" `zeros`
// zeroes.
uint32_t crc32c_zero_extend(uint32_t crc, ssize_t zeros);
#ifdef __cplusplus
}
#endif
#endif