haval.pas
来自「用于开发税务票据管理的软件」· PAS 代码 · 共 549 行 · 第 1/3 页
PAS
549 行
{******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (davebarton@bigfoot.com) *************}
{******************************************************************************}
{* A binary compatible implementation of Haval ********************************}
{******************************************************************************}
{* Copyright (c) 1999-2000 David Barton *}
{* Permission is hereby granted, free of charge, to any person obtaining a *}
{* copy of this software and associated documentation files (the "Software"), *}
{* to deal in the Software without restriction, including without limitation *}
{* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
{* and/or sell copies of the Software, and to permit persons to whom the *}
{* Software is furnished to do so, subject to the following conditions: *}
{* *}
{* The above copyright notice and this permission notice shall be included in *}
{* all copies or substantial portions of the Software. *}
{* *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
{* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
{* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
{* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************}
unit Haval;
interface
uses
Classes, Sysutils, DCPcrypt, DCPconst;
type
TDCP_haval= class(TDCP_hash)
protected
LenHi: longint;
LenLo2, LenLo1: word; { annoying fix for D1-3 users who don't have longword }
Index: DWord;
CurrentHash: array[0..7] of DWord;
HashBuffer: array[0..127] of byte;
procedure Compress;
public
class function GetId: longint; override;
class function GetAlgorithm: string; override;
class function GetHashSize: longint; override;
class function SelfTest: boolean; override;
procedure Init; override;
procedure Burn; override;
procedure Update(const Buffer; Size: longint); override;
procedure Final(var Digest); override;
end;
{******************************************************************************}
{******************************************************************************}
implementation
{$R-}{$Q-}
procedure TDCP_haval.Compress;
var
t7, t6, t5, t4, t3, t2, t1, t0: DWord;
W: array[0..31] of DWord;
Temp: dword;
begin
t0:= CurrentHash[0];
t1:= CurrentHash[1];
t2:= CurrentHash[2];
t3:= CurrentHash[3];
t4:= CurrentHash[4];
t5:= CurrentHash[5];
t6:= CurrentHash[6];
t7:= CurrentHash[7];
Move(HashBuffer,W,Sizeof(W));
Temp:= ((t2) and ((t6) xor (t1)) xor (t5) and (t4) xor (t0) and (t3) xor (t6));
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0];
Temp:= ((t1) and ((t5) xor (t0)) xor (t4) and (t3) xor (t7) and (t2) xor (t5));
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 1];
Temp:= ((t0) and ((t4) xor (t7)) xor (t3) and (t2) xor (t6) and (t1) xor (t4));
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 2];
Temp:= ((t7) and ((t3) xor (t6)) xor (t2) and (t1) xor (t5) and (t0) xor (t3));
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3];
Temp:= ((t6) and ((t2) xor (t5)) xor (t1) and (t0) xor (t4) and (t7) xor (t2));
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4];
Temp:= ((t5) and ((t1) xor (t4)) xor (t0) and (t7) xor (t3) and (t6) xor (t1));
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 5];
Temp:= ((t4) and ((t0) xor (t3)) xor (t7) and (t6) xor (t2) and (t5) xor (t0));
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 6];
Temp:= ((t3) and ((t7) xor (t2)) xor (t6) and (t5) xor (t1) and (t4) xor (t7));
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 7];
Temp:= ((t2) and ((t6) xor (t1)) xor (t5) and (t4) xor (t0) and (t3) xor (t6));
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 8];
Temp:= ((t1) and ((t5) xor (t0)) xor (t4) and (t3) xor (t7) and (t2) xor (t5));
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9];
Temp:= ((t0) and ((t4) xor (t7)) xor (t3) and (t2) xor (t6) and (t1) xor (t4));
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[10];
Temp:= ((t7) and ((t3) xor (t6)) xor (t2) and (t1) xor (t5) and (t0) xor (t3));
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[11];
Temp:= ((t6) and ((t2) xor (t5)) xor (t1) and (t0) xor (t4) and (t7) xor (t2));
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[12];
Temp:= ((t5) and ((t1) xor (t4)) xor (t0) and (t7) xor (t3) and (t6) xor (t1));
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[13];
Temp:= ((t4) and ((t0) xor (t3)) xor (t7) and (t6) xor (t2) and (t5) xor (t0));
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[14];
Temp:= ((t3) and ((t7) xor (t2)) xor (t6) and (t5) xor (t1) and (t4) xor (t7));
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15];
Temp:= ((t2) and ((t6) xor (t1)) xor (t5) and (t4) xor (t0) and (t3) xor (t6));
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[16];
Temp:= ((t1) and ((t5) xor (t0)) xor (t4) and (t3) xor (t7) and (t2) xor (t5));
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[17];
Temp:= ((t0) and ((t4) xor (t7)) xor (t3) and (t2) xor (t6) and (t1) xor (t4));
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[18];
Temp:= ((t7) and ((t3) xor (t6)) xor (t2) and (t1) xor (t5) and (t0) xor (t3));
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[19];
Temp:= ((t6) and ((t2) xor (t5)) xor (t1) and (t0) xor (t4) and (t7) xor (t2));
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[20];
Temp:= ((t5) and ((t1) xor (t4)) xor (t0) and (t7) xor (t3) and (t6) xor (t1));
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[21];
Temp:= ((t4) and ((t0) xor (t3)) xor (t7) and (t6) xor (t2) and (t5) xor (t0));
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[22];
Temp:= ((t3) and ((t7) xor (t2)) xor (t6) and (t5) xor (t1) and (t4) xor (t7));
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23];
Temp:= ((t2) and ((t6) xor (t1)) xor (t5) and (t4) xor (t0) and (t3) xor (t6));
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24];
Temp:= ((t1) and ((t5) xor (t0)) xor (t4) and (t3) xor (t7) and (t2) xor (t5));
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[25];
Temp:= ((t0) and ((t4) xor (t7)) xor (t3) and (t2) xor (t6) and (t1) xor (t4));
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26];
Temp:= ((t7) and ((t3) xor (t6)) xor (t2) and (t1) xor (t5) and (t0) xor (t3));
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[27];
Temp:= ((t6) and ((t2) xor (t5)) xor (t1) and (t0) xor (t4) and (t7) xor (t2));
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28];
Temp:= ((t5) and ((t1) xor (t4)) xor (t0) and (t7) xor (t3) and (t6) xor (t1));
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[29];
Temp:= ((t4) and ((t0) xor (t3)) xor (t7) and (t6) xor (t2) and (t5) xor (t0));
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[30];
Temp:= ((t3) and ((t7) xor (t2)) xor (t6) and (t5) xor (t1) and (t4) xor (t7));
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[31];
Temp:= (t3 and (t4 and (not t0) xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $452821E6;
Temp:= (t2 and (t3 and (not t7) xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $38D01377;
Temp:= (t1 and (t2 and (not t6) xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[26] + $BE5466CF;
Temp:= (t0 and (t1 and (not t5) xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[18] + $34E90C6C;
Temp:= (t7 and (t0 and (not t4) xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[11] + $C0AC29B7;
Temp:= (t6 and (t7 and (not t3) xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[28] + $C97C50DD;
Temp:= (t5 and (t6 and (not t2) xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 7] + $3F84D5B5;
Temp:= (t4 and (t5 and (not t1) xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[16] + $B5470917;
Temp:= (t3 and (t4 and (not t0) xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 0] + $9216D5D9;
Temp:= (t2 and (t3 and (not t7) xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $8979FB1B;
Temp:= (t1 and (t2 and (not t6) xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[20] + $D1310BA6;
Temp:= (t0 and (t1 and (not t5) xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $98DFB5AC;
Temp:= (t7 and (t0 and (not t4) xor t5 and t6 xor t2 xor t1) xor t5 and (t0 xor t6) xor t4 and t6 xor t1);
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $2FFD72DB;
Temp:= (t6 and (t7 and (not t3) xor t4 and t5 xor t1 xor t0) xor t4 and (t7 xor t5) xor t3 and t5 xor t0);
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $D01ADFB7;
Temp:= (t5 and (t6 and (not t2) xor t3 and t4 xor t0 xor t7) xor t3 and (t6 xor t4) xor t2 and t4 xor t7);
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 4] + $B8E1AFED;
Temp:= (t4 and (t5 and (not t1) xor t2 and t3 xor t7 xor t6) xor t2 and (t5 xor t3) xor t1 and t3 xor t6);
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 8] + $6A267E96;
Temp:= (t3 and (t4 and (not t0) xor t1 and t2 xor t6 xor t5) xor t1 and (t4 xor t2) xor t0 and t2 xor t5);
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[30] + $BA7C9045;
Temp:= (t2 and (t3 and (not t7) xor t0 and t1 xor t5 xor t4) xor t0 and (t3 xor t1) xor t7 and t1 xor t4);
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $F12C7F99;
Temp:= (t1 and (t2 and (not t6) xor t7 and t0 xor t4 xor t3) xor t7 and (t2 xor t0) xor t6 and t0 xor t3);
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $24A19947;
Temp:= (t0 and (t1 and (not t5) xor t6 and t7 xor t3 xor t2) xor t6 and (t1 xor t7) xor t5 and t7 xor t2);
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 9] + $B3916CF7;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?