]> git.ipfire.org Git - people/ms/u-boot.git/blob - lib/crc8.c
lib/asm-offsets - make GD_RELOCADDR, GD_RELOC_OFF & GD_START_ADDR_SP available for...
[people/ms/u-boot.git] / lib / crc8.c
1 /*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7 #include "linux/crc8.h"
8
9 unsigned int crc8(const unsigned char *vptr, int len)
10 {
11 const unsigned char *data = vptr;
12 unsigned int crc = 0;
13 int i, j;
14
15 for (j = len; j; j--, data++) {
16 crc ^= (*data << 8);
17 for (i = 8; i; i--) {
18 if (crc & 0x8000)
19 crc ^= (0x1070 << 3);
20 crc <<= 1;
21 }
22 }
23
24 return (crc >> 8) & 0xff;
25 }