crc16.h revision ca2634a46ab9da85a3a015a7772770d9dbe5848e
1/* 2 * crc16.h - CRC-16 routine 3 * 4 * Implements the standard CRC-16: 5 * Width 16 6 * Poly 0x8005 (x16 + x15 + x2 + 1) 7 * Init 0 8 * 9 * Copyright (c) 2005 Ben Gardner <bgardner@wabtec.com> 10 * 11 * This source code is licensed under the GNU General Public License, 12 * Version 2. See the file COPYING for more details. 13 */ 14 15#ifndef __CRC16_H 16#define __CRC16_H 17 18#include <ext2fs/ext2_types.h> 19 20extern __u16 const crc16_table[256]; 21 22#ifdef WORDS_BIGENDIAN 23/* for an unknown reason, PPC treats __u16 as signed and keeps doing sign 24 * extension on the value. Instead, use only the low 16 bits of an 25 * unsigned int for holding the CRC value to avoid this. 26 */ 27typedef unsigned crc16_t; 28 29static inline crc16_t crc16_byte(crc16_t crc, const unsigned char data) 30{ 31 return (((crc >> 8) & 0xffU) ^ crc16_table[(crc ^ data) & 0xffU]) & 32 0x0000ffffU; 33} 34#else 35typedef __u16 crc16_t; 36 37static inline crc16_t crc16_byte(crc16_t crc, const unsigned char data) 38{ 39 return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff]; 40} 41#endif 42 43extern crc16_t crc16(crc16_t crc, const void *buffer, unsigned int len); 44 45#endif /* __CRC16_H */ 46