1 // Common/CRC.h 2 3 #ifndef __COMMON_CRC_H 4 #define __COMMON_CRC_H 5 6 #include <stddef.h> 7 #include "Types.h" 8 9 class CCRC 10 { 11 UInt32 _value; 12 public: 13 static UInt32 Table[256]; 14 static void InitTable(); 15 CCRC()16 CCRC(): _value(0xFFFFFFFF){}; Init()17 void Init() { _value = 0xFFFFFFFF; } 18 void UpdateByte(Byte v); 19 void UpdateUInt16(UInt16 v); 20 void UpdateUInt32(UInt32 v); 21 void UpdateUInt64(UInt64 v); 22 void Update(const void *data, size_t size); GetDigest()23 UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } CalculateDigest(const void * data,size_t size)24 static UInt32 CalculateDigest(const void *data, size_t size) 25 { 26 CCRC crc; 27 crc.Update(data, size); 28 return crc.GetDigest(); 29 } VerifyDigest(UInt32 digest,const void * data,size_t size)30 static bool VerifyDigest(UInt32 digest, const void *data, size_t size) 31 { 32 return (CalculateDigest(data, size) == digest); 33 } 34 }; 35 36 #endif 37