2 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4 * Based on busybox code:
5 * CRC32 table fill function
6 * Copyright (C) 2006 by Rob Sullivan <cogito.ergo.cogito@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
21 crc32_filltable(uint32_t *crc_table
)
23 uint32_t polynomial
= 0xedb88320;
27 for (i
= 0; i
< 256; i
++) {
30 c
= (c
&1) ? ((c
>> 1) ^ polynomial
) : (c
>> 1);
36 static inline uint32_t
37 crc32_block(uint32_t val
, const void *buf
, unsigned len
, uint32_t *crc_table
)
39 const void *end
= (uint8_t*)buf
+ len
;
42 val
= crc_table
[(uint8_t)val
^ *(uint8_t*)buf
] ^ (val
>> 8);
43 buf
= (uint8_t*)buf
+ 1;