1 /* 2 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved. 3 * 4 * This software may be freely used, copied, modified, and distributed 5 * provided that the above copyright notice is preserved in all copies of the 6 * software. 7 */ 8 9 /* -*-C-*- 10 * 11 * $Revision: 1.3 $ 12 * $Date: 2004/12/27 14:00:54 $ 13 * 14 * 15 * crc.h - describes some "standard" CRC calculation routines. 16 */ 17 #ifndef angel_crc_h 18 #define angel_crc_h 19 20 /* 21 * manifests 22 */ 23 24 /* 25 * When using "crc32" or "crc16" these initial CRC values must be given to 26 * the respective function the first time it is called. The function can 27 * then be called with the return value from the last call of the function 28 * to generate a running CRC over multiple data blocks. 29 * When the last data block has been processed using the "crc32" algorithm 30 * the CRC value should be inverted to produce the final CRC value: 31 * e.g. CRC = ~CRC 32 */ 33 34 #define startCRC32 (0xFFFFFFFF) /* CRC initialised to all 1s */ 35 #define startCRC16 (0x0000) /* CRC initialised to all 0s */ 36 37 /* 38 * For the CRC-32 residual to be calculated correctly requires that the CRC 39 * value is in memory little-endian due to the byte read, bit-ordering 40 * nature of the algorithm. 41 */ 42 #define CRC32residual (0xDEBB20E3) /* good CRC-32 residual */ 43 44 45 /**********************************************************************/ 46 47 /* 48 * exported functions 49 */ 50 51 /* 52 * Function: crc32 53 * Purpose: Provides a table driven implementation of the IEEE-802.3 54 * 32-bit CRC algorithm for byte data. 55 * 56 * Params: 57 * Input: address pointer to the byte data 58 * size number of bytes of data to be processed 59 * crc initial CRC value to be used (can be the output 60 * from a previous call to this function). 61 * Returns: 62 * OK: 32-bit CRC value for the specified data 63 */ 64 extern unsigned int crc32(unsigned char *address, unsigned int size, 65 unsigned int crc); 66 67 /**********************************************************************/ 68 69 /* 70 * 71 * Function: crc16 72 * Purpose: Generates a table driven 16-bit CRC-CCITT for byte data 73 * 74 * Params: 75 * Input: address pointer to the byte data 76 * size number of bytes of data to be processed 77 * crc initial CRC value to be used (can be the output 78 * from a previous call to this function). 79 * 80 * Returns: 81 * OK: 16-bit CRC value for the specified data 82 */ 83 extern unsigned short crc16(unsigned char *address, unsigned int size, 84 unsigned short crc); 85 86 /**********************************************************************/ 87 88 #endif /* !defined(angel_crc_h) */ 89 90 /* EOF crc.h */ 91