diff src/win32/7zip/7z/C/7zCrc.c @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/C/7zCrc.c	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,35 @@
     1.4 +/* 7zCrc.c -- CRC32 calculation
     1.5 +2008-08-05
     1.6 +Igor Pavlov
     1.7 +Public domain */
     1.8 +
     1.9 +#include "7zCrc.h"
    1.10 +
    1.11 +#define kCrcPoly 0xEDB88320
    1.12 +UInt32 g_CrcTable[256];
    1.13 +
    1.14 +void MY_FAST_CALL CrcGenerateTable(void)
    1.15 +{
    1.16 +  UInt32 i;
    1.17 +  for (i = 0; i < 256; i++)
    1.18 +  {
    1.19 +    UInt32 r = i;
    1.20 +    int j;
    1.21 +    for (j = 0; j < 8; j++)
    1.22 +      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
    1.23 +    g_CrcTable[i] = r;
    1.24 +  }
    1.25 +}
    1.26 +
    1.27 +UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
    1.28 +{
    1.29 +  const Byte *p = (const Byte *)data;
    1.30 +  for (; size > 0 ; size--, p++)
    1.31 +    v = CRC_UPDATE_BYTE(v, *p);
    1.32 +  return v;
    1.33 +}
    1.34 +
    1.35 +UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
    1.36 +{
    1.37 +  return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;
    1.38 +}