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:
parent
920328bc9e
commit
7cf0914092
28
util/crc.c
Normal file
28
util/crc.c
Normal 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
6
util/crc.h
Normal 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);
|
@ -7,6 +7,8 @@ util_lib = static_library(
|
||||
capnhook.get_variable('hook_dep'),
|
||||
],
|
||||
sources : [
|
||||
'crc.c',
|
||||
'crc.h',
|
||||
'dprintf.c',
|
||||
'dprintf.h',
|
||||
'setupapi.c',
|
||||
|
Loading…
Reference in New Issue
Block a user