1 /* 2 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name> 3 * 4 * Based on busybox code: 5 * CRC32 table fill function 6 * Copyright (C) 2006 by Rob Sullivan <cogito.ergo.cogito@gmail.com> 7 * 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 11 * 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. 16 */ 17 #ifndef __BB_CRC32_H 18 #define __BB_CRC32_H 19 20 #include <stdint.h> 21 22 static inline void 23 crc32_filltable(uint32_t *crc_table) 24 { 25 uint32_t polynomial = 0xedb88320; 26 uint32_t c; 27 int i, j; 28 29 for (i = 0; i < 256; i++) { 30 c = i; 31 for (j = 8; j; j--) 32 c = (c&1) ? ((c >> 1) ^ polynomial) : (c >> 1); 33 34 *crc_table++ = c; 35 } 36 } 37 38 static inline uint32_t 39 crc32_block(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) 40 { 41 const void *end = (uint8_t*)buf + len; 42 43 while (buf != end) { 44 val = crc_table[(uint8_t)val ^ *(uint8_t*)buf] ^ (val >> 8); 45 buf = (uint8_t*)buf + 1; 46 } 47 return val; 48 } 49 50 #endif 51
This page was automatically generated by LXR 0.3.1. • OpenWrt