From 83aef192e447c800cba6f4dbde8a450a4f8581a5 Mon Sep 17 00:00:00 2001 From: Jacques Comeaux Date: Mon, 1 Jul 2024 12:16:02 -0500 Subject: Use in-house CRC32 computation for boot sector --- octedit/crc32.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 octedit/crc32.c (limited to 'octedit/crc32.c') diff --git a/octedit/crc32.c b/octedit/crc32.c new file mode 100644 index 0000000..175ab50 --- /dev/null +++ b/octedit/crc32.c @@ -0,0 +1,22 @@ +#include +#include +#include + +#define DATA_LEN 252 +#define DIVISOR 0x04C11DB7 + +int main() { + uint8_t data[DATA_LEN]; + read(STDIN_FILENO, data, DATA_LEN); + uint32_t crc = 0xFFFFFFFF; + for (size_t i = 0; i < DATA_LEN; i++) { + crc ^= data[i] << 24; + for (uint8_t j = 0; j < 8; j++) { + uint8_t nskip = crc >> 31; + crc <<= 1; + if (nskip) crc ^= DIVISOR; + } + } + write(STDOUT_FILENO, (uint8_t *) &crc, 4); + return 0; +} -- cgit v1.2.3