Home | History | Annotate | Download | only in C
      1 /* XzCrc64.c -- CRC64 calculation
      2 2010-04-16 : Igor Pavlov : Public domain */
      3 
      4 #include "XzCrc64.h"
      5 
      6 #define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42)
      7 UInt64 g_Crc64Table[256];
      8 
      9 void MY_FAST_CALL Crc64GenerateTable(void)
     10 {
     11   UInt32 i;
     12   for (i = 0; i < 256; i++)
     13   {
     14     UInt64 r = i;
     15     int j;
     16     for (j = 0; j < 8; j++)
     17       r = (r >> 1) ^ ((UInt64)kCrc64Poly & ~((r & 1) - 1));
     18     g_Crc64Table[i] = r;
     19   }
     20 }
     21 
     22 UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size)
     23 {
     24   const Byte *p = (const Byte *)data;
     25   for (; size > 0 ; size--, p++)
     26     v = CRC64_UPDATE_BYTE(v, *p);
     27   return v;
     28 }
     29 
     30 UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size)
     31 {
     32   return CRC64_GET_DIGEST(Crc64Update(CRC64_INIT_VAL, data, size));
     33 }
     34