NSIS/Source/7zip/Common/CRC.cpp
kichik ec6957f356 fixed bug #1005296 - NSIS build error on Linux with g++ 3.4.0
- upgraded to the latest LZMA SDK


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3637 212acab6-be3b-0410-9dea-997c60f758d6
2004-08-20 19:17:21 +00:00

55 lines
938 B
C++

// Common/CRC.cpp
#include "StdAfx.h"
#include "CRC.h"
static const UInt32 kCRCPoly = 0xEDB88320;
UInt32 CCRC::Table[256];
void CCRC::InitTable()
{
for (UInt32 i = 0; i < 256; i++)
{
UInt32 r = i;
for (int j = 0; j < 8; j++)
if (r & 1)
r = (r >> 1) ^ kCRCPoly;
else
r >>= 1;
CCRC::Table[i] = r;
}
}
class CCRCTableInit
{
public:
CCRCTableInit() { CCRC::InitTable(); }
} g_CRCTableInit;
void CCRC::Update(Byte b)
{
_value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);
}
void CCRC::Update(UInt32 v)
{
for (int i = 0; i < 4; i++)
Update((Byte)(v >> (8 * i)));
}
void CCRC::Update(const UInt64 &v)
{
for (int i = 0; i < 8; i++)
Update((Byte)(v >> (8 * i)));
}
void CCRC::Update(const void *data, UInt32 size)
{
UInt32 v = _value;
const Byte *p = (const Byte *)data;
for (; size > 0 ; size--, p++)
v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);
_value = v;
}