blob: 8b68a29e40be79d95c85ce88c9c6bd65b643a1be [file] [log] [blame]
Simon Glass60d18d32013-11-10 10:26:47 -07001/*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include "linux/crc8.h"
8
9unsigned 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}