Initial commit
This commit is contained in:
24
game_payload/include/crc32.h
Normal file
24
game_payload/include/crc32.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
// Modified from https://stackoverflow.com/a/27950866
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* CRC-32C (iSCSI) polynomial in reversed bit order. */
|
||||
#define __POLY 0x82f63b78
|
||||
|
||||
static inline uint32_t crc32c(uint32_t crc, const unsigned char *buf, size_t len) {
|
||||
crc = ~crc;
|
||||
|
||||
while (len--) {
|
||||
crc ^= *buf++;
|
||||
for (int k = 0; k < 8; k++) {
|
||||
crc = crc & 1 ? (crc >> 1) ^ __POLY : crc >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
#undef __POLY
|
||||
Reference in New Issue
Block a user