crc.h

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 //! CRC Checksum Calculation
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     std::string AlgorithmName() const {return "CRC32";}
00028 
00029         void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
00030         byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];}
00031 
00032 private:
00033         void Reset() {m_crc = CRC32_NEGL;}
00034         
00035         static const word32 m_tab[256];
00036         word32 m_crc;
00037 };
00038 
00039 NAMESPACE_END
00040 
00041 #endif

Generated on Fri Jun 1 11:11:20 2007 for Crypto++ by  doxygen 1.5.2