coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
crc_byte.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <crc_byte.h>
4 
6 {
7  const uint8_t g = 0x89;
8  prev_crc ^= data;
9  for (int i = 0; i < 8; i++) {
10  if (prev_crc & 0x80)
11  prev_crc ^= g;
12  prev_crc <<= 1;
13  }
14  return prev_crc;
15 }
16 
18 {
19  prev_crc = (uint8_t)(prev_crc >> 8)|(prev_crc << 8);
20  prev_crc ^= data;
21  prev_crc ^= (uint8_t)(prev_crc & 0xff) >> 4;
22  prev_crc ^= (prev_crc << 8) << 4;
23  prev_crc ^= ((prev_crc & 0xff) << 4) << 1;
24  return prev_crc;
25 }
26 
28 {
29  prev_crc ^= (uint32_t)data << 24;
30 
31  for (int i = 0; i < 8; i++) {
32  if ((prev_crc & 0x80000000UL) != 0)
33  prev_crc = ((prev_crc << 1) ^ 0x04C11DB7UL);
34  else
35  prev_crc <<= 1;
36  }
37 
38  return prev_crc;
39 }
uint16_t crc16_byte(uint16_t prev_crc, uint8_t data)
Definition: crc_byte.c:17
uint8_t crc7_byte(uint8_t prev_crc, uint8_t data)
Definition: crc_byte.c:5
uint32_t crc32_byte(uint32_t prev_crc, uint8_t data)
Definition: crc_byte.c:27
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8