Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // Reverse CRC table for Castagnoli polynomial (0x1EDC6F41)
  2. static const unsigned long crc32c_revTable[16] =
  3. {
  4. 0x00000000L, 0x05EC76F1L, 0x0BD8EDE2L, 0x0E349B13L,
  5. 0x17B1DBC4L, 0x125DAD35L, 0x1C693626L, 0x198540D7L,
  6. 0x2F63B788L, 0x2A8FC179L, 0x24BB5A6AL, 0x21572C9BL,
  7. 0x38D26C4CL, 0x3D3E1ABDL, 0x330A81AEL, 0x36E6F75FL
  8. };
  9.  
  10. unsigned long calcReverseCRC32C(unsigned long crc32c,
  11. const unsigned char* pData,
  12. unsigned long len)
  13. {
  14. while (len--)
  15. {
  16. crc32c = (crc32c << 4) ^ crc32c_revTable[crc32c >> 28];
  17. crc32c = (crc32c << 4) ^ crc32c_revTable[crc32c >> 28];
  18. crc32c ^= *pData--;
  19. }
  20.  
  21. return crc32c;
  22. }
  23.  
  24. {
  25. // This array contains test data with 4 bytes CRC appended
  26. // The result of CRC-32C calculation using this data is zero
  27. unsigned char test[13] = {0x31, 0x32, 0x33, 0x34,
  28. 0x35, 0x36, 0x37, 0x38,
  29. 0x39,
  30. 0x7c, 0x6d, 0xf9, 0x1c};
  31.  
  32. unsigned long expectedResultOfCRC = 0;
  33. unsigned long init = calcReverseCRC32C(expectedResultOfCRC ,
  34. &test[12],
  35. 13);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement