crc32.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * \file stdout
  3. * Functions and types for CRC checks.
  4. *
  5. * Generated on Tue Jun 30 21:35:19 2009,
  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 __STDOUT__
  18. #define __STDOUT__
  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. typedef uint32_t crc_t;
  34. /**
  35. * Reflect all bits of a \a data word of \a data_len bytes.
  36. *
  37. * \param data The data word to be reflected.
  38. * \param data_len The width of \a data expressed in number of bits.
  39. * \return The reflected data.
  40. *****************************************************************************/
  41. long crc_reflect(long data, size_t data_len);
  42. /**
  43. * Calculate the initial crc value.
  44. *
  45. * \return The initial crc value.
  46. *****************************************************************************/
  47. static inline crc_t crc_init(void)
  48. {
  49. return 0xffffffff;
  50. }
  51. /**
  52. * Update the crc value with new data.
  53. *
  54. * \param crc The current crc value.
  55. * \param data Pointer to a buffer of \a data_len bytes.
  56. * \param data_len Number of bytes in the \a data buffer.
  57. * \return The updated crc value.
  58. *****************************************************************************/
  59. crc_t crc_update(crc_t crc, const unsigned char *data, size_t data_len);
  60. /**
  61. * Calculate the final crc value.
  62. *
  63. * \param crc The current crc value.
  64. * \return The final crc value.
  65. *****************************************************************************/
  66. static inline crc_t crc_finalize(crc_t crc)
  67. {
  68. return crc_reflect(crc, 32) ^ 0xffffffff;
  69. }
  70. #ifdef __cplusplus
  71. } /* closing brace for extern "C" */
  72. #endif
  73. #endif /* __STDOUT__ */