-
Notifications
You must be signed in to change notification settings - Fork 3
/
rhlShiftAndXor.pas
57 lines (45 loc) · 940 Bytes
/
rhlShiftAndXor.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
unit rhlShiftAndXor;
interface
uses
rhlCore;
type
{ TrhlShiftAndXor }
TrhlShiftAndXor = class(TrhlHash)
private
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
{ TrhlShiftAndXor }
procedure TrhlShiftAndXor.UpdateBytes(const ABuffer; ASize: LongWord);
var
b: PByte;
begin
b := @ABuffer;
while ASize > 0 do
begin
m_hash := m_hash xor ((m_hash shl 5) + (m_hash shr 2) + b^);
Inc(b);
Dec(ASize);
end;
end;
constructor TrhlShiftAndXor.Create;
begin
HashSize := 4;
BlockSize := 1;
end;
procedure TrhlShiftAndXor.Init;
begin
inherited Init;
m_hash := 0;
end;
procedure TrhlShiftAndXor.Final(var ADigest);
begin
Move(m_hash, ADigest, 4);
end;
end.