|
libclod
C library for interacting with NBTs, region files, LOD data and other things.
|
Classes | |
| struct | clod_sip64_state |
Macros | |
| #define | clod_sip64_init(seed) |
| #define | clod_sip64(seed, data, size) |
| #define | clod_crc64_init() |
| #define | clod_crc64_add_at(crc, data, data_size, offset) |
| #define | clod_crc64_finalise(crc) |
| #define | clod_crc64(data, size) |
| #define | clod_crc32_init() |
| #define | clod_crc32_add_at(crc, data, data_size, offset) |
| #define | clod_crc32_finalise(crc) |
| #define | clod_crc32(data, size) |
| #define | clod_crc24_init() |
| #define | clod_crc24_add_at(crc, data, data_size, offset) |
| #define | clod_crc24_finalise(crc) |
| #define | clod_crc24(data, size) |
| #define | clod_crc16_init() |
| #define | clod_crc16_add_at(crc, data, data_size, offset) |
| #define | clod_crc16_finalise(crc) |
| #define | clod_crc16(data, size) |
| #define | clod_crc8_init() |
| #define | clod_crc8_add_at(crc, data, data_size, offset) |
| #define | clod_crc8_finalise(crc) |
| #define | clod_crc8(data, size) |
Functions | |
| clod_sip64_state | clod_sip64_add (clod_sip64_state state, const void *data, size_t size) |
| uint64_t | clod_sip64_finalise (clod_sip64_state state) |
| uint64_t | clod_crc64_add (uint64_t crc, const void *data, size_t data_len) |
| uint32_t | clod_crc32_add (uint32_t crc, const void *data, size_t data_len) |
| uint32_t | clod_crc24_add (uint32_t crc, const void *data, size_t data_len) |
| uint16_t | clod_crc16_add (uint16_t crc, const void *data, size_t data_len) |
| uint8_t | clod_crc8_add (uint8_t crc, const void *data, size_t data_len) |
The general idea is each hash method provides an init/add/finalise method. Initialisation creates a hash state which is initialised to some constant optionally including a seed value. Adding is the meat of the implementation and updates the state with new data. Finalisation parses the state to produce a final output. In the case of CRC, finalisation is a single xor with a constant, which can be undone to produce the hash state as it was before finalisation by simply performing finalisation a second time.
The CRC methods use lookup tables. See libclod/src/hash/crc_tables_generate.c for how they are generated, and libclod/src/hash/crc.c for how they are used.
Often, using streaming methods is an annoying complexity, so a method for computing the checksum of a single blob of data is provided.
In addition, the crc add methods can be provided a null data argument to skip the crc ahead so many bytes. This enables some fun gymnastics such as the offset add methods. One can create a crc for some large data set without actually reading or hashing it, and then add different parts of the data later - sparse data sets can be hashed efficiently.
Or, an already computed crc can be updated when a small portion of the original data is modified without needing to hash anything other than the modified section.
| #define clod_sip64_init | ( | seed | ) |
Initialise the hash state.
| [in] | seed | Seed value for the hash |
| #define clod_sip64 | ( | seed, | |
| data, | |||
| size ) |
One-shot a SipHash result.
This is a modified variant of SipHash to support streaming, so results will be incompatible with the reference implementation.
| [in] | seed | Seed value for the hash |
| [in] | data | Value to be hashed |
| [in] | size | Size of data |
| #define clod_crc64_init | ( | ) |
| #define clod_crc64_add_at | ( | crc, | |
| data, | |||
| data_size, | |||
| offset ) |
Add data to the hash state at an offset. The added data is conceptually xored with any existing data.
| [in] | crc | Hash state |
| [in] | data | The data to add to the hash state |
| [in] | data_size | The size of data |
| [in] | offset | The offset of data from the end of the hashed data |
| #define clod_crc64_finalise | ( | crc | ) |
| #define clod_crc64 | ( | data, | |
| size ) |
One-shot a crc64 hash.
| [in] | data | Data to hash |
| [in] | size | Size of data |
| #define clod_crc32_init | ( | ) |
| #define clod_crc32_add_at | ( | crc, | |
| data, | |||
| data_size, | |||
| offset ) |
Add data to the hash state at an offset. The added data is conceptually xored with any existing data.
| [in] | crc | Hash state |
| [in] | data | The data to add to the hash state |
| [in] | data_size | The size of data |
| [in] | offset | The offset of data from the end of the hashed data |
| #define clod_crc32_finalise | ( | crc | ) |
| #define clod_crc32 | ( | data, | |
| size ) |
One-shot a crc32 hash.
| [in] | data | Data to hash |
| [in] | size | Size of data |
| #define clod_crc24_init | ( | ) |
| #define clod_crc24_add_at | ( | crc, | |
| data, | |||
| data_size, | |||
| offset ) |
Add data to the hash state at an offset. The added data is conceptually xored with any existing data.
| [in] | crc | Hash state |
| [in] | data | The data to add to the hash state |
| [in] | data_size | The size of data |
| [in] | offset | The offset of data from the end of the hashed data |
| #define clod_crc24_finalise | ( | crc | ) |
| #define clod_crc24 | ( | data, | |
| size ) |
One-shot a crc24 hash.
| [in] | data | Data to hash |
| [in] | size | Size of data |
| #define clod_crc16_init | ( | ) |
| #define clod_crc16_add_at | ( | crc, | |
| data, | |||
| data_size, | |||
| offset ) |
Add data to the hash state at an offset. The added data is conceptually xored with any existing data.
| [in] | crc | Hash state |
| [in] | data | The data to add to the hash state |
| [in] | data_size | The size of data |
| [in] | offset | The offset of data from the end of the hashed data |
| #define clod_crc16_finalise | ( | crc | ) |
| #define clod_crc16 | ( | data, | |
| size ) |
One-shot a crc16 hash.
| [in] | data | Data to hash |
| [in] | size | Size of data |
| #define clod_crc8_init | ( | ) |
| #define clod_crc8_add_at | ( | crc, | |
| data, | |||
| data_size, | |||
| offset ) |
Add data to the hash state at an offset. The added data is conceptually xored with any existing data.
| [in] | crc | Hash state |
| [in] | data | The data to add to the hash state |
| [in] | data_size | The size of data |
| [in] | offset | The offset of data from the end of the hashed data |
| #define clod_crc8_finalise | ( | crc | ) |
| #define clod_crc8 | ( | data, | |
| size ) |
One-shot a crc8 hash.
| [in] | data | Data to hash |
| [in] | size | Size of data |
| clod_sip64_state clod_sip64_add | ( | clod_sip64_state | state, |
| const void * | data, | ||
| size_t | size ) |
Add data to a SipHash state.
This is a modified variant of SipHash to support streaming, so results will be incompatible with the reference implementation.
| [in] | state | Hash state |
| [in] | data | Value to be hashed |
| [in] | size | Size of data |
| uint64_t clod_sip64_finalise | ( | clod_sip64_state | state | ) |
| uint64_t clod_crc64_add | ( | uint64_t | crc, |
| const void * | data, | ||
| size_t | data_len ) |
Add data to the hash state. If data is null it functions as if data was zeroed, but can skip almost all the work.
Polynomial: 0x42F0E1EBA9EA3693 Reflected: false
| [in] | crc | Hash state |
| [in] | data | (nullable) Data to add to hash state |
| [in] | data_len | Size of data |
| uint32_t clod_crc32_add | ( | uint32_t | crc, |
| const void * | data, | ||
| size_t | data_len ) |
Add data to the hash state. If data is null it functions as if data was zeroed, but can skip almost all the work.
This method uses CPU intrinsics for CRC generation when possible.
Polynomial: 0x1EDC6F41 Reflected: true
| [in] | crc | Hash state |
| [in] | data | (nullable) Data to add to hash state |
| [in] | data_len | Size of data |
| uint32_t clod_crc24_add | ( | uint32_t | crc, |
| const void * | data, | ||
| size_t | data_len ) |
Add data to the hash state. If data is null it functions as if data was zeroed, but can skip almost all the work.
Polynomial: 0x864CFB Reflected: false
| [in] | crc | Hash state |
| [in] | data | (nullable) Data to add to hash state |
| [in] | data_len | Size of data |
| uint16_t clod_crc16_add | ( | uint16_t | crc, |
| const void * | data, | ||
| size_t | data_len ) |
Add data to the hash state. If data is null it functions as if data was zeroed, but can skip almost all the work.
Polynomial: 0x1021 Reflected: true
| [in] | crc | Hash state |
| [in] | data | (nullable) Data to add to hash state |
| [in] | data_len | Size of data |
| uint8_t clod_crc8_add | ( | uint8_t | crc, |
| const void * | data, | ||
| size_t | data_len ) |
Add data to the hash state. If data is null it functions as if data was zeroed, but can skip almost all the work.
Polynomial: 0x7 Reflected: false
| [in] | crc | Hash state |
| [in] | data | (nullable) Data to add to hash state |
| [in] | data_len | Size of data |