Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Common/CRC.h |
michael@0 | 2 | |
michael@0 | 3 | #ifndef __COMMON_CRC_H |
michael@0 | 4 | #define __COMMON_CRC_H |
michael@0 | 5 | |
michael@0 | 6 | #include <stddef.h> |
michael@0 | 7 | #include "Types.h" |
michael@0 | 8 | |
michael@0 | 9 | class CCRC |
michael@0 | 10 | { |
michael@0 | 11 | UInt32 _value; |
michael@0 | 12 | public: |
michael@0 | 13 | static UInt32 Table[256]; |
michael@0 | 14 | static void InitTable(); |
michael@0 | 15 | |
michael@0 | 16 | CCRC(): _value(0xFFFFFFFF){}; |
michael@0 | 17 | void Init() { _value = 0xFFFFFFFF; } |
michael@0 | 18 | void UpdateByte(Byte v); |
michael@0 | 19 | void UpdateUInt16(UInt16 v); |
michael@0 | 20 | void UpdateUInt32(UInt32 v); |
michael@0 | 21 | void UpdateUInt64(UInt64 v); |
michael@0 | 22 | void Update(const void *data, size_t size); |
michael@0 | 23 | UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } |
michael@0 | 24 | static UInt32 CalculateDigest(const void *data, size_t size) |
michael@0 | 25 | { |
michael@0 | 26 | CCRC crc; |
michael@0 | 27 | crc.Update(data, size); |
michael@0 | 28 | return crc.GetDigest(); |
michael@0 | 29 | } |
michael@0 | 30 | static bool VerifyDigest(UInt32 digest, const void *data, size_t size) |
michael@0 | 31 | { |
michael@0 | 32 | return (CalculateDigest(data, size) == digest); |
michael@0 | 33 | } |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | #endif |