Files
system76-coreboot/src/lib/crc_byte.c
Angel Pons 118a9c7b03 src/lib: Use SPDX for GPL-2.0-only files
Done with sed and God Lines. Only done for C-like code for now.

Change-Id: Id3a0b63272ebda3dad13803700bcff36d36f4815
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/40054
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
2020-04-04 16:35:53 +00:00

41 lines
861 B
C

/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */
#include <crc_byte.h>
uint8_t crc7_byte(uint8_t prev_crc, uint8_t data)
{
const uint8_t g = 0x89;
prev_crc ^= data;
for (int i = 0; i < 8; i++) {
if (prev_crc & 0x80)
prev_crc ^= g;
prev_crc <<= 1;
}
return prev_crc;
}
uint16_t crc16_byte(uint16_t prev_crc, uint8_t data)
{
prev_crc = (uint8_t)(prev_crc >> 8)|(prev_crc << 8);
prev_crc ^= data;
prev_crc ^= (uint8_t)(prev_crc & 0xff) >> 4;
prev_crc ^= (prev_crc << 8) << 4;
prev_crc ^= ((prev_crc & 0xff) << 4) << 1;
return prev_crc;
}
uint32_t crc32_byte(uint32_t prev_crc, uint8_t data)
{
prev_crc ^= (uint32_t)data << 24;
for (int i = 0; i < 8; i++) {
if ((prev_crc & 0x80000000UL) != 0)
prev_crc = ((prev_crc << 1) ^ 0x04C11DB7UL);
else
prev_crc <<= 1;
}
return prev_crc;
}