crc.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**********************************************************************
  2. *
  3. * Filename: crc.h
  4. *
  5. * Description: A header file describing the various CRC standards.
  6. *
  7. * Notes:
  8. *
  9. *
  10. * Copyright (c) 2000 by Michael Barr. This software is placed into
  11. * the public domain and may be used for any purpose. However, this
  12. * notice must not be changed or removed and no warranty is either
  13. * expressed or implied by its publication or distribution.
  14. **********************************************************************/
  15. #ifndef _crc_h
  16. #define _crc_h
  17. #define FALSE 0
  18. #define TRUE !FALSE
  19. /*
  20. * Select the CRC standard from the list that follows.
  21. */
  22. #define CRC32
  23. #if defined(CRC_CCITT)
  24. typedef unsigned short crc;
  25. #define CRC_NAME "CRC-CCITT"
  26. #define POLYNOMIAL 0x1021
  27. #define INITIAL_REMAINDER 0xFFFF
  28. #define FINAL_XOR_VALUE 0x0000
  29. #define REFLECT_DATA FALSE
  30. #define REFLECT_REMAINDER FALSE
  31. #define CHECK_VALUE 0x29B1
  32. #elif defined(CRC16)
  33. typedef unsigned short crc;
  34. #define CRC_NAME "CRC-16"
  35. #define POLYNOMIAL 0x8005
  36. #define INITIAL_REMAINDER 0x0000
  37. #define FINAL_XOR_VALUE 0x0000
  38. #define REFLECT_DATA TRUE
  39. #define REFLECT_REMAINDER TRUE
  40. #define CHECK_VALUE 0xBB3D
  41. #elif defined(CRC32)
  42. typedef unsigned long crc;
  43. #define CRC_NAME "CRC-32"
  44. #define POLYNOMIAL 0x04C11DB7
  45. #define INITIAL_REMAINDER 0xFFFFFFFF
  46. #define FINAL_XOR_VALUE 0xFFFFFFFF
  47. #define REFLECT_DATA TRUE
  48. #define REFLECT_REMAINDER TRUE
  49. #define CHECK_VALUE 0xCBF43926
  50. #else
  51. #error "One of CRC_CCITT, CRC16, or CRC32 must be #define'd."
  52. #endif
  53. void crcInit(void);
  54. crc crcSlow(unsigned char const message[], int nBytes);
  55. crc crcFast(unsigned char const message[], int nBytes);
  56. #endif /* _crc_h */