00001 #ifndef UT_CRC32_H 00002 #define UT_CRC32_H 00003 #include "ut_types.h" 00004 00005 const UT_uint32 CRC32_NEGL = 0xffffffffL; 00006 #ifdef UT_LITTLE_ENDIAN 00007 #define CRC32_INDEX(c) (c & 0xff) 00008 #define CRC32_SHIFTED(c) (c >> 8) 00009 #else 00010 #define CRC32_INDEX(c) (c >> 24) 00011 #define CRC32_SHIFTED(c) (c << 8) 00012 #endif 00013 00015 class ABI_EXPORT UT_CRC32 00016 { 00017 public: 00018 enum {DIGESTSIZE = 4}; 00019 UT_CRC32(); 00020 void Fill(const char *input); 00021 void Fill(const char *input, UT_uint32 length); 00022 void Fill(const unsigned char *input, UT_uint32 length); 00023 UT_uint32 DigestSize() const {return DIGESTSIZE;} 00024 00025 void UpdateByte(unsigned char b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} 00026 unsigned char GetCrcByte(UT_uint32 i) const {return ((const unsigned char *)&(m_crc))[i];} 00027 UT_uint32 GetCRC32(void) const { return m_crc;} 00028 private: 00029 void Reset() {m_crc = CRC32_NEGL;} 00030 00031 static const UT_uint32 m_tab[256]; 00032 UT_uint32 m_crc; 00033 }; 00034 00035 00036 #endif /* UT_CRC32_H */