Files
ternfs-XTXMarkets/cpp/crc32c/crc32c.h
Francesco Mazzoli 110705db8d EggsFS -> TernFS rename
Things not done because probably disruptive:

* kmod filesystem string
* sysctl/debugfs/trace
* metrics names
* xmon instance names

Some of these might be renamed too, but starting with a relatively
safe set.
2025-09-03 09:29:53 +01: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 TERN_CRC32C
#define TERN_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