home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Source / crc32.c < prev    next >
C/C++ Source or Header  |  2002-08-19  |  708b  |  30 lines

  1. #include "exehead/config.h"
  2. #ifdef NSIS_CONFIG_CRC_SUPPORT
  3.  
  4. // this is based on the (slow,small) CRC32 implementation from zlib.
  5. unsigned long NSISCALL CRC32(unsigned long crc, const unsigned char *buf, unsigned int len)
  6. {
  7.     static unsigned long crc_table[256];
  8.  
  9.     if (!crc_table[1])
  10.     {
  11.       unsigned long c;
  12.       int n, k;
  13.  
  14.       for (n = 0; n < 256; n++)
  15.       {
  16.         c = (unsigned long)n;
  17.         for (k = 0; k < 8; k++) c = (c >> 1) ^ (c & 1 ? 0xedb88320L : 0);
  18.         crc_table[n] = c;
  19.       }
  20.     }
  21.  
  22.     crc = crc ^ 0xffffffffL;
  23.     while (len-- > 0) {
  24.       crc = crc_table[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
  25.     }
  26.     return crc ^ 0xffffffffL;
  27. }
  28.  
  29. #endif
  30.