54c232903549308008968fd45a2eb330b3a907a8
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.
23 crc32_filltable(uint32_t *crc_table
)
25 uint32_t polynomial
= 0xedb88320;
29 for (i
= 0; i
< 256; i
++) {
32 c
= (c
&1) ? ((c
>> 1) ^ polynomial
) : (c
>> 1);
38 static inline uint32_t
39 crc32_block(uint32_t val
, const void *buf
, unsigned len
, uint32_t *crc_table
)
41 const void *end
= (uint8_t*)buf
+ len
;
44 val
= crc_table
[(uint8_t)val
^ *(uint8_t*)buf
] ^ (val
>> 8);
45 buf
= (uint8_t*)buf
+ 1;