1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #include "CRC.h"
4 
5 extern "C" {
6 #include "lib/7z/7zCrc.h"
7 }
8 
9 
10 static bool crcTableInitialized;
11 
12 
CRC()13 CRC::CRC()
14 {
15 	crc = CRC_INIT_VAL;
16 	if (!crcTableInitialized) {
17 		crcTableInitialized = true;
18 		CrcGenerateTable();
19 	}
20 }
21 
22 
GetDigest() const23 unsigned int CRC::GetDigest() const
24 {
25 	// make a temporary copy to get away with the const
26 	unsigned int temp = crc;
27 	return CRC_GET_DIGEST(temp);
28 }
29 
30 
GetCRC(const void * data,unsigned int size)31 unsigned int CRC::GetCRC(const void* data, unsigned int size)
32 {
33 	return CrcUpdate(0, data, size);
34 }
35 
36 
Update(const void * data,unsigned int size)37 CRC& CRC::Update(const void* data, unsigned int size)
38 {
39 	crc = CrcUpdate(crc, data, size);
40 	return *this;
41 }
42 
43 
Update(unsigned int data)44 CRC& CRC::Update(unsigned int data)
45 {
46 	crc = CrcUpdate(crc, &data, sizeof(unsigned));
47 	return *this;
48 }
49