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