2002-10-04 17:31:41 +00:00
|
|
|
#ifndef CRYPTOPP_CRC32_H
|
|
|
|
#define CRYPTOPP_CRC32_H
|
|
|
|
|
|
|
|
#include "cryptlib.h"
|
|
|
|
|
|
|
|
NAMESPACE_BEGIN(CryptoPP)
|
|
|
|
|
|
|
|
const word32 CRC32_NEGL = 0xffffffffL;
|
|
|
|
|
|
|
|
#ifdef IS_LITTLE_ENDIAN
|
|
|
|
#define CRC32_INDEX(c) (c & 0xff)
|
|
|
|
#define CRC32_SHIFTED(c) (c >> 8)
|
|
|
|
#else
|
|
|
|
#define CRC32_INDEX(c) (c >> 24)
|
|
|
|
#define CRC32_SHIFTED(c) (c << 8)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//! CRC Checksum Calculation
|
|
|
|
class CRC32 : public HashTransformation
|
|
|
|
{
|
|
|
|
public:
|
2006-12-14 11:41:39 +00:00
|
|
|
CRYPTOPP_CONSTANT(DIGESTSIZE = 4)
|
2002-10-04 17:31:41 +00:00
|
|
|
CRC32();
|
2005-07-12 04:23:32 +00:00
|
|
|
void Update(const byte *input, size_t length);
|
|
|
|
void TruncatedFinal(byte *hash, size_t size);
|
2002-10-04 17:31:41 +00:00
|
|
|
unsigned int DigestSize() const {return DIGESTSIZE;}
|
2006-12-25 08:03:32 +00:00
|
|
|
std::string AlgorithmName() const {return "CRC32";}
|
2002-10-04 17:31:41 +00:00
|
|
|
|
|
|
|
void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);}
|
2005-07-12 04:23:32 +00:00
|
|
|
byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];}
|
2002-10-04 17:31:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void Reset() {m_crc = CRC32_NEGL;}
|
|
|
|
|
|
|
|
static const word32 m_tab[256];
|
|
|
|
word32 m_crc;
|
|
|
|
};
|
|
|
|
|
|
|
|
NAMESPACE_END
|
|
|
|
|
|
|
|
#endif
|