CRC functions

CRC functions - { crc = (crc << 8) ^ crc32_table[(crc...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//---------------------------- CRC functions --------------------------------// u_long crc32_table[256]; /* Initialized first time "crc32()" is called. If you prefer, you can * statically initialize it at compile time. [Another exercise.] */ u_long crc32(u_char *buf, int len) { u_char *p; u_long crc; if (!crc32_table[1]) { init_crc32(); /* if not already done, build table */ } crc = 0xffffffff; /* preload shift register, per CRC-32 spec */ for (p = buf; len > 0; ++p, --len)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p]; } return ~crc; /* transmit complement, per CRC-32 spec */ } /* Build auxiliary table for parallel byte-at-a-time CRC-32. */ #define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */ void init_crc32(void) { int i, j; u_long c; for (i = 0; i < 256; ++i) { for (c = i << 24, j = 8; j > 0; --j) { c &= 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1); } crc32_table[i] = c; } }...
View Full Document

This document was uploaded on 02/08/2012.

Ask a homework question - tutors are online