-
Notifications
You must be signed in to change notification settings - Fork 3
/
rhlPJW.pas
69 lines (55 loc) · 1.21 KB
/
rhlPJW.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
unit rhlPJW;
interface
uses
rhlCore;
type
{ TrhlPJW }
TrhlPJW = class(TrhlHash)
private
const
BitsInUnsignedInt = SizeOf(DWord) * 8;
ThreeQuarters = (BitsInUnsignedInt * 3) div 4;
OneEighth = BitsInUnsignedInt div 8;
HighBits = High(DWord) shl (BitsInUnsignedInt - OneEighth);
var
m_hash: DWord;
protected
procedure UpdateBytes(const ABuffer; ASize: LongWord); override;
public
constructor Create; override;
procedure Init; override;
procedure Final(var ADigest); override;
end;
implementation
{ TrhlPJW }
procedure TrhlPJW.UpdateBytes(const ABuffer; ASize: LongWord);
var
b: PByte;
test: DWord;
begin
b := @ABuffer;
while ASize > 0 do
begin
m_hash := (m_hash shl OneEighth) + b^;
test := m_hash and HighBits;
if (test <> 0) then
m_hash := ((m_hash xor (test shr ThreeQuarters)) and (not HighBits));
Inc(b);
Dec(ASize);
end;
end;
constructor TrhlPJW.Create;
begin
HashSize := 4;
BlockSize := 1;
end;
procedure TrhlPJW.Init;
begin
inherited Init;
m_hash := 0;
end;
procedure TrhlPJW.Final(var ADigest);
begin
Move(m_hash, ADigest, 4);
end;
end.