]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
60d18d3f SG |
2 | /* |
3 | * Copyright (c) 2013 Google, Inc | |
60d18d3f SG |
4 | */ |
5 | ||
6 | #include "linux/crc8.h" | |
7 | ||
456ecd08 SR |
8 | #define POLY (0x1070U << 3) |
9 | ||
10 | static unsigned char _crc8(unsigned short data) | |
60d18d3f | 11 | { |
456ecd08 SR |
12 | int i; |
13 | ||
14 | for (i = 0; i < 8; i++) { | |
15 | if (data & 0x8000) | |
16 | data = data ^ POLY; | |
17 | data = data << 1; | |
60d18d3f SG |
18 | } |
19 | ||
456ecd08 SR |
20 | return (unsigned char)(data >> 8); |
21 | } | |
22 | ||
23 | unsigned int crc8(unsigned int crc, const unsigned char *vptr, int len) | |
24 | { | |
25 | int i; | |
26 | ||
27 | for (i = 0; i < len; i++) | |
28 | crc = _crc8((crc ^ vptr[i]) << 8); | |
29 | ||
30 | return crc; | |
60d18d3f | 31 | } |