1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-23 21:10:57 +01:00

util/crc.c: Add simple CRC-32 implementation

This commit is contained in:
Tau 2018-11-08 10:20:21 -05:00
parent 920328bc9e
commit 7cf0914092
3 changed files with 36 additions and 0 deletions

28
util/crc.c Normal file
View File

@ -0,0 +1,28 @@
#include <stddef.h>
#include <stdint.h>
#include "util/crc.h"
uint32_t crc32(const void *src, size_t nbytes, uint32_t in)
{
const uint8_t *bytes;
uint32_t crc;
size_t i;
bytes = src;
crc = ~in;
for (i = 0 ; i < nbytes * 8 ; i++) {
if (i % 8 == 0) {
crc ^= *bytes++;
}
if (crc & 1) {
crc = (crc >> 1) ^ 0xEDB88320;
} else {
crc = (crc >> 1);
}
}
return ~crc;
}

6
util/crc.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
uint32_t crc32(const void *src, size_t nbytes, uint32_t in);

View File

@ -7,6 +7,8 @@ util_lib = static_library(
capnhook.get_variable('hook_dep'), capnhook.get_variable('hook_dep'),
], ],
sources : [ sources : [
'crc.c',
'crc.h',
'dprintf.c', 'dprintf.c',
'dprintf.h', 'dprintf.h',
'setupapi.c', 'setupapi.c',