7zCrc.c 626 B

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