📄 dcpripemd160.pas
字号:
{******************************************************************************}
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
{******************************************************************************}
{* A binary compatible implementation of RipeMD-160 ***************************}
{******************************************************************************}
{* Copyright (c) 1999-2002 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 DCPripemd160;
interface
uses
Classes, Sysutils, DCPcrypt2, DCPconst;
type
TDCP_ripemd160= class(TDCP_hash)
protected
LenHi, LenLo: longword;
Index: DWord;
CurrentHash: array[0..4] of DWord;
HashBuffer: array[0..63] of byte;
procedure Compress;
public
class function GetId: integer; override;
class function GetAlgorithm: string; override;
class function GetHashSize: integer; override;
class function SelfTest: boolean; override;
procedure Init; override;
procedure Burn; override;
procedure Update(const Buffer; Size: longword); override;
procedure Final(var Digest); override;
end;
{******************************************************************************}
{******************************************************************************}
implementation
{$R-}{$Q-}
procedure TDCP_ripemd160.Compress;
var
aa, bb, cc, dd, ee, aaa, bbb, ccc, ddd, eee: DWord;
X: array[0..15] of DWord;
begin
Move(HashBuffer,X,Sizeof(X));
aa:= CurrentHash[0];
aaa:= CurrentHash[0];
bb:= CurrentHash[1];
bbb:= CurrentHash[1];
cc:= CurrentHash[2];
ccc:= CurrentHash[2];
dd:= CurrentHash[3];
ddd:= CurrentHash[3];
ee:= CurrentHash[4];
eee:= CurrentHash[4];
aa:= aa + (bb xor cc xor dd) + X[ 0];
aa:= ((aa shl 11) or (aa shr (32-11))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + (aa xor bb xor cc) + X[ 1];
ee:= ((ee shl 14) or (ee shr (32-14))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + (ee xor aa xor bb) + X[ 2];
dd:= ((dd shl 15) or (dd shr (32-15))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + (dd xor ee xor aa) + X[ 3];
cc:= ((cc shl 12) or (cc shr (32-12))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + (cc xor dd xor ee) + X[ 4];
bb:= ((bb shl 5) or (bb shr (32-5))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + (bb xor cc xor dd) + X[ 5];
aa:= ((aa shl 8) or (aa shr (32-8))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + (aa xor bb xor cc) + X[ 6];
ee:= ((ee shl 7) or (ee shr (32-7))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + (ee xor aa xor bb) + X[ 7];
dd:= ((dd shl 9) or (dd shr (32-9))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + (dd xor ee xor aa) + X[ 8];
cc:= ((cc shl 11) or (cc shr (32-11))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + (cc xor dd xor ee) + X[ 9];
bb:= ((bb shl 13) or (bb shr (32-13))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + (bb xor cc xor dd) + X[10];
aa:= ((aa shl 14) or (aa shr (32-14))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + (aa xor bb xor cc) + X[11];
ee:= ((ee shl 15) or (ee shr (32-15))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + (ee xor aa xor bb) + X[12];
dd:= ((dd shl 6) or (dd shr (32-6))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + (dd xor ee xor aa) + X[13];
cc:= ((cc shl 7) or (cc shr (32-7))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + (cc xor dd xor ee) + X[14];
bb:= ((bb shl 9) or (bb shr (32-9))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + (bb xor cc xor dd) + X[15];
aa:= ((aa shl 8) or (aa shr (32-8))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + ((aa and bb) or ((not aa) and cc)) + X[ 7] + $5a827999;
ee:= ((ee shl 7) or (ee shr (32-7))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + ((ee and aa) or ((not ee) and bb)) + X[ 4] + $5a827999;
dd:= ((dd shl 6) or (dd shr (32-6))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + ((dd and ee) or ((not dd) and aa)) + X[13] + $5a827999;
cc:= ((cc shl 8) or (cc shr (32-8))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + ((cc and dd) or ((not cc) and ee)) + X[ 1] + $5a827999;
bb:= ((bb shl 13) or (bb shr (32-13))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + ((bb and cc) or ((not bb) and dd)) + X[10] + $5a827999;
aa:= ((aa shl 11) or (aa shr (32-11))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + ((aa and bb) or ((not aa) and cc)) + X[ 6] + $5a827999;
ee:= ((ee shl 9) or (ee shr (32-9))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + ((ee and aa) or ((not ee) and bb)) + X[15] + $5a827999;
dd:= ((dd shl 7) or (dd shr (32-7))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + ((dd and ee) or ((not dd) and aa)) + X[ 3] + $5a827999;
cc:= ((cc shl 15) or (cc shr (32-15))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + ((cc and dd) or ((not cc) and ee)) + X[12] + $5a827999;
bb:= ((bb shl 7) or (bb shr (32-7))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + ((bb and cc) or ((not bb) and dd)) + X[ 0] + $5a827999;
aa:= ((aa shl 12) or (aa shr (32-12))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + ((aa and bb) or ((not aa) and cc)) + X[ 9] + $5a827999;
ee:= ((ee shl 15) or (ee shr (32-15))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + ((ee and aa) or ((not ee) and bb)) + X[ 5] + $5a827999;
dd:= ((dd shl 9) or (dd shr (32-9))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + ((dd and ee) or ((not dd) and aa)) + X[ 2] + $5a827999;
cc:= ((cc shl 11) or (cc shr (32-11))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + ((cc and dd) or ((not cc) and ee)) + X[14] + $5a827999;
bb:= ((bb shl 7) or (bb shr (32-7))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + ((bb and cc) or ((not bb) and dd)) + X[11] + $5a827999;
aa:= ((aa shl 13) or (aa shr (32-13))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + ((aa and bb) or ((not aa) and cc)) + X[ 8] + $5a827999;
ee:= ((ee shl 12) or (ee shr (32-12))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + ((ee or (not aa)) xor bb) + X[ 3] + $6ed9eba1;
dd:= ((dd shl 11) or (dd shr (32-11))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + ((dd or (not ee)) xor aa) + X[10] + $6ed9eba1;
cc:= ((cc shl 13) or (cc shr (32-13))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + ((cc or (not dd)) xor ee) + X[14] + $6ed9eba1;
bb:= ((bb shl 6) or (bb shr (32-6))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + ((bb or (not cc)) xor dd) + X[ 4] + $6ed9eba1;
aa:= ((aa shl 7) or (aa shr (32-7))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + ((aa or (not bb)) xor cc) + X[ 9] + $6ed9eba1;
ee:= ((ee shl 14) or (ee shr (32-14))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + ((ee or (not aa)) xor bb) + X[15] + $6ed9eba1;
dd:= ((dd shl 9) or (dd shr (32-9))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + ((dd or (not ee)) xor aa) + X[ 8] + $6ed9eba1;
cc:= ((cc shl 13) or (cc shr (32-13))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + ((cc or (not dd)) xor ee) + X[ 1] + $6ed9eba1;
bb:= ((bb shl 15) or (bb shr (32-15))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + ((bb or (not cc)) xor dd) + X[ 2] + $6ed9eba1;
aa:= ((aa shl 14) or (aa shr (32-14))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + ((aa or (not bb)) xor cc) + X[ 7] + $6ed9eba1;
ee:= ((ee shl 8) or (ee shr (32-8))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + ((ee or (not aa)) xor bb) + X[ 0] + $6ed9eba1;
dd:= ((dd shl 13) or (dd shr (32-13))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + ((dd or (not ee)) xor aa) + X[ 6] + $6ed9eba1;
cc:= ((cc shl 6) or (cc shr (32-6))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + ((cc or (not dd)) xor ee) + X[13] + $6ed9eba1;
bb:= ((bb shl 5) or (bb shr (32-5))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + ((bb or (not cc)) xor dd) + X[11] + $6ed9eba1;
aa:= ((aa shl 12) or (aa shr (32-12))) + ee;
cc:= ((cc shl 10) or (cc shr (32-10)));
ee:= ee + ((aa or (not bb)) xor cc) + X[ 5] + $6ed9eba1;
ee:= ((ee shl 7) or (ee shr (32-7))) + dd;
bb:= ((bb shl 10) or (bb shr (32-10)));
dd:= dd + ((ee or (not aa)) xor bb) + X[12] + $6ed9eba1;
dd:= ((dd shl 5) or (dd shr (32-5))) + cc;
aa:= ((aa shl 10) or (aa shr (32-10)));
cc:= cc + ((dd and aa) or (ee and (not aa))) + X[ 1] + $8f1bbcdc;
cc:= ((cc shl 11) or (cc shr (32-11))) + bb;
ee:= ((ee shl 10) or (ee shr (32-10)));
bb:= bb + ((cc and ee) or (dd and (not ee))) + X[ 9] + $8f1bbcdc;
bb:= ((bb shl 12) or (bb shr (32-12))) + aa;
dd:= ((dd shl 10) or (dd shr (32-10)));
aa:= aa + ((bb and dd) or (cc and (not dd))) + X[11] + $8f1bbcdc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -