-
Notifications
You must be signed in to change notification settings - Fork 3
/
CRC32_AUTOSAR.pas
84 lines (72 loc) · 3.8 KB
/
CRC32_AUTOSAR.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
unit CRC32_AUTOSAR;
//CRC-32 AUTOSAR
//Author: domasz
//Last Update: 2022-11-20
//Licence: MIT
interface
uses SysUtils, HasherBase;
type THasherCRC32_AUTOSAR= class(THasherbase)
private
FHash: Cardinal;
public
constructor Create; override;
procedure Update(Msg: PByte; Length: Integer); override;
function Final: String; override;
end;
implementation
var Table: array[0..255] of LongInt = (
$00000000, $30850FF5, $610A1FEA, $518F101F, $C2143FD4, $F2913021, $A31E203E, $939B2FCB,
$159615F7, $25131A02, $749C0A1D, $441905E8, $D7822A23, $E70725D6, $B68835C9, $860D3A3C,
$2B2C2BEE, $1BA9241B, $4A263404, $7AA33BF1, $E938143A, $D9BD1BCF, $88320BD0, $B8B70425,
$3EBA3E19, $0E3F31EC, $5FB021F3, $6F352E06, $FCAE01CD, $CC2B0E38, $9DA41E27, $AD2111D2,
$565857DC, $66DD5829, $37524836, $07D747C3, $944C6808, $A4C967FD, $F54677E2, $C5C37817,
$43CE422B, $734B4DDE, $22C45DC1, $12415234, $81DA7DFF, $B15F720A, $E0D06215, $D0556DE0,
$7D747C32, $4DF173C7, $1C7E63D8, $2CFB6C2D, $BF6043E6, $8FE54C13, $DE6A5C0C, $EEEF53F9,
$68E269C5, $58676630, $09E8762F, $396D79DA, $AAF65611, $9A7359E4, $CBFC49FB, $FB79460E,
$ACB0AFB8, $9C35A04D, $CDBAB052, $FD3FBFA7, $6EA4906C, $5E219F99, $0FAE8F86, $3F2B8073,
$B926BA4F, $89A3B5BA, $D82CA5A5, $E8A9AA50, $7B32859B, $4BB78A6E, $1A389A71, $2ABD9584,
$879C8456, $B7198BA3, $E6969BBC, $D6139449, $4588BB82, $750DB477, $2482A468, $1407AB9D,
$920A91A1, $A28F9E54, $F3008E4B, $C38581BE, $501EAE75, $609BA180, $3114B19F, $0191BE6A,
$FAE8F864, $CA6DF791, $9BE2E78E, $AB67E87B, $38FCC7B0, $0879C845, $59F6D85A, $6973D7AF,
$EF7EED93, $DFFBE266, $8E74F279, $BEF1FD8C, $2D6AD247, $1DEFDDB2, $4C60CDAD, $7CE5C258,
$D1C4D38A, $E141DC7F, $B0CECC60, $804BC395, $13D0EC5E, $2355E3AB, $72DAF3B4, $425FFC41,
$C452C67D, $F4D7C988, $A558D997, $95DDD662, $0646F9A9, $36C3F65C, $674CE643, $57C9E9B6,
$C8DF352F, $F85A3ADA, $A9D52AC5, $99502530, $0ACB0AFB, $3A4E050E, $6BC11511, $5B441AE4,
$DD4920D8, $EDCC2F2D, $BC433F32, $8CC630C7, $1F5D1F0C, $2FD810F9, $7E5700E6, $4ED20F13,
$E3F31EC1, $D3761134, $82F9012B, $B27C0EDE, $21E72115, $11622EE0, $40ED3EFF, $7068310A,
$F6650B36, $C6E004C3, $976F14DC, $A7EA1B29, $347134E2, $04F43B17, $557B2B08, $65FE24FD,
$9E8762F3, $AE026D06, $FF8D7D19, $CF0872EC, $5C935D27, $6C1652D2, $3D9942CD, $0D1C4D38,
$8B117704, $BB9478F1, $EA1B68EE, $DA9E671B, $490548D0, $79804725, $280F573A, $188A58CF,
$B5AB491D, $852E46E8, $D4A156F7, $E4245902, $77BF76C9, $473A793C, $16B56923, $263066D6,
$A03D5CEA, $90B8531F, $C1374300, $F1B24CF5, $6229633E, $52AC6CCB, $03237CD4, $33A67321,
$646F9A97, $54EA9562, $0565857D, $35E08A88, $A67BA543, $96FEAAB6, $C771BAA9, $F7F4B55C,
$71F98F60, $417C8095, $10F3908A, $20769F7F, $B3EDB0B4, $8368BF41, $D2E7AF5E, $E262A0AB,
$4F43B179, $7FC6BE8C, $2E49AE93, $1ECCA166, $8D578EAD, $BDD28158, $EC5D9147, $DCD89EB2,
$5AD5A48E, $6A50AB7B, $3BDFBB64, $0B5AB491, $98C19B5A, $A84494AF, $F9CB84B0, $C94E8B45,
$3237CD4B, $02B2C2BE, $533DD2A1, $63B8DD54, $F023F29F, $C0A6FD6A, $9129ED75, $A1ACE280,
$27A1D8BC, $1724D749, $46ABC756, $762EC8A3, $E5B5E768, $D530E89D, $84BFF882, $B43AF777,
$191BE6A5, $299EE950, $7811F94F, $4894F6BA, $DB0FD971, $EB8AD684, $BA05C69B, $8A80C96E,
$0C8DF352, $3C08FCA7, $6D87ECB8, $5D02E34D, $CE99CC86, $FE1CC373, $AF93D36C, $9F16DC99
);
constructor THasherCRC32_AUTOSAR.Create;
begin
inherited Create;
FHash := $FFFFFFFF;
Check := '1697D06A';
end;
procedure THasherCRC32_AUTOSAR.Update(Msg: PByte; Length: Integer);
var i: Integer;
begin
for i:=0 to Length-1 do begin
FHash := (FHash shr 8) xor Table[byte(FHash) xor Msg^];
Inc(Msg);
end;
end;
function THasherCRC32_AUTOSAR.Final: String;
begin
FHash := FHash xor $FFFFFFFF;
Result := IntToHex(FHash, 8);
end;
initialization
HasherList.RegisterHasher('CRC-32 AUTOSAR', THasherCRC32_AUTOSAR);
end.