Andrew Jeffery | eba19a3 | 2021-03-09 23:09:40 +1030 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 */ |
| 2 | /* Copyright 2021 IBM Corp. */ |
| 3 | |
| 4 | #include "crc32.h" |
| 5 | |
| 6 | #include <limits.h> |
| 7 | |
| 8 | /* Very dumb CRC-32 implementation */ |
| 9 | uint32_t crc32(const void *buf, size_t len) |
| 10 | { |
| 11 | const uint8_t *buf8 = buf; |
| 12 | uint32_t rem = 0xffffffff; |
| 13 | |
| 14 | for (; len; len--) { |
| 15 | int i; |
| 16 | |
| 17 | rem = rem ^ *buf8; |
| 18 | for (i = 0; i < CHAR_BIT; i++) |
| 19 | rem = (rem >> 1) ^ ((rem & 1) * 0xEDB88320); |
| 20 | |
| 21 | buf8++; |
| 22 | } |
| 23 | |
| 24 | return rem ^ 0xffffffff; |
| 25 | } |