From 4cfc607ebbff840991d893a8c0fa3a004caeb416 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sun, 26 Apr 2026 07:56:38 +0200 Subject: lib: Move CRC implementations to a subfolder Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/crc8.c | 64 ---------------------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 src/lib/crc8.c (limited to 'src/lib/crc8.c') diff --git a/src/lib/crc8.c b/src/lib/crc8.c deleted file mode 100644 index e8b9685a..00000000 --- a/src/lib/crc8.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2026 - * - * 8-bit Cyclic Redundancy Check (AUTOSAR variant) - * - * Dimitri Staessens - * Sander Vrijders - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., http://www.fsf.org/about/contact/. - */ - -/* - * CRC-8/AUTOSAR (reveng catalog): - * poly = 0x2f - * init = 0xff - * refin = false - * refout = false - * xorout = 0xff - * check = crc8_autosar("123456789") == 0xdf - */ - -#include "config.h" - -#include - -/* Bit-by-bit MSB-first CRC. The expected use case is header check - * sequences of a handful of bytes; a 256-byte lookup table would not - * pay for the extra .rodata footprint at typical input sizes. - */ -void crc8_autosar(uint8_t * crc, - const void * buf, - size_t len) -{ - const uint8_t * p; - uint8_t c; - size_t n; - int i; - - p = (const uint8_t *) buf; - c = *crc ^ 0xff; - - for (n = 0; n < len; n++) { - c ^= p[n]; - for (i = 0; i < 8; i++) { - if (c & 0x80) - c = (uint8_t) ((c << 1) ^ 0x2f); - else - c = (uint8_t) (c << 1); - } - } - - *crc = c ^ 0xff; -} -- cgit v1.2.3