7zCrc.c 718 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* 7zCrc.c -- CRC32 calculation
  2. 2008-08-05
  3. Igor Pavlov
  4. Public domain */
  5. #include "7zCrc.h"
  6. #define kCrcPoly 0xEDB88320
  7. UInt32 g_CrcTable[256];
  8. void MY_FAST_CALL CrcGenerateTable(void)
  9. {
  10. UInt32 i;
  11. for (i = 0; i < 256; i++)
  12. {
  13. UInt32 r = i;
  14. int j;
  15. for (j = 0; j < 8; j++)
  16. r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
  17. g_CrcTable[i] = r;
  18. }
  19. }
  20. UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
  21. {
  22. const Byte *p = (const Byte *)data;
  23. for (; size > 0 ; size--, p++)
  24. v = CRC_UPDATE_BYTE(v, *p);
  25. return v;
  26. }
  27. UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
  28. {
  29. return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;
  30. }