You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
// crc32.h: Schnittstelle für die Klasse CRC32.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#if !defined(_CRC32_H)
|
|
#define _CRC32_H
|
|
|
|
typedef unsigned long crc32l;
|
|
|
|
const long CRC32_NEGL = 0xffffffffLU;
|
|
|
|
#define IS_LITTLE_ENDIAN
|
|
|
|
#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
|
|
|
|
|
|
class CRC32
|
|
{
|
|
public:
|
|
CRC32();
|
|
|
|
void Update(const unsigned char *input, unsigned int length);
|
|
crc32l GetFinal();
|
|
|
|
void UpdateByte(unsigned char b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);};
|
|
unsigned char GetCrcByte(unsigned int i) const {return ((unsigned char *)&(m_crc))[i];};
|
|
|
|
static char * GetFileCRCString(char * filename, char * path=0);
|
|
static crc32l GetFileCRC(char * filename, char * path=0);
|
|
static crc32l GetMemCRC(char * buf, int size);
|
|
|
|
void TruncatedFinal(unsigned char *hash, unsigned int size);
|
|
|
|
private:
|
|
void Reset() {m_crc = CRC32_NEGL;};
|
|
|
|
static const crc32l m_tab[256];
|
|
crc32l m_crc;
|
|
};
|
|
|
|
#endif // !defined(_CRC32_H)
|