1#ifndef CRYPTOPP_CRC32_H 2#define CRYPTOPP_CRC32_H 3 4#include "cryptlib.h" 5 6NAMESPACE_BEGIN(CryptoPP) 7 8const word32 CRC32_NEGL = 0xffffffffL; 9 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 18//! CRC Checksum Calculation 19class CRC32 : public HashTransformation 20{ 21public: 22 CRYPTOPP_CONSTANT(DIGESTSIZE = 4) 23 CRC32(); 24 void Update(const byte *input, size_t length); 25 void TruncatedFinal(byte *hash, size_t size); 26 unsigned int DigestSize() const {return DIGESTSIZE;} 27 static const char * StaticAlgorithmName() {return "CRC32";} 28 std::string AlgorithmName() const {return StaticAlgorithmName();} 29 30 void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} 31 byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];} 32 33private: 34 void Reset() {m_crc = CRC32_NEGL;} 35 36 static const word32 m_tab[256]; 37 word32 m_crc; 38}; 39 40NAMESPACE_END 41 42#endif 43