CRC.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/Support/CRC.h - Cyclic Redundancy Check-------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file contains implementations of CRC functions.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_SUPPORT_CRC_H
  18. #define LLVM_SUPPORT_CRC_H
  19. #include "llvm/Support/DataTypes.h"
  20. namespace llvm {
  21. template <typename T> class ArrayRef;
  22. // Compute the CRC-32 of Data.
  23. uint32_t crc32(ArrayRef<uint8_t> Data);
  24. // Compute the running CRC-32 of Data, with CRC being the previous value of the
  25. // checksum.
  26. uint32_t crc32(uint32_t CRC, ArrayRef<uint8_t> Data);
  27. // Class for computing the JamCRC.
  28. //
  29. // We will use the "Rocksoft^tm Model CRC Algorithm" to describe the properties
  30. // of this CRC:
  31. // Width : 32
  32. // Poly : 04C11DB7
  33. // Init : FFFFFFFF
  34. // RefIn : True
  35. // RefOut : True
  36. // XorOut : 00000000
  37. // Check : 340BC6D9 (result of CRC for "123456789")
  38. //
  39. // In other words, this is the same as CRC-32, except that XorOut is 0 instead
  40. // of FFFFFFFF.
  41. //
  42. // N.B. We permit flexibility of the "Init" value. Some consumers of this need
  43. // it to be zero.
  44. class JamCRC {
  45. public:
  46. JamCRC(uint32_t Init = 0xFFFFFFFFU) : CRC(Init) {}
  47. // Update the CRC calculation with Data.
  48. void update(ArrayRef<uint8_t> Data);
  49. uint32_t getCRC() const { return CRC; }
  50. private:
  51. uint32_t CRC;
  52. };
  53. } // end namespace llvm
  54. #endif
  55. #ifdef __GNUC__
  56. #pragma GCC diagnostic pop
  57. #endif