crc32defs.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * There are multiple 16-bit CRC polynomials in common use, but this is
  3. * *the* standard CRC-32 polynomial, first popularized by Ethernet.
  4. * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
  5. */
  6. #define CRCPOLY_LE 0xedb88320
  7. #define CRCPOLY_BE 0x04c11db7
  8. /*
  9. * This is the CRC32c polynomial, as outlined by Castagnoli.
  10. * x^32+x^28+x^27+x^26+x^25+x^23+x^22+x^20+x^19+x^18+x^14+x^13+x^11+x^10+x^9+
  11. * x^8+x^6+x^0
  12. */
  13. #define CRC32C_POLY_LE 0x82F63B78
  14. /* Try to choose an implementation variant via Kconfig */
  15. #ifdef CONFIG_CRC32_SLICEBY8
  16. # define CRC_LE_BITS 64
  17. # define CRC_BE_BITS 64
  18. #endif
  19. #ifdef CONFIG_CRC32_SLICEBY4
  20. # define CRC_LE_BITS 32
  21. # define CRC_BE_BITS 32
  22. #endif
  23. #ifdef CONFIG_CRC32_SARWATE
  24. # define CRC_LE_BITS 8
  25. # define CRC_BE_BITS 8
  26. #endif
  27. #ifdef CONFIG_CRC32_BIT
  28. # define CRC_LE_BITS 1
  29. # define CRC_BE_BITS 1
  30. #endif
  31. /*
  32. * How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64.
  33. * For less performance-sensitive, use 4 or 8 to save table size.
  34. * For larger systems choose same as CPU architecture as default.
  35. * This works well on X86_64, SPARC64 systems. This may require some
  36. * elaboration after experiments with other architectures.
  37. */
  38. #ifndef CRC_LE_BITS
  39. # ifdef CONFIG_64BIT
  40. # define CRC_LE_BITS 64
  41. # else
  42. # define CRC_LE_BITS 32
  43. # endif
  44. #endif
  45. #ifndef CRC_BE_BITS
  46. # ifdef CONFIG_64BIT
  47. # define CRC_BE_BITS 64
  48. # else
  49. # define CRC_BE_BITS 32
  50. # endif
  51. #endif
  52. /*
  53. * Little-endian CRC computation. Used with serial bit streams sent
  54. * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC.
  55. */
  56. #if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \
  57. CRC_LE_BITS & CRC_LE_BITS-1
  58. # error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}"
  59. #endif
  60. /*
  61. * Big-endian CRC computation. Used with serial bit streams sent
  62. * msbit-first. Be sure to use cpu_to_be32() to append the computed CRC.
  63. */
  64. #if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \
  65. CRC_BE_BITS & CRC_BE_BITS-1
  66. # error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}"
  67. #endif