CRC.h 1.6 KB

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