Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

  1. // crc.h - written and placed in the public domain by Wei Dai
  2. //! \file
  3. //! \headerfile crc.h
  4. //! \brief Classes for CRC-32 checksum algorithm
  5. #ifndef CRYPTOPP_CRC32_H
  6. #define CRYPTOPP_CRC32_H
  7. #include "cryptlib.h"
  8. NAMESPACE_BEGIN(CryptoPP)
  9. const word32 CRC32_NEGL = 0xffffffffL;
  10. #ifdef IS_LITTLE_ENDIAN
  11. #define CRC32_INDEX(c) (c & 0xff)
  12. #define CRC32_SHIFTED(c) (c >> 8)
  13. #else
  14. #define CRC32_INDEX(c) (c >> 24)
  15. #define CRC32_SHIFTED(c) (c << 8)
  16. #endif
  17. //! CRC Checksum Calculation
  18. class CRC32 : public HashTransformation
  19. {
  20. public:
  21. CRYPTOPP_CONSTANT(DIGESTSIZE = 4)
  22. CRC32();
  23. void Update(const byte *input, size_t length);
  24. void TruncatedFinal(byte *hash, size_t size);
  25. unsigned int DigestSize() const {return DIGESTSIZE;}
  26. static const char * StaticAlgorithmName() {return "CRC32";}
  27. std::string AlgorithmName() const {return StaticAlgorithmName();}
  28. void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
  29. byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];}
  30. private:
  31. void Reset() {m_crc = CRC32_NEGL;}
  32. static const word32 m_tab[256];
  33. word32 m_crc;
  34. };
  35. NAMESPACE_END
  36. #endif