Simon Glass | 46e0bc9 | 2013-11-10 10:26:47 -0700 | [diff] [blame^] | 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 | } |