crc32.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * \file crc32.h
  3. * Functions and types for CRC checks.
  4. *
  5. * Generated on Mon Feb 21 23:03:39 2011,
  6. * by pycrc v0.7.1, http://www.tty1.net/pycrc/
  7. * using the configuration:
  8. * Width = 32
  9. * Poly = 0x04c11db7
  10. * XorIn = 0xffffffff
  11. * ReflectIn = True
  12. * XorOut = 0xffffffff
  13. * ReflectOut = True
  14. * Algorithm = bit-by-bit-fast
  15. * Direct = True
  16. *****************************************************************************/
  17. #ifndef __CRC___H__
  18. #define __CRC___H__
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /**
  25. * The definition of the used algorithm.
  26. *****************************************************************************/
  27. #define CRC_ALGO_BIT_BY_BIT_FAST 1
  28. /**
  29. * The type of the CRC values.
  30. *
  31. * This type must be big enough to contain at least 32 bits.
  32. *****************************************************************************/
  33. /**
  34. * Reflect all bits of a \a data word of \a data_len bytes.
  35. *
  36. * \param data The data word to be reflected.
  37. * \param data_len The width of \a data expressed in number of bits.
  38. * \return The reflected data.
  39. *****************************************************************************/
  40. uint32_t crc_reflect( uint32_t data, size_t data_len );
  41. /**
  42. * Calculate the initial crc value.
  43. *
  44. * \return The initial crc value.
  45. *****************************************************************************/
  46. static inline uint32_t crc_init( void )
  47. {
  48. return 0xffffffff;
  49. }
  50. /**
  51. * Update the crc value with new data.
  52. *
  53. * \param crc The current crc value.
  54. * \param data Pointer to a buffer of \a data_len bytes.
  55. * \param data_len Number of bytes in the \a data buffer.
  56. * \return The updated crc value.
  57. *****************************************************************************/
  58. uint32_t crc32_update( uint32_t crc, const unsigned char data );
  59. /**
  60. * Calculate the final crc value.
  61. *
  62. * \param crc The current crc value.
  63. * \return The final crc value.
  64. *****************************************************************************/
  65. static inline uint32_t crc_finalize( uint32_t crc )
  66. {
  67. return crc_reflect( crc, 32 ) ^ 0xffffffff;
  68. }
  69. #ifdef __cplusplus
  70. } /* closing brace for extern "C" */
  71. #endif
  72. #endif /* __CRC___H__ */