00001 #ifndef CRYPTOPP_CRC32_H
00002 #define CRYPTOPP_CRC32_H
00003
00004 #include "cryptlib.h"
00005
00006 NAMESPACE_BEGIN(CryptoPP)
00007
00008 const word32 CRC32_NEGL = 0xffffffffL;
00009
00010 #ifdef IS_LITTLE_ENDIAN
00011 #define CRC32_INDEX(c) (c & 0xff)
00012 #define CRC32_SHIFTED(c) (c >> 8)
00013 #else
00014 #define CRC32_INDEX(c) (c >> 24)
00015 #define CRC32_SHIFTED(c) (c << 8)
00016 #endif
00017
00018
00019 class CRC32 : public HashTransformation
00020 {
00021 public:
00022 CRYPTOPP_CONSTANT(DIGESTSIZE = 4)
00023 CRC32();
00024 void Update(const byte *input, size_t length);
00025 void TruncatedFinal(byte *hash, size_t size);
00026 unsigned int DigestSize() const {return DIGESTSIZE;}
00027 static const char * StaticAlgorithmName() {return "CRC32";}
00028 std::string AlgorithmName() const {return StaticAlgorithmName();}
00029
00030 void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
00031 byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];}
00032
00033 private:
00034 void Reset() {m_crc = CRC32_NEGL;}
00035
00036 static const word32 m_tab[256];
00037 word32 m_crc;
00038 };
00039
00040 NAMESPACE_END
00041
00042 #endif