Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

# 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         enum {DIGESTSIZE = 4};
    00023         CRC32();
    00024         void Update(const byte *input, unsigned int length);
    00025         void TruncatedFinal(byte *hash, unsigned int size);
    00026         unsigned int DigestSize() const {return DIGESTSIZE;}
    00027
    00028         void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
    00029         byte GetCrcByte(unsigned int i) const {return ((byte *)&(m_crc))[i];}
    00030
    00031 private:
    00032         void Reset() {m_crc = CRC32_NEGL;}
    00033
    00034         static const word32 m_tab[256];
    00035         word32 m_crc;
    00036 };
    00037
    00038 NAMESPACE_END
    00039
    00040 #endif