//======================================================== file = crc32.c ===== //= Program to compute CRC-32 using the "table method" for 8-bit subtracts = //============================================================================= //= Notes: Uses the standard "Charles Michael Heard" code available from = //= http://cell-relay.indiana.edu/cell-relay/publications/software = //= /CRC which was adapted from the algorithm described by Avarm = //= Perez, "Byte-wise CRC Calculations," IEEE Micro 3, 40 (1983). = //=---------------------------------------------------------------------------= //= Build: bcc32 crc32.c, gcc crc32.c = //=---------------------------------------------------------------------------= //= History: KJC (8/24/00) - Genesis (from Heard code, see above) = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() #include // Needed for rand() //----- Type defines ---------------------------------------------------------- typedef unsigned char byte; // Byte is a char typedef unsigned short int word16; // 16-bit word is a short int typedef unsigned int word32; // 32-bit word is an int //----- Defines --------------------------------------------------------------- #define POLYNOMIAL 0x04c11db7L // Standard CRC-32 ppolynomial #define BUFFER_LEN 4096L // Length of buffer //----- Gloabl variables ------------------------------------------------------ static word32 crc_table[256]; // Table of 8-bit remainders //----- Prototypes ------------------------------------------------------------ void gen_crc_table(void); word32 update_crc(word32 crc_accum, byte *data_blk_ptr, word32 data_blk_size); //===== Main program ========================================================== void main(void) { byte buff[BUFFER_LEN]; // Buffer of packet bytes word32 crc32; // 32-bit CRC value word16 i; // Loop counter (16 bit) word32 j; // Loop counter (32 bit) // Initialize the CRC table gen_crc_table(); // Load buffer with BUFFER_LEN random bytes for (i=0; i> 24) ^ *data_blk_ptr++) & 0xFF; crc_accum = (crc_accum << 8) ^ crc_table[i]; } crc_accum = ~crc_accum; return crc_accum; }