mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-24 10:12:20 -05:00
Simba: Hash Functions
This commit is contained in:
parent
2b8fa3839c
commit
f14f484c28
@ -69,6 +69,12 @@ uses
|
||||
httpsend,
|
||||
superobject,
|
||||
Clipbrd,
|
||||
DCPcrypt2,
|
||||
DCPhaval,
|
||||
DCPmd4, DCPmd5,
|
||||
DCPripemd128, DCPripemd160,
|
||||
DCPsha1, DCPsha256, DCPsha512,
|
||||
DCPtiger,
|
||||
SimbaUnit,updateform, mmisc, mmlpsthread; // for GetTickCount and others.//Writeln
|
||||
|
||||
{$ifdef Linux}
|
||||
@ -157,6 +163,7 @@ end;
|
||||
{$I ../../Units/MMLAddon/PSInc/Wrappers/window.inc}
|
||||
{$I ../../Units/MMLAddon/PSInc/Wrappers/tpa.inc}
|
||||
{$I ../../Units/MMLAddon/PSInc/Wrappers/strings.inc}
|
||||
{$I ../../Units/MMLAddon/PSInc/Wrappers/crypto.inc}
|
||||
{$I ../../Units/MMLAddon/PSInc/Wrappers/colour.inc}
|
||||
{$I ../../Units/MMLAddon/PSInc/Wrappers/colourconv.inc}
|
||||
{$I ../../Units/MMLAddon/PSInc/Wrappers/math.inc}
|
||||
|
201
Units/MMLAddon/PSInc/Wrappers/crypto.inc
Normal file
201
Units/MMLAddon/PSInc/Wrappers/crypto.inc
Normal file
@ -0,0 +1,201 @@
|
||||
|
||||
function ps_haval(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_haval;
|
||||
Digest: array[0..31] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_haval.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 31 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_md4(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_md4;
|
||||
Digest: array[0..15] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_md4.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 15 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_md5(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_md5;
|
||||
Digest: array[0..15] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_md5.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 15 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_ripemd128(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_ripemd128;
|
||||
Digest: array[0..15] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_ripemd128.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 15 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_ripemd160(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_ripemd160;
|
||||
Digest: array[0..19] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_ripemd160.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 19 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_sha1(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_sha1;
|
||||
Digest: array[0..19] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_sha1.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 19 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_sha256(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_sha256;
|
||||
Digest: array[0..31] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_sha256.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 31 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_sha384(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_sha384;
|
||||
Digest: array[0..47] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_sha384.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 47 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_sha512(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_sha512;
|
||||
Digest: array[0..63] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_sha512.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 63 do
|
||||
Result := Result + IntToHex(Digest[I], 2);
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function ps_tiger(Data: string): string;
|
||||
var
|
||||
HASH: TDCP_tiger;
|
||||
Digest: array[0..23] of byte;
|
||||
I: integer;
|
||||
begin
|
||||
dcpFillChar(Digest, SizeOf(Digest), 0);
|
||||
Hash := TDCP_tiger.Create(nil);
|
||||
try
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Data);
|
||||
Hash.Final(Digest);
|
||||
Result := '';
|
||||
for I := 0 to 23 do
|
||||
Result := Result + string(IntToHex(Digest[I], 2));
|
||||
finally
|
||||
Hash.Free;
|
||||
end;
|
||||
end;
|
||||
|
@ -232,7 +232,18 @@ AddFunction(@ps_SplitRegExpr,'procedure SplitRegExpr( const RegExpr, InputStr :
|
||||
AddFunction(@ps_ReplaceRegExpr,'function ReplaceRegExpr( const RegExpr, InputStr, ReplaceStr : String; UseSubstitution : boolean) : String;');
|
||||
AddFunction(@ps_posex, 'function PosEx(needle, haystack: String; offset: integer): integer;');
|
||||
|
||||
|
||||
{crypto}
|
||||
SetCurrSection('Crypto');
|
||||
AddFunction(@ps_haval, 'function haval(Data: string): string;');
|
||||
AddFunction(@ps_md4, 'function md4(Data: string): string;');
|
||||
AddFunction(@ps_md5, 'function md5(Data: string): string;');
|
||||
AddFunction(@ps_ripemd128, 'function ripemd128(Data: string): string;');
|
||||
AddFunction(@ps_ripemd160, 'function ripemd160(Data: string): string;');
|
||||
AddFunction(@ps_sha1, 'function sha1(Data: string): string;');
|
||||
AddFunction(@ps_sha256, 'function sha256(Data: string): string;');
|
||||
AddFunction(@ps_sha384, 'function sha384(Data: string): string;');
|
||||
AddFunction(@ps_sha512, 'function sha512(Data: string): string;');
|
||||
AddFunction(@ps_tiger, 'function tiger(Data: string): string;');
|
||||
|
||||
{web}
|
||||
SetCurrSection('Web');
|
||||
|
@ -262,7 +262,13 @@ uses
|
||||
forms,//Forms
|
||||
SynRegExpr,
|
||||
lclintf, // for GetTickCount and others.
|
||||
Clipbrd;
|
||||
Clipbrd,
|
||||
DCPcrypt2,
|
||||
DCPhaval,
|
||||
DCPmd4, DCPmd5,
|
||||
DCPripemd128, DCPripemd160,
|
||||
DCPsha1, DCPsha256, DCPsha512,
|
||||
DCPtiger;
|
||||
{$ifdef Linux}
|
||||
{$define PS_SafeCall}
|
||||
{$else}
|
||||
@ -509,6 +515,7 @@ end;
|
||||
{$I PSInc/Wrappers/window.inc}
|
||||
{$I PSInc/Wrappers/tpa.inc}
|
||||
{$I PSInc/Wrappers/strings.inc}
|
||||
{$I PSInc/Wrappers/crypto.inc}
|
||||
{$I PSInc/Wrappers/colour.inc}
|
||||
{$I PSInc/Wrappers/colourconv.inc}
|
||||
{$I PSInc/Wrappers/math.inc}
|
||||
|
339
Units/Misc/DCPhaval5.inc
Normal file
339
Units/Misc/DCPhaval5.inc
Normal file
@ -0,0 +1,339 @@
|
||||
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;
|
||||
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[17] + $0801F2E2;
|
||||
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[24] + $858EFC16;
|
||||
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[29] + $636920D8;
|
||||
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[ 6] + $71574E69;
|
||||
|
||||
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[19] + $A458FEA3;
|
||||
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[12] + $F4933D7E;
|
||||
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[15] + $0D95748F;
|
||||
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[13] + $728EB658;
|
||||
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[ 2] + $718BCD58;
|
||||
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[25] + $82154AEE;
|
||||
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[31] + $7B54A41D;
|
||||
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[27] + $C25A59B5;
|
||||
|
||||
temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $9C30D539;
|
||||
temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $2AF26013;
|
||||
temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 4] + $C5D1B023;
|
||||
temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $286085F0;
|
||||
temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[28] + $CA417918;
|
||||
temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[17] + $B8DB38EF;
|
||||
temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 8] + $8E79DCB0;
|
||||
temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[22] + $603A180E;
|
||||
|
||||
temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[29] + $6C9E0E8B;
|
||||
temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[14] + $B01E8A3E;
|
||||
temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[25] + $D71577C1;
|
||||
temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[12] + $BD314B27;
|
||||
temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[24] + $78AF2FDA;
|
||||
temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[30] + $55605C60;
|
||||
temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $E65525F3;
|
||||
temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[26] + $AA55AB94;
|
||||
|
||||
temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[31] + $57489862;
|
||||
temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[15] + $63E81440;
|
||||
temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 7] + $55CA396A;
|
||||
temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 3] + $2AAB10B6;
|
||||
temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 1] + $B4CC5C34;
|
||||
temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 0] + $1141E8CE;
|
||||
temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[18] + $A15486AF;
|
||||
temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[27] + $7C72E993;
|
||||
|
||||
temp:= (t4 and (t1 and t3 xor t2 xor t5) xor t1 and t0 xor t3 and t6 xor t5);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[13] + $B3EE1411;
|
||||
temp:= (t3 and (t0 and t2 xor t1 xor t4) xor t0 and t7 xor t2 and t5 xor t4);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $636FBC2A;
|
||||
temp:= (t2 and (t7 and t1 xor t0 xor t3) xor t7 and t6 xor t1 and t4 xor t3);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $2BA9C55D;
|
||||
temp:= (t1 and (t6 and t0 xor t7 xor t2) xor t6 and t5 xor t0 and t3 xor t2);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[10] + $741831F6;
|
||||
temp:= (t0 and (t5 and t7 xor t6 xor t1) xor t5 and t4 xor t7 and t2 xor t1);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[23] + $CE5C3E16;
|
||||
temp:= (t7 and (t4 and t6 xor t5 xor t0) xor t4 and t3 xor t6 and t1 xor t0);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $9B87931E;
|
||||
temp:= (t6 and (t3 and t5 xor t4 xor t7) xor t3 and t2 xor t5 and t0 xor t7);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[ 5] + $AFD6BA33;
|
||||
temp:= (t5 and (t2 and t4 xor t3 xor t6) xor t2 and t1 xor t4 and t7 xor t6);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 2] + $6C24CF5C;
|
||||
|
||||
temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[24] + $7A325381;
|
||||
temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 4] + $28958677;
|
||||
temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 0] + $3B8F4898;
|
||||
temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[14] + $6B4BB9AF;
|
||||
temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 2] + $C4BFE81B;
|
||||
temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 7] + $66282193;
|
||||
temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[28] + $61D809CC;
|
||||
temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[23] + $FB21A991;
|
||||
|
||||
temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[26] + $487CAC60;
|
||||
temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 6] + $5DEC8032;
|
||||
temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[30] + $EF845D5D;
|
||||
temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[20] + $E98575B1;
|
||||
temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[18] + $DC262302;
|
||||
temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[25] + $EB651B88;
|
||||
temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[19] + $23893E81;
|
||||
temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 3] + $D396ACC5;
|
||||
|
||||
temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[22] + $0F6D6FF3;
|
||||
temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[11] + $83F44239;
|
||||
temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[31] + $2E0B4482;
|
||||
temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[21] + $A4842004;
|
||||
temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 8] + $69C8F04A;
|
||||
temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[27] + $9E1F9B5E;
|
||||
temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[12] + $21C66842;
|
||||
temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[ 9] + $F6E96C9A;
|
||||
|
||||
temp:= (t3 and (t5 and not t0 xor t2 and not t1 xor t4 xor t1 xor t6) xor t2 and (t4 and t0 xor t5 xor t1) xor t0 and t1 xor t6);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 1] + $670C9C61;
|
||||
temp:= (t2 and (t4 and not t7 xor t1 and not t0 xor t3 xor t0 xor t5) xor t1 and (t3 and t7 xor t4 xor t0) xor t7 and t0 xor t5);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[29] + $ABD388F0;
|
||||
temp:= (t1 and (t3 and not t6 xor t0 and not t7 xor t2 xor t7 xor t4) xor t0 and (t2 and t6 xor t3 xor t7) xor t6 and t7 xor t4);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[ 5] + $6A51A0D2;
|
||||
temp:= (t0 and (t2 and not t5 xor t7 and not t6 xor t1 xor t6 xor t3) xor t7 and (t1 and t5 xor t2 xor t6) xor t5 and t6 xor t3);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[15] + $D8542F68;
|
||||
temp:= (t7 and (t1 and not t4 xor t6 and not t5 xor t0 xor t5 xor t2) xor t6 and (t0 and t4 xor t1 xor t5) xor t4 and t5 xor t2);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $960FA728;
|
||||
temp:= (t6 and (t0 and not t3 xor t5 and not t4 xor t7 xor t4 xor t1) xor t5 and (t7 and t3 xor t0 xor t4) xor t3 and t4 xor t1);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[10] + $AB5133A3;
|
||||
temp:= (t5 and (t7 and not t2 xor t4 and not t3 xor t6 xor t3 xor t0) xor t4 and (t6 and t2 xor t7 xor t3) xor t2 and t3 xor t0);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[16] + $6EEF0B6C;
|
||||
temp:= (t4 and (t6 and not t1 xor t3 and not t2 xor t5 xor t2 xor t7) xor t3 and (t5 and t1 xor t6 xor t2) xor t1 and t2 xor t7);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[13] + $137A3BE4;
|
||||
|
||||
temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[27] + $BA3BF050;
|
||||
temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 3] + $7EFB2A98;
|
||||
temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[21] + $A1F1651D;
|
||||
temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[26] + $39AF0176;
|
||||
temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[17] + $66CA593E;
|
||||
temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[11] + $82430E88;
|
||||
temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[20] + $8CEE8619;
|
||||
temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[29] + $456F9FB4;
|
||||
|
||||
temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[19] + $7D84A5C3;
|
||||
temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 0] + $3B8B5EBE;
|
||||
temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[12] + $E06F75D8;
|
||||
temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[ 7] + $85C12073;
|
||||
temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[13] + $401A449F;
|
||||
temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 8] + $56C16AA6;
|
||||
temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[31] + $4ED3AA62;
|
||||
temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[10] + $363F7706;
|
||||
|
||||
temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 5] + $1BFEDF72;
|
||||
temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[ 9] + $429B023D;
|
||||
temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[14] + $37D0D724;
|
||||
temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[30] + $D00A1248;
|
||||
temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[18] + $DB0FEAD3;
|
||||
temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 6] + $49F1C09B;
|
||||
temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[28] + $075372C9;
|
||||
temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[24] + $80991B7B;
|
||||
|
||||
temp:= (t1 and (t3 and t4 and t6 xor not t5) xor t3 and t0 xor t4 and t5 xor t6 and t2);
|
||||
t7:= ((temp shr 7) or (temp shl 25)) + ((t7 shr 11) or (t7 shl 21)) + w[ 2] + $25D479D8;
|
||||
temp:= (t0 and (t2 and t3 and t5 xor not t4) xor t2 and t7 xor t3 and t4 xor t5 and t1);
|
||||
t6:= ((temp shr 7) or (temp shl 25)) + ((t6 shr 11) or (t6 shl 21)) + w[23] + $F6E8DEF7;
|
||||
temp:= (t7 and (t1 and t2 and t4 xor not t3) xor t1 and t6 xor t2 and t3 xor t4 and t0);
|
||||
t5:= ((temp shr 7) or (temp shl 25)) + ((t5 shr 11) or (t5 shl 21)) + w[16] + $E3FE501A;
|
||||
temp:= (t6 and (t0 and t1 and t3 xor not t2) xor t0 and t5 xor t1 and t2 xor t3 and t7);
|
||||
t4:= ((temp shr 7) or (temp shl 25)) + ((t4 shr 11) or (t4 shl 21)) + w[22] + $B6794C3B;
|
||||
temp:= (t5 and (t7 and t0 and t2 xor not t1) xor t7 and t4 xor t0 and t1 xor t2 and t6);
|
||||
t3:= ((temp shr 7) or (temp shl 25)) + ((t3 shr 11) or (t3 shl 21)) + w[ 4] + $976CE0BD;
|
||||
temp:= (t4 and (t6 and t7 and t1 xor not t0) xor t6 and t3 xor t7 and t0 xor t1 and t5);
|
||||
t2:= ((temp shr 7) or (temp shl 25)) + ((t2 shr 11) or (t2 shl 21)) + w[ 1] + $04C006BA;
|
||||
temp:= (t3 and (t5 and t6 and t0 xor not t7) xor t5 and t2 xor t6 and t7 xor t0 and t4);
|
||||
t1:= ((temp shr 7) or (temp shl 25)) + ((t1 shr 11) or (t1 shl 21)) + w[25] + $C1A94FB6;
|
||||
temp:= (t2 and (t4 and t5 and t7 xor not t6) xor t4 and t1 xor t5 and t6 xor t7 and t3);
|
||||
t0:= ((temp shr 7) or (temp shl 25)) + ((t0 shr 11) or (t0 shl 21)) + w[15] + $409F60C4;
|
520
Units/Misc/DCPtiger.inc
Normal file
520
Units/Misc/DCPtiger.inc
Normal file
@ -0,0 +1,520 @@
|
||||
const
|
||||
t1: array[0..255] of int64= (
|
||||
$02AAB17CF7E90C5E, $AC424B03E243A8EC,
|
||||
$72CD5BE30DD5FCD3, $6D019B93F6F97F3A,
|
||||
$CD9978FFD21F9193, $7573A1C9708029E2,
|
||||
$B164326B922A83C3, $46883EEE04915870,
|
||||
$EAACE3057103ECE6, $C54169B808A3535C,
|
||||
$4CE754918DDEC47C, $0AA2F4DFDC0DF40C,
|
||||
$10B76F18A74DBEFA, $C6CCB6235AD1AB6A,
|
||||
$13726121572FE2FF, $1A488C6F199D921E,
|
||||
$4BC9F9F4DA0007CA, $26F5E6F6E85241C7,
|
||||
$859079DBEA5947B6, $4F1885C5C99E8C92,
|
||||
$D78E761EA96F864B, $8E36428C52B5C17D,
|
||||
$69CF6827373063C1, $B607C93D9BB4C56E,
|
||||
$7D820E760E76B5EA, $645C9CC6F07FDC42,
|
||||
$BF38A078243342E0, $5F6B343C9D2E7D04,
|
||||
$F2C28AEB600B0EC6, $6C0ED85F7254BCAC,
|
||||
$71592281A4DB4FE5, $1967FA69CE0FED9F,
|
||||
$FD5293F8B96545DB, $C879E9D7F2A7600B,
|
||||
$860248920193194E, $A4F9533B2D9CC0B3,
|
||||
$9053836C15957613, $DB6DCF8AFC357BF1,
|
||||
$18BEEA7A7A370F57, $037117CA50B99066,
|
||||
$6AB30A9774424A35, $F4E92F02E325249B,
|
||||
$7739DB07061CCAE1, $D8F3B49CECA42A05,
|
||||
$BD56BE3F51382F73, $45FAED5843B0BB28,
|
||||
$1C813D5C11BF1F83, $8AF0E4B6D75FA169,
|
||||
$33EE18A487AD9999, $3C26E8EAB1C94410,
|
||||
$B510102BC0A822F9, $141EEF310CE6123B,
|
||||
$FC65B90059DDB154, $E0158640C5E0E607,
|
||||
$884E079826C3A3CF, $930D0D9523C535FD,
|
||||
$35638D754E9A2B00, $4085FCCF40469DD5,
|
||||
$C4B17AD28BE23A4C, $CAB2F0FC6A3E6A2E,
|
||||
$2860971A6B943FCD, $3DDE6EE212E30446,
|
||||
$6222F32AE01765AE, $5D550BB5478308FE,
|
||||
$A9EFA98DA0EDA22A, $C351A71686C40DA7,
|
||||
$1105586D9C867C84, $DCFFEE85FDA22853,
|
||||
$CCFBD0262C5EEF76, $BAF294CB8990D201,
|
||||
$E69464F52AFAD975, $94B013AFDF133E14,
|
||||
$06A7D1A32823C958, $6F95FE5130F61119,
|
||||
$D92AB34E462C06C0, $ED7BDE33887C71D2,
|
||||
$79746D6E6518393E, $5BA419385D713329,
|
||||
$7C1BA6B948A97564, $31987C197BFDAC67,
|
||||
$DE6C23C44B053D02, $581C49FED002D64D,
|
||||
$DD474D6338261571, $AA4546C3E473D062,
|
||||
$928FCE349455F860, $48161BBACAAB94D9,
|
||||
$63912430770E6F68, $6EC8A5E602C6641C,
|
||||
$87282515337DDD2B, $2CDA6B42034B701B,
|
||||
$B03D37C181CB096D, $E108438266C71C6F,
|
||||
$2B3180C7EB51B255, $DF92B82F96C08BBC,
|
||||
$5C68C8C0A632F3BA, $5504CC861C3D0556,
|
||||
$ABBFA4E55FB26B8F, $41848B0AB3BACEB4,
|
||||
$B334A273AA445D32, $BCA696F0A85AD881,
|
||||
$24F6EC65B528D56C, $0CE1512E90F4524A,
|
||||
$4E9DD79D5506D35A, $258905FAC6CE9779,
|
||||
$2019295B3E109B33, $F8A9478B73A054CC,
|
||||
$2924F2F934417EB0, $3993357D536D1BC4,
|
||||
$38A81AC21DB6FF8B, $47C4FBF17D6016BF,
|
||||
$1E0FAADD7667E3F5, $7ABCFF62938BEB96,
|
||||
$A78DAD948FC179C9, $8F1F98B72911E50D,
|
||||
$61E48EAE27121A91, $4D62F7AD31859808,
|
||||
$ECEBA345EF5CEAEB, $F5CEB25EBC9684CE,
|
||||
$F633E20CB7F76221, $A32CDF06AB8293E4,
|
||||
$985A202CA5EE2CA4, $CF0B8447CC8A8FB1,
|
||||
$9F765244979859A3, $A8D516B1A1240017,
|
||||
$0BD7BA3EBB5DC726, $E54BCA55B86ADB39,
|
||||
$1D7A3AFD6C478063, $519EC608E7669EDD,
|
||||
$0E5715A2D149AA23, $177D4571848FF194,
|
||||
$EEB55F3241014C22, $0F5E5CA13A6E2EC2,
|
||||
$8029927B75F5C361, $AD139FABC3D6E436,
|
||||
$0D5DF1A94CCF402F, $3E8BD948BEA5DFC8,
|
||||
$A5A0D357BD3FF77E, $A2D12E251F74F645,
|
||||
$66FD9E525E81A082, $2E0C90CE7F687A49,
|
||||
$C2E8BCBEBA973BC5, $000001BCE509745F,
|
||||
$423777BBE6DAB3D6, $D1661C7EAEF06EB5,
|
||||
$A1781F354DAACFD8, $2D11284A2B16AFFC,
|
||||
$F1FC4F67FA891D1F, $73ECC25DCB920ADA,
|
||||
$AE610C22C2A12651, $96E0A810D356B78A,
|
||||
$5A9A381F2FE7870F, $D5AD62EDE94E5530,
|
||||
$D225E5E8368D1427, $65977B70C7AF4631,
|
||||
$99F889B2DE39D74F, $233F30BF54E1D143,
|
||||
$9A9675D3D9A63C97, $5470554FF334F9A8,
|
||||
$166ACB744A4F5688, $70C74CAAB2E4AEAD,
|
||||
$F0D091646F294D12, $57B82A89684031D1,
|
||||
$EFD95A5A61BE0B6B, $2FBD12E969F2F29A,
|
||||
$9BD37013FEFF9FE8, $3F9B0404D6085A06,
|
||||
$4940C1F3166CFE15, $09542C4DCDF3DEFB,
|
||||
$B4C5218385CD5CE3, $C935B7DC4462A641,
|
||||
$3417F8A68ED3B63F, $B80959295B215B40,
|
||||
$F99CDAEF3B8C8572, $018C0614F8FCB95D,
|
||||
$1B14ACCD1A3ACDF3, $84D471F200BB732D,
|
||||
$C1A3110E95E8DA16, $430A7220BF1A82B8,
|
||||
$B77E090D39DF210E, $5EF4BD9F3CD05E9D,
|
||||
$9D4FF6DA7E57A444, $DA1D60E183D4A5F8,
|
||||
$B287C38417998E47, $FE3EDC121BB31886,
|
||||
$C7FE3CCC980CCBEF, $E46FB590189BFD03,
|
||||
$3732FD469A4C57DC, $7EF700A07CF1AD65,
|
||||
$59C64468A31D8859, $762FB0B4D45B61F6,
|
||||
$155BAED099047718, $68755E4C3D50BAA6,
|
||||
$E9214E7F22D8B4DF, $2ADDBF532EAC95F4,
|
||||
$32AE3909B4BD0109, $834DF537B08E3450,
|
||||
$FA209DA84220728D, $9E691D9B9EFE23F7,
|
||||
$0446D288C4AE8D7F, $7B4CC524E169785B,
|
||||
$21D87F0135CA1385, $CEBB400F137B8AA5,
|
||||
$272E2B66580796BE, $3612264125C2B0DE,
|
||||
$057702BDAD1EFBB2, $D4BABB8EACF84BE9,
|
||||
$91583139641BC67B, $8BDC2DE08036E024,
|
||||
$603C8156F49F68ED, $F7D236F7DBEF5111,
|
||||
$9727C4598AD21E80, $A08A0896670A5FD7,
|
||||
$CB4A8F4309EBA9CB, $81AF564B0F7036A1,
|
||||
$C0B99AA778199ABD, $959F1EC83FC8E952,
|
||||
$8C505077794A81B9, $3ACAAF8F056338F0,
|
||||
$07B43F50627A6778, $4A44AB49F5ECCC77,
|
||||
$3BC3D6E4B679EE98, $9CC0D4D1CF14108C,
|
||||
$4406C00B206BC8A0, $82A18854C8D72D89,
|
||||
$67E366B35C3C432C, $B923DD61102B37F2,
|
||||
$56AB2779D884271D, $BE83E1B0FF1525AF,
|
||||
$FB7C65D4217E49A9, $6BDBE0E76D48E7D4,
|
||||
$08DF828745D9179E, $22EA6A9ADD53BD34,
|
||||
$E36E141C5622200A, $7F805D1B8CB750EE,
|
||||
$AFE5C7A59F58E837, $E27F996A4FB1C23C,
|
||||
$D3867DFB0775F0D0, $D0E673DE6E88891A,
|
||||
$123AEB9EAFB86C25, $30F1D5D5C145B895,
|
||||
$BB434A2DEE7269E7, $78CB67ECF931FA38,
|
||||
$F33B0372323BBF9C, $52D66336FB279C74,
|
||||
$505F33AC0AFB4EAA, $E8A5CD99A2CCE187,
|
||||
$534974801E2D30BB, $8D2D5711D5876D90,
|
||||
$1F1A412891BC038E, $D6E2E71D82E56648,
|
||||
$74036C3A497732B7, $89B67ED96361F5AB,
|
||||
$FFED95D8F1EA02A2, $E72B3BD61464D43D,
|
||||
$A6300F170BDC4820, $EBC18760ED78A77A);
|
||||
|
||||
t2: array[0..255] of int64= (
|
||||
$E6A6BE5A05A12138, $B5A122A5B4F87C98,
|
||||
$563C6089140B6990, $4C46CB2E391F5DD5,
|
||||
$D932ADDBC9B79434, $08EA70E42015AFF5,
|
||||
$D765A6673E478CF1, $C4FB757EAB278D99,
|
||||
$DF11C6862D6E0692, $DDEB84F10D7F3B16,
|
||||
$6F2EF604A665EA04, $4A8E0F0FF0E0DFB3,
|
||||
$A5EDEEF83DBCBA51, $FC4F0A2A0EA4371E,
|
||||
$E83E1DA85CB38429, $DC8FF882BA1B1CE2,
|
||||
$CD45505E8353E80D, $18D19A00D4DB0717,
|
||||
$34A0CFEDA5F38101, $0BE77E518887CAF2,
|
||||
$1E341438B3C45136, $E05797F49089CCF9,
|
||||
$FFD23F9DF2591D14, $543DDA228595C5CD,
|
||||
$661F81FD99052A33, $8736E641DB0F7B76,
|
||||
$15227725418E5307, $E25F7F46162EB2FA,
|
||||
$48A8B2126C13D9FE, $AFDC541792E76EEA,
|
||||
$03D912BFC6D1898F, $31B1AAFA1B83F51B,
|
||||
$F1AC2796E42AB7D9, $40A3A7D7FCD2EBAC,
|
||||
$1056136D0AFBBCC5, $7889E1DD9A6D0C85,
|
||||
$D33525782A7974AA, $A7E25D09078AC09B,
|
||||
$BD4138B3EAC6EDD0, $920ABFBE71EB9E70,
|
||||
$A2A5D0F54FC2625C, $C054E36B0B1290A3,
|
||||
$F6DD59FF62FE932B, $3537354511A8AC7D,
|
||||
$CA845E9172FADCD4, $84F82B60329D20DC,
|
||||
$79C62CE1CD672F18, $8B09A2ADD124642C,
|
||||
$D0C1E96A19D9E726, $5A786A9B4BA9500C,
|
||||
$0E020336634C43F3, $C17B474AEB66D822,
|
||||
$6A731AE3EC9BAAC2, $8226667AE0840258,
|
||||
$67D4567691CAECA5, $1D94155C4875ADB5,
|
||||
$6D00FD985B813FDF, $51286EFCB774CD06,
|
||||
$5E8834471FA744AF, $F72CA0AEE761AE2E,
|
||||
$BE40E4CDAEE8E09A, $E9970BBB5118F665,
|
||||
$726E4BEB33DF1964, $703B000729199762,
|
||||
$4631D816F5EF30A7, $B880B5B51504A6BE,
|
||||
$641793C37ED84B6C, $7B21ED77F6E97D96,
|
||||
$776306312EF96B73, $AE528948E86FF3F4,
|
||||
$53DBD7F286A3F8F8, $16CADCE74CFC1063,
|
||||
$005C19BDFA52C6DD, $68868F5D64D46AD3,
|
||||
$3A9D512CCF1E186A, $367E62C2385660AE,
|
||||
$E359E7EA77DCB1D7, $526C0773749ABE6E,
|
||||
$735AE5F9D09F734B, $493FC7CC8A558BA8,
|
||||
$B0B9C1533041AB45, $321958BA470A59BD,
|
||||
$852DB00B5F46C393, $91209B2BD336B0E5,
|
||||
$6E604F7D659EF19F, $B99A8AE2782CCB24,
|
||||
$CCF52AB6C814C4C7, $4727D9AFBE11727B,
|
||||
$7E950D0C0121B34D, $756F435670AD471F,
|
||||
$F5ADD442615A6849, $4E87E09980B9957A,
|
||||
$2ACFA1DF50AEE355, $D898263AFD2FD556,
|
||||
$C8F4924DD80C8FD6, $CF99CA3D754A173A,
|
||||
$FE477BACAF91BF3C, $ED5371F6D690C12D,
|
||||
$831A5C285E687094, $C5D3C90A3708A0A4,
|
||||
$0F7F903717D06580, $19F9BB13B8FDF27F,
|
||||
$B1BD6F1B4D502843, $1C761BA38FFF4012,
|
||||
$0D1530C4E2E21F3B, $8943CE69A7372C8A,
|
||||
$E5184E11FEB5CE66, $618BDB80BD736621,
|
||||
$7D29BAD68B574D0B, $81BB613E25E6FE5B,
|
||||
$071C9C10BC07913F, $C7BEEB7909AC2D97,
|
||||
$C3E58D353BC5D757, $EB017892F38F61E8,
|
||||
$D4EFFB9C9B1CC21A, $99727D26F494F7AB,
|
||||
$A3E063A2956B3E03, $9D4A8B9A4AA09C30,
|
||||
$3F6AB7D500090FB4, $9CC0F2A057268AC0,
|
||||
$3DEE9D2DEDBF42D1, $330F49C87960A972,
|
||||
$C6B2720287421B41, $0AC59EC07C00369C,
|
||||
$EF4EAC49CB353425, $F450244EEF0129D8,
|
||||
$8ACC46E5CAF4DEB6, $2FFEAB63989263F7,
|
||||
$8F7CB9FE5D7A4578, $5BD8F7644E634635,
|
||||
$427A7315BF2DC900, $17D0C4AA2125261C,
|
||||
$3992486C93518E50, $B4CBFEE0A2D7D4C3,
|
||||
$7C75D6202C5DDD8D, $DBC295D8E35B6C61,
|
||||
$60B369D302032B19, $CE42685FDCE44132,
|
||||
$06F3DDB9DDF65610, $8EA4D21DB5E148F0,
|
||||
$20B0FCE62FCD496F, $2C1B912358B0EE31,
|
||||
$B28317B818F5A308, $A89C1E189CA6D2CF,
|
||||
$0C6B18576AAADBC8, $B65DEAA91299FAE3,
|
||||
$FB2B794B7F1027E7, $04E4317F443B5BEB,
|
||||
$4B852D325939D0A6, $D5AE6BEEFB207FFC,
|
||||
$309682B281C7D374, $BAE309A194C3B475,
|
||||
$8CC3F97B13B49F05, $98A9422FF8293967,
|
||||
$244B16B01076FF7C, $F8BF571C663D67EE,
|
||||
$1F0D6758EEE30DA1, $C9B611D97ADEB9B7,
|
||||
$B7AFD5887B6C57A2, $6290AE846B984FE1,
|
||||
$94DF4CDEACC1A5FD, $058A5BD1C5483AFF,
|
||||
$63166CC142BA3C37, $8DB8526EB2F76F40,
|
||||
$E10880036F0D6D4E, $9E0523C9971D311D,
|
||||
$45EC2824CC7CD691, $575B8359E62382C9,
|
||||
$FA9E400DC4889995, $D1823ECB45721568,
|
||||
$DAFD983B8206082F, $AA7D29082386A8CB,
|
||||
$269FCD4403B87588, $1B91F5F728BDD1E0,
|
||||
$E4669F39040201F6, $7A1D7C218CF04ADE,
|
||||
$65623C29D79CE5CE, $2368449096C00BB1,
|
||||
$AB9BF1879DA503BA, $BC23ECB1A458058E,
|
||||
$9A58DF01BB401ECC, $A070E868A85F143D,
|
||||
$4FF188307DF2239E, $14D565B41A641183,
|
||||
$EE13337452701602, $950E3DCF3F285E09,
|
||||
$59930254B9C80953, $3BF299408930DA6D,
|
||||
$A955943F53691387, $A15EDECAA9CB8784,
|
||||
$29142127352BE9A0, $76F0371FFF4E7AFB,
|
||||
$0239F450274F2228, $BB073AF01D5E868B,
|
||||
$BFC80571C10E96C1, $D267088568222E23,
|
||||
$9671A3D48E80B5B0, $55B5D38AE193BB81,
|
||||
$693AE2D0A18B04B8, $5C48B4ECADD5335F,
|
||||
$FD743B194916A1CA, $2577018134BE98C4,
|
||||
$E77987E83C54A4AD, $28E11014DA33E1B9,
|
||||
$270CC59E226AA213, $71495F756D1A5F60,
|
||||
$9BE853FB60AFEF77, $ADC786A7F7443DBF,
|
||||
$0904456173B29A82, $58BC7A66C232BD5E,
|
||||
$F306558C673AC8B2, $41F639C6B6C9772A,
|
||||
$216DEFE99FDA35DA, $11640CC71C7BE615,
|
||||
$93C43694565C5527, $EA038E6246777839,
|
||||
$F9ABF3CE5A3E2469, $741E768D0FD312D2,
|
||||
$0144B883CED652C6, $C20B5A5BA33F8552,
|
||||
$1AE69633C3435A9D, $97A28CA4088CFDEC,
|
||||
$8824A43C1E96F420, $37612FA66EEEA746,
|
||||
$6B4CB165F9CF0E5A, $43AA1C06A0ABFB4A,
|
||||
$7F4DC26FF162796B, $6CBACC8E54ED9B0F,
|
||||
$A6B7FFEFD2BB253E, $2E25BC95B0A29D4F,
|
||||
$86D6A58BDEF1388C, $DED74AC576B6F054,
|
||||
$8030BDBC2B45805D, $3C81AF70E94D9289,
|
||||
$3EFF6DDA9E3100DB, $B38DC39FDFCC8847,
|
||||
$123885528D17B87E, $F2DA0ED240B1B642,
|
||||
$44CEFADCD54BF9A9, $1312200E433C7EE6,
|
||||
$9FFCC84F3A78C748, $F0CD1F72248576BB,
|
||||
$EC6974053638CFE4, $2BA7B67C0CEC4E4C,
|
||||
$AC2F4DF3E5CE32ED, $CB33D14326EA4C11,
|
||||
$A4E9044CC77E58BC, $5F513293D934FCEF,
|
||||
$5DC9645506E55444, $50DE418F317DE40A,
|
||||
$388CB31A69DDE259, $2DB4A83455820A86,
|
||||
$9010A91E84711AE9, $4DF7F0B7B1498371,
|
||||
$D62A2EABC0977179, $22FAC097AA8D5C0E);
|
||||
|
||||
t3: array[0..255] of int64= (
|
||||
$F49FCC2FF1DAF39B, $487FD5C66FF29281,
|
||||
$E8A30667FCDCA83F, $2C9B4BE3D2FCCE63,
|
||||
$DA3FF74B93FBBBC2, $2FA165D2FE70BA66,
|
||||
$A103E279970E93D4, $BECDEC77B0E45E71,
|
||||
$CFB41E723985E497, $B70AAA025EF75017,
|
||||
$D42309F03840B8E0, $8EFC1AD035898579,
|
||||
$96C6920BE2B2ABC5, $66AF4163375A9172,
|
||||
$2174ABDCCA7127FB, $B33CCEA64A72FF41,
|
||||
$F04A4933083066A5, $8D970ACDD7289AF5,
|
||||
$8F96E8E031C8C25E, $F3FEC02276875D47,
|
||||
$EC7BF310056190DD, $F5ADB0AEBB0F1491,
|
||||
$9B50F8850FD58892, $4975488358B74DE8,
|
||||
$A3354FF691531C61, $0702BBE481D2C6EE,
|
||||
$89FB24057DEDED98, $AC3075138596E902,
|
||||
$1D2D3580172772ED, $EB738FC28E6BC30D,
|
||||
$5854EF8F63044326, $9E5C52325ADD3BBE,
|
||||
$90AA53CF325C4623, $C1D24D51349DD067,
|
||||
$2051CFEEA69EA624, $13220F0A862E7E4F,
|
||||
$CE39399404E04864, $D9C42CA47086FCB7,
|
||||
$685AD2238A03E7CC, $066484B2AB2FF1DB,
|
||||
$FE9D5D70EFBF79EC, $5B13B9DD9C481854,
|
||||
$15F0D475ED1509AD, $0BEBCD060EC79851,
|
||||
$D58C6791183AB7F8, $D1187C5052F3EEE4,
|
||||
$C95D1192E54E82FF, $86EEA14CB9AC6CA2,
|
||||
$3485BEB153677D5D, $DD191D781F8C492A,
|
||||
$F60866BAA784EBF9, $518F643BA2D08C74,
|
||||
$8852E956E1087C22, $A768CB8DC410AE8D,
|
||||
$38047726BFEC8E1A, $A67738B4CD3B45AA,
|
||||
$AD16691CEC0DDE19, $C6D4319380462E07,
|
||||
$C5A5876D0BA61938, $16B9FA1FA58FD840,
|
||||
$188AB1173CA74F18, $ABDA2F98C99C021F,
|
||||
$3E0580AB134AE816, $5F3B05B773645ABB,
|
||||
$2501A2BE5575F2F6, $1B2F74004E7E8BA9,
|
||||
$1CD7580371E8D953, $7F6ED89562764E30,
|
||||
$B15926FF596F003D, $9F65293DA8C5D6B9,
|
||||
$6ECEF04DD690F84C, $4782275FFF33AF88,
|
||||
$E41433083F820801, $FD0DFE409A1AF9B5,
|
||||
$4325A3342CDB396B, $8AE77E62B301B252,
|
||||
$C36F9E9F6655615A, $85455A2D92D32C09,
|
||||
$F2C7DEA949477485, $63CFB4C133A39EBA,
|
||||
$83B040CC6EBC5462, $3B9454C8FDB326B0,
|
||||
$56F56A9E87FFD78C, $2DC2940D99F42BC6,
|
||||
$98F7DF096B096E2D, $19A6E01E3AD852BF,
|
||||
$42A99CCBDBD4B40B, $A59998AF45E9C559,
|
||||
$366295E807D93186, $6B48181BFAA1F773,
|
||||
$1FEC57E2157A0A1D, $4667446AF6201AD5,
|
||||
$E615EBCACFB0F075, $B8F31F4F68290778,
|
||||
$22713ED6CE22D11E, $3057C1A72EC3C93B,
|
||||
$CB46ACC37C3F1F2F, $DBB893FD02AAF50E,
|
||||
$331FD92E600B9FCF, $A498F96148EA3AD6,
|
||||
$A8D8426E8B6A83EA, $A089B274B7735CDC,
|
||||
$87F6B3731E524A11, $118808E5CBC96749,
|
||||
$9906E4C7B19BD394, $AFED7F7E9B24A20C,
|
||||
$6509EADEEB3644A7, $6C1EF1D3E8EF0EDE,
|
||||
$B9C97D43E9798FB4, $A2F2D784740C28A3,
|
||||
$7B8496476197566F, $7A5BE3E6B65F069D,
|
||||
$F96330ED78BE6F10, $EEE60DE77A076A15,
|
||||
$2B4BEE4AA08B9BD0, $6A56A63EC7B8894E,
|
||||
$02121359BA34FEF4, $4CBF99F8283703FC,
|
||||
$398071350CAF30C8, $D0A77A89F017687A,
|
||||
$F1C1A9EB9E423569, $8C7976282DEE8199,
|
||||
$5D1737A5DD1F7ABD, $4F53433C09A9FA80,
|
||||
$FA8B0C53DF7CA1D9, $3FD9DCBC886CCB77,
|
||||
$C040917CA91B4720, $7DD00142F9D1DCDF,
|
||||
$8476FC1D4F387B58, $23F8E7C5F3316503,
|
||||
$032A2244E7E37339, $5C87A5D750F5A74B,
|
||||
$082B4CC43698992E, $DF917BECB858F63C,
|
||||
$3270B8FC5BF86DDA, $10AE72BB29B5DD76,
|
||||
$576AC94E7700362B, $1AD112DAC61EFB8F,
|
||||
$691BC30EC5FAA427, $FF246311CC327143,
|
||||
$3142368E30E53206, $71380E31E02CA396,
|
||||
$958D5C960AAD76F1, $F8D6F430C16DA536,
|
||||
$C8FFD13F1BE7E1D2, $7578AE66004DDBE1,
|
||||
$05833F01067BE646, $BB34B5AD3BFE586D,
|
||||
$095F34C9A12B97F0, $247AB64525D60CA8,
|
||||
$DCDBC6F3017477D1, $4A2E14D4DECAD24D,
|
||||
$BDB5E6D9BE0A1EEB, $2A7E70F7794301AB,
|
||||
$DEF42D8A270540FD, $01078EC0A34C22C1,
|
||||
$E5DE511AF4C16387, $7EBB3A52BD9A330A,
|
||||
$77697857AA7D6435, $004E831603AE4C32,
|
||||
$E7A21020AD78E312, $9D41A70C6AB420F2,
|
||||
$28E06C18EA1141E6, $D2B28CBD984F6B28,
|
||||
$26B75F6C446E9D83, $BA47568C4D418D7F,
|
||||
$D80BADBFE6183D8E, $0E206D7F5F166044,
|
||||
$E258A43911CBCA3E, $723A1746B21DC0BC,
|
||||
$C7CAA854F5D7CDD3, $7CAC32883D261D9C,
|
||||
$7690C26423BA942C, $17E55524478042B8,
|
||||
$E0BE477656A2389F, $4D289B5E67AB2DA0,
|
||||
$44862B9C8FBBFD31, $B47CC8049D141365,
|
||||
$822C1B362B91C793, $4EB14655FB13DFD8,
|
||||
$1ECBBA0714E2A97B, $6143459D5CDE5F14,
|
||||
$53A8FBF1D5F0AC89, $97EA04D81C5E5B00,
|
||||
$622181A8D4FDB3F3, $E9BCD341572A1208,
|
||||
$1411258643CCE58A, $9144C5FEA4C6E0A4,
|
||||
$0D33D06565CF620F, $54A48D489F219CA1,
|
||||
$C43E5EAC6D63C821, $A9728B3A72770DAF,
|
||||
$D7934E7B20DF87EF, $E35503B61A3E86E5,
|
||||
$CAE321FBC819D504, $129A50B3AC60BFA6,
|
||||
$CD5E68EA7E9FB6C3, $B01C90199483B1C7,
|
||||
$3DE93CD5C295376C, $AED52EDF2AB9AD13,
|
||||
$2E60F512C0A07884, $BC3D86A3E36210C9,
|
||||
$35269D9B163951CE, $0C7D6E2AD0CDB5FA,
|
||||
$59E86297D87F5733, $298EF221898DB0E7,
|
||||
$55000029D1A5AA7E, $8BC08AE1B5061B45,
|
||||
$C2C31C2B6C92703A, $94CC596BAF25EF42,
|
||||
$0A1D73DB22540456, $04B6A0F9D9C4179A,
|
||||
$EFFDAFA2AE3D3C60, $F7C8075BB49496C4,
|
||||
$9CC5C7141D1CD4E3, $78BD1638218E5534,
|
||||
$B2F11568F850246A, $EDFABCFA9502BC29,
|
||||
$796CE5F2DA23051B, $AAE128B0DC93537C,
|
||||
$3A493DA0EE4B29AE, $B5DF6B2C416895D7,
|
||||
$FCABBD25122D7F37, $70810B58105DC4B1,
|
||||
$E10FDD37F7882A90, $524DCAB5518A3F5C,
|
||||
$3C9E85878451255B, $4029828119BD34E2,
|
||||
$74A05B6F5D3CECCB, $B610021542E13ECA,
|
||||
$0FF979D12F59E2AC, $6037DA27E4F9CC50,
|
||||
$5E92975A0DF1847D, $D66DE190D3E623FE,
|
||||
$5032D6B87B568048, $9A36B7CE8235216E,
|
||||
$80272A7A24F64B4A, $93EFED8B8C6916F7,
|
||||
$37DDBFF44CCE1555, $4B95DB5D4B99BD25,
|
||||
$92D3FDA169812FC0, $FB1A4A9A90660BB6,
|
||||
$730C196946A4B9B2, $81E289AA7F49DA68,
|
||||
$64669A0F83B1A05F, $27B3FF7D9644F48B,
|
||||
$CC6B615C8DB675B3, $674F20B9BCEBBE95,
|
||||
$6F31238275655982, $5AE488713E45CF05,
|
||||
$BF619F9954C21157, $EABAC46040A8EAE9,
|
||||
$454C6FE9F2C0C1CD, $419CF6496412691C,
|
||||
$D3DC3BEF265B0F70, $6D0E60F5C3578A9E);
|
||||
|
||||
t4: array[0..255] of int64= (
|
||||
$5B0E608526323C55, $1A46C1A9FA1B59F5,
|
||||
$A9E245A17C4C8FFA, $65CA5159DB2955D7,
|
||||
$05DB0A76CE35AFC2, $81EAC77EA9113D45,
|
||||
$528EF88AB6AC0A0D, $A09EA253597BE3FF,
|
||||
$430DDFB3AC48CD56, $C4B3A67AF45CE46F,
|
||||
$4ECECFD8FBE2D05E, $3EF56F10B39935F0,
|
||||
$0B22D6829CD619C6, $17FD460A74DF2069,
|
||||
$6CF8CC8E8510ED40, $D6C824BF3A6ECAA7,
|
||||
$61243D581A817049, $048BACB6BBC163A2,
|
||||
$D9A38AC27D44CC32, $7FDDFF5BAAF410AB,
|
||||
$AD6D495AA804824B, $E1A6A74F2D8C9F94,
|
||||
$D4F7851235DEE8E3, $FD4B7F886540D893,
|
||||
$247C20042AA4BFDA, $096EA1C517D1327C,
|
||||
$D56966B4361A6685, $277DA5C31221057D,
|
||||
$94D59893A43ACFF7, $64F0C51CCDC02281,
|
||||
$3D33BCC4FF6189DB, $E005CB184CE66AF1,
|
||||
$FF5CCD1D1DB99BEA, $B0B854A7FE42980F,
|
||||
$7BD46A6A718D4B9F, $D10FA8CC22A5FD8C,
|
||||
$D31484952BE4BD31, $C7FA975FCB243847,
|
||||
$4886ED1E5846C407, $28CDDB791EB70B04,
|
||||
$C2B00BE2F573417F, $5C9590452180F877,
|
||||
$7A6BDDFFF370EB00, $CE509E38D6D9D6A4,
|
||||
$EBEB0F00647FA702, $1DCC06CF76606F06,
|
||||
$E4D9F28BA286FF0A, $D85A305DC918C262,
|
||||
$475B1D8732225F54, $2D4FB51668CCB5FE,
|
||||
$A679B9D9D72BBA20, $53841C0D912D43A5,
|
||||
$3B7EAA48BF12A4E8, $781E0E47F22F1DDF,
|
||||
$EFF20CE60AB50973, $20D261D19DFFB742,
|
||||
$16A12B03062A2E39, $1960EB2239650495,
|
||||
$251C16FED50EB8B8, $9AC0C330F826016E,
|
||||
$ED152665953E7671, $02D63194A6369570,
|
||||
$5074F08394B1C987, $70BA598C90B25CE1,
|
||||
$794A15810B9742F6, $0D5925E9FCAF8C6C,
|
||||
$3067716CD868744E, $910AB077E8D7731B,
|
||||
$6A61BBDB5AC42F61, $93513EFBF0851567,
|
||||
$F494724B9E83E9D5, $E887E1985C09648D,
|
||||
$34B1D3C675370CFD, $DC35E433BC0D255D,
|
||||
$D0AAB84234131BE0, $08042A50B48B7EAF,
|
||||
$9997C4EE44A3AB35, $829A7B49201799D0,
|
||||
$263B8307B7C54441, $752F95F4FD6A6CA6,
|
||||
$927217402C08C6E5, $2A8AB754A795D9EE,
|
||||
$A442F7552F72943D, $2C31334E19781208,
|
||||
$4FA98D7CEAEE6291, $55C3862F665DB309,
|
||||
$BD0610175D53B1F3, $46FE6CB840413F27,
|
||||
$3FE03792DF0CFA59, $CFE700372EB85E8F,
|
||||
$A7BE29E7ADBCE118, $E544EE5CDE8431DD,
|
||||
$8A781B1B41F1873E, $A5C94C78A0D2F0E7,
|
||||
$39412E2877B60728, $A1265EF3AFC9A62C,
|
||||
$BCC2770C6A2506C5, $3AB66DD5DCE1CE12,
|
||||
$E65499D04A675B37, $7D8F523481BFD216,
|
||||
$0F6F64FCEC15F389, $74EFBE618B5B13C8,
|
||||
$ACDC82B714273E1D, $DD40BFE003199D17,
|
||||
$37E99257E7E061F8, $FA52626904775AAA,
|
||||
$8BBBF63A463D56F9, $F0013F1543A26E64,
|
||||
$A8307E9F879EC898, $CC4C27A4150177CC,
|
||||
$1B432F2CCA1D3348, $DE1D1F8F9F6FA013,
|
||||
$606602A047A7DDD6, $D237AB64CC1CB2C7,
|
||||
$9B938E7225FCD1D3, $EC4E03708E0FF476,
|
||||
$FEB2FBDA3D03C12D, $AE0BCED2EE43889A,
|
||||
$22CB8923EBFB4F43, $69360D013CF7396D,
|
||||
$855E3602D2D4E022, $073805BAD01F784C,
|
||||
$33E17A133852F546, $DF4874058AC7B638,
|
||||
$BA92B29C678AA14A, $0CE89FC76CFAADCD,
|
||||
$5F9D4E0908339E34, $F1AFE9291F5923B9,
|
||||
$6E3480F60F4A265F, $EEBF3A2AB29B841C,
|
||||
$E21938A88F91B4AD, $57DFEFF845C6D3C3,
|
||||
$2F006B0BF62CAAF2, $62F479EF6F75EE78,
|
||||
$11A55AD41C8916A9, $F229D29084FED453,
|
||||
$42F1C27B16B000E6, $2B1F76749823C074,
|
||||
$4B76ECA3C2745360, $8C98F463B91691BD,
|
||||
$14BCC93CF1ADE66A, $8885213E6D458397,
|
||||
$8E177DF0274D4711, $B49B73B5503F2951,
|
||||
$10168168C3F96B6B, $0E3D963B63CAB0AE,
|
||||
$8DFC4B5655A1DB14, $F789F1356E14DE5C,
|
||||
$683E68AF4E51DAC1, $C9A84F9D8D4B0FD9,
|
||||
$3691E03F52A0F9D1, $5ED86E46E1878E80,
|
||||
$3C711A0E99D07150, $5A0865B20C4E9310,
|
||||
$56FBFC1FE4F0682E, $EA8D5DE3105EDF9B,
|
||||
$71ABFDB12379187A, $2EB99DE1BEE77B9C,
|
||||
$21ECC0EA33CF4523, $59A4D7521805C7A1,
|
||||
$3896F5EB56AE7C72, $AA638F3DB18F75DC,
|
||||
$9F39358DABE9808E, $B7DEFA91C00B72AC,
|
||||
$6B5541FD62492D92, $6DC6DEE8F92E4D5B,
|
||||
$353F57ABC4BEEA7E, $735769D6DA5690CE,
|
||||
$0A234AA642391484, $F6F9508028F80D9D,
|
||||
$B8E319A27AB3F215, $31AD9C1151341A4D,
|
||||
$773C22A57BEF5805, $45C7561A07968633,
|
||||
$F913DA9E249DBE36, $DA652D9B78A64C68,
|
||||
$4C27A97F3BC334EF, $76621220E66B17F4,
|
||||
$967743899ACD7D0B, $F3EE5BCAE0ED6782,
|
||||
$409F753600C879FC, $06D09A39B5926DB6,
|
||||
$6F83AEB0317AC588, $01E6CA4A86381F21,
|
||||
$66FF3462D19F3025, $72207C24DDFD3BFB,
|
||||
$4AF6B6D3E2ECE2EB, $9C994DBEC7EA08DE,
|
||||
$49ACE597B09A8BC4, $B38C4766CF0797BA,
|
||||
$131B9373C57C2A75, $B1822CCE61931E58,
|
||||
$9D7555B909BA1C0C, $127FAFDD937D11D2,
|
||||
$29DA3BADC66D92E4, $A2C1D57154C2ECBC,
|
||||
$58C5134D82F6FE24, $1C3AE3515B62274F,
|
||||
$E907C82E01CB8126, $F8ED091913E37FCB,
|
||||
$3249D8F9C80046C9, $80CF9BEDE388FB63,
|
||||
$1881539A116CF19E, $5103F3F76BD52457,
|
||||
$15B7E6F5AE47F7A8, $DBD7C6DED47E9CCF,
|
||||
$44E55C410228BB1A, $B647D4255EDB4E99,
|
||||
$5D11882BB8AAFC30, $F5098BBB29D3212A,
|
||||
$8FB5EA14E90296B3, $677B942157DD025A,
|
||||
$FB58E7C0A390ACB5, $89D3674C83BD4A01,
|
||||
$9E2DA4DF4BF3B93B, $FCC41E328CAB4829,
|
||||
$03F38C96BA582C52, $CAD1BDBD7FD85DB2,
|
||||
$BBB442C16082AE83, $B95FE86BA5DA9AB0,
|
||||
$B22E04673771A93F, $845358C9493152D8,
|
||||
$BE2A488697B4541E, $95A2DC2DD38E6966,
|
||||
$C02C11AC923C852B, $2388B1990DF2A87B,
|
||||
$7C8008FA1B4F37BE, $1F70D0C84D54E503,
|
||||
$5490ADEC7ECE57D4, $002B3C27D9063A3A,
|
||||
$7EAEA3848030A2BF, $C602326DED2003C0,
|
||||
$83A7287D69A94086, $C57A5FCB30F57A8A,
|
||||
$B56844E479EBE779, $A373B40F05DCBCE9,
|
||||
$D71A786E88570EE2, $879CBACDBDE8F6A0,
|
||||
$976AD1BCC164A32F, $AB21E25E9666D78B,
|
||||
$901063AAE5E5C33C, $9818B34448698D90,
|
||||
$E36487AE3E1E8ABB, $AFBDF931893BDCB4,
|
||||
$6345A0DC5FBBD519, $8628FE269B9465CA,
|
||||
$1E5D01603F9C51EC, $4DE44006A15049B7,
|
||||
$BF6C70E5F776CBB1, $411218F2EF552BED,
|
||||
$CB0C0708705A36A3, $E74D14754F986044,
|
||||
$CD56D9430EA8280E, $C12591D7535F5065,
|
||||
$C83223F1720AEF96, $C3A0396F7363A51F);
|
72
Units/Misc/dcpconst.pas
Normal file
72
Units/Misc/dcpconst.pas
Normal file
@ -0,0 +1,72 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* Constants for use with DCPcrypt ********************************************}
|
||||
{******************************************************************************}
|
||||
{* 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 DCPconst;
|
||||
|
||||
interface
|
||||
|
||||
{******************************************************************************}
|
||||
const
|
||||
{ Component registration }
|
||||
DCPcipherpage = 'DCPciphers';
|
||||
DCPhashpage = 'DCPhashes';
|
||||
|
||||
{ ID values }
|
||||
DCP_rc2 = 1;
|
||||
DCP_sha1 = 2;
|
||||
DCP_rc5 = 3;
|
||||
DCP_rc6 = 4;
|
||||
DCP_blowfish = 5;
|
||||
DCP_twofish = 6;
|
||||
DCP_cast128 = 7;
|
||||
DCP_gost = 8;
|
||||
DCP_rijndael = 9;
|
||||
DCP_ripemd160 = 10;
|
||||
DCP_misty1 = 11;
|
||||
DCP_idea = 12;
|
||||
DCP_mars = 13;
|
||||
DCP_haval = 14;
|
||||
DCP_cast256 = 15;
|
||||
DCP_md5 = 16;
|
||||
DCP_md4 = 17;
|
||||
DCP_tiger = 18;
|
||||
DCP_rc4 = 19;
|
||||
DCP_ice = 20;
|
||||
DCP_thinice = 21;
|
||||
DCP_ice2 = 22;
|
||||
DCP_des = 23;
|
||||
DCP_3des = 24;
|
||||
DCP_tea = 25;
|
||||
DCP_serpent = 26;
|
||||
DCP_ripemd128 = 27;
|
||||
DCP_sha256 = 28;
|
||||
DCP_sha384 = 29;
|
||||
DCP_sha512 = 30;
|
||||
|
||||
|
||||
{******************************************************************************}
|
||||
{******************************************************************************}
|
||||
implementation
|
||||
|
||||
end.
|
702
Units/Misc/dcpcrypt2.pas
Normal file
702
Units/Misc/dcpcrypt2.pas
Normal file
@ -0,0 +1,702 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* Main component definitions *************************************************}
|
||||
{******************************************************************************}
|
||||
{* Copyright (c) 1999-2003 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 DCPcrypt2;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPbase64;
|
||||
|
||||
//{$DEFINE DCP1COMPAT} { DCPcrypt v1.31 compatiblity mode - see documentation }
|
||||
|
||||
{******************************************************************************}
|
||||
{ A few predefined types to help out }
|
||||
|
||||
type
|
||||
{$IFNDEF FPC}
|
||||
Pbyte= ^byte;
|
||||
Pword= ^word;
|
||||
Pdword= ^dword;
|
||||
Pint64= ^int64;
|
||||
dword= longword;
|
||||
Pwordarray= ^Twordarray;
|
||||
Twordarray= array[0..19383] of word;
|
||||
{$ENDIF}
|
||||
Pdwordarray= ^Tdwordarray;
|
||||
Tdwordarray= array[0..8191] of dword;
|
||||
|
||||
|
||||
{******************************************************************************}
|
||||
{ The base class from which all hash algorithms are to be derived }
|
||||
|
||||
type
|
||||
EDCP_hash= class(Exception);
|
||||
TDCP_hash= class(TComponent)
|
||||
protected
|
||||
fInitialized: boolean; { Whether or not the algorithm has been initialized }
|
||||
|
||||
procedure DeadInt(Value: integer); { Knudge to display vars in the object inspector }
|
||||
procedure DeadStr(Value: string); { Knudge to display vars in the object inspector }
|
||||
|
||||
private
|
||||
function _GetId: integer;
|
||||
function _GetAlgorithm: string;
|
||||
function _GetHashSize: integer;
|
||||
|
||||
public
|
||||
property Initialized: boolean
|
||||
read fInitialized;
|
||||
|
||||
class function GetId: integer; virtual;
|
||||
{ Get the algorithm id }
|
||||
class function GetAlgorithm: string; virtual;
|
||||
{ Get the algorithm name }
|
||||
class function GetHashSize: integer; virtual;
|
||||
{ Get the size of the digest produced - in bits }
|
||||
class function SelfTest: boolean; virtual;
|
||||
{ Tests the implementation with several test vectors }
|
||||
|
||||
procedure Init; virtual;
|
||||
{ Initialize the hash algorithm }
|
||||
procedure Final(var Digest); virtual;
|
||||
{ Create the final digest and clear the stored information.
|
||||
The size of the Digest var must be at least equal to the hash size }
|
||||
procedure Burn; virtual;
|
||||
{ Clear any stored information with out creating the final digest }
|
||||
|
||||
procedure Update(const Buffer; Size: longword); virtual;
|
||||
{ Update the hash buffer with Size bytes of data from Buffer }
|
||||
procedure UpdateStream(Stream: TStream; Size: longword);
|
||||
{ Update the hash buffer with Size bytes of data from the stream }
|
||||
procedure UpdateStr(const Str: string);
|
||||
{ Update the hash buffer with the string }
|
||||
|
||||
destructor Destroy; override;
|
||||
|
||||
published
|
||||
property Id: integer
|
||||
read _GetId write DeadInt;
|
||||
property Algorithm: string
|
||||
read _GetAlgorithm write DeadStr;
|
||||
property HashSize: integer
|
||||
read _GetHashSize write DeadInt;
|
||||
end;
|
||||
TDCP_hashclass= class of TDCP_hash;
|
||||
|
||||
|
||||
{******************************************************************************}
|
||||
{ The base class from which all encryption components will be derived. }
|
||||
{ Stream ciphers will be derived directly from this class where as }
|
||||
{ Block ciphers will have a further foundation class TDCP_blockcipher. }
|
||||
|
||||
type
|
||||
EDCP_cipher= class(Exception);
|
||||
TDCP_cipher= class(TComponent)
|
||||
protected
|
||||
fInitialized: boolean; { Whether or not the key setup has been done yet }
|
||||
|
||||
procedure DeadInt(Value: integer); { Knudge to display vars in the object inspector }
|
||||
procedure DeadStr(Value: string); { Knudge to display vars in the object inspector }
|
||||
|
||||
private
|
||||
function _GetId: integer;
|
||||
function _GetAlgorithm: string;
|
||||
function _GetMaxKeySize: integer;
|
||||
|
||||
public
|
||||
property Initialized: boolean
|
||||
read fInitialized;
|
||||
|
||||
class function GetId: integer; virtual;
|
||||
{ Get the algorithm id }
|
||||
class function GetAlgorithm: string; virtual;
|
||||
{ Get the algorithm name }
|
||||
class function GetMaxKeySize: integer; virtual;
|
||||
{ Get the maximum key size (in bits) }
|
||||
class function SelfTest: boolean; virtual;
|
||||
{ Tests the implementation with several test vectors }
|
||||
|
||||
procedure Init(const Key; Size: longword; InitVector: pointer); virtual;
|
||||
{ Do key setup based on the data in Key, size is in bits }
|
||||
procedure InitStr(const Key: string; HashType: TDCP_hashclass);
|
||||
{ Do key setup based on a hash of the key string }
|
||||
procedure Burn; virtual;
|
||||
{ Clear all stored key information }
|
||||
procedure Reset; virtual;
|
||||
{ Reset any stored chaining information }
|
||||
procedure Encrypt(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Encrypt size bytes of data and place in Outdata }
|
||||
procedure Decrypt(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Decrypt size bytes of data and place in Outdata }
|
||||
function EncryptStream(InStream, OutStream: TStream; Size: longword): longword;
|
||||
{ Encrypt size bytes of data from InStream and place in OutStream }
|
||||
function DecryptStream(InStream, OutStream: TStream; Size: longword): longword;
|
||||
{ Decrypt size bytes of data from InStream and place in OutStream }
|
||||
function EncryptString(const Str: string): string; virtual;
|
||||
{ Encrypt a string and return Base64 encoded }
|
||||
function DecryptString(const Str: string): string; virtual;
|
||||
{ Decrypt a Base64 encoded string }
|
||||
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
|
||||
published
|
||||
property Id: integer
|
||||
read _GetId write DeadInt;
|
||||
property Algorithm: string
|
||||
read _GetAlgorithm write DeadStr;
|
||||
property MaxKeySize: integer
|
||||
read _GetMaxKeySize write DeadInt;
|
||||
end;
|
||||
TDCP_cipherclass= class of TDCP_cipher;
|
||||
|
||||
|
||||
{******************************************************************************}
|
||||
{ The base class from which all block ciphers are to be derived, this }
|
||||
{ extra class takes care of the different block encryption modes. }
|
||||
|
||||
type
|
||||
TDCP_ciphermode= (cmCBC, cmCFB8bit, cmCFBblock, cmOFB, cmCTR); // cmCFB8bit is equal to DCPcrypt v1.xx's CFB mode
|
||||
EDCP_blockcipher= class(EDCP_cipher);
|
||||
TDCP_blockcipher= class(TDCP_cipher)
|
||||
protected
|
||||
fCipherMode: TDCP_ciphermode; { The cipher mode the encrypt method uses }
|
||||
|
||||
procedure InitKey(const Key; Size: longword); virtual;
|
||||
|
||||
private
|
||||
function _GetBlockSize: integer;
|
||||
|
||||
public
|
||||
class function GetBlockSize: integer; virtual;
|
||||
{ Get the block size of the cipher (in bits) }
|
||||
|
||||
procedure SetIV(const Value); virtual;
|
||||
{ Sets the IV to Value and performs a reset }
|
||||
procedure GetIV(var Value); virtual;
|
||||
{ Returns the current chaining information, not the actual IV }
|
||||
|
||||
procedure Encrypt(const Indata; var Outdata; Size: longword); override;
|
||||
{ Encrypt size bytes of data and place in Outdata using CipherMode }
|
||||
procedure Decrypt(const Indata; var Outdata; Size: longword); override;
|
||||
{ Decrypt size bytes of data and place in Outdata using CipherMode }
|
||||
function EncryptString(const Str: string): string; override;
|
||||
{ Encrypt a string and return Base64 encoded }
|
||||
function DecryptString(const Str: string): string; override;
|
||||
{ Decrypt a Base64 encoded string }
|
||||
procedure EncryptECB(const Indata; var Outdata); virtual;
|
||||
{ Encrypt a block of data using the ECB method of encryption }
|
||||
procedure DecryptECB(const Indata; var Outdata); virtual;
|
||||
{ Decrypt a block of data using the ECB method of decryption }
|
||||
procedure EncryptCBC(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Encrypt size bytes of data using the CBC method of encryption }
|
||||
procedure DecryptCBC(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Decrypt size bytes of data using the CBC method of decryption }
|
||||
procedure EncryptCFB8bit(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Encrypt size bytes of data using the CFB (8 bit) method of encryption }
|
||||
procedure DecryptCFB8bit(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Decrypt size bytes of data using the CFB (8 bit) method of decryption }
|
||||
procedure EncryptCFBblock(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Encrypt size bytes of data using the CFB (block) method of encryption }
|
||||
procedure DecryptCFBblock(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Decrypt size bytes of data using the CFB (block) method of decryption }
|
||||
procedure EncryptOFB(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Encrypt size bytes of data using the OFB method of encryption }
|
||||
procedure DecryptOFB(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Decrypt size bytes of data using the OFB method of decryption }
|
||||
procedure EncryptCTR(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Encrypt size bytes of data using the CTR method of encryption }
|
||||
procedure DecryptCTR(const Indata; var Outdata; Size: longword); virtual;
|
||||
{ Decrypt size bytes of data using the CTR method of decryption }
|
||||
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
|
||||
published
|
||||
property BlockSize: integer
|
||||
read _GetBlockSize write DeadInt;
|
||||
property CipherMode: TDCP_ciphermode
|
||||
read fCipherMode write fCipherMode default cmCBC;
|
||||
end;
|
||||
TDCP_blockcipherclass= class of TDCP_blockcipher;
|
||||
|
||||
|
||||
{******************************************************************************}
|
||||
{ Helper functions }
|
||||
|
||||
procedure XorBlock(var InData1, InData2; Size: longword);
|
||||
// Supposed to be an optimized version of XorBlock() using 32-bit xor
|
||||
procedure XorBlockEx(var InData1, InData2; Size: longword);
|
||||
// removes the compiler hint due to first param being 'var' instead of 'out'
|
||||
procedure dcpFillChar(out x; count: SizeInt; Value: Byte); overload;
|
||||
procedure dcpFillChar(out x; count: SizeInt; Value: Char); overload;
|
||||
procedure ZeroMemory(Destination: Pointer; Length: PtrUInt);
|
||||
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
{$Q-}{$R-}
|
||||
|
||||
|
||||
{** TDCP_hash *****************************************************************}
|
||||
|
||||
procedure TDCP_hash.DeadInt(Value: integer);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_hash.DeadStr(Value: string);
|
||||
begin
|
||||
end;
|
||||
|
||||
function TDCP_hash._GetId: integer;
|
||||
begin
|
||||
Result:= GetId;
|
||||
end;
|
||||
|
||||
function TDCP_hash._GetAlgorithm: string;
|
||||
begin
|
||||
Result:= GetAlgorithm;
|
||||
end;
|
||||
|
||||
function TDCP_hash._GetHashSize: integer;
|
||||
begin
|
||||
Result:= GetHashSize;
|
||||
end;
|
||||
|
||||
class function TDCP_hash.GetId: integer;
|
||||
begin
|
||||
Result:= -1;
|
||||
end;
|
||||
|
||||
class function TDCP_hash.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= '';
|
||||
end;
|
||||
|
||||
class function TDCP_hash.GetHashSize: integer;
|
||||
begin
|
||||
Result:= -1;
|
||||
end;
|
||||
|
||||
class function TDCP_hash.SelfTest: boolean;
|
||||
begin
|
||||
Result:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_hash.Init;
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_hash.Final(var Digest);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_hash.Burn;
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_hash.Update(const Buffer; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_hash.UpdateStream(Stream: TStream; Size: longword);
|
||||
var
|
||||
Buffer: array[0..8191] of byte;
|
||||
i, read: integer;
|
||||
begin
|
||||
dcpFillChar(Buffer, SizeOf(Buffer), 0);
|
||||
for i:= 1 to (Size div Sizeof(Buffer)) do
|
||||
begin
|
||||
read:= Stream.Read(Buffer,Sizeof(Buffer));
|
||||
Update(Buffer,read);
|
||||
end;
|
||||
if (Size mod Sizeof(Buffer))<> 0 then
|
||||
begin
|
||||
read:= Stream.Read(Buffer,Size mod Sizeof(Buffer));
|
||||
Update(Buffer,read);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDCP_hash.UpdateStr(const Str: string);
|
||||
begin
|
||||
Update(Str[1],Length(Str));
|
||||
end;
|
||||
|
||||
destructor TDCP_hash.Destroy;
|
||||
begin
|
||||
if fInitialized then
|
||||
Burn;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
||||
{** TDCP_cipher ***************************************************************}
|
||||
|
||||
procedure TDCP_cipher.DeadInt(Value: integer);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_cipher.DeadStr(Value: string);
|
||||
begin
|
||||
end;
|
||||
|
||||
function TDCP_cipher._GetId: integer;
|
||||
begin
|
||||
Result:= GetId;
|
||||
end;
|
||||
|
||||
function TDCP_cipher._GetAlgorithm: string;
|
||||
begin
|
||||
Result:= GetAlgorithm;
|
||||
end;
|
||||
|
||||
function TDCP_cipher._GetMaxKeySize: integer;
|
||||
begin
|
||||
Result:= GetMaxKeySize;
|
||||
end;
|
||||
|
||||
class function TDCP_cipher.GetId: integer;
|
||||
begin
|
||||
Result:= -1;
|
||||
end;
|
||||
|
||||
class function TDCP_cipher.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= '';
|
||||
end;
|
||||
|
||||
class function TDCP_cipher.GetMaxKeySize: integer;
|
||||
begin
|
||||
Result:= -1;
|
||||
end;
|
||||
|
||||
class function TDCP_cipher.SelfTest: boolean;
|
||||
begin
|
||||
Result:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_cipher.Init(const Key; Size: longword; InitVector: pointer);
|
||||
begin
|
||||
if fInitialized then
|
||||
Burn;
|
||||
if (Size <= 0) or ((Size and 3)<> 0) or (Size> longword(GetMaxKeySize)) then
|
||||
raise EDCP_cipher.Create('Invalid key size')
|
||||
else
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_cipher.InitStr(const Key: string; HashType: TDCP_hashclass);
|
||||
var
|
||||
Hash: TDCP_hash;
|
||||
Digest: pointer;
|
||||
begin
|
||||
if fInitialized then
|
||||
Burn;
|
||||
try
|
||||
GetMem(Digest,HashType.GetHashSize div 8);
|
||||
Hash:= HashType.Create(Self);
|
||||
Hash.Init;
|
||||
Hash.UpdateStr(Key);
|
||||
Hash.Final(Digest^);
|
||||
Hash.Free;
|
||||
if MaxKeySize< HashType.GetHashSize then
|
||||
begin
|
||||
Init(Digest^,MaxKeySize,nil);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Init(Digest^,HashType.GetHashSize,nil);
|
||||
end;
|
||||
FillChar(Digest^,HashType.GetHashSize div 8,$FF);
|
||||
FreeMem(Digest);
|
||||
except
|
||||
raise EDCP_cipher.Create('Unable to allocate sufficient memory for hash digest');
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDCP_cipher.Burn;
|
||||
begin
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_cipher.Reset;
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_cipher.Encrypt(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_cipher.Decrypt(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
function TDCP_cipher.EncryptStream(InStream, OutStream: TStream; Size: longword): longword;
|
||||
var
|
||||
Buffer: array[0..8191] of byte;
|
||||
i, Read: longword;
|
||||
begin
|
||||
dcpFillChar(Buffer, SizeOf(Buffer), 0);
|
||||
Result:= 0;
|
||||
for i:= 1 to (Size div Sizeof(Buffer)) do
|
||||
begin
|
||||
Read:= InStream.Read(Buffer,Sizeof(Buffer));
|
||||
Inc(Result,Read);
|
||||
Encrypt(Buffer,Buffer,Read);
|
||||
OutStream.Write(Buffer,Read);
|
||||
end;
|
||||
if (Size mod Sizeof(Buffer))<> 0 then
|
||||
begin
|
||||
Read:= InStream.Read(Buffer,Size mod Sizeof(Buffer));
|
||||
Inc(Result,Read);
|
||||
Encrypt(Buffer,Buffer,Read);
|
||||
OutStream.Write(Buffer,Read);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TDCP_cipher.DecryptStream(InStream, OutStream: TStream; Size: longword): longword;
|
||||
var
|
||||
Buffer: array[0..8191] of byte;
|
||||
i, Read: longword;
|
||||
begin
|
||||
dcpFillChar(Buffer, SizeOf(Buffer), 0);
|
||||
Result:= 0;
|
||||
for i:= 1 to (Size div Sizeof(Buffer)) do
|
||||
begin
|
||||
Read:= InStream.Read(Buffer,Sizeof(Buffer));
|
||||
Inc(Result,Read);
|
||||
Decrypt(Buffer,Buffer,Read);
|
||||
OutStream.Write(Buffer,Read);
|
||||
end;
|
||||
if (Size mod Sizeof(Buffer))<> 0 then
|
||||
begin
|
||||
Read:= InStream.Read(Buffer,Size mod Sizeof(Buffer));
|
||||
Inc(Result,Read);
|
||||
Decrypt(Buffer,Buffer,Read);
|
||||
OutStream.Write(Buffer,Read);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TDCP_cipher.EncryptString(const Str: string): string;
|
||||
begin
|
||||
SetLength(Result,Length(Str));
|
||||
Encrypt(Str[1],Result[1],Length(Str));
|
||||
Result:= Base64EncodeStr(Result);
|
||||
end;
|
||||
|
||||
function TDCP_cipher.DecryptString(const Str: string): string;
|
||||
begin
|
||||
Result:= Base64DecodeStr(Str);
|
||||
Decrypt(Result[1],Result[1],Length(Result));
|
||||
end;
|
||||
|
||||
constructor TDCP_cipher.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
Burn;
|
||||
end;
|
||||
|
||||
destructor TDCP_cipher.Destroy;
|
||||
begin
|
||||
if fInitialized then
|
||||
Burn;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
||||
{** TDCP_blockcipher **********************************************************}
|
||||
|
||||
procedure TDCP_blockcipher.InitKey(const Key; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
function TDCP_blockcipher._GetBlockSize: integer;
|
||||
begin
|
||||
Result:= GetBlockSize;
|
||||
end;
|
||||
|
||||
class function TDCP_blockcipher.GetBlockSize: integer;
|
||||
begin
|
||||
Result:= -1;
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.SetIV(const Value);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.GetIV(var Value);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.Encrypt(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
case fCipherMode of
|
||||
cmCBC: EncryptCBC(Indata,Outdata,Size);
|
||||
cmCFB8bit: EncryptCFB8bit(Indata,Outdata,Size);
|
||||
cmCFBblock: EncryptCFBblock(Indata,Outdata,Size);
|
||||
cmOFB: EncryptOFB(Indata,Outdata,Size);
|
||||
cmCTR: EncryptCTR(Indata,Outdata,Size);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TDCP_blockcipher.EncryptString(const Str: string): string;
|
||||
begin
|
||||
SetLength(Result,Length(Str));
|
||||
EncryptCFB8bit(Str[1],Result[1],Length(Str));
|
||||
Result:= Base64EncodeStr(Result);
|
||||
end;
|
||||
|
||||
function TDCP_blockcipher.DecryptString(const Str: string): string;
|
||||
begin
|
||||
Result:= Base64DecodeStr(Str);
|
||||
DecryptCFB8bit(Result[1],Result[1],Length(Result));
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.Decrypt(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
case fCipherMode of
|
||||
cmCBC: DecryptCBC(Indata,Outdata,Size);
|
||||
cmCFB8bit: DecryptCFB8bit(Indata,Outdata,Size);
|
||||
cmCFBblock: DecryptCFBblock(Indata,Outdata,Size);
|
||||
cmOFB: DecryptOFB(Indata,Outdata,Size);
|
||||
cmCTR: DecryptCTR(Indata,Outdata,Size);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.EncryptECB(const Indata; var Outdata);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.DecryptECB(const Indata; var Outdata);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.EncryptCBC(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.DecryptCBC(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.EncryptCFB8bit(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.DecryptCFB8bit(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.EncryptCFBblock(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.DecryptCFBblock(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.EncryptOFB(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.DecryptOFB(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.EncryptCTR(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TDCP_blockcipher.DecryptCTR(const Indata; var Outdata; Size: longword);
|
||||
begin
|
||||
end;
|
||||
|
||||
constructor TDCP_blockcipher.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
fCipherMode:= cmCBC;
|
||||
end;
|
||||
|
||||
|
||||
{** Helpher functions *********************************************************}
|
||||
procedure XorBlock(var InData1, InData2; Size: longword);
|
||||
var
|
||||
b1: PByteArray;
|
||||
b2: PByteArray;
|
||||
i: longword;
|
||||
begin
|
||||
b1 := @InData1;
|
||||
b2 := @InData2;
|
||||
for i := 0 to size-1 do
|
||||
b1[i] := b1[i] xor b2[i];
|
||||
end;
|
||||
|
||||
procedure dcpFillChar(out x; count: SizeInt; Value: Byte);
|
||||
begin
|
||||
{$HINTS OFF}
|
||||
FillChar(x, count, value);
|
||||
{$HINTS ON}
|
||||
end;
|
||||
|
||||
procedure ZeroMemory(Destination: Pointer; Length: PtrUInt);
|
||||
begin
|
||||
FillChar(Destination^, Length, 0);
|
||||
end;
|
||||
|
||||
procedure dcpFillChar(out x; count: SizeInt; Value: Char);
|
||||
begin
|
||||
{$HINTS OFF}
|
||||
FillChar(x, count, Value);
|
||||
{$HINTS ON}
|
||||
end;
|
||||
|
||||
// Supposed to be an optimized version of XorBlock() using 32-bit xor
|
||||
procedure XorBlockEx(var InData1, InData2; Size: longword);
|
||||
var
|
||||
l1: PIntegerArray;
|
||||
l2: PIntegerArray;
|
||||
b1: PByteArray;
|
||||
b2: PByteArray;
|
||||
i: integer;
|
||||
c: integer;
|
||||
begin
|
||||
l1 := @inData1;
|
||||
l2 := @inData2;
|
||||
for i := 0 to size div sizeof(LongWord)-1 do
|
||||
l1[i] := l1[i] xor l2[i];
|
||||
|
||||
// the rest of the buffer (3 bytes)
|
||||
c := size mod sizeof(longWord);
|
||||
if c > 0 then begin
|
||||
b1 := @InData1;
|
||||
b2 := @InData2;
|
||||
for i := (size-c) to size-1 do
|
||||
b1[i] := b1[i] xor b2[i];
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
503
Units/Misc/dcphaval.pas
Normal file
503
Units/Misc/dcphaval.pas
Normal file
@ -0,0 +1,503 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A binary compatible implementation of Haval ********************************}
|
||||
{******************************************************************************}
|
||||
{* 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 DCPhaval;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPcrypt2, DCPconst;
|
||||
|
||||
type
|
||||
TDCP_haval= class(TDCP_hash)
|
||||
protected
|
||||
LenHi, LenLo: longword;
|
||||
Index: DWord;
|
||||
CurrentHash: array[0..7] of DWord;
|
||||
HashBuffer: array[0..127] 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;
|
||||
|
||||
{ Choose how many passes (previous versions of DCPcrypt uses 5 passes) }
|
||||
{ ONLY UNCOMMENT ONE! }
|
||||
//{$DEFINE PASS3}
|
||||
//{$DEFINE PASS4}
|
||||
{$DEFINE PASS5}
|
||||
|
||||
{ Choose digest length (previous versions of DCPcrypt uses 256bits) }
|
||||
{ ONLY UNCOMMENT ONE! }
|
||||
//{$DEFINE DIGEST128}
|
||||
//{$DEFINE DIGEST160}
|
||||
//{$DEFINE DIGEST192}
|
||||
//{$DEFINE DIGEST224}
|
||||
{$DEFINE DIGEST256}
|
||||
|
||||
|
||||
{******************************************************************************}
|
||||
{******************************************************************************}
|
||||
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
|
||||
dcpFillChar(W, SizeOf(W), 0);
|
||||
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));
|
||||
|
||||
{$IFDEF PASS3}
|
||||
{$INCLUDE DCPhaval3.inc}
|
||||
{$ELSE}
|
||||
{$IFDEF PASS4}
|
||||
{$INCLUDE DCPhaval4.inc}
|
||||
{$ELSE}
|
||||
{$INCLUDE DCPhaval5.inc}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
Inc(CurrentHash[0],t0);
|
||||
Inc(CurrentHash[1],t1);
|
||||
Inc(CurrentHash[2],t2);
|
||||
Inc(CurrentHash[3],t3);
|
||||
Inc(CurrentHash[4],t4);
|
||||
Inc(CurrentHash[5],t5);
|
||||
Inc(CurrentHash[6],t6);
|
||||
Inc(CurrentHash[7],t7);
|
||||
FillChar(W,Sizeof(W),0);
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
class function TDCP_haval.GetHashSize: integer;
|
||||
begin
|
||||
{$IFDEF DIGEST128}
|
||||
Result:= 128;
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST160}
|
||||
Result:= 160;
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST192}
|
||||
Result:= 192;
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST224}
|
||||
Result:= 224;
|
||||
{$ELSE}
|
||||
Result:= 256;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
class function TDCP_haval.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_haval;
|
||||
end;
|
||||
|
||||
class function TDCP_haval.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'Haval (';
|
||||
{$IFDEF DIGEST128}
|
||||
Result:= Result+'128bit, ';
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST160}
|
||||
Result:= Result+'160bit, ';
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST192}
|
||||
Result:= Result+'192bit, ';
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST224}
|
||||
Result:= Result+'224bit, ';
|
||||
{$ELSE}
|
||||
Result:= Result+'256bit, ';
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$IFDEF PASS3}
|
||||
Result:= Result+'3 passes)';
|
||||
{$ELSE}
|
||||
{$IFDEF PASS4}
|
||||
Result:= Result+'4 passes)';
|
||||
{$ELSE}
|
||||
Result:= Result+'5 passes)';
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
class function TDCP_haval.SelfTest: boolean;
|
||||
{$IFDEF PASS3}
|
||||
{$IFDEF DIGEST128}
|
||||
const
|
||||
Test1Out: array[0..15] of byte=
|
||||
($1B,$DC,$55,$6B,$29,$AD,$02,$EC,$09,$AF,$8C,$66,$47,$7F,$2A,$87);
|
||||
var
|
||||
TestHash: TDCP_haval;
|
||||
TestOut: array[0..15] of byte;
|
||||
begin
|
||||
TestHash:= TDCP_haval.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Free;
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST160}
|
||||
const
|
||||
Test1Out: array[0..19] of byte=
|
||||
($5E,$16,$10,$FC,$ED,$1D,$3A,$DB,$0B,$B1,
|
||||
$8E,$92,$AC,$2B,$11,$F0,$BD,$99,$D8,$ED);
|
||||
var
|
||||
TestHash: TDCP_haval;
|
||||
TestOut: array[0..19] of byte;
|
||||
begin
|
||||
TestHash:= TDCP_haval.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('a');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Free;
|
||||
{$ELSE}
|
||||
begin
|
||||
Result:= true;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ELSE}
|
||||
{$IFDEF PASS4}
|
||||
{$IFDEF DIGEST192}
|
||||
const
|
||||
Test1Out: array[0..23] of byte=
|
||||
($74,$AA,$31,$18,$2F,$F0,$9B,$CC,$E4,$53,$A7,$F7,
|
||||
$1B,$5A,$7C,$5E,$80,$87,$2F,$A9,$0C,$D9,$3A,$E4);
|
||||
var
|
||||
TestHash: TDCP_haval;
|
||||
TestOut: array[0..23] of byte;
|
||||
begin
|
||||
TestHash:= TDCP_haval.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('HAVAL');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Free;
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST224}
|
||||
const
|
||||
Test1Out: array[0..27] of byte=
|
||||
($14,$4C,$B2,$DE,$11,$F0,$5D,$F7,$C3,$56,$28,$2A,$3B,$48,
|
||||
$57,$96,$DA,$65,$3F,$6B,$70,$28,$68,$C7,$DC,$F4,$AE,$76);
|
||||
var
|
||||
TestHash: TDCP_haval;
|
||||
TestOut: array[0..27] of byte;
|
||||
begin
|
||||
TestHash:= TDCP_haval.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('0123456789');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Free;
|
||||
{$ELSE}
|
||||
begin
|
||||
Result:= true;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ELSE}
|
||||
{$IFDEF DIGEST256}
|
||||
const
|
||||
Test1Out: array[0..31] of byte=
|
||||
($1A,$1D,$C8,$09,$9B,$DA,$A7,$F3,$5B,$4D,$A4,$E8,$05,$F1,$A2,$8F,
|
||||
$EE,$90,$9D,$8D,$EE,$92,$01,$98,$18,$5C,$BC,$AE,$D8,$A1,$0A,$8D);
|
||||
Test2Out: array[0..31] of byte=
|
||||
($C5,$64,$7F,$C6,$C1,$87,$7F,$FF,$96,$74,$2F,$27,$E9,$26,$6B,$68,
|
||||
$74,$89,$4F,$41,$A0,$8F,$59,$13,$03,$3D,$9D,$53,$2A,$ED,$DB,$39);
|
||||
var
|
||||
TestHash: TDCP_haval;
|
||||
TestOut: array[0..31] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
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.
|
237
Units/Misc/dcpmd4.pas
Normal file
237
Units/Misc/dcpmd4.pas
Normal file
@ -0,0 +1,237 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A binary compatible implementation of MD4 **********************************}
|
||||
{******************************************************************************}
|
||||
{* 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 DCPmd4;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPcrypt2, DCPconst;
|
||||
|
||||
type
|
||||
TDCP_md4= class(TDCP_hash)
|
||||
protected
|
||||
LenHi, LenLo: longword;
|
||||
Index: DWord;
|
||||
CurrentHash: array[0..3] 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-}
|
||||
|
||||
function LRot32(a, b: longword): longword;
|
||||
begin
|
||||
Result:= (a shl b) or (a shr (32-b));
|
||||
end;
|
||||
|
||||
procedure TDCP_md4.Compress;
|
||||
var
|
||||
Data: array[0..15] of dword;
|
||||
A, B, C, D: dword;
|
||||
begin
|
||||
dcpFillChar(Data, SizeOf(Data), 0);
|
||||
Move(HashBuffer,Data,Sizeof(Data));
|
||||
A:= CurrentHash[0];
|
||||
B:= CurrentHash[1];
|
||||
C:= CurrentHash[2];
|
||||
D:= CurrentHash[3];
|
||||
|
||||
A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 0],3);
|
||||
D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 1],7);
|
||||
C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 2],11);
|
||||
B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 3],19);
|
||||
A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 4],3);
|
||||
D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 5],7);
|
||||
C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 6],11);
|
||||
B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 7],19);
|
||||
A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 8],3);
|
||||
D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 9],7);
|
||||
C:= LRot32(C + (B xor (D and (A xor B))) + Data[10],11);
|
||||
B:= LRot32(B + (A xor (C and (D xor A))) + Data[11],19);
|
||||
A:= LRot32(A + (D xor (B and (C xor D))) + Data[12],3);
|
||||
D:= LRot32(D + (C xor (A and (B xor C))) + Data[13],7);
|
||||
C:= LRot32(C + (B xor (D and (A xor B))) + Data[14],11);
|
||||
B:= LRot32(B + (A xor (C and (D xor A))) + Data[15],19);
|
||||
|
||||
A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 0] + $5a827999,3);
|
||||
D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 4] + $5a827999,5);
|
||||
C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 8] + $5a827999,9);
|
||||
B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[12] + $5a827999,13);
|
||||
A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 1] + $5a827999,3);
|
||||
D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 5] + $5a827999,5);
|
||||
C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 9] + $5a827999,9);
|
||||
B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[13] + $5a827999,13);
|
||||
A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 2] + $5a827999,3);
|
||||
D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 6] + $5a827999,5);
|
||||
C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[10] + $5a827999,9);
|
||||
B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[14] + $5a827999,13);
|
||||
A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 3] + $5a827999,3);
|
||||
D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 7] + $5a827999,5);
|
||||
C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[11] + $5a827999,9);
|
||||
B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[15] + $5a827999,13);
|
||||
|
||||
A:= LRot32(A + (B xor C xor D) + Data[ 0] + $6ed9eba1,3);
|
||||
D:= LRot32(D + (A xor B xor C) + Data[ 8] + $6ed9eba1,9);
|
||||
C:= LRot32(C + (D xor A xor B) + Data[ 4] + $6ed9eba1,11);
|
||||
B:= LRot32(B + (C xor D xor A) + Data[12] + $6ed9eba1,15);
|
||||
A:= LRot32(A + (B xor C xor D) + Data[ 2] + $6ed9eba1,3);
|
||||
D:= LRot32(D + (A xor B xor C) + Data[10] + $6ed9eba1,9);
|
||||
C:= LRot32(C + (D xor A xor B) + Data[ 6] + $6ed9eba1,11);
|
||||
B:= LRot32(B + (C xor D xor A) + Data[14] + $6ed9eba1,15);
|
||||
A:= LRot32(A + (B xor C xor D) + Data[ 1] + $6ed9eba1,3);
|
||||
D:= LRot32(D + (A xor B xor C) + Data[ 9] + $6ed9eba1,9);
|
||||
C:= LRot32(C + (D xor A xor B) + Data[ 5] + $6ed9eba1,11);
|
||||
B:= LRot32(B + (C xor D xor A) + Data[13] + $6ed9eba1,15);
|
||||
A:= LRot32(A + (B xor C xor D) + Data[ 3] + $6ed9eba1,3);
|
||||
D:= LRot32(D + (A xor B xor C) + Data[11] + $6ed9eba1,9);
|
||||
C:= LRot32(C + (D xor A xor B) + Data[ 7] + $6ed9eba1,11);
|
||||
B:= LRot32(B + (C xor D xor A) + Data[15] + $6ed9eba1,15);
|
||||
|
||||
Inc(CurrentHash[0],A);
|
||||
Inc(CurrentHash[1],B);
|
||||
Inc(CurrentHash[2],C);
|
||||
Inc(CurrentHash[3],D);
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
class function TDCP_md4.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 128;
|
||||
end;
|
||||
|
||||
class function TDCP_md4.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_md4;
|
||||
end;
|
||||
|
||||
class function TDCP_md4.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'MD4';
|
||||
end;
|
||||
|
||||
class function TDCP_md4.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..15] of byte=
|
||||
($a4,$48,$01,$7a,$af,$21,$d8,$52,$5f,$c1,$0a,$e8,$7a,$a6,$72,$9d);
|
||||
Test2Out: array[0..15] of byte=
|
||||
($d7,$9e,$1c,$30,$8a,$a5,$bb,$cd,$ee,$a8,$ed,$63,$df,$41,$2d,$a9);
|
||||
var
|
||||
TestHash: TDCP_md4;
|
||||
TestOut: array[0..19] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_md4.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abc');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_md4.Init;
|
||||
begin
|
||||
Burn;
|
||||
CurrentHash[0]:= $67452301;
|
||||
CurrentHash[1]:= $efcdab89;
|
||||
CurrentHash[2]:= $98badcfe;
|
||||
CurrentHash[3]:= $10325476;
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_md4.Burn;
|
||||
begin
|
||||
LenHi:= 0; LenLo:= 0;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
FillChar(CurrentHash,Sizeof(CurrentHash),0);
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_md4.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_md4.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $80;
|
||||
if Index>= 56 then
|
||||
Compress;
|
||||
PDWord(@HashBuffer[56])^:= LenLo;
|
||||
PDWord(@HashBuffer[60])^:= LenHi;
|
||||
Compress;
|
||||
Move(CurrentHash,Digest,Sizeof(CurrentHash));
|
||||
Burn;
|
||||
end;
|
||||
|
||||
end.
|
254
Units/Misc/dcpmd5.pas
Normal file
254
Units/Misc/dcpmd5.pas
Normal file
@ -0,0 +1,254 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A binary compatible implementation of MD5 **********************************}
|
||||
{******************************************************************************}
|
||||
{* 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 DCPmd5;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPcrypt2, DCPconst;
|
||||
|
||||
type
|
||||
TDCP_md5= class(TDCP_hash)
|
||||
protected
|
||||
LenHi, LenLo: longword;
|
||||
Index: DWord;
|
||||
CurrentHash: array[0..3] 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-}
|
||||
|
||||
function LRot32(a, b: longword): longword;
|
||||
begin
|
||||
Result:= (a shl b) or (a shr (32-b));
|
||||
end;
|
||||
|
||||
procedure TDCP_md5.Compress;
|
||||
var
|
||||
Data: array[0..15] of dword;
|
||||
A, B, C, D: dword;
|
||||
begin
|
||||
dcpFillChar(Data, SizeOf(Data), 0);
|
||||
Move(HashBuffer,Data,Sizeof(Data));
|
||||
A:= CurrentHash[0];
|
||||
B:= CurrentHash[1];
|
||||
C:= CurrentHash[2];
|
||||
D:= CurrentHash[3];
|
||||
|
||||
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 0] + $d76aa478,7);
|
||||
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 1] + $e8c7b756,12);
|
||||
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 2] + $242070db,17);
|
||||
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 3] + $c1bdceee,22);
|
||||
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 4] + $f57c0faf,7);
|
||||
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 5] + $4787c62a,12);
|
||||
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[ 6] + $a8304613,17);
|
||||
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[ 7] + $fd469501,22);
|
||||
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[ 8] + $698098d8,7);
|
||||
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[ 9] + $8b44f7af,12);
|
||||
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[10] + $ffff5bb1,17);
|
||||
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[11] + $895cd7be,22);
|
||||
A:= B + LRot32(A + (D xor (B and (C xor D))) + Data[12] + $6b901122,7);
|
||||
D:= A + LRot32(D + (C xor (A and (B xor C))) + Data[13] + $fd987193,12);
|
||||
C:= D + LRot32(C + (B xor (D and (A xor B))) + Data[14] + $a679438e,17);
|
||||
B:= C + LRot32(B + (A xor (C and (D xor A))) + Data[15] + $49b40821,22);
|
||||
|
||||
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 1] + $f61e2562,5);
|
||||
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[ 6] + $c040b340,9);
|
||||
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[11] + $265e5a51,14);
|
||||
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 0] + $e9b6c7aa,20);
|
||||
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 5] + $d62f105d,5);
|
||||
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[10] + $02441453,9);
|
||||
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[15] + $d8a1e681,14);
|
||||
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 4] + $e7d3fbc8,20);
|
||||
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[ 9] + $21e1cde6,5);
|
||||
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[14] + $c33707d6,9);
|
||||
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[ 3] + $f4d50d87,14);
|
||||
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[ 8] + $455a14ed,20);
|
||||
A:= B + LRot32(A + (C xor (D and (B xor C))) + Data[13] + $a9e3e905,5);
|
||||
D:= A + LRot32(D + (B xor (C and (A xor B))) + Data[ 2] + $fcefa3f8,9);
|
||||
C:= D + LRot32(C + (A xor (B and (D xor A))) + Data[ 7] + $676f02d9,14);
|
||||
B:= C + LRot32(B + (D xor (A and (C xor D))) + Data[12] + $8d2a4c8a,20);
|
||||
|
||||
A:= B + LRot32(A + (B xor C xor D) + Data[ 5] + $fffa3942,4);
|
||||
D:= A + LRot32(D + (A xor B xor C) + Data[ 8] + $8771f681,11);
|
||||
C:= D + LRot32(C + (D xor A xor B) + Data[11] + $6d9d6122,16);
|
||||
B:= C + LRot32(B + (C xor D xor A) + Data[14] + $fde5380c,23);
|
||||
A:= B + LRot32(A + (B xor C xor D) + Data[ 1] + $a4beea44,4);
|
||||
D:= A + LRot32(D + (A xor B xor C) + Data[ 4] + $4bdecfa9,11);
|
||||
C:= D + LRot32(C + (D xor A xor B) + Data[ 7] + $f6bb4b60,16);
|
||||
B:= C + LRot32(B + (C xor D xor A) + Data[10] + $bebfbc70,23);
|
||||
A:= B + LRot32(A + (B xor C xor D) + Data[13] + $289b7ec6,4);
|
||||
D:= A + LRot32(D + (A xor B xor C) + Data[ 0] + $eaa127fa,11);
|
||||
C:= D + LRot32(C + (D xor A xor B) + Data[ 3] + $d4ef3085,16);
|
||||
B:= C + LRot32(B + (C xor D xor A) + Data[ 6] + $04881d05,23);
|
||||
A:= B + LRot32(A + (B xor C xor D) + Data[ 9] + $d9d4d039,4);
|
||||
D:= A + LRot32(D + (A xor B xor C) + Data[12] + $e6db99e5,11);
|
||||
C:= D + LRot32(C + (D xor A xor B) + Data[15] + $1fa27cf8,16);
|
||||
B:= C + LRot32(B + (C xor D xor A) + Data[ 2] + $c4ac5665,23);
|
||||
|
||||
A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 0] + $f4292244,6);
|
||||
D:= A + LRot32(D + (B xor (A or (not C))) + Data[ 7] + $432aff97,10);
|
||||
C:= D + LRot32(C + (A xor (D or (not B))) + Data[14] + $ab9423a7,15);
|
||||
B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 5] + $fc93a039,21);
|
||||
A:= B + LRot32(A + (C xor (B or (not D))) + Data[12] + $655b59c3,6);
|
||||
D:= A + LRot32(D + (B xor (A or (not C))) + Data[ 3] + $8f0ccc92,10);
|
||||
C:= D + LRot32(C + (A xor (D or (not B))) + Data[10] + $ffeff47d,15);
|
||||
B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 1] + $85845dd1,21);
|
||||
A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 8] + $6fa87e4f,6);
|
||||
D:= A + LRot32(D + (B xor (A or (not C))) + Data[15] + $fe2ce6e0,10);
|
||||
C:= D + LRot32(C + (A xor (D or (not B))) + Data[ 6] + $a3014314,15);
|
||||
B:= C + LRot32(B + (D xor (C or (not A))) + Data[13] + $4e0811a1,21);
|
||||
A:= B + LRot32(A + (C xor (B or (not D))) + Data[ 4] + $f7537e82,6);
|
||||
D:= A + LRot32(D + (B xor (A or (not C))) + Data[11] + $bd3af235,10);
|
||||
C:= D + LRot32(C + (A xor (D or (not B))) + Data[ 2] + $2ad7d2bb,15);
|
||||
B:= C + LRot32(B + (D xor (C or (not A))) + Data[ 9] + $eb86d391,21);
|
||||
|
||||
Inc(CurrentHash[0],A);
|
||||
Inc(CurrentHash[1],B);
|
||||
Inc(CurrentHash[2],C);
|
||||
Inc(CurrentHash[3],D);
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
class function TDCP_md5.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 128;
|
||||
end;
|
||||
|
||||
class function TDCP_md5.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_md5;
|
||||
end;
|
||||
|
||||
class function TDCP_md5.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'MD5';
|
||||
end;
|
||||
|
||||
class function TDCP_md5.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..15] of byte=
|
||||
($90,$01,$50,$98,$3c,$d2,$4f,$b0,$d6,$96,$3f,$7d,$28,$e1,$7f,$72);
|
||||
Test2Out: array[0..15] of byte=
|
||||
($c3,$fc,$d3,$d7,$61,$92,$e4,$00,$7d,$fb,$49,$6c,$ca,$67,$e1,$3b);
|
||||
var
|
||||
TestHash: TDCP_md5;
|
||||
TestOut: array[0..19] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_md5.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abc');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_md5.Init;
|
||||
begin
|
||||
Burn;
|
||||
CurrentHash[0]:= $67452301;
|
||||
CurrentHash[1]:= $efcdab89;
|
||||
CurrentHash[2]:= $98badcfe;
|
||||
CurrentHash[3]:= $10325476;
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_md5.Burn;
|
||||
begin
|
||||
LenHi:= 0; LenLo:= 0;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
FillChar(CurrentHash,Sizeof(CurrentHash),0);
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_md5.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_md5.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $80;
|
||||
if Index>= 56 then
|
||||
Compress;
|
||||
PDWord(@HashBuffer[56])^:= LenLo;
|
||||
PDWord(@HashBuffer[60])^:= LenHi;
|
||||
Compress;
|
||||
Move(CurrentHash,Digest,Sizeof(CurrentHash));
|
||||
Burn;
|
||||
end;
|
||||
|
||||
end.
|
321
Units/Misc/dcpripemd128.pas
Normal file
321
Units/Misc/dcpripemd128.pas
Normal file
@ -0,0 +1,321 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A binary compatible implementation of RipeMD-128 ***************************}
|
||||
{******************************************************************************}
|
||||
{* Copyright (c) 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 DCPripemd128;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPcrypt2, DCPconst;
|
||||
|
||||
type
|
||||
TDCP_ripemd128= class(TDCP_hash)
|
||||
protected
|
||||
LenHi, LenLo: longword;
|
||||
Index: DWord;
|
||||
CurrentHash: array[0..3] 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_ripemd128.Compress;
|
||||
var
|
||||
X: array[0..15] of DWord;
|
||||
a, aa, b, bb, c, cc, d, dd, t: dword;
|
||||
begin
|
||||
dcpFillChar(X, SizeOf(X), 0);
|
||||
Move(HashBuffer,X,Sizeof(X));
|
||||
a:= CurrentHash[0]; aa:= a;
|
||||
b:= CurrentHash[1]; bb:= b;
|
||||
c:= CurrentHash[2]; cc:= c;
|
||||
d:= CurrentHash[3]; dd:= d;
|
||||
|
||||
t:= a + (b xor c xor d) + X[ 0]; a:= (t shl 11) or (t shr (32-11));
|
||||
t:= d + (a xor b xor c) + X[ 1]; d:= (t shl 14) or (t shr (32-14));
|
||||
t:= c + (d xor a xor b) + X[ 2]; c:= (t shl 15) or (t shr (32-15));
|
||||
t:= b + (c xor d xor a) + X[ 3]; b:= (t shl 12) or (t shr (32-12));
|
||||
t:= a + (b xor c xor d) + X[ 4]; a:= (t shl 5) or (t shr (32-5));
|
||||
t:= d + (a xor b xor c) + X[ 5]; d:= (t shl 8) or (t shr (32-8));
|
||||
t:= c + (d xor a xor b) + X[ 6]; c:= (t shl 7) or (t shr (32-7));
|
||||
t:= b + (c xor d xor a) + X[ 7]; b:= (t shl 9) or (t shr (32-9));
|
||||
t:= a + (b xor c xor d) + X[ 8]; a:= (t shl 11) or (t shr (32-11));
|
||||
t:= d + (a xor b xor c) + X[ 9]; d:= (t shl 13) or (t shr (32-13));
|
||||
t:= c + (d xor a xor b) + X[10]; c:= (t shl 14) or (t shr (32-14));
|
||||
t:= b + (c xor d xor a) + X[11]; b:= (t shl 15) or (t shr (32-15));
|
||||
t:= a + (b xor c xor d) + X[12]; a:= (t shl 6) or (t shr (32-6));
|
||||
t:= d + (a xor b xor c) + X[13]; d:= (t shl 7) or (t shr (32-7));
|
||||
t:= c + (d xor a xor b) + X[14]; c:= (t shl 9) or (t shr (32-9));
|
||||
t:= b + (c xor d xor a) + X[15]; b:= (t shl 8) or (t shr (32-8));
|
||||
|
||||
t:= a + ((b and c) or (not b and d)) + X[ 7]+$5A827999; a:= (t shl 7) or (t shr (32-7));
|
||||
t:= d + ((a and b) or (not a and c)) + X[ 4]+$5A827999; d:= (t shl 6) or (t shr (32-6));
|
||||
t:= c + ((d and a) or (not d and b)) + X[13]+$5A827999; c:= (t shl 8) or (t shr (32-8));
|
||||
t:= b + ((c and d) or (not c and a)) + X[ 1]+$5A827999; b:= (t shl 13) or (t shr (32-13));
|
||||
t:= a + ((b and c) or (not b and d)) + X[10]+$5A827999; a:= (t shl 11) or (t shr (32-11));
|
||||
t:= d + ((a and b) or (not a and c)) + X[ 6]+$5A827999; d:= (t shl 9) or (t shr (32-9));
|
||||
t:= c + ((d and a) or (not d and b)) + X[15]+$5A827999; c:= (t shl 7) or (t shr (32-7));
|
||||
t:= b + ((c and d) or (not c and a)) + X[ 3]+$5A827999; b:= (t shl 15) or (t shr (32-15));
|
||||
t:= a + ((b and c) or (not b and d)) + X[12]+$5A827999; a:= (t shl 7) or (t shr (32-7));
|
||||
t:= d + ((a and b) or (not a and c)) + X[ 0]+$5A827999; d:= (t shl 12) or (t shr (32-12));
|
||||
t:= c + ((d and a) or (not d and b)) + X[ 9]+$5A827999; c:= (t shl 15) or (t shr (32-15));
|
||||
t:= b + ((c and d) or (not c and a)) + X[ 5]+$5A827999; b:= (t shl 9) or (t shr (32-9));
|
||||
t:= a + ((b and c) or (not b and d)) + X[ 2]+$5A827999; a:= (t shl 11) or (t shr (32-11));
|
||||
t:= d + ((a and b) or (not a and c)) + X[14]+$5A827999; d:= (t shl 7) or (t shr (32-7));
|
||||
t:= c + ((d and a) or (not d and b)) + X[11]+$5A827999; c:= (t shl 13) or (t shr (32-13));
|
||||
t:= b + ((c and d) or (not c and a)) + X[ 8]+$5A827999; b:= (t shl 12) or (t shr (32-12));
|
||||
|
||||
t:= a + ((b or not c) xor d) + X[ 3]+$6ED9EBA1; a:= (t shl 11) or (t shr (32-11));
|
||||
t:= d + ((a or not b) xor c) + X[10]+$6ED9EBA1; d:= (t shl 13) or (t shr (32-13));
|
||||
t:= c + ((d or not a) xor b) + X[14]+$6ED9EBA1; c:= (t shl 6) or (t shr (32-6));
|
||||
t:= b + ((c or not d) xor a) + X[ 4]+$6ED9EBA1; b:= (t shl 7) or (t shr (32-7));
|
||||
t:= a + ((b or not c) xor d) + X[ 9]+$6ED9EBA1; a:= (t shl 14) or (t shr (32-14));
|
||||
t:= d + ((a or not b) xor c) + X[15]+$6ED9EBA1; d:= (t shl 9) or (t shr (32-9));
|
||||
t:= c + ((d or not a) xor b) + X[ 8]+$6ED9EBA1; c:= (t shl 13) or (t shr (32-13));
|
||||
t:= b + ((c or not d) xor a) + X[ 1]+$6ED9EBA1; b:= (t shl 15) or (t shr (32-15));
|
||||
t:= a + ((b or not c) xor d) + X[ 2]+$6ED9EBA1; a:= (t shl 14) or (t shr (32-14));
|
||||
t:= d + ((a or not b) xor c) + X[ 7]+$6ED9EBA1; d:= (t shl 8) or (t shr (32-8));
|
||||
t:= c + ((d or not a) xor b) + X[ 0]+$6ED9EBA1; c:= (t shl 13) or (t shr (32-13));
|
||||
t:= b + ((c or not d) xor a) + X[ 6]+$6ED9EBA1; b:= (t shl 6) or (t shr (32-6));
|
||||
t:= a + ((b or not c) xor d) + X[13]+$6ED9EBA1; a:= (t shl 5) or (t shr (32-5));
|
||||
t:= d + ((a or not b) xor c) + X[11]+$6ED9EBA1; d:= (t shl 12) or (t shr (32-12));
|
||||
t:= c + ((d or not a) xor b) + X[ 5]+$6ED9EBA1; c:= (t shl 7) or (t shr (32-7));
|
||||
t:= b + ((c or not d) xor a) + X[12]+$6ED9EBA1; b:= (t shl 5) or (t shr (32-5));
|
||||
|
||||
t:= a + ((b and d) or (c and not d)) + X[ 1]+$8F1BBCDC; a:= (t shl 11) or (t shr (32-11));
|
||||
t:= d + ((a and c) or (b and not c)) + X[ 9]+$8F1BBCDC; d:= (t shl 12) or (t shr (32-12));
|
||||
t:= c + ((d and b) or (a and not b)) + X[11]+$8F1BBCDC; c:= (t shl 14) or (t shr (32-14));
|
||||
t:= b + ((c and a) or (d and not a)) + X[10]+$8F1BBCDC; b:= (t shl 15) or (t shr (32-15));
|
||||
t:= a + ((b and d) or (c and not d)) + X[ 0]+$8F1BBCDC; a:= (t shl 14) or (t shr (32-14));
|
||||
t:= d + ((a and c) or (b and not c)) + X[ 8]+$8F1BBCDC; d:= (t shl 15) or (t shr (32-15));
|
||||
t:= c + ((d and b) or (a and not b)) + X[12]+$8F1BBCDC; c:= (t shl 9) or (t shr (32-9));
|
||||
t:= b + ((c and a) or (d and not a)) + X[ 4]+$8F1BBCDC; b:= (t shl 8) or (t shr (32-8));
|
||||
t:= a + ((b and d) or (c and not d)) + X[13]+$8F1BBCDC; a:= (t shl 9) or (t shr (32-9));
|
||||
t:= d + ((a and c) or (b and not c)) + X[ 3]+$8F1BBCDC; d:= (t shl 14) or (t shr (32-14));
|
||||
t:= c + ((d and b) or (a and not b)) + X[ 7]+$8F1BBCDC; c:= (t shl 5) or (t shr (32-5));
|
||||
t:= b + ((c and a) or (d and not a)) + X[15]+$8F1BBCDC; b:= (t shl 6) or (t shr (32-6));
|
||||
t:= a + ((b and d) or (c and not d)) + X[14]+$8F1BBCDC; a:= (t shl 8) or (t shr (32-8));
|
||||
t:= d + ((a and c) or (b and not c)) + X[ 5]+$8F1BBCDC; d:= (t shl 6) or (t shr (32-6));
|
||||
t:= c + ((d and b) or (a and not b)) + X[ 6]+$8F1BBCDC; c:= (t shl 5) or (t shr (32-5));
|
||||
t:= b + ((c and a) or (d and not a)) + X[ 2]+$8F1BBCDC; b:= (t shl 12) or (t shr (32-12));
|
||||
|
||||
t:= aa + ((bb and dd) or (cc and not dd)) + X[ 5]+$50A28BE6; aa:= (t shl 8) or (t shr (32-8));
|
||||
t:= dd + ((aa and cc) or (bb and not cc)) + X[14]+$50A28BE6; dd:= (t shl 9) or (t shr (32-9));
|
||||
t:= cc + ((dd and bb) or (aa and not bb)) + X[ 7]+$50A28BE6; cc:= (t shl 9) or (t shr (32-9));
|
||||
t:= bb + ((cc and aa) or (dd and not aa)) + X[ 0]+$50A28BE6; bb:= (t shl 11) or (t shr (32-11));
|
||||
t:= aa + ((bb and dd) or (cc and not dd)) + X[ 9]+$50A28BE6; aa:= (t shl 13) or (t shr (32-13));
|
||||
t:= dd + ((aa and cc) or (bb and not cc)) + X[ 2]+$50A28BE6; dd:= (t shl 15) or (t shr (32-15));
|
||||
t:= cc + ((dd and bb) or (aa and not bb)) + X[11]+$50A28BE6; cc:= (t shl 15) or (t shr (32-15));
|
||||
t:= bb + ((cc and aa) or (dd and not aa)) + X[ 4]+$50A28BE6; bb:= (t shl 5) or (t shr (32-5));
|
||||
t:= aa + ((bb and dd) or (cc and not dd)) + X[13]+$50A28BE6; aa:= (t shl 7) or (t shr (32-7));
|
||||
t:= dd + ((aa and cc) or (bb and not cc)) + X[ 6]+$50A28BE6; dd:= (t shl 7) or (t shr (32-7));
|
||||
t:= cc + ((dd and bb) or (aa and not bb)) + X[15]+$50A28BE6; cc:= (t shl 8) or (t shr (32-8));
|
||||
t:= bb + ((cc and aa) or (dd and not aa)) + X[ 8]+$50A28BE6; bb:= (t shl 11) or (t shr (32-11));
|
||||
t:= aa + ((bb and dd) or (cc and not dd)) + X[ 1]+$50A28BE6; aa:= (t shl 14) or (t shr (32-14));
|
||||
t:= dd + ((aa and cc) or (bb and not cc)) + X[10]+$50A28BE6; dd:= (t shl 14) or (t shr (32-14));
|
||||
t:= cc + ((dd and bb) or (aa and not bb)) + X[ 3]+$50A28BE6; cc:= (t shl 12) or (t shr (32-12));
|
||||
t:= bb + ((cc and aa) or (dd and not aa)) + X[12]+$50A28BE6; bb:= (t shl 6) or (t shr (32-6));
|
||||
|
||||
t:= aa + ((bb or not cc) xor dd) + X[ 6]+$5C4DD124; aa:= (t shl 9) or (t shr (32-9));
|
||||
t:= dd + ((aa or not bb) xor cc) + X[11]+$5C4DD124; dd:= (t shl 13) or (t shr (32-13));
|
||||
t:= cc + ((dd or not aa) xor bb) + X[ 3]+$5C4DD124; cc:= (t shl 15) or (t shr (32-15));
|
||||
t:= bb + ((cc or not dd) xor aa) + X[ 7]+$5C4DD124; bb:= (t shl 7) or (t shr (32-7));
|
||||
t:= aa + ((bb or not cc) xor dd) + X[ 0]+$5C4DD124; aa:= (t shl 12) or (t shr (32-12));
|
||||
t:= dd + ((aa or not bb) xor cc) + X[13]+$5C4DD124; dd:= (t shl 8) or (t shr (32-8));
|
||||
t:= cc + ((dd or not aa) xor bb) + X[ 5]+$5C4DD124; cc:= (t shl 9) or (t shr (32-9));
|
||||
t:= bb + ((cc or not dd) xor aa) + X[10]+$5C4DD124; bb:= (t shl 11) or (t shr (32-11));
|
||||
t:= aa + ((bb or not cc) xor dd) + X[14]+$5C4DD124; aa:= (t shl 7) or (t shr (32-7));
|
||||
t:= dd + ((aa or not bb) xor cc) + X[15]+$5C4DD124; dd:= (t shl 7) or (t shr (32-7));
|
||||
t:= cc + ((dd or not aa) xor bb) + X[ 8]+$5C4DD124; cc:= (t shl 12) or (t shr (32-12));
|
||||
t:= bb + ((cc or not dd) xor aa) + X[12]+$5C4DD124; bb:= (t shl 7) or (t shr (32-7));
|
||||
t:= aa + ((bb or not cc) xor dd) + X[ 4]+$5C4DD124; aa:= (t shl 6) or (t shr (32-6));
|
||||
t:= dd + ((aa or not bb) xor cc) + X[ 9]+$5C4DD124; dd:= (t shl 15) or (t shr (32-15));
|
||||
t:= cc + ((dd or not aa) xor bb) + X[ 1]+$5C4DD124; cc:= (t shl 13) or (t shr (32-13));
|
||||
t:= bb + ((cc or not dd) xor aa) + X[ 2]+$5C4DD124; bb:= (t shl 11) or (t shr (32-11));
|
||||
|
||||
t:= aa + ((bb and cc) or (not bb and dd)) + X[15]+$6D703EF3; aa:= (t shl 9) or (t shr (32-9));
|
||||
t:= dd + ((aa and bb) or (not aa and cc)) + X[ 5]+$6D703EF3; dd:= (t shl 7) or (t shr (32-7));
|
||||
t:= cc + ((dd and aa) or (not dd and bb)) + X[ 1]+$6D703EF3; cc:= (t shl 15) or (t shr (32-15));
|
||||
t:= bb + ((cc and dd) or (not cc and aa)) + X[ 3]+$6D703EF3; bb:= (t shl 11) or (t shr (32-11));
|
||||
t:= aa + ((bb and cc) or (not bb and dd)) + X[ 7]+$6D703EF3; aa:= (t shl 8) or (t shr (32-8));
|
||||
t:= dd + ((aa and bb) or (not aa and cc)) + X[14]+$6D703EF3; dd:= (t shl 6) or (t shr (32-6));
|
||||
t:= cc + ((dd and aa) or (not dd and bb)) + X[ 6]+$6D703EF3; cc:= (t shl 6) or (t shr (32-6));
|
||||
t:= bb + ((cc and dd) or (not cc and aa)) + X[ 9]+$6D703EF3; bb:= (t shl 14) or (t shr (32-14));
|
||||
t:= aa + ((bb and cc) or (not bb and dd)) + X[11]+$6D703EF3; aa:= (t shl 12) or (t shr (32-12));
|
||||
t:= dd + ((aa and bb) or (not aa and cc)) + X[ 8]+$6D703EF3; dd:= (t shl 13) or (t shr (32-13));
|
||||
t:= cc + ((dd and aa) or (not dd and bb)) + X[12]+$6D703EF3; cc:= (t shl 5) or (t shr (32-5));
|
||||
t:= bb + ((cc and dd) or (not cc and aa)) + X[ 2]+$6D703EF3; bb:= (t shl 14) or (t shr (32-14));
|
||||
t:= aa + ((bb and cc) or (not bb and dd)) + X[10]+$6D703EF3; aa:= (t shl 13) or (t shr (32-13));
|
||||
t:= dd + ((aa and bb) or (not aa and cc)) + X[ 0]+$6D703EF3; dd:= (t shl 13) or (t shr (32-13));
|
||||
t:= cc + ((dd and aa) or (not dd and bb)) + X[ 4]+$6D703EF3; cc:= (t shl 7) or (t shr (32-7));
|
||||
t:= bb + ((cc and dd) or (not cc and aa)) + X[13]+$6D703EF3; bb:= (t shl 5) or (t shr (32-5));
|
||||
|
||||
t:= aa + (bb xor cc xor dd) + X[ 8]; aa:= (t shl 15) or (t shr (32-15));
|
||||
t:= dd + (aa xor bb xor cc) + X[ 6]; dd:= (t shl 5) or (t shr (32-5));
|
||||
t:= cc + (dd xor aa xor bb) + X[ 4]; cc:= (t shl 8) or (t shr (32-8));
|
||||
t:= bb + (cc xor dd xor aa) + X[ 1]; bb:= (t shl 11) or (t shr (32-11));
|
||||
t:= aa + (bb xor cc xor dd) + X[ 3]; aa:= (t shl 14) or (t shr (32-14));
|
||||
t:= dd + (aa xor bb xor cc) + X[11]; dd:= (t shl 14) or (t shr (32-14));
|
||||
t:= cc + (dd xor aa xor bb) + X[15]; cc:= (t shl 6) or (t shr (32-6));
|
||||
t:= bb + (cc xor dd xor aa) + X[ 0]; bb:= (t shl 14) or (t shr (32-14));
|
||||
t:= aa + (bb xor cc xor dd) + X[ 5]; aa:= (t shl 6) or (t shr (32-6));
|
||||
t:= dd + (aa xor bb xor cc) + X[12]; dd:= (t shl 9) or (t shr (32-9));
|
||||
t:= cc + (dd xor aa xor bb) + X[ 2]; cc:= (t shl 12) or (t shr (32-12));
|
||||
t:= bb + (cc xor dd xor aa) + X[13]; bb:= (t shl 9) or (t shr (32-9));
|
||||
t:= aa + (bb xor cc xor dd) + X[ 9]; aa:= (t shl 12) or (t shr (32-12));
|
||||
t:= dd + (aa xor bb xor cc) + X[ 7]; dd:= (t shl 5) or (t shr (32-5));
|
||||
t:= cc + (dd xor aa xor bb) + X[10]; cc:= (t shl 15) or (t shr (32-15));
|
||||
t:= bb + (cc xor dd xor aa) + X[14]; bb:= (t shl 8) or (t shr (32-8));
|
||||
|
||||
Inc(dd,c + CurrentHash[1]);
|
||||
CurrentHash[1]:= CurrentHash[2] + d + aa;
|
||||
CurrentHash[2]:= CurrentHash[3] + a + bb;
|
||||
CurrentHash[3]:= CurrentHash[0] + b + cc;
|
||||
CurrentHash[0]:= dd;
|
||||
|
||||
FillChar(X,Sizeof(X),0);
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
class function TDCP_ripemd128.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 128;
|
||||
end;
|
||||
|
||||
class function TDCP_ripemd128.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_ripemd128;
|
||||
end;
|
||||
|
||||
class function TDCP_ripemd128.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'RipeMD-128';
|
||||
end;
|
||||
|
||||
class function TDCP_ripemd128.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..15] of byte=
|
||||
($86,$be,$7a,$fa,$33,$9d,$0f,$c7,$cf,$c7,$85,$e7,$2f,$57,$8d,$33);
|
||||
Test2Out: array[0..15] of byte=
|
||||
($fd,$2a,$a6,$07,$f7,$1d,$c8,$f5,$10,$71,$49,$22,$b3,$71,$83,$4e);
|
||||
var
|
||||
TestHash: TDCP_ripemd128;
|
||||
TestOut: array[0..15] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_ripemd128.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('a');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_ripemd128.Init;
|
||||
begin
|
||||
Burn;
|
||||
CurrentHash[0]:= $67452301;
|
||||
CurrentHash[1]:= $efcdab89;
|
||||
CurrentHash[2]:= $98badcfe;
|
||||
CurrentHash[3]:= $10325476;
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_ripemd128.Burn;
|
||||
begin
|
||||
LenHi:= 0; LenLo:= 0;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
FillChar(CurrentHash,Sizeof(CurrentHash),0);
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_ripemd128.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_ripemd128.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $80;
|
||||
if Index>= 56 then
|
||||
Compress;
|
||||
PDWord(@HashBuffer[56])^:= LenLo;
|
||||
PDWord(@HashBuffer[60])^:= LenHi;
|
||||
Compress;
|
||||
Move(CurrentHash,Digest,Sizeof(CurrentHash));
|
||||
Burn;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
682
Units/Misc/dcpripemd160.pas
Normal file
682
Units/Misc/dcpripemd160.pas
Normal file
@ -0,0 +1,682 @@
|
||||
{******************************************************************************}
|
||||
{* 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;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
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
|
||||
dcpFillChar(X, SizeOf(X), 0);
|
||||
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;
|
||||
aa:= ((aa shl 14) or (aa shr (32-14))) + ee;
|
||||
cc:= ((cc shl 10) or (cc shr (32-10)));
|
||||
ee:= ee + ((aa and cc) or (bb and (not cc))) + X[10] + $8f1bbcdc;
|
||||
ee:= ((ee shl 15) or (ee shr (32-15))) + dd;
|
||||
bb:= ((bb shl 10) or (bb shr (32-10)));
|
||||
dd:= dd + ((ee and bb) or (aa and (not bb))) + X[ 0] + $8f1bbcdc;
|
||||
dd:= ((dd shl 14) or (dd shr (32-14))) + cc;
|
||||
aa:= ((aa shl 10) or (aa shr (32-10)));
|
||||
cc:= cc + ((dd and aa) or (ee and (not aa))) + X[ 8] + $8f1bbcdc;
|
||||
cc:= ((cc shl 15) or (cc shr (32-15))) + bb;
|
||||
ee:= ((ee shl 10) or (ee shr (32-10)));
|
||||
bb:= bb + ((cc and ee) or (dd and (not ee))) + X[12] + $8f1bbcdc;
|
||||
bb:= ((bb shl 9) or (bb shr (32-9))) + aa;
|
||||
dd:= ((dd shl 10) or (dd shr (32-10)));
|
||||
aa:= aa + ((bb and dd) or (cc and (not dd))) + X[ 4] + $8f1bbcdc;
|
||||
aa:= ((aa shl 8) or (aa shr (32-8))) + ee;
|
||||
cc:= ((cc shl 10) or (cc shr (32-10)));
|
||||
ee:= ee + ((aa and cc) or (bb and (not cc))) + X[13] + $8f1bbcdc;
|
||||
ee:= ((ee shl 9) or (ee shr (32-9))) + dd;
|
||||
bb:= ((bb shl 10) or (bb shr (32-10)));
|
||||
dd:= dd + ((ee and bb) or (aa and (not bb))) + X[ 3] + $8f1bbcdc;
|
||||
dd:= ((dd shl 14) or (dd shr (32-14))) + cc;
|
||||
aa:= ((aa shl 10) or (aa shr (32-10)));
|
||||
cc:= cc + ((dd and aa) or (ee and (not aa))) + X[ 7] + $8f1bbcdc;
|
||||
cc:= ((cc shl 5) or (cc shr (32-5))) + bb;
|
||||
ee:= ((ee shl 10) or (ee shr (32-10)));
|
||||
bb:= bb + ((cc and ee) or (dd and (not ee))) + X[15] + $8f1bbcdc;
|
||||
bb:= ((bb shl 6) or (bb shr (32-6))) + aa;
|
||||
dd:= ((dd shl 10) or (dd shr (32-10)));
|
||||
aa:= aa + ((bb and dd) or (cc and (not dd))) + X[14] + $8f1bbcdc;
|
||||
aa:= ((aa shl 8) or (aa shr (32-8))) + ee;
|
||||
cc:= ((cc shl 10) or (cc shr (32-10)));
|
||||
ee:= ee + ((aa and cc) or (bb and (not cc))) + X[ 5] + $8f1bbcdc;
|
||||
ee:= ((ee shl 6) or (ee shr (32-6))) + dd;
|
||||
bb:= ((bb shl 10) or (bb shr (32-10)));
|
||||
dd:= dd + ((ee and bb) or (aa and (not bb))) + X[ 6] + $8f1bbcdc;
|
||||
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[ 2] + $8f1bbcdc;
|
||||
cc:= ((cc shl 12) or (cc shr (32-12))) + bb;
|
||||
ee:= ((ee shl 10) or (ee shr (32-10)));
|
||||
|
||||
bb:= bb + (cc xor (dd or (not ee))) + X[ 4] + $a953fd4e;
|
||||
bb:= ((bb shl 9) or (bb shr (32-9))) + aa;
|
||||
dd:= ((dd shl 10) or (dd shr (32-10)));
|
||||
aa:= aa + (bb xor (cc or (not dd))) + X[ 0] + $a953fd4e;
|
||||
aa:= ((aa shl 15) or (aa shr (32-15))) + ee;
|
||||
cc:= ((cc shl 10) or (cc shr (32-10)));
|
||||
ee:= ee + (aa xor (bb or (not cc))) + X[ 5] + $a953fd4e;
|
||||
ee:= ((ee shl 5) or (ee shr (32-5))) + dd;
|
||||
bb:= ((bb shl 10) or (bb shr (32-10)));
|
||||
dd:= dd + (ee xor (aa or (not bb))) + X[ 9] + $a953fd4e;
|
||||
dd:= ((dd shl 11) or (dd shr (32-11))) + cc;
|
||||
aa:= ((aa shl 10) or (aa shr (32-10)));
|
||||
cc:= cc + (dd xor (ee or (not aa))) + X[ 7] + $a953fd4e;
|
||||
cc:= ((cc shl 6) or (cc shr (32-6))) + bb;
|
||||
ee:= ((ee shl 10) or (ee shr (32-10)));
|
||||
bb:= bb + (cc xor (dd or (not ee))) + X[12] + $a953fd4e;
|
||||
bb:= ((bb shl 8) or (bb shr (32-8))) + aa;
|
||||
dd:= ((dd shl 10) or (dd shr (32-10)));
|
||||
aa:= aa + (bb xor (cc or (not dd))) + X[ 2] + $a953fd4e;
|
||||
aa:= ((aa shl 13) or (aa shr (32-13))) + ee;
|
||||
cc:= ((cc shl 10) or (cc shr (32-10)));
|
||||
ee:= ee + (aa xor (bb or (not cc))) + X[10] + $a953fd4e;
|
||||
ee:= ((ee shl 12) or (ee shr (32-12))) + dd;
|
||||
bb:= ((bb shl 10) or (bb shr (32-10)));
|
||||
dd:= dd + (ee xor (aa or (not bb))) + X[14] + $a953fd4e;
|
||||
dd:= ((dd shl 5) or (dd shr (32-5))) + cc;
|
||||
aa:= ((aa shl 10) or (aa shr (32-10)));
|
||||
cc:= cc + (dd xor (ee or (not aa))) + X[ 1] + $a953fd4e;
|
||||
cc:= ((cc shl 12) or (cc shr (32-12))) + bb;
|
||||
ee:= ((ee shl 10) or (ee shr (32-10)));
|
||||
bb:= bb + (cc xor (dd or (not ee))) + X[ 3] + $a953fd4e;
|
||||
bb:= ((bb shl 13) or (bb shr (32-13))) + aa;
|
||||
dd:= ((dd shl 10) or (dd shr (32-10)));
|
||||
aa:= aa + (bb xor (cc or (not dd))) + X[ 8] + $a953fd4e;
|
||||
aa:= ((aa shl 14) or (aa shr (32-14))) + ee;
|
||||
cc:= ((cc shl 10) or (cc shr (32-10)));
|
||||
ee:= ee + (aa xor (bb or (not cc))) + X[11] + $a953fd4e;
|
||||
ee:= ((ee shl 11) or (ee shr (32-11))) + dd;
|
||||
bb:= ((bb shl 10) or (bb shr (32-10)));
|
||||
dd:= dd + (ee xor (aa or (not bb))) + X[ 6] + $a953fd4e;
|
||||
dd:= ((dd shl 8) or (dd shr (32-8))) + cc;
|
||||
aa:= ((aa shl 10) or (aa shr (32-10)));
|
||||
cc:= cc + (dd xor (ee or (not aa))) + X[15] + $a953fd4e;
|
||||
cc:= ((cc shl 5) or (cc shr (32-5))) + bb;
|
||||
ee:= ((ee shl 10) or (ee shr (32-10)));
|
||||
bb:= bb + (cc xor (dd or (not ee))) + X[13] + $a953fd4e;
|
||||
bb:= ((bb shl 6) or (bb shr (32-6))) + aa;
|
||||
dd:= ((dd shl 10) or (dd shr (32-10)));
|
||||
|
||||
aaa:= aaa + (bbb xor (ccc or (not ddd))) + X[ 5] + $50a28be6;
|
||||
aaa:= ((aaa shl 8) or (aaa shr (32-8))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + (aaa xor (bbb or (not ccc))) + X[14] + $50a28be6;
|
||||
eee:= ((eee shl 9) or (eee shr (32-9))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + (eee xor (aaa or (not bbb))) + X[ 7] + $50a28be6;
|
||||
ddd:= ((ddd shl 9) or (ddd shr (32-9))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + (ddd xor (eee or (not aaa))) + X[ 0] + $50a28be6;
|
||||
ccc:= ((ccc shl 11) or (ccc shr (32-11))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + (ccc xor (ddd or (not eee))) + X[ 9] + $50a28be6;
|
||||
bbb:= ((bbb shl 13) or (bbb shr (32-13))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + (bbb xor (ccc or (not ddd))) + X[ 2] + $50a28be6;
|
||||
aaa:= ((aaa shl 15) or (aaa shr (32-15))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + (aaa xor (bbb or (not ccc))) + X[11] + $50a28be6;
|
||||
eee:= ((eee shl 15) or (eee shr (32-15))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + (eee xor (aaa or (not bbb))) + X[ 4] + $50a28be6;
|
||||
ddd:= ((ddd shl 5) or (ddd shr (32-5))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + (ddd xor (eee or (not aaa))) + X[13] + $50a28be6;
|
||||
ccc:= ((ccc shl 7) or (ccc shr (32-7))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + (ccc xor (ddd or (not eee))) + X[ 6] + $50a28be6;
|
||||
bbb:= ((bbb shl 7) or (bbb shr (32-7))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + (bbb xor (ccc or (not ddd))) + X[15] + $50a28be6;
|
||||
aaa:= ((aaa shl 8) or (aaa shr (32-8))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + (aaa xor (bbb or (not ccc))) + X[ 8] + $50a28be6;
|
||||
eee:= ((eee shl 11) or (eee shr (32-11))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + (eee xor (aaa or (not bbb))) + X[ 1] + $50a28be6;
|
||||
ddd:= ((ddd shl 14) or (ddd shr (32-14))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + (ddd xor (eee or (not aaa))) + X[10] + $50a28be6;
|
||||
ccc:= ((ccc shl 14) or (ccc shr (32-14))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + (ccc xor (ddd or (not eee))) + X[ 3] + $50a28be6;
|
||||
bbb:= ((bbb shl 12) or (bbb shr (32-12))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + (bbb xor (ccc or (not ddd))) + X[12] + $50a28be6;
|
||||
aaa:= ((aaa shl 6) or (aaa shr (32-6))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
|
||||
eee:= eee + ((aaa and ccc) or (bbb and (not ccc))) + X[ 6] + $5c4dd124;
|
||||
eee:= ((eee shl 9) or (eee shr (32-9))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee and bbb) or (aaa and (not bbb))) + X[11] + $5c4dd124;
|
||||
ddd:= ((ddd shl 13) or (ddd shr (32-13))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd and aaa) or (eee and (not aaa))) + X[ 3] + $5c4dd124;
|
||||
ccc:= ((ccc shl 15) or (ccc shr (32-15))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc and eee) or (ddd and (not eee))) + X[ 7] + $5c4dd124;
|
||||
bbb:= ((bbb shl 7) or (bbb shr (32-7))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb and ddd) or (ccc and (not ddd))) + X[ 0] + $5c4dd124;
|
||||
aaa:= ((aaa shl 12) or (aaa shr (32-12))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa and ccc) or (bbb and (not ccc))) + X[13] + $5c4dd124;
|
||||
eee:= ((eee shl 8) or (eee shr (32-8))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee and bbb) or (aaa and (not bbb))) + X[ 5] + $5c4dd124;
|
||||
ddd:= ((ddd shl 9) or (ddd shr (32-9))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd and aaa) or (eee and (not aaa))) + X[10] + $5c4dd124;
|
||||
ccc:= ((ccc shl 11) or (ccc shr (32-11))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc and eee) or (ddd and (not eee))) + X[14] + $5c4dd124;
|
||||
bbb:= ((bbb shl 7) or (bbb shr (32-7))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb and ddd) or (ccc and (not ddd))) + X[15] + $5c4dd124;
|
||||
aaa:= ((aaa shl 7) or (aaa shr (32-7))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa and ccc) or (bbb and (not ccc))) + X[ 8] + $5c4dd124;
|
||||
eee:= ((eee shl 12) or (eee shr (32-12))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee and bbb) or (aaa and (not bbb))) + X[12] + $5c4dd124;
|
||||
ddd:= ((ddd shl 7) or (ddd shr (32-7))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd and aaa) or (eee and (not aaa))) + X[ 4] + $5c4dd124;
|
||||
ccc:= ((ccc shl 6) or (ccc shr (32-6))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc and eee) or (ddd and (not eee))) + X[ 9] + $5c4dd124;
|
||||
bbb:= ((bbb shl 15) or (bbb shr (32-15))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb and ddd) or (ccc and (not ddd))) + X[ 1] + $5c4dd124;
|
||||
aaa:= ((aaa shl 13) or (aaa shr (32-13))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa and ccc) or (bbb and (not ccc))) + X[ 2] + $5c4dd124;
|
||||
eee:= ((eee shl 11) or (eee shr (32-11))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
|
||||
ddd:= ddd + ((eee or (not aaa)) xor bbb) + X[15] + $6d703ef3;
|
||||
ddd:= ((ddd shl 9) or (ddd shr (32-9))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd or (not eee)) xor aaa) + X[ 5] + $6d703ef3;
|
||||
ccc:= ((ccc shl 7) or (ccc shr (32-7))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc or (not ddd)) xor eee) + X[ 1] + $6d703ef3;
|
||||
bbb:= ((bbb shl 15) or (bbb shr (32-15))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb or (not ccc)) xor ddd) + X[ 3] + $6d703ef3;
|
||||
aaa:= ((aaa shl 11) or (aaa shr (32-11))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa or (not bbb)) xor ccc) + X[ 7] + $6d703ef3;
|
||||
eee:= ((eee shl 8) or (eee shr (32-8))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee or (not aaa)) xor bbb) + X[14] + $6d703ef3;
|
||||
ddd:= ((ddd shl 6) or (ddd shr (32-6))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd or (not eee)) xor aaa) + X[ 6] + $6d703ef3;
|
||||
ccc:= ((ccc shl 6) or (ccc shr (32-6))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc or (not ddd)) xor eee) + X[ 9] + $6d703ef3;
|
||||
bbb:= ((bbb shl 14) or (bbb shr (32-14))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb or (not ccc)) xor ddd) + X[11] + $6d703ef3;
|
||||
aaa:= ((aaa shl 12) or (aaa shr (32-12))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa or (not bbb)) xor ccc) + X[ 8] + $6d703ef3;
|
||||
eee:= ((eee shl 13) or (eee shr (32-13))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee or (not aaa)) xor bbb) + X[12] + $6d703ef3;
|
||||
ddd:= ((ddd shl 5) or (ddd shr (32-5))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd or (not eee)) xor aaa) + X[ 2] + $6d703ef3;
|
||||
ccc:= ((ccc shl 14) or (ccc shr (32-14))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc or (not ddd)) xor eee) + X[10] + $6d703ef3;
|
||||
bbb:= ((bbb shl 13) or (bbb shr (32-13))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb or (not ccc)) xor ddd) + X[ 0] + $6d703ef3;
|
||||
aaa:= ((aaa shl 13) or (aaa shr (32-13))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa or (not bbb)) xor ccc) + X[ 4] + $6d703ef3;
|
||||
eee:= ((eee shl 7) or (eee shr (32-7))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee or (not aaa)) xor bbb) + X[13] + $6d703ef3;
|
||||
ddd:= ((ddd shl 5) or (ddd shr (32-5))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
|
||||
ccc:= ccc + ((ddd and eee) or ((not ddd) and aaa)) + X[ 8] + $7a6d76e9;
|
||||
ccc:= ((ccc shl 15) or (ccc shr (32-15))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc and ddd) or ((not ccc) and eee)) + X[ 6] + $7a6d76e9;
|
||||
bbb:= ((bbb shl 5) or (bbb shr (32-5))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb and ccc) or ((not bbb) and ddd)) + X[ 4] + $7a6d76e9;
|
||||
aaa:= ((aaa shl 8) or (aaa shr (32-8))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa and bbb) or ((not aaa) and ccc)) + X[ 1] + $7a6d76e9;
|
||||
eee:= ((eee shl 11) or (eee shr (32-11))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee and aaa) or ((not eee) and bbb)) + X[ 3] + $7a6d76e9;
|
||||
ddd:= ((ddd shl 14) or (ddd shr (32-14))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd and eee) or ((not ddd) and aaa)) + X[11] + $7a6d76e9;
|
||||
ccc:= ((ccc shl 14) or (ccc shr (32-14))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc and ddd) or ((not ccc) and eee)) + X[15] + $7a6d76e9;
|
||||
bbb:= ((bbb shl 6) or (bbb shr (32-6))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb and ccc) or ((not bbb) and ddd)) + X[ 0] + $7a6d76e9;
|
||||
aaa:= ((aaa shl 14) or (aaa shr (32-14))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa and bbb) or ((not aaa) and ccc)) + X[ 5] + $7a6d76e9;
|
||||
eee:= ((eee shl 6) or (eee shr (32-6))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee and aaa) or ((not eee) and bbb)) + X[12] + $7a6d76e9;
|
||||
ddd:= ((ddd shl 9) or (ddd shr (32-9))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd and eee) or ((not ddd) and aaa)) + X[ 2] + $7a6d76e9;
|
||||
ccc:= ((ccc shl 12) or (ccc shr (32-12))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + ((ccc and ddd) or ((not ccc) and eee)) + X[13] + $7a6d76e9;
|
||||
bbb:= ((bbb shl 9) or (bbb shr (32-9))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + ((bbb and ccc) or ((not bbb) and ddd)) + X[ 9] + $7a6d76e9;
|
||||
aaa:= ((aaa shl 12) or (aaa shr (32-12))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + ((aaa and bbb) or ((not aaa) and ccc)) + X[ 7] + $7a6d76e9;
|
||||
eee:= ((eee shl 5) or (eee shr (32-5))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + ((eee and aaa) or ((not eee) and bbb)) + X[10] + $7a6d76e9;
|
||||
ddd:= ((ddd shl 15) or (ddd shr (32-15))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + ((ddd and eee) or ((not ddd) and aaa)) + X[14] + $7a6d76e9;
|
||||
ccc:= ((ccc shl 8) or (ccc shr (32-8))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
|
||||
bbb:= bbb + (ccc xor ddd xor eee) + X[12];
|
||||
bbb:= ((bbb shl 8) or (bbb shr (32-8))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + (bbb xor ccc xor ddd) + X[15];
|
||||
aaa:= ((aaa shl 5) or (aaa shr (32-5))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + (aaa xor bbb xor ccc) + X[10];
|
||||
eee:= ((eee shl 12) or (eee shr (32-12))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + (eee xor aaa xor bbb) + X[ 4];
|
||||
ddd:= ((ddd shl 9) or (ddd shr (32-9))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + (ddd xor eee xor aaa) + X[ 1];
|
||||
ccc:= ((ccc shl 12) or (ccc shr (32-12))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + (ccc xor ddd xor eee) + X[ 5];
|
||||
bbb:= ((bbb shl 5) or (bbb shr (32-5))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + (bbb xor ccc xor ddd) + X[ 8];
|
||||
aaa:= ((aaa shl 14) or (aaa shr (32-14))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + (aaa xor bbb xor ccc) + X[ 7];
|
||||
eee:= ((eee shl 6) or (eee shr (32-6))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + (eee xor aaa xor bbb) + X[ 6];
|
||||
ddd:= ((ddd shl 8) or (ddd shr (32-8))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + (ddd xor eee xor aaa) + X[ 2];
|
||||
ccc:= ((ccc shl 13) or (ccc shr (32-13))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + (ccc xor ddd xor eee) + X[13];
|
||||
bbb:= ((bbb shl 6) or (bbb shr (32-6))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
aaa:= aaa + (bbb xor ccc xor ddd) + X[14];
|
||||
aaa:= ((aaa shl 5) or (aaa shr (32-5))) + eee;
|
||||
ccc:= ((ccc shl 10) or (ccc shr (32-10)));
|
||||
eee:= eee + (aaa xor bbb xor ccc) + X[ 0];
|
||||
eee:= ((eee shl 15) or (eee shr (32-15))) + ddd;
|
||||
bbb:= ((bbb shl 10) or (bbb shr (32-10)));
|
||||
ddd:= ddd + (eee xor aaa xor bbb) + X[ 3];
|
||||
ddd:= ((ddd shl 13) or (ddd shr (32-13))) + ccc;
|
||||
aaa:= ((aaa shl 10) or (aaa shr (32-10)));
|
||||
ccc:= ccc + (ddd xor eee xor aaa) + X[ 9];
|
||||
ccc:= ((ccc shl 11) or (ccc shr (32-11))) + bbb;
|
||||
eee:= ((eee shl 10) or (eee shr (32-10)));
|
||||
bbb:= bbb + (ccc xor ddd xor eee) + X[11];
|
||||
bbb:= ((bbb shl 11) or (bbb shr (32-11))) + aaa;
|
||||
ddd:= ((ddd shl 10) or (ddd shr (32-10)));
|
||||
|
||||
ddd:= ddd + cc + CurrentHash[1];
|
||||
CurrentHash[1]:= CurrentHash[2] + dd + eee;
|
||||
CurrentHash[2]:= CurrentHash[3] + ee + aaa;
|
||||
CurrentHash[3]:= CurrentHash[4] + aa + bbb;
|
||||
CurrentHash[4]:= CurrentHash[0] + bb + ccc;
|
||||
CurrentHash[0]:= ddd;
|
||||
FillChar(X,Sizeof(X),0);
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
class function TDCP_ripemd160.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 160;
|
||||
end;
|
||||
|
||||
class function TDCP_ripemd160.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_ripemd160;
|
||||
end;
|
||||
|
||||
class function TDCP_ripemd160.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'RipeMD-160';
|
||||
end;
|
||||
|
||||
class function TDCP_ripemd160.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..19] of byte=
|
||||
($0B,$DC,$9D,$2D,$25,$6B,$3E,$E9,$DA,$AE,$34,$7B,$E6,$F4,$DC,$83,$5A,$46,$7F,$FE);
|
||||
Test2Out: array[0..19] of byte=
|
||||
($F7,$1C,$27,$10,$9C,$69,$2C,$1B,$56,$BB,$DC,$EB,$5B,$9D,$28,$65,$B3,$70,$8D,$BC);
|
||||
var
|
||||
TestHash: TDCP_ripemd160;
|
||||
TestOut: array[0..19] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_ripemd160.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('a');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_ripemd160.Init;
|
||||
begin
|
||||
Burn;
|
||||
CurrentHash[0]:= $67452301;
|
||||
CurrentHash[1]:= $efcdab89;
|
||||
CurrentHash[2]:= $98badcfe;
|
||||
CurrentHash[3]:= $10325476;
|
||||
CurrentHash[4]:= $c3d2e1f0;
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_ripemd160.Burn;
|
||||
begin
|
||||
LenHi:= 0; LenLo:= 0;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
FillChar(CurrentHash,Sizeof(CurrentHash),0);
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_ripemd160.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_ripemd160.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $80;
|
||||
if Index>= 56 then
|
||||
Compress;
|
||||
PDWord(@HashBuffer[56])^:= LenLo;
|
||||
PDWord(@HashBuffer[60])^:= LenHi;
|
||||
Compress;
|
||||
Move(CurrentHash,Digest,Sizeof(CurrentHash));
|
||||
Burn;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
278
Units/Misc/dcpsha1.pas
Normal file
278
Units/Misc/dcpsha1.pas
Normal file
@ -0,0 +1,278 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A binary compatible implementation of SHA1 *********************************}
|
||||
{******************************************************************************}
|
||||
{* 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 DCPsha1;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPcrypt2, DCPconst;
|
||||
|
||||
type
|
||||
TDCP_sha1= 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 Final(var Digest); override;
|
||||
procedure Burn; override;
|
||||
procedure Update(const Buffer; Size: longword); override;
|
||||
end;
|
||||
|
||||
{******************************************************************************}
|
||||
{******************************************************************************}
|
||||
implementation
|
||||
{$R-}{$Q-}
|
||||
|
||||
function SwapDWord(a: dword): dword;
|
||||
begin
|
||||
Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24);
|
||||
end;
|
||||
|
||||
procedure TDCP_sha1.Compress;
|
||||
var
|
||||
A, B, C, D, E: DWord;
|
||||
W: array[0..79] of DWord;
|
||||
i: longword;
|
||||
begin
|
||||
Index:= 0;
|
||||
dcpFillChar(W, SizeOf(W), 0);
|
||||
Move(HashBuffer,W,Sizeof(HashBuffer));
|
||||
for i:= 0 to 15 do
|
||||
W[i]:= SwapDWord(W[i]);
|
||||
for i:= 16 to 79 do
|
||||
W[i]:= ((W[i-3] xor W[i-8] xor W[i-14] xor W[i-16]) shl 1) or ((W[i-3] xor W[i-8] xor W[i-14] xor W[i-16]) shr 31);
|
||||
A:= CurrentHash[0]; B:= CurrentHash[1]; C:= CurrentHash[2]; D:= CurrentHash[3]; E:= CurrentHash[4];
|
||||
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[ 0]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[ 1]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[ 2]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[ 3]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[ 4]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[ 5]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[ 6]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[ 7]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[ 8]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[ 9]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[10]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[11]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[12]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[13]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[14]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (D xor (B and (C xor D))) + $5A827999 + W[15]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (C xor (A and (B xor C))) + $5A827999 + W[16]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (B xor (E and (A xor B))) + $5A827999 + W[17]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (A xor (D and (E xor A))) + $5A827999 + W[18]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (E xor (C and (D xor E))) + $5A827999 + W[19]); C:= (C shl 30) or (C shr 2);
|
||||
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[20]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[21]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[22]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[23]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[24]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[25]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[26]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[27]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[28]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[29]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[30]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[31]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[32]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[33]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[34]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $6ED9EBA1 + W[35]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $6ED9EBA1 + W[36]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $6ED9EBA1 + W[37]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $6ED9EBA1 + W[38]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $6ED9EBA1 + W[39]); C:= (C shl 30) or (C shr 2);
|
||||
|
||||
Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[40]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[41]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[42]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[43]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[44]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[45]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[46]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[47]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[48]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[49]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[50]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[51]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[52]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[53]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[54]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + ((B and C) or (D and (B or C))) + $8F1BBCDC + W[55]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + ((A and B) or (C and (A or B))) + $8F1BBCDC + W[56]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + ((E and A) or (B and (E or A))) + $8F1BBCDC + W[57]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + ((D and E) or (A and (D or E))) + $8F1BBCDC + W[58]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + ((C and D) or (E and (C or D))) + $8F1BBCDC + W[59]); C:= (C shl 30) or (C shr 2);
|
||||
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[60]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[61]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[62]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[63]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[64]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[65]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[66]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[67]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[68]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[69]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[70]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[71]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[72]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[73]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[74]); C:= (C shl 30) or (C shr 2);
|
||||
Inc(E,((A shl 5) or (A shr 27)) + (B xor C xor D) + $CA62C1D6 + W[75]); B:= (B shl 30) or (B shr 2);
|
||||
Inc(D,((E shl 5) or (E shr 27)) + (A xor B xor C) + $CA62C1D6 + W[76]); A:= (A shl 30) or (A shr 2);
|
||||
Inc(C,((D shl 5) or (D shr 27)) + (E xor A xor B) + $CA62C1D6 + W[77]); E:= (E shl 30) or (E shr 2);
|
||||
Inc(B,((C shl 5) or (C shr 27)) + (D xor E xor A) + $CA62C1D6 + W[78]); D:= (D shl 30) or (D shr 2);
|
||||
Inc(A,((B shl 5) or (B shr 27)) + (C xor D xor E) + $CA62C1D6 + W[79]); C:= (C shl 30) or (C shr 2);
|
||||
|
||||
CurrentHash[0]:= CurrentHash[0] + A;
|
||||
CurrentHash[1]:= CurrentHash[1] + B;
|
||||
CurrentHash[2]:= CurrentHash[2] + C;
|
||||
CurrentHash[3]:= CurrentHash[3] + D;
|
||||
CurrentHash[4]:= CurrentHash[4] + E;
|
||||
FillChar(W,Sizeof(W),0);
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
class function TDCP_sha1.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'SHA1';
|
||||
end;
|
||||
|
||||
class function TDCP_sha1.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_sha1;
|
||||
end;
|
||||
|
||||
class function TDCP_sha1.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 160;
|
||||
end;
|
||||
|
||||
class function TDCP_sha1.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..19] of byte=
|
||||
($A9,$99,$3E,$36,$47,$06,$81,$6A,$BA,$3E,$25,$71,$78,$50,$C2,$6C,$9C,$D0,$D8,$9D);
|
||||
Test2Out: array[0..19] of byte=
|
||||
($84,$98,$3E,$44,$1C,$3B,$D2,$6E,$BA,$AE,$4A,$A1,$F9,$51,$29,$E5,$E5,$46,$70,$F1);
|
||||
var
|
||||
TestHash: TDCP_sha1;
|
||||
TestOut: array[0..19] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_sha1.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abc');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha1.Init;
|
||||
begin
|
||||
Burn;
|
||||
CurrentHash[0]:= $67452301;
|
||||
CurrentHash[1]:= $EFCDAB89;
|
||||
CurrentHash[2]:= $98BADCFE;
|
||||
CurrentHash[3]:= $10325476;
|
||||
CurrentHash[4]:= $C3D2E1F0;
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha1.Burn;
|
||||
begin
|
||||
LenHi:= 0; LenLo:= 0;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
FillChar(CurrentHash,Sizeof(CurrentHash),0);
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha1.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_sha1.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $80;
|
||||
if Index>= 56 then
|
||||
Compress;
|
||||
PDWord(@HashBuffer[56])^:= SwapDWord(LenHi);
|
||||
PDWord(@HashBuffer[60])^:= SwapDWord(LenLo);
|
||||
Compress;
|
||||
CurrentHash[0]:= SwapDWord(CurrentHash[0]);
|
||||
CurrentHash[1]:= SwapDWord(CurrentHash[1]);
|
||||
CurrentHash[2]:= SwapDWord(CurrentHash[2]);
|
||||
CurrentHash[3]:= SwapDWord(CurrentHash[3]);
|
||||
CurrentHash[4]:= SwapDWord(CurrentHash[4]);
|
||||
Move(CurrentHash,Digest,Sizeof(CurrentHash));
|
||||
Burn;
|
||||
end;
|
||||
|
||||
end.
|
284
Units/Misc/dcpsha256.pas
Normal file
284
Units/Misc/dcpsha256.pas
Normal file
@ -0,0 +1,284 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A binary compatible implementation of SHA256 *******************************}
|
||||
{******************************************************************************}
|
||||
{* 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 DCPsha256;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPcrypt2, DCPconst;
|
||||
|
||||
type
|
||||
TDCP_sha256= class(TDCP_hash)
|
||||
protected
|
||||
LenHi, LenLo: longword;
|
||||
Index: DWord;
|
||||
CurrentHash: array[0..7] 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 Final(var Digest); override;
|
||||
procedure Burn; override;
|
||||
procedure Update(const Buffer; Size: longword); override;
|
||||
end;
|
||||
|
||||
{******************************************************************************}
|
||||
{******************************************************************************}
|
||||
implementation
|
||||
{$R-}{$Q-}
|
||||
|
||||
function SwapDWord(a: dword): dword;
|
||||
begin
|
||||
Result:= ((a and $FF) shl 24) or ((a and $FF00) shl 8) or ((a and $FF0000) shr 8) or ((a and $FF000000) shr 24);
|
||||
end;
|
||||
|
||||
procedure TDCP_sha256.Compress;
|
||||
var
|
||||
a, b, c, d, e, f, g, h, t1, t2: DWord;
|
||||
W: array[0..63] of DWord;
|
||||
i: longword;
|
||||
begin
|
||||
Index:= 0;
|
||||
dcpFillChar(W, SizeOf(W), 0);
|
||||
a:= CurrentHash[0]; b:= CurrentHash[1]; c:= CurrentHash[2]; d:= CurrentHash[3];
|
||||
e:= CurrentHash[4]; f:= CurrentHash[5]; g:= CurrentHash[6]; h:= CurrentHash[7];
|
||||
Move(HashBuffer,W,Sizeof(HashBuffer));
|
||||
for i:= 0 to 15 do
|
||||
W[i]:= SwapDWord(W[i]);
|
||||
for i:= 16 to 63 do
|
||||
W[i]:= (((W[i-2] shr 17) or (W[i-2] shl 15)) xor ((W[i-2] shr 19) or (W[i-2] shl 13)) xor
|
||||
(W[i-2] shr 10)) + W[i-7] + (((W[i-15] shr 7) or (W[i-15] shl 25)) xor
|
||||
((W[i-15] shr 18) or (W[i-15] shl 14)) xor (W[i-15] shr 3)) + W[i-16];
|
||||
{
|
||||
Non-optimised version
|
||||
for i:= 0 to 63 do
|
||||
begin
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) +
|
||||
((e and f) xor (not e and g)) + K[i] + W[i];
|
||||
t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) +
|
||||
((a and b) xor (a and c) xor (b and c));
|
||||
h:= g; g:= f; f:= e; e:= d + t1; d:= c; c:= b; b:= a; a:= t1 + t2;
|
||||
end;
|
||||
}
|
||||
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $428a2f98 + W[0]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
|
||||
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $71374491 + W[1]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
|
||||
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $b5c0fbcf + W[2]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
|
||||
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $e9b5dba5 + W[3]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
|
||||
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $3956c25b + W[4]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
|
||||
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $59f111f1 + W[5]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
|
||||
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $923f82a4 + W[6]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
|
||||
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $ab1c5ed5 + W[7]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $d807aa98 + W[8]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
|
||||
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $12835b01 + W[9]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
|
||||
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $243185be + W[10]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
|
||||
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $550c7dc3 + W[11]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
|
||||
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $72be5d74 + W[12]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
|
||||
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $80deb1fe + W[13]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
|
||||
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $9bdc06a7 + W[14]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
|
||||
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $c19bf174 + W[15]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $e49b69c1 + W[16]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
|
||||
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $efbe4786 + W[17]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
|
||||
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $0fc19dc6 + W[18]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
|
||||
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $240ca1cc + W[19]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
|
||||
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $2de92c6f + W[20]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
|
||||
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $4a7484aa + W[21]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
|
||||
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $5cb0a9dc + W[22]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
|
||||
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $76f988da + W[23]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $983e5152 + W[24]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
|
||||
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $a831c66d + W[25]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
|
||||
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $b00327c8 + W[26]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
|
||||
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $bf597fc7 + W[27]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
|
||||
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $c6e00bf3 + W[28]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
|
||||
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $d5a79147 + W[29]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
|
||||
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $06ca6351 + W[30]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
|
||||
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $14292967 + W[31]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $27b70a85 + W[32]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
|
||||
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $2e1b2138 + W[33]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
|
||||
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $4d2c6dfc + W[34]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
|
||||
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $53380d13 + W[35]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
|
||||
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $650a7354 + W[36]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
|
||||
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $766a0abb + W[37]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
|
||||
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $81c2c92e + W[38]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
|
||||
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $92722c85 + W[39]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $a2bfe8a1 + W[40]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
|
||||
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $a81a664b + W[41]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
|
||||
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $c24b8b70 + W[42]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
|
||||
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $c76c51a3 + W[43]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
|
||||
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $d192e819 + W[44]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
|
||||
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $d6990624 + W[45]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
|
||||
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $f40e3585 + W[46]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
|
||||
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $106aa070 + W[47]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $19a4c116 + W[48]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
|
||||
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $1e376c08 + W[49]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
|
||||
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $2748774c + W[50]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
|
||||
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $34b0bcb5 + W[51]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
|
||||
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $391c0cb3 + W[52]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
|
||||
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $4ed8aa4a + W[53]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
|
||||
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $5b9cca4f + W[54]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
|
||||
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $682e6ff3 + W[55]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
|
||||
t1:= h + (((e shr 6) or (e shl 26)) xor ((e shr 11) or (e shl 21)) xor ((e shr 25) or (e shl 7))) + ((e and f) xor (not e and g)) + $748f82ee + W[56]; t2:= (((a shr 2) or (a shl 30)) xor ((a shr 13) or (a shl 19)) xor ((a shr 22) xor (a shl 10))) + ((a and b) xor (a and c) xor (b and c)); h:= t1 + t2; d:= d + t1;
|
||||
t1:= g + (((d shr 6) or (d shl 26)) xor ((d shr 11) or (d shl 21)) xor ((d shr 25) or (d shl 7))) + ((d and e) xor (not d and f)) + $78a5636f + W[57]; t2:= (((h shr 2) or (h shl 30)) xor ((h shr 13) or (h shl 19)) xor ((h shr 22) xor (h shl 10))) + ((h and a) xor (h and b) xor (a and b)); g:= t1 + t2; c:= c + t1;
|
||||
t1:= f + (((c shr 6) or (c shl 26)) xor ((c shr 11) or (c shl 21)) xor ((c shr 25) or (c shl 7))) + ((c and d) xor (not c and e)) + $84c87814 + W[58]; t2:= (((g shr 2) or (g shl 30)) xor ((g shr 13) or (g shl 19)) xor ((g shr 22) xor (g shl 10))) + ((g and h) xor (g and a) xor (h and a)); f:= t1 + t2; b:= b + t1;
|
||||
t1:= e + (((b shr 6) or (b shl 26)) xor ((b shr 11) or (b shl 21)) xor ((b shr 25) or (b shl 7))) + ((b and c) xor (not b and d)) + $8cc70208 + W[59]; t2:= (((f shr 2) or (f shl 30)) xor ((f shr 13) or (f shl 19)) xor ((f shr 22) xor (f shl 10))) + ((f and g) xor (f and h) xor (g and h)); e:= t1 + t2; a:= a + t1;
|
||||
t1:= d + (((a shr 6) or (a shl 26)) xor ((a shr 11) or (a shl 21)) xor ((a shr 25) or (a shl 7))) + ((a and b) xor (not a and c)) + $90befffa + W[60]; t2:= (((e shr 2) or (e shl 30)) xor ((e shr 13) or (e shl 19)) xor ((e shr 22) xor (e shl 10))) + ((e and f) xor (e and g) xor (f and g)); d:= t1 + t2; h:= h + t1;
|
||||
t1:= c + (((h shr 6) or (h shl 26)) xor ((h shr 11) or (h shl 21)) xor ((h shr 25) or (h shl 7))) + ((h and a) xor (not h and b)) + $a4506ceb + W[61]; t2:= (((d shr 2) or (d shl 30)) xor ((d shr 13) or (d shl 19)) xor ((d shr 22) xor (d shl 10))) + ((d and e) xor (d and f) xor (e and f)); c:= t1 + t2; g:= g + t1;
|
||||
t1:= b + (((g shr 6) or (g shl 26)) xor ((g shr 11) or (g shl 21)) xor ((g shr 25) or (g shl 7))) + ((g and h) xor (not g and a)) + $bef9a3f7 + W[62]; t2:= (((c shr 2) or (c shl 30)) xor ((c shr 13) or (c shl 19)) xor ((c shr 22) xor (c shl 10))) + ((c and d) xor (c and e) xor (d and e)); b:= t1 + t2; f:= f + t1;
|
||||
t1:= a + (((f shr 6) or (f shl 26)) xor ((f shr 11) or (f shl 21)) xor ((f shr 25) or (f shl 7))) + ((f and g) xor (not f and h)) + $c67178f2 + W[63]; t2:= (((b shr 2) or (b shl 30)) xor ((b shr 13) or (b shl 19)) xor ((b shr 22) xor (b shl 10))) + ((b and c) xor (b and d) xor (c and d)); a:= t1 + t2; e:= e + t1;
|
||||
|
||||
CurrentHash[0]:= CurrentHash[0] + a;
|
||||
CurrentHash[1]:= CurrentHash[1] + b;
|
||||
CurrentHash[2]:= CurrentHash[2] + c;
|
||||
CurrentHash[3]:= CurrentHash[3] + d;
|
||||
CurrentHash[4]:= CurrentHash[4] + e;
|
||||
CurrentHash[5]:= CurrentHash[5] + f;
|
||||
CurrentHash[6]:= CurrentHash[6] + g;
|
||||
CurrentHash[7]:= CurrentHash[7] + h;
|
||||
FillChar(W,Sizeof(W),0);
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
class function TDCP_sha256.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'SHA256';
|
||||
end;
|
||||
|
||||
class function TDCP_sha256.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_sha256;
|
||||
end;
|
||||
|
||||
class function TDCP_sha256.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 256;
|
||||
end;
|
||||
|
||||
class function TDCP_sha256.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..31] of byte=
|
||||
($ba,$78,$16,$bf,$8f,$01,$cf,$ea,$41,$41,$40,$de,$5d,$ae,$22,$23,
|
||||
$b0,$03,$61,$a3,$96,$17,$7a,$9c,$b4,$10,$ff,$61,$f2,$00,$15,$ad);
|
||||
Test2Out: array[0..31] of byte=
|
||||
($24,$8d,$6a,$61,$d2,$06,$38,$b8,$e5,$c0,$26,$93,$0c,$3e,$60,$39,
|
||||
$a3,$3c,$e4,$59,$64,$ff,$21,$67,$f6,$ec,$ed,$d4,$19,$db,$06,$c1);
|
||||
var
|
||||
TestHash: TDCP_sha256;
|
||||
TestOut: array[0..31] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_sha256.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abc');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha256.Init;
|
||||
begin
|
||||
Burn;
|
||||
CurrentHash[0]:= $6a09e667;
|
||||
CurrentHash[1]:= $bb67ae85;
|
||||
CurrentHash[2]:= $3c6ef372;
|
||||
CurrentHash[3]:= $a54ff53a;
|
||||
CurrentHash[4]:= $510e527f;
|
||||
CurrentHash[5]:= $9b05688c;
|
||||
CurrentHash[6]:= $1f83d9ab;
|
||||
CurrentHash[7]:= $5be0cd19;
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha256.Burn;
|
||||
begin
|
||||
LenHi:= 0; LenLo:= 0;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
FillChar(CurrentHash,Sizeof(CurrentHash),0);
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha256.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_sha256.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $80;
|
||||
if Index>= 56 then
|
||||
Compress;
|
||||
PDWord(@HashBuffer[56])^:= SwapDWord(LenHi);
|
||||
PDWord(@HashBuffer[60])^:= SwapDWord(LenLo);
|
||||
Compress;
|
||||
CurrentHash[0]:= SwapDWord(CurrentHash[0]);
|
||||
CurrentHash[1]:= SwapDWord(CurrentHash[1]);
|
||||
CurrentHash[2]:= SwapDWord(CurrentHash[2]);
|
||||
CurrentHash[3]:= SwapDWord(CurrentHash[3]);
|
||||
CurrentHash[4]:= SwapDWord(CurrentHash[4]);
|
||||
CurrentHash[5]:= SwapDWord(CurrentHash[5]);
|
||||
CurrentHash[6]:= SwapDWord(CurrentHash[6]);
|
||||
CurrentHash[7]:= SwapDWord(CurrentHash[7]);
|
||||
Move(CurrentHash,Digest,Sizeof(CurrentHash));
|
||||
Burn;
|
||||
end;
|
||||
|
||||
end.
|
397
Units/Misc/dcpsha512.pas
Normal file
397
Units/Misc/dcpsha512.pas
Normal file
@ -0,0 +1,397 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A binary compatible implementation of SHA512 *******************************}
|
||||
{******************************************************************************}
|
||||
{* 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 DCPsha512;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPcrypt2, DCPconst;
|
||||
|
||||
type
|
||||
TDCP_sha512base= class(TDCP_hash)
|
||||
protected
|
||||
LenHi, LenLo: int64;
|
||||
Index: DWord;
|
||||
CurrentHash: array[0..7] of int64;
|
||||
HashBuffer: array[0..127] of byte;
|
||||
procedure Compress;
|
||||
public
|
||||
procedure Update(const Buffer; Size: longword); override;
|
||||
procedure Burn; override;
|
||||
end;
|
||||
|
||||
TDCP_sha384= class(TDCP_sha512base)
|
||||
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 Final(var Digest); override;
|
||||
end;
|
||||
|
||||
TDCP_sha512= class(TDCP_sha512base)
|
||||
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 Final(var Digest); override;
|
||||
end;
|
||||
|
||||
{******************************************************************************}
|
||||
{******************************************************************************}
|
||||
implementation
|
||||
{$R-}{$Q-}
|
||||
|
||||
function SwapDWord(a: int64): int64;
|
||||
begin
|
||||
Result:= ((a and $FF) shl 56) or ((a and $FF00) shl 40) or ((a and $FF0000) shl 24) or ((a and $FF000000) shl 8) or
|
||||
((a and $FF00000000) shr 8) or ((a and $FF0000000000) shr 24) or ((a and $FF000000000000) shr 40) or ((a and $FF00000000000000) shr 56);
|
||||
end;
|
||||
|
||||
procedure TDCP_sha512base.Compress;
|
||||
var
|
||||
a, b, c, d, e, f, g, h, t1, t2: int64;
|
||||
W: array[0..79] of int64;
|
||||
i: longword;
|
||||
begin
|
||||
Index:= 0;
|
||||
dcpFillChar(W, SizeOf(W), 0);
|
||||
a:= CurrentHash[0]; b:= CurrentHash[1]; c:= CurrentHash[2]; d:= CurrentHash[3];
|
||||
e:= CurrentHash[4]; f:= CurrentHash[5]; g:= CurrentHash[6]; h:= CurrentHash[7];
|
||||
Move(HashBuffer,W,Sizeof(HashBuffer));
|
||||
for i:= 0 to 15 do
|
||||
W[i]:= SwapDWord(W[i]);
|
||||
for i:= 16 to 79 do
|
||||
W[i]:= (((W[i-2] shr 19) or (W[i-2] shl 45)) xor ((W[i-2] shr 61) or (W[i-2] shl 3)) xor
|
||||
(W[i-2] shr 6)) + W[i-7] + (((W[i-15] shr 1) or (W[i-15] shl 63)) xor ((W[i-15] shr 8) or
|
||||
(W[i-15] shl 56)) xor (W[i-15] shr 7)) + W[i-16];
|
||||
|
||||
{
|
||||
Non-optimised version
|
||||
for i:= 0 to 79 do
|
||||
begin
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) +
|
||||
((e and f) xor (not e and g)) + K[i] + W[i];
|
||||
t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) +
|
||||
((a and b) xor (a and c) xor (b and c));
|
||||
h:= g; g:= f; f:= e; e:= d + t1; d:= c; c:= b; b:= a; a:= t1 + t2;
|
||||
end;
|
||||
}
|
||||
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $428a2f98d728ae22 + W[0]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $7137449123ef65cd + W[1]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $b5c0fbcfec4d3b2f + W[2]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $e9b5dba58189dbbc + W[3]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $3956c25bf348b538 + W[4]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $59f111f1b605d019 + W[5]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $923f82a4af194f9b + W[6]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $ab1c5ed5da6d8118 + W[7]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $d807aa98a3030242 + W[8]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $12835b0145706fbe + W[9]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $243185be4ee4b28c + W[10]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $550c7dc3d5ffb4e2 + W[11]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $72be5d74f27b896f + W[12]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $80deb1fe3b1696b1 + W[13]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $9bdc06a725c71235 + W[14]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $c19bf174cf692694 + W[15]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $e49b69c19ef14ad2 + W[16]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $efbe4786384f25e3 + W[17]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $0fc19dc68b8cd5b5 + W[18]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $240ca1cc77ac9c65 + W[19]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $2de92c6f592b0275 + W[20]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $4a7484aa6ea6e483 + W[21]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5cb0a9dcbd41fbd4 + W[22]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $76f988da831153b5 + W[23]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $983e5152ee66dfab + W[24]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $a831c66d2db43210 + W[25]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $b00327c898fb213f + W[26]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $bf597fc7beef0ee4 + W[27]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $c6e00bf33da88fc2 + W[28]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $d5a79147930aa725 + W[29]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $06ca6351e003826f + W[30]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $142929670a0e6e70 + W[31]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $27b70a8546d22ffc + W[32]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $2e1b21385c26c926 + W[33]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $4d2c6dfc5ac42aed + W[34]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $53380d139d95b3df + W[35]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $650a73548baf63de + W[36]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $766a0abb3c77b2a8 + W[37]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $81c2c92e47edaee6 + W[38]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $92722c851482353b + W[39]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $a2bfe8a14cf10364 + W[40]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $a81a664bbc423001 + W[41]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $c24b8b70d0f89791 + W[42]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $c76c51a30654be30 + W[43]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $d192e819d6ef5218 + W[44]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $d69906245565a910 + W[45]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $f40e35855771202a + W[46]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $106aa07032bbd1b8 + W[47]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $19a4c116b8d2d0c8 + W[48]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $1e376c085141ab53 + W[49]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $2748774cdf8eeb99 + W[50]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $34b0bcb5e19b48a8 + W[51]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $391c0cb3c5c95a63 + W[52]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $4ed8aa4ae3418acb + W[53]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5b9cca4f7763e373 + W[54]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $682e6ff3d6b2b8a3 + W[55]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $748f82ee5defb2fc + W[56]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $78a5636f43172f60 + W[57]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $84c87814a1f0ab72 + W[58]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $8cc702081a6439ec + W[59]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $90befffa23631e28 + W[60]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $a4506cebde82bde9 + W[61]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $bef9a3f7b2c67915 + W[62]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $c67178f2e372532b + W[63]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $ca273eceea26619c + W[64]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $d186b8c721c0c207 + W[65]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $eada7dd6cde0eb1e + W[66]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $f57d4f7fee6ed178 + W[67]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $06f067aa72176fba + W[68]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $0a637dc5a2c898a6 + W[69]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $113f9804bef90dae + W[70]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $1b710b35131c471b + W[71]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
t1:= h + (((e shr 14) or (e shl 50)) xor ((e shr 18) or (e shl 46)) xor ((e shr 41) or (e shl 23))) + ((e and f) xor (not e and g)) + $28db77f523047d84 + W[72]; t2:= (((a shr 28) or (a shl 36)) xor ((a shr 34) or (a shl 30)) xor ((a shr 39) or (a shl 25))) + ((a and b) xor (a and c) xor (b and c)); d:= d + t1; h:= t1 + t2;
|
||||
t1:= g + (((d shr 14) or (d shl 50)) xor ((d shr 18) or (d shl 46)) xor ((d shr 41) or (d shl 23))) + ((d and e) xor (not d and f)) + $32caab7b40c72493 + W[73]; t2:= (((h shr 28) or (h shl 36)) xor ((h shr 34) or (h shl 30)) xor ((h shr 39) or (h shl 25))) + ((h and a) xor (h and b) xor (a and b)); c:= c + t1; g:= t1 + t2;
|
||||
t1:= f + (((c shr 14) or (c shl 50)) xor ((c shr 18) or (c shl 46)) xor ((c shr 41) or (c shl 23))) + ((c and d) xor (not c and e)) + $3c9ebe0a15c9bebc + W[74]; t2:= (((g shr 28) or (g shl 36)) xor ((g shr 34) or (g shl 30)) xor ((g shr 39) or (g shl 25))) + ((g and h) xor (g and a) xor (h and a)); b:= b + t1; f:= t1 + t2;
|
||||
t1:= e + (((b shr 14) or (b shl 50)) xor ((b shr 18) or (b shl 46)) xor ((b shr 41) or (b shl 23))) + ((b and c) xor (not b and d)) + $431d67c49c100d4c + W[75]; t2:= (((f shr 28) or (f shl 36)) xor ((f shr 34) or (f shl 30)) xor ((f shr 39) or (f shl 25))) + ((f and g) xor (f and h) xor (g and h)); a:= a + t1; e:= t1 + t2;
|
||||
t1:= d + (((a shr 14) or (a shl 50)) xor ((a shr 18) or (a shl 46)) xor ((a shr 41) or (a shl 23))) + ((a and b) xor (not a and c)) + $4cc5d4becb3e42b6 + W[76]; t2:= (((e shr 28) or (e shl 36)) xor ((e shr 34) or (e shl 30)) xor ((e shr 39) or (e shl 25))) + ((e and f) xor (e and g) xor (f and g)); h:= h + t1; d:= t1 + t2;
|
||||
t1:= c + (((h shr 14) or (h shl 50)) xor ((h shr 18) or (h shl 46)) xor ((h shr 41) or (h shl 23))) + ((h and a) xor (not h and b)) + $597f299cfc657e2a + W[77]; t2:= (((d shr 28) or (d shl 36)) xor ((d shr 34) or (d shl 30)) xor ((d shr 39) or (d shl 25))) + ((d and e) xor (d and f) xor (e and f)); g:= g + t1; c:= t1 + t2;
|
||||
t1:= b + (((g shr 14) or (g shl 50)) xor ((g shr 18) or (g shl 46)) xor ((g shr 41) or (g shl 23))) + ((g and h) xor (not g and a)) + $5fcb6fab3ad6faec + W[78]; t2:= (((c shr 28) or (c shl 36)) xor ((c shr 34) or (c shl 30)) xor ((c shr 39) or (c shl 25))) + ((c and d) xor (c and e) xor (d and e)); f:= f + t1; b:= t1 + t2;
|
||||
t1:= a + (((f shr 14) or (f shl 50)) xor ((f shr 18) or (f shl 46)) xor ((f shr 41) or (f shl 23))) + ((f and g) xor (not f and h)) + $6c44198c4a475817 + W[79]; t2:= (((b shr 28) or (b shl 36)) xor ((b shr 34) or (b shl 30)) xor ((b shr 39) or (b shl 25))) + ((b and c) xor (b and d) xor (c and d)); e:= e + t1; a:= t1 + t2;
|
||||
|
||||
CurrentHash[0]:= CurrentHash[0] + a;
|
||||
CurrentHash[1]:= CurrentHash[1] + b;
|
||||
CurrentHash[2]:= CurrentHash[2] + c;
|
||||
CurrentHash[3]:= CurrentHash[3] + d;
|
||||
CurrentHash[4]:= CurrentHash[4] + e;
|
||||
CurrentHash[5]:= CurrentHash[5] + f;
|
||||
CurrentHash[6]:= CurrentHash[6] + g;
|
||||
CurrentHash[7]:= CurrentHash[7] + h;
|
||||
FillChar(W,Sizeof(W),0);
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
procedure TDCP_sha512base.Burn;
|
||||
begin
|
||||
LenHi:= 0; LenLo:= 0;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
FillChar(CurrentHash,Sizeof(CurrentHash),0);
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha512base.Update(const Buffer; Size: longword);
|
||||
var
|
||||
PBuf: ^byte;
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
|
||||
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;
|
||||
|
||||
{******************************************************************************}
|
||||
class function TDCP_sha384.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'SHA384';
|
||||
end;
|
||||
|
||||
class function TDCP_sha384.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_sha384;
|
||||
end;
|
||||
|
||||
class function TDCP_sha384.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 384;
|
||||
end;
|
||||
|
||||
class function TDCP_sha384.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..47] of byte=
|
||||
($cb,$00,$75,$3f,$45,$a3,$5e,$8b,$b5,$a0,$3d,$69,$9a,$c6,$50,$07,
|
||||
$27,$2c,$32,$ab,$0e,$de,$d1,$63,$1a,$8b,$60,$5a,$43,$ff,$5b,$ed,
|
||||
$80,$86,$07,$2b,$a1,$e7,$cc,$23,$58,$ba,$ec,$a1,$34,$c8,$25,$a7);
|
||||
Test2Out: array[0..47] of byte=
|
||||
($09,$33,$0c,$33,$f7,$11,$47,$e8,$3d,$19,$2f,$c7,$82,$cd,$1b,$47,
|
||||
$53,$11,$1b,$17,$3b,$3b,$05,$d2,$2f,$a0,$80,$86,$e3,$b0,$f7,$12,
|
||||
$fc,$c7,$c7,$1a,$55,$7e,$2d,$b9,$66,$c3,$e9,$fa,$91,$74,$60,$39);
|
||||
var
|
||||
TestHash: TDCP_sha384;
|
||||
TestOut: array[0..47] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_sha384.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abc');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha384.Init;
|
||||
begin
|
||||
Burn;
|
||||
CurrentHash[0]:= $cbbb9d5dc1059ed8;
|
||||
CurrentHash[1]:= $629a292a367cd507;
|
||||
CurrentHash[2]:= $9159015a3070dd17;
|
||||
CurrentHash[3]:= $152fecd8f70e5939;
|
||||
CurrentHash[4]:= $67332667ffc00b31;
|
||||
CurrentHash[5]:= $8eb44a8768581511;
|
||||
CurrentHash[6]:= $db0c2e0d64f98fa7;
|
||||
CurrentHash[7]:= $47b5481dbefa4fa4;
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha384.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $80;
|
||||
if Index>= 112 then
|
||||
Compress;
|
||||
Pint64(@HashBuffer[112])^:= SwapDWord(LenHi);
|
||||
Pint64(@HashBuffer[120])^:= SwapDWord(LenLo);
|
||||
Compress;
|
||||
CurrentHash[0]:= SwapDWord(CurrentHash[0]);
|
||||
CurrentHash[1]:= SwapDWord(CurrentHash[1]);
|
||||
CurrentHash[2]:= SwapDWord(CurrentHash[2]);
|
||||
CurrentHash[3]:= SwapDWord(CurrentHash[3]);
|
||||
CurrentHash[4]:= SwapDWord(CurrentHash[4]);
|
||||
CurrentHash[5]:= SwapDWord(CurrentHash[5]);
|
||||
Move(CurrentHash,Digest,384 div 8);
|
||||
Burn;
|
||||
end;
|
||||
|
||||
{******************************************************************************}
|
||||
class function TDCP_sha512.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'SHA512';
|
||||
end;
|
||||
|
||||
class function TDCP_sha512.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_sha512;
|
||||
end;
|
||||
|
||||
class function TDCP_sha512.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 512;
|
||||
end;
|
||||
|
||||
class function TDCP_sha512.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..63] of byte=
|
||||
($dd,$af,$35,$a1,$93,$61,$7a,$ba,$cc,$41,$73,$49,$ae,$20,$41,$31,
|
||||
$12,$e6,$fa,$4e,$89,$a9,$7e,$a2,$0a,$9e,$ee,$e6,$4b,$55,$d3,$9a,
|
||||
$21,$92,$99,$2a,$27,$4f,$c1,$a8,$36,$ba,$3c,$23,$a3,$fe,$eb,$bd,
|
||||
$45,$4d,$44,$23,$64,$3c,$e8,$0e,$2a,$9a,$c9,$4f,$a5,$4c,$a4,$9f);
|
||||
Test2Out: array[0..63] of byte=
|
||||
($8e,$95,$9b,$75,$da,$e3,$13,$da,$8c,$f4,$f7,$28,$14,$fc,$14,$3f,
|
||||
$8f,$77,$79,$c6,$eb,$9f,$7f,$a1,$72,$99,$ae,$ad,$b6,$88,$90,$18,
|
||||
$50,$1d,$28,$9e,$49,$00,$f7,$e4,$33,$1b,$99,$de,$c4,$b5,$43,$3a,
|
||||
$c7,$d3,$29,$ee,$b6,$dd,$26,$54,$5e,$96,$e5,$5b,$87,$4b,$e9,$09);
|
||||
var
|
||||
TestHash: TDCP_sha512;
|
||||
TestOut: array[0..63] of byte;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_sha512.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abc');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= boolean(CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out)));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= boolean(CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out))) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha512.Init;
|
||||
begin
|
||||
Burn;
|
||||
CurrentHash[0]:= $6a09e667f3bcc908;
|
||||
CurrentHash[1]:= $bb67ae8584caa73b;
|
||||
CurrentHash[2]:= $3c6ef372fe94f82b;
|
||||
CurrentHash[3]:= $a54ff53a5f1d36f1;
|
||||
CurrentHash[4]:= $510e527fade682d1;
|
||||
CurrentHash[5]:= $9b05688c2b3e6c1f;
|
||||
CurrentHash[6]:= $1f83d9abfb41bd6b;
|
||||
CurrentHash[7]:= $5be0cd19137e2179;
|
||||
fInitialized:= true;
|
||||
end;
|
||||
|
||||
procedure TDCP_sha512.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $80;
|
||||
if Index>= 112 then
|
||||
Compress;
|
||||
Pint64(@HashBuffer[112])^:= SwapDWord(LenHi);
|
||||
Pint64(@HashBuffer[120])^:= SwapDWord(LenLo);
|
||||
Compress;
|
||||
CurrentHash[0]:= SwapDWord(CurrentHash[0]);
|
||||
CurrentHash[1]:= SwapDWord(CurrentHash[1]);
|
||||
CurrentHash[2]:= SwapDWord(CurrentHash[2]);
|
||||
CurrentHash[3]:= SwapDWord(CurrentHash[3]);
|
||||
CurrentHash[4]:= SwapDWord(CurrentHash[4]);
|
||||
CurrentHash[5]:= SwapDWord(CurrentHash[5]);
|
||||
CurrentHash[6]:= SwapDWord(CurrentHash[6]);
|
||||
CurrentHash[7]:= SwapDWord(CurrentHash[7]);
|
||||
Move(CurrentHash,Digest,Sizeof(CurrentHash));
|
||||
Burn;
|
||||
end;
|
||||
|
||||
end.
|
304
Units/Misc/dcptiger.pas
Normal file
304
Units/Misc/dcptiger.pas
Normal file
@ -0,0 +1,304 @@
|
||||
{******************************************************************************}
|
||||
{* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
|
||||
{******************************************************************************}
|
||||
{* A binary compatible implementation of Tiger ********************************}
|
||||
{******************************************************************************}
|
||||
{* Copyright (c) 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 DCPtiger;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
interface
|
||||
uses
|
||||
Classes, Sysutils, DCPcrypt2, DCPconst;
|
||||
|
||||
type
|
||||
TDCP_tiger= class(TDCP_hash)
|
||||
protected
|
||||
Len: int64;
|
||||
Index: DWord;
|
||||
CurrentHash: array[0..2] of int64;
|
||||
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-}
|
||||
|
||||
{$INCLUDE DCPtiger.inc}
|
||||
|
||||
procedure TDCP_tiger.Compress;
|
||||
var
|
||||
a, b, c, aa, bb, cc: int64;
|
||||
x: array[0..7] of int64;
|
||||
begin
|
||||
dcpFillChar(x, SizeOf(x), 0);
|
||||
a:= CurrentHash[0]; aa:= a;
|
||||
b:= CurrentHash[1]; bb:= b;
|
||||
c:= CurrentHash[2]; cc:= c;
|
||||
|
||||
Move(HashBuffer,x,Sizeof(x));
|
||||
|
||||
c:= c xor x[0];
|
||||
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
|
||||
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
|
||||
b:= b * 5;
|
||||
a:= a xor x[1];
|
||||
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
|
||||
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
|
||||
c:= c * 5;
|
||||
b:= b xor x[2];
|
||||
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
|
||||
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
|
||||
a:= a * 5;
|
||||
c:= c xor x[3];
|
||||
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
|
||||
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
|
||||
b:= b * 5;
|
||||
a:= a xor x[4];
|
||||
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
|
||||
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
|
||||
c:= c * 5;
|
||||
b:= b xor x[5];
|
||||
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
|
||||
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
|
||||
a:= a * 5;
|
||||
c:= c xor x[6];
|
||||
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
|
||||
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
|
||||
b:= b * 5;
|
||||
a:= a xor x[7];
|
||||
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
|
||||
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
|
||||
c:= c * 5;
|
||||
x[0]:= x[0] - (x[7] xor $A5A5A5A5A5A5A5A5);
|
||||
x[1]:= x[1] xor x[0];
|
||||
x[2]:= x[2] + x[1];
|
||||
x[3]:= x[3] - (x[2] xor ((not x[1]) shl 19));
|
||||
x[4]:= x[4] xor x[3];
|
||||
x[5]:= x[5] + x[4];
|
||||
x[6]:= x[6] - (x[5] xor ((not x[4]) shr 23));
|
||||
x[7]:= x[7] xor x[6];
|
||||
x[0]:= x[0] + x[7];
|
||||
x[1]:= x[1] - (x[0] xor ((not x[7]) shl 19));
|
||||
x[2]:= x[2] xor x[1];
|
||||
x[3]:= x[3] + x[2];
|
||||
x[4]:= x[4] - (x[3] xor ((not x[2]) shr 23));
|
||||
x[5]:= x[5] xor x[4];
|
||||
x[6]:= x[6] + x[5];
|
||||
x[7]:= x[7] - (x[6] xor $0123456789ABCDEF);
|
||||
b:= b xor x[0];
|
||||
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
|
||||
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
|
||||
a:= a * 7;
|
||||
c:= c xor x[1];
|
||||
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
|
||||
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
|
||||
b:= b * 7;
|
||||
a:= a xor x[2];
|
||||
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
|
||||
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
|
||||
c:= c * 7;
|
||||
b:= b xor x[3];
|
||||
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
|
||||
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
|
||||
a:= a * 7;
|
||||
c:= c xor x[4];
|
||||
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
|
||||
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
|
||||
b:= b * 7;
|
||||
a:= a xor x[5];
|
||||
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
|
||||
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
|
||||
c:= c * 7;
|
||||
b:= b xor x[6];
|
||||
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
|
||||
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
|
||||
a:= a * 7;
|
||||
c:= c xor x[7];
|
||||
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
|
||||
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
|
||||
b:= b * 7;
|
||||
x[0]:= x[0] - (x[7] xor $A5A5A5A5A5A5A5A5);
|
||||
x[1]:= x[1] xor x[0];
|
||||
x[2]:= x[2] + x[1];
|
||||
x[3]:= x[3] - (x[2] xor ((not x[1]) shl 19));
|
||||
x[4]:= x[4] xor x[3];
|
||||
x[5]:= x[5] + x[4];
|
||||
x[6]:= x[6] - (x[5] xor ((not x[4]) shr 23));
|
||||
x[7]:= x[7] xor x[6];
|
||||
x[0]:= x[0] + x[7];
|
||||
x[1]:= x[1] - (x[0] xor ((not x[7]) shl 19));
|
||||
x[2]:= x[2] xor x[1];
|
||||
x[3]:= x[3] + x[2];
|
||||
x[4]:= x[4] - (x[3] xor ((not x[2]) shr 23));
|
||||
x[5]:= x[5] xor x[4];
|
||||
x[6]:= x[6] + x[5];
|
||||
x[7]:= x[7] - (x[6] xor $0123456789ABCDEF);
|
||||
a:= a xor x[0];
|
||||
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
|
||||
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
|
||||
c:= c * 9;
|
||||
b:= b xor x[1];
|
||||
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
|
||||
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
|
||||
a:= a * 9;
|
||||
c:= c xor x[2];
|
||||
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
|
||||
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
|
||||
b:= b * 9;
|
||||
a:= a xor x[3];
|
||||
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
|
||||
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
|
||||
c:= c * 9;
|
||||
b:= b xor x[4];
|
||||
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
|
||||
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
|
||||
a:= a * 9;
|
||||
c:= c xor x[5];
|
||||
a:= a - (t1[c and $FF] xor t2[(c shr 16) and $FF] xor t3[(c shr 32) and $FF] xor t4[(c shr 48) and $FF]);
|
||||
b:= b + (t4[(c shr 8) and $FF] xor t3[(c shr 24) and $FF] xor t2[(c shr 40) and $FF] xor t1[(c shr 56) and $FF]);
|
||||
b:= b * 9;
|
||||
a:= a xor x[6];
|
||||
b:= b - (t1[a and $FF] xor t2[(a shr 16) and $FF] xor t3[(a shr 32) and $FF] xor t4[(a shr 48) and $FF]);
|
||||
c:= c + (t4[(a shr 8) and $FF] xor t3[(a shr 24) and $FF] xor t2[(a shr 40) and $FF] xor t1[(a shr 56) and $FF]);
|
||||
c:= c * 9;
|
||||
b:= b xor x[7];
|
||||
c:= c - (t1[b and $FF] xor t2[(b shr 16) and $FF] xor t3[(b shr 32) and $FF] xor t4[(b shr 48) and $FF]);
|
||||
a:= a + (t4[(b shr 8) and $FF] xor t3[(b shr 24) and $FF] xor t2[(b shr 40) and $FF] xor t1[(b shr 56) and $FF]);
|
||||
a:= a * 9;
|
||||
|
||||
CurrentHash[0]:= a xor aa;
|
||||
CurrentHash[1]:= b - bb;
|
||||
CurrentHash[2]:= c + cc;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
end;
|
||||
|
||||
class function TDCP_tiger.GetHashSize: integer;
|
||||
begin
|
||||
Result:= 192;
|
||||
end;
|
||||
|
||||
class function TDCP_tiger.GetId: integer;
|
||||
begin
|
||||
Result:= DCP_tiger;
|
||||
end;
|
||||
|
||||
class function TDCP_tiger.GetAlgorithm: string;
|
||||
begin
|
||||
Result:= 'Tiger';
|
||||
end;
|
||||
|
||||
class function TDCP_tiger.SelfTest: boolean;
|
||||
const
|
||||
Test1Out: array[0..2] of int64=
|
||||
($87FB2A9083851CF7,$470D2CF810E6DF9E,$B586445034A5A386);
|
||||
Test2Out: array[0..2] of int64=
|
||||
($0C410A042968868A,$1671DA5A3FD29A72,$5EC1E457D3CDB303);
|
||||
var
|
||||
TestHash: TDCP_tiger;
|
||||
TestOut: array[0..2] of int64;
|
||||
begin
|
||||
dcpFillChar(TestOut, SizeOf(TestOut), 0);
|
||||
TestHash:= TDCP_tiger.Create(nil);
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
|
||||
TestHash.Init;
|
||||
TestHash.UpdateStr('Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham');
|
||||
TestHash.Final(TestOut);
|
||||
Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
|
||||
TestHash.Free;
|
||||
end;
|
||||
|
||||
procedure TDCP_tiger.Init;
|
||||
begin
|
||||
Burn;
|
||||
fInitialized:= true;
|
||||
CurrentHash[0]:= $0123456789ABCDEF;
|
||||
CurrentHash[1]:= $FEDCBA9876543210;
|
||||
CurrentHash[2]:= $F096A5B4C3B2E187;
|
||||
end;
|
||||
|
||||
procedure TDCP_tiger.Burn;
|
||||
begin
|
||||
Len:= 0;
|
||||
Index:= 0;
|
||||
FillChar(HashBuffer,Sizeof(HashBuffer),0);
|
||||
FillChar(CurrentHash,Sizeof(CurrentHash),0);
|
||||
fInitialized:= false;
|
||||
end;
|
||||
|
||||
procedure TDCP_tiger.Update(const Buffer; Size: longword);
|
||||
var
|
||||
PBuf: ^byte;
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
|
||||
Inc(Len,Size*8);
|
||||
|
||||
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_tiger.Final(var Digest);
|
||||
begin
|
||||
if not fInitialized then
|
||||
raise EDCP_hash.Create('Hash not initialized');
|
||||
HashBuffer[Index]:= $01;
|
||||
if Index>= 56 then
|
||||
Compress;
|
||||
Pint64(@HashBuffer[56])^:= Len;
|
||||
Compress;
|
||||
Move(CurrentHash,Digest,Sizeof(CurrentHash));
|
||||
Burn;
|
||||
end;
|
||||
|
||||
end.
|
Loading…
Reference in New Issue
Block a user