📄 dcphaval.pas
字号:
TestHash: TDCP_haval;
TestOut: array[0..31] of byte;
begin
TestHash:= TDCP_haval.Create(nil);
TestHash.Init;
TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
TestHash.Init;
TestHash.UpdateStr('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
TestHash.Final(TestOut);
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
TestHash.Free;
{$ELSE}
begin
Result:= true;
{$ENDIF}
{$ENDIF}
{$ENDIF}
end;
procedure TDCP_haval.Init;
begin
Burn;
CurrentHash[0]:= $243F6A88;
CurrentHash[1]:= $85A308D3;
CurrentHash[2]:= $13198A2E;
CurrentHash[3]:= $03707344;
CurrentHash[4]:= $A4093822;
CurrentHash[5]:= $299F31D0;
CurrentHash[6]:= $082EFA98;
CurrentHash[7]:= $EC4E6C89;
fInitialized:= true;
end;
procedure TDCP_haval.Burn;
begin
LenHi:= 0; LenLo:= 0;
Index:= 0;
FillChar(HashBuffer,Sizeof(HashBuffer),0);
FillChar(CurrentHash,Sizeof(CurrentHash),0);
fInitialized:= false;
end;
procedure TDCP_haval.Update(const Buffer; Size: longword);
var
PBuf: ^byte;
begin
if not fInitialized then
raise EDCP_hash.Create('Hash not initialized');
Inc(LenHi,Size shr 29);
Inc(LenLo,Size*8);
if LenLo< (Size*8) then
Inc(LenHi);
PBuf:= @Buffer;
while Size> 0 do
begin
if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
begin
Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
Dec(Size,Sizeof(HashBuffer)-Index);
Inc(PBuf,Sizeof(HashBuffer)-Index);
Compress;
end
else
begin
Move(PBuf^,HashBuffer[Index],Size);
Inc(Index,Size);
Size:= 0;
end;
end;
end;
procedure TDCP_haval.Final(var Digest);
{$IFNDEF DIGEST256}
{$IFNDEF DIGEST224}
var
temp: dword;
{$ENDIF}
{$ENDIF}
begin
if not fInitialized then
raise EDCP_hash.Create('Hash not initialized');
HashBuffer[Index]:= $80;
if Index>= 118 then
Compress;
{$IFDEF PASS3}
{$IFDEF DIGEST128}
HashBuffer[118]:= ((128 and 3) shl 6) or (3 shl 3) or 1;
HashBuffer[119]:= (128 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST160}
HashBuffer[118]:= ((160 and 3) shl 6) or (3 shl 3) or 1;
HashBuffer[119]:= (160 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST192}
HashBuffer[118]:= ((192 and 3) shl 6) or (3 shl 3) or 1;
HashBuffer[119]:= (192 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST224}
HashBuffer[118]:= ((224 and 3) shl 6) or (3 shl 3) or 1;
HashBuffer[119]:= (224 shr 2) and $FF;
{$ELSE}
HashBuffer[118]:= ((256 and 3) shl 6) or (3 shl 3) or 1;
HashBuffer[119]:= (256 shr 2) and $FF;
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ELSE}
{$IFDEF PASS4}
{$IFDEF DIGEST128}
HashBuffer[118]:= ((128 and 3) shl 6) or (4 shl 3) or 1;
HashBuffer[119]:= (128 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST160}
HashBuffer[118]:= ((160 and 3) shl 6) or (4 shl 3) or 1;
HashBuffer[119]:= (160 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST192}
HashBuffer[118]:= ((192 and 3) shl 6) or (4 shl 3) or 1;
HashBuffer[119]:= (192 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST224}
HashBuffer[118]:= ((224 and 3) shl 6) or (4 shl 3) or 1;
HashBuffer[119]:= (224 shr 2) and $FF;
{$ELSE}
HashBuffer[118]:= ((256 and 3) shl 6) or (4 shl 3) or 1;
HashBuffer[119]:= (256 shr 2) and $FF;
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ELSE}
{$IFDEF DIGEST128}
HashBuffer[118]:= ((128 and 3) shl 6) or (5 shl 3) or 1;
HashBuffer[119]:= (2128 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST160}
HashBuffer[118]:= ((160 and 3) shl 6) or (5 shl 3) or 1;
HashBuffer[119]:= (160 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST192}
HashBuffer[118]:= ((192 and 3) shl 6) or (5 shl 3) or 1;
HashBuffer[119]:= (192 shr 2) and $FF;
{$ELSE}
{$IFDEF DIGEST224}
HashBuffer[118]:= ((224 and 3) shl 6) or (5 shl 3) or 1;
HashBuffer[119]:= (224 shr 2) and $FF;
{$ELSE}
HashBuffer[118]:= ((256 and 3) shl 6) or (5 shl 3) or 1;
HashBuffer[119]:= (256 shr 2) and $FF;
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
PDWord(@HashBuffer[120])^:= LenLo;
PDWord(@HashBuffer[124])^:= LenHi;
Compress;
{$IFDEF DIGEST128}
temp:= (CurrentHash[7] and $000000FF) or
(CurrentHash[6] and $FF000000) or
(CurrentHash[5] and $00FF0000) or
(CurrentHash[4] and $0000FF00);
Inc(CurrentHash[0],(temp shr 8) or (temp shl 24));
temp:= (CurrentHash[7] and $0000FF00) or
(CurrentHash[6] and $000000FF) or
(CurrentHash[5] and $FF000000) or
(CurrentHash[4] and $00FF0000);
Inc(CurrentHash[1],(temp shr 16) or (temp shl 16));
temp:= (CurrentHash[7] and $00FF0000) or
(CurrentHash[6] and $0000FF00) or
(CurrentHash[5] and $000000FF) or
(CurrentHash[4] and $FF000000);
Inc(CurrentHash[2],(temp shr 24) or (temp shl 8));
temp:= (CurrentHash[7] and $FF000000) or
(CurrentHash[6] and $00FF0000) or
(CurrentHash[5] and $0000FF00) or
(CurrentHash[4] and $000000FF);
Inc(CurrentHash[3],temp);
Move(CurrentHash,Digest,128 div 8);
{$ELSE}
{$IFDEF DIGEST160}
temp:= (CurrentHash[7] and $3F) or
(CurrentHash[6] and ($7F shl 25)) or
(CurrentHash[5] and ($3F shl 19));
Inc(CurrentHash[0],(temp shr 19) or (temp shl 13));
temp:= (CurrentHash[7] and ($3F shl 6)) or
(CurrentHash[6] and $3F) or
(CurrentHash[5] and ($7F shl 25));
Inc(CurrentHash[1],(temp shr 25) or (temp shl 7));
temp:= (CurrentHash[7] and ($7F shl 12)) or
(CurrentHash[6] and ($3F shl 6)) or
(CurrentHash[5] and $3F);
Inc(CurrentHash[2],temp);
temp:= (CurrentHash[7] and ($3F shl 19)) or
(CurrentHash[6] and ($7F shl 12)) or
(CurrentHash[5] and ($3F shl 6));
Inc(CurrentHash[3],temp shr 6);
temp:= (CurrentHash[7] and ($7F shl 25)) or
(CurrentHash[6] and ($3F shl 19)) or
(CurrentHash[5] and ($7F shl 12));
Inc(CurrentHash[4],temp shr 12);
Move(CurrentHash,Digest,160 div 8);
{$ELSE}
{$IFDEF DIGEST192}
temp:= (CurrentHash[7] and $1F) or
(CurrentHash[6] and ($3F shl 26));
Inc(CurrentHash[0],(temp shr 26) or (temp shl 6));
temp:= (CurrentHash[7] and ($1F shl 5)) or
(CurrentHash[6] and $1F);
Inc(CurrentHash[1],temp);
temp:= (CurrentHash[7] and ($3F shl 10)) or
(CurrentHash[6] and ($1F shl 5));
Inc(CurrentHash[2],temp shr 5);
temp:= (CurrentHash[7] and ($1F shl 16)) or
(CurrentHash[6] and ($3F shl 10));
Inc(CurrentHash[3],temp shr 10);
temp:= (CurrentHash[7] and ($1F shl 21)) or
(CurrentHash[6] and ($1F shl 16));
Inc(CurrentHash[4],temp shr 16);
temp:= (CurrentHash[7] and ($3F shl 26)) or
(CurrentHash[6] and ($1F shl 21));
Inc(CurrentHash[5],temp shr 21);
Move(CurrentHash,Digest,192 div 8);
{$ELSE}
{$IFDEF DIGEST224}
Inc(CurrentHash[0],(CurrentHash[7] shr 27) and $1F);
Inc(CurrentHash[1],(CurrentHash[7] shr 22) and $1F);
Inc(CurrentHash[2],(CurrentHash[7] shr 18) and $F);
Inc(CurrentHash[3],(CurrentHash[7] shr 13) and $1F);
Inc(CurrentHash[4],(CurrentHash[7] shr 9) and $F);
Inc(CurrentHash[5],(CurrentHash[7] shr 4) and $1F);
Inc(CurrentHash[6],CurrentHash[7] and $F);
Move(CurrentHash,Digest,224 div 8);
{$ELSE}
Move(CurrentHash,Digest,256 div 8);
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
Burn;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -