crc32.h#

#include <sif/utils/crc32.h>
SIF_UTILS_CRC32_H#

CRC32 checksum, used to validate the .xfield and .xgrid formats.

Two ways in. sif_crc32() checksums one buffer and is the whole story for a caller with contiguous data. The running form – #SIF_CRC32_INIT, sif_crc32_update(), sif_crc32_final() – chains several buffers into one checksum, which is what the binary writers need: a field’s coordinates, velocities and weights live in separate allocations but are one payload.

uint32_t sif_crc32(const void *data, size_t length)#

Compute the CRC32 checksum of a data buffer.

Uses the standard IEEE 802.3 polynomial (0xEDB88320), table-driven, one byte per iteration.

Parameters:
  • data – Buffer to checksum.

  • length – Size of the buffer, in bytes.

Returns:

The 32-bit checksum. A zero-length buffer checksums to 0.

Note

This is an error-detecting code, not a cryptographic hash: it says whether bytes changed in transit, not whether someone changed them on purpose.

SIF_CRC32_INIT#

Starting value for a running checksum.

uint32_t sif_crc32_update(uint32_t crc, const void *data, size_t length)#

Fold another buffer into a running checksum.

Order matters: the same buffers folded in a different order give a different checksum, so a reader has to walk the payload exactly as the writer did.

Parameters:
  • crc – Running value, starting from #SIF_CRC32_INIT.

  • data – Buffer to fold in.

  • length – Size of the buffer, in bytes.

Returns:

The updated running value, which is not yet a checksum – pass it to sif_crc32_final().

uint32_t sif_crc32_final(uint32_t crc)#

Turn a running value into the checksum.

Parameters:
  • crc – Running value from sif_crc32_update().

Returns:

The 32-bit checksum.