uses
dcrc32;
...
var
S: AnsiString;
Crc: Cardinal;
...
Crc := GetCrc32Hash(@S[1], Length(S));
var
Crc: Cardinal;
...
// Initialize checksum
Crc := Crc32Init;
for {Each portion of data (Data, Size)} do
Crc := Crc32Update(Crc, Data, Size);
// Get final checksum
Crc := Crc32Final(Crc);
It is possible to use dcrc32_table unit to build any CRC-32 checksum calculator.
First, generate lookup-table with GenerateCrc32Table
for specified polynomial (in reversed form):
var
CRC32C_TABLE: array[0..255] of Cardinal;
...
// Generate table for CRC-32C (Castagnoli)
// Reversed polynomial for CRC-32C is $82F63B78
GenerateCrc32Table($82F63B78, @CRC32C_TABLE[0]);
Second, use AccumulateCrc32
for each portion of data to compute checksum. For example, here is how to compute CRC-32C:
function GetCrc32CHash(P: Pointer; Size: SizeUInt): Cardinal; inline;
begin
Result := AccumulateCrc32(
$FFFFFFFF, // InitValue for CRC-32C is $FFFFFFFF
@CRC32C_TABLE[0],
P,
Size) xor $FFFFFFFF; // XorOut for CRC-32C is $FFFFFFFF
end;