1
0
mirror of https://git.code.sf.net/p/lazarus-ccr/dcpcrypt synced 2025-07-12 23:10:12 +02:00

Rather large fix to correctly support 64-bit platforms.

* My previous attempt was not thorough enough and I missed a
  lot of details.
* More testing was done and now it seems to work correctly on 32-bit
  and 64-bit Linux.
This commit is contained in:
Graeme Geldenhuys
2009-11-17 17:07:00 +02:00
parent 4ab5087350
commit a6a0258b48
20 changed files with 178 additions and 171 deletions

View File

@ -47,9 +47,8 @@ type
end;
{******************************************************************************}
{******************************************************************************}
implementation
{$R-}{$Q-}
{$I DCPblowfish.inc}
@ -151,7 +150,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
xL:= Pdword(@InData)^;
xR:= Pdword(longword(@InData)+4)^;
xR:= Pdword(pointer(@InData)+4)^;
xL:= ((xL and $FF) shl 24) or ((xL and $FF00) shl 8) or ((xL and $FF0000) shr 8) or ((xL and $FF000000) shr 24);
xR:= ((xR and $FF) shl 24) or ((xR and $FF00) shl 8) or ((xR and $FF0000) shr 8) or ((xR and $FF000000) shr 24);
xL:= xL xor PBox[0];
@ -191,7 +190,7 @@ begin
xL:= ((xL and $FF) shl 24) or ((xL and $FF00) shl 8) or ((xL and $FF0000) shr 8) or ((xL and $FF000000) shr 24);
xR:= ((xR and $FF) shl 24) or ((xR and $FF00) shl 8) or ((xR and $FF0000) shr 8) or ((xR and $FF000000) shr 24);
Pdword(@OutData)^:= xR;
Pdword(longword(@OutData)+4)^:= xL;
Pdword(pointer(@OutData)+4)^:= xL;
end;
procedure TDCP_blowfish.DecryptECB(const InData; var OutData);
@ -201,7 +200,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
xL:= Pdword(@InData)^;
xR:= Pdword(longword(@InData)+4)^;
xR:= Pdword(pointer(@InData)+4)^;
xL:= (xL shr 24) or ((xL shr 8) and $FF00) or ((xL shl 8) and $FF0000) or (xL shl 24);
xR:= (xR shr 24) or ((xR shr 8) and $FF00) or ((xR shl 8) and $FF0000) or (xR shl 24);
xL:= xL xor PBox[17];
@ -241,7 +240,7 @@ begin
xL:= (xL shr 24) or ((xL shr 8) and $FF00) or ((xL shl 8) and $FF0000) or (xL shl 24);
xR:= (xR shr 24) or ((xR shr 8) and $FF00) or ((xR shl 8) and $FF0000) or (xR shl 24);
Pdword(@OutData)^:= xR;
Pdword(longword(@OutData)+4)^:= xL;
Pdword(pointer(@OutData)+4)^:= xL;
end;
end.

View File

@ -250,7 +250,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
l:= Pdword(@InData)^;
r:= Pdword(longword(@InData)+4)^;
r:= Pdword(Pointer(@InData)+4)^;
l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24);
r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24);
t:= LRot32(KeyData[0]+r, KeyData[0+16]);
@ -307,7 +307,7 @@ begin
l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24);
r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24);
Pdword(@OutData)^:= r;
Pdword(longword(@OutData)+4)^:= l;
Pdword(pointer(@OutData)+4)^:= l;
end;
procedure TDCP_cast128.DecryptECB(const InData; var OutData);
@ -317,7 +317,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
r:= Pdword(@InData)^;
l:= Pdword(longword(@InData)+4)^;
l:= Pdword(pointer(@InData)+4)^;
l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24);
r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24);
if Rounds> 12 then
@ -374,7 +374,7 @@ begin
l:= (l shr 24) or ((l shr 8) and $FF00) or ((l shl 8) and $FF0000) or (l shl 24);
r:= (r shr 24) or ((r shr 8) and $FF00) or ((r shl 8) and $FF0000) or (r shl 24);
Pdword(@OutData)^:= l;
Pdword(longword(@OutData)+4)^:= r;
Pdword(pointer(@OutData)+4)^:= r;
end;

View File

@ -221,9 +221,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
A[0]:= PDWord(@InData)^;
A[1]:= PDWord(longword(@InData)+4)^;
A[2]:= PDWord(longword(@InData)+8)^;
A[3]:= PDWord(longword(@InData)+12)^;
A[1]:= PDWord(pointer(@InData)+4)^;
A[2]:= PDWord(pointer(@InData)+8)^;
A[3]:= PDWord(pointer(@InData)+12)^;
A[0]:= SwapDWord(A[0]);
A[1]:= SwapDWord(A[1]);
@ -284,9 +284,9 @@ begin
A[3]:= SwapDWord(A[3]);
PDWord(@OutData)^:= A[0];
PDWord(longword(@OutData)+4)^:= A[1];
PDWord(longword(@OutData)+8)^:= A[2];
PDWord(longword(@OutData)+12)^:= A[3];
PDWord(pointer(@OutData)+4)^:= A[1];
PDWord(pointer(@OutData)+8)^:= A[2];
PDWord(pointer(@OutData)+12)^:= A[3];
end;
procedure TDCP_cast256.DecryptECB(const InData; var OutData);
@ -296,9 +296,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
A[0]:= PDWord(@InData)^;
A[1]:= PDWord(longword(@InData)+4)^;
A[2]:= PDWord(longword(@InData)+8)^;
A[3]:= PDWord(longword(@InData)+12)^;
A[1]:= PDWord(pointer(@InData)+4)^;
A[2]:= PDWord(pointer(@InData)+8)^;
A[3]:= PDWord(pointer(@InData)+12)^;
A[0]:= SwapDWord(A[0]);
A[1]:= SwapDWord(A[1]);
@ -359,9 +359,9 @@ begin
A[3]:= SwapDWord(A[3]);
PDWord(@OutData)^:= A[0];
PDWord(longword(@OutData)+4)^:= A[1];
PDWord(longword(@OutData)+8)^:= A[2];
PDWord(longword(@OutData)+12)^:= A[3];
PDWord(pointer(@OutData)+4)^:= A[1];
PDWord(pointer(@OutData)+8)^:= A[2];
PDWord(pointer(@OutData)+12)^:= A[3];
end;

View File

@ -146,7 +146,7 @@ var
i: longint;
begin
r:= PDword(@InData)^;
l:= PDword(dword(@InData)+4)^;
l:= PDword(pointer(@InData)+4)^;
t:= ((l shr 4) xor r) and $0f0f0f0f;
r:= r xor t;
l:= l xor (t shl 4);
@ -231,7 +231,7 @@ begin
l:= l xor t;
r:= r xor (t shl 4);
PDword(@OutData)^:= l;
PDword(dword(@OutData)+4)^:= r;
PDword(pointer(@OutData)+4)^:= r;
end;
procedure TDCP_customdes.DecryptBlock(const InData; var OutData; KeyData: PDWordArray);
@ -240,7 +240,7 @@ var
i: longint;
begin
r:= PDword(@InData)^;
l:= PDword(dword(@InData)+4)^;
l:= PDword(pointer(@InData)+4)^;
t:= ((l shr 4) xor r) and $0f0f0f0f;
r:= r xor t;
l:= l xor (t shl 4);
@ -325,7 +325,7 @@ begin
l:= l xor t;
r:= r xor (t shl 4);
PDword(@OutData)^:= l;
PDword(dword(@OutData)+4)^:= r;
PDword(pointer(@OutData)+4)^:= r;
end;
class function TDCP_des.GetMaxKeySize: integer;

View File

@ -140,7 +140,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
n1:= PDword(@InData)^;
n2:= PDword(dword(@InData)+4)^;
n2:= PDword(pointer(@InData)+4)^;
for i:= 0 to 2 do
begin
n2:= n2 xor (sTable[3,(n1+KeyData[0]) shr 24] xor sTable[2,((n1+KeyData[0]) shr 16) and $FF]
@ -177,7 +177,7 @@ begin
n1:= n1 xor (sTable[3,(n2+KeyData[0]) shr 24] xor sTable[2,((n2+KeyData[0]) shr 16) and $FF]
xor sTable[1,((n2+KeyData[0]) shr 8) and $FF] xor sTable[0,(n2+KeyData[0]) and $FF]);
PDword(@OutData)^:= n2;
PDword(dword(@OutData)+4)^:= n1;
PDword(pointer(@OutData)+4)^:= n1;
end;
procedure TDCP_gost.DecryptECB(const InData; var OutData);
@ -188,7 +188,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
n1:= PDword(@InData)^;
n2:= PDword(dword(@InData)+4)^;
n2:= PDword(pointer(@InData)+4)^;
n2:= n2 xor (sTable[3,(n1+KeyData[0]) shr 24] xor sTable[2,((n1+KeyData[0]) shr 16) and $FF]
xor sTable[1,((n1+KeyData[0]) shr 8) and $FF] xor sTable[0,(n1+KeyData[0]) and $FF]);
n1:= n1 xor (sTable[3,(n2+KeyData[1]) shr 24] xor sTable[2,((n2+KeyData[1]) shr 16) and $FF]
@ -225,7 +225,7 @@ begin
xor sTable[1,((n2+KeyData[0]) shr 8) and $FF] xor sTable[0,(n2+KeyData[0]) and $FF]);
end;
PDword(@OutData)^:= n2;
PDword(dword(@OutData)+4)^:= n1;
PDword(pointer(@OutData)+4)^:= n1;
end;

View File

@ -272,7 +272,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
l:= SwapDWord(Pdword(@InData)^);
r:= SwapDWord(Pdword(longword(@InData)+4)^);
r:= SwapDWord(Pdword(pointer(@InData)+4)^);
i:= 0;
while i< rounds do
begin
@ -281,7 +281,7 @@ begin
Inc(i,2);
end;
Pdword(@OutData)^:= SwapDWord(r);
Pdword(longword(@OutData)+4)^:= SwapDWord(l);
Pdword(pointer(@OutData)+4)^:= SwapDWord(l);
end;
procedure TDCP_customice.DecryptECB(const InData; var OutData);
@ -292,7 +292,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
l:= SwapDWord(Pdword(@InData)^);
r:= SwapDWord(Pdword(longword(@InData)+4)^);
r:= SwapDWord(Pdword(pointer(@InData)+4)^);
i:= rounds-1;
while i> 0 do
begin
@ -301,7 +301,7 @@ begin
Dec(i,2);
end;
Pdword(@OutData)^:= SwapDWord(r);
Pdword(longword(@OutData)+4)^:= SwapDWord(l);
Pdword(pointer(@OutData)+4)^:= SwapDWord(l);
end;
constructor TDCP_customice.Create(AOwner: TComponent);

View File

@ -214,7 +214,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
PDword(@X[1])^:= PDword(@InData)^;
PDword(@X[3])^:= PDword(dword(@InData)+4)^;
PDword(@X[3])^:= PDword(pointer(@InData)+4)^;
for i:= 1 to 4 do
x[i]:= (x[i] shl 8) or (x[i] shr 8);
for i:= 0 to 7 do
@ -246,7 +246,7 @@ begin
x[4]:= (x[4] shl 8) or (x[4] shr 8);
x[2]:= s2;
PDword(@OutData)^:= PDword(@x[1])^;
PDword(dword(@OutData)+4)^:= PDword(@x[3])^;
PDword(pointer(@OutData)+4)^:= PDword(@x[3])^;
end;
procedure TDCP_idea.DecryptECB(const InData; var OutData);
@ -258,7 +258,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
PDword(@X[1])^:= PDword(@InData)^;
PDword(@X[3])^:= PDword(dword(@InData)+4)^;
PDword(@X[3])^:= PDword(pointer(@InData)+4)^;
for i:= 1 to 4 do
x[i]:= (x[i] shl 8) or (x[i] shr 8);
for i:= 0 to 7 do
@ -290,7 +290,7 @@ begin
x[4]:= (x[4] shl 8) or (x[4] shr 8);
x[2]:= s2;
PDword(@OutData)^:= PDword(@x[1])^;
PDword(dword(@OutData)+4)^:= PDword(@x[3])^;
PDword(pointer(@OutData)+4)^:= PDword(@x[3])^;
end;

View File

@ -188,9 +188,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
Blk[0]:= PDWord(@InData)^;
Blk[1]:= PDWord(longword(@InData)+4)^;
Blk[2]:= PDWord(longword(@InData)+8)^;
Blk[3]:= PDWord(longword(@InData)+12)^;
Blk[1]:= PDWord(pointer(@InData)+4)^;
Blk[2]:= PDWord(pointer(@InData)+8)^;
Blk[3]:= PDWord(pointer(@InData)+12)^;
blk[0]:= blk[0] + KeyData[0]; blk[1]:= blk[1] + KeyData[1];
blk[2]:= blk[2] + KeyData[2]; blk[3]:= blk[3] + KeyData[3];
@ -438,9 +438,9 @@ begin
blk[2]:= blk[2] - KeyData[38]; blk[3]:= blk[3] - KeyData[39];
PDWord(@OutData)^:= Blk[0];
PDWord(longword(@OutData)+4)^:= Blk[1];
PDWord(longword(@OutData)+8)^:= Blk[2];
PDWord(longword(@OutData)+12)^:= Blk[3];
PDWord(pointer(@OutData)+4)^:= Blk[1];
PDWord(pointer(@OutData)+8)^:= Blk[2];
PDWord(pointer(@OutData)+12)^:= Blk[3];
end;
procedure TDCP_mars.DecryptECB(const InData; var OutData);
@ -451,9 +451,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
Blk[0]:= PDWord(@InData)^;
Blk[1]:= PDWord(longword(@InData)+4)^;
Blk[2]:= PDWord(longword(@InData)+8)^;
Blk[3]:= PDWord(longword(@InData)+12)^;
Blk[1]:= PDWord(pointer(@InData)+4)^;
Blk[2]:= PDWord(pointer(@InData)+8)^;
Blk[3]:= PDWord(pointer(@InData)+12)^;
blk[0]:= blk[0] + KeyData[36]; blk[1]:= blk[1] + KeyData[37];
blk[2]:= blk[2] + KeyData[38]; blk[3]:= blk[3] + KeyData[39];
@ -701,9 +701,9 @@ begin
blk[2]:= blk[2] - KeyData[2]; blk[3]:= blk[3] - KeyData[3];
PDWord(@OutData)^:= Blk[0];
PDWord(longword(@OutData)+4)^:= Blk[1];
PDWord(longword(@OutData)+8)^:= Blk[2];
PDWord(longword(@OutData)+12)^:= Blk[3];
PDWord(pointer(@OutData)+4)^:= Blk[1];
PDWord(pointer(@OutData)+8)^:= Blk[2];
PDWord(pointer(@OutData)+12)^:= Blk[3];
end;
end.

View File

@ -214,7 +214,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
d0:= SwapDWord(PDWord(@InData)^);
d1:= SwapDWord(PDWord(longword(@InData)+4)^);
d1:= SwapDWord(PDWord(pointer(@InData)+4)^);
for i:= 0 to NUMROUNDS-1 do
begin
if (i mod 2)= 0 then
@ -229,7 +229,7 @@ begin
d0:= FL(d0,NUMROUNDS);
d1:= FL(d1,NUMROUNDS+1);
PDWord(@OutData)^:= SwapDWord(d1);
PDWord(longword(@OutData)+4)^:= SwapDWord(d0);
PDWord(pointer(@OutData)+4)^:= SwapDWord(d0);
end;
procedure TDCP_misty1.DecryptECB(const InData; var OutData);
@ -240,7 +240,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
d1:= SwapDWord(PDWord(@InData)^);
d0:= SwapDWord(PDWord(longword(@InData)+4)^);
d0:= SwapDWord(PDWord(pointer(@InData)+4)^);
d1:= FLINV(d1,NUMROUNDS+1);
d0:= FLINV(d0,NUMROUNDS);
for i:= NUMROUNDS-1 downto 0 do
@ -255,7 +255,7 @@ begin
d0:= d0 xor FO(d1,i);
end;
PDWord(@OutData)^:= SwapDWord(d0);
PDWord(longword(@OutData)+4)^:= SwapDWord(d1);
PDWord(pointer(@OutData)+4)^:= SwapDWord(d1);
end;
end.

View File

@ -138,7 +138,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
Pdword(@w[0])^:= Pdword(@InData)^;
Pdword(@w[2])^:= Pdword(longword(@InData)+4)^;
Pdword(@w[2])^:= Pdword(pointer(@InData)+4)^;
for i:= 0 to 15 do
begin
j:= i*4;
@ -155,7 +155,7 @@ begin
end;
end;
Pdword(@OutData)^:= Pdword(@w[0])^;
Pdword(longword(@OutData)+4)^:= Pdword(@w[2])^;
Pdword(pointer(@OutData)+4)^:= Pdword(@w[2])^;
end;
procedure TDCP_rc2.DecryptECB(const InData; var OutData);
@ -166,7 +166,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
Pdword(@w[0])^:= Pdword(@InData)^;
Pdword(@w[2])^:= Pdword(longword(@InData)+4)^;
Pdword(@w[2])^:= Pdword(pointer(@InData)+4)^;
for i:= 15 downto 0 do
begin
j:= i*4;
@ -183,7 +183,7 @@ begin
end;
end;
Pdword(@OutData)^:= Pdword(@w[0])^;
Pdword(longword(@OutData)+4)^:= Pdword(@w[2])^;
Pdword(pointer(@OutData)+4)^:= Pdword(@w[2])^;
end;
end.

View File

@ -99,21 +99,21 @@ begin
while i< 255 do
begin
KeyData[i]:= i;
xKey[i]:= PByte(longword(@Key)+(i mod Size))^;
xKey[i]:= PByte(pointer(@Key)+(i mod Size))^;
KeyData[i+1]:= i+1;
xKey[i+1]:= PByte(longword(@Key)+((i+1) mod Size))^;
xKey[i+1]:= PByte(pointer(@Key)+((i+1) mod Size))^;
KeyData[i+2]:= i+2;
xKey[i+2]:= PByte(longword(@Key)+((i+2) mod Size))^;
xKey[i+2]:= PByte(pointer(@Key)+((i+2) mod Size))^;
KeyData[i+3]:= i+3;
xKey[i+3]:= PByte(longword(@Key)+((i+3) mod Size))^;
xKey[i+3]:= PByte(pointer(@Key)+((i+3) mod Size))^;
KeyData[i+4]:= i+4;
xKey[i+4]:= PByte(longword(@Key)+((i+4) mod Size))^;
xKey[i+4]:= PByte(pointer(@Key)+((i+4) mod Size))^;
KeyData[i+5]:= i+5;
xKey[i+5]:= PByte(longword(@Key)+((i+5) mod Size))^;
xKey[i+5]:= PByte(pointer(@Key)+((i+5) mod Size))^;
KeyData[i+6]:= i+6;
xKey[i+6]:= PByte(longword(@Key)+((i+6) mod Size))^;
xKey[i+6]:= PByte(pointer(@Key)+((i+6) mod Size))^;
KeyData[i+7]:= i+7;
xKey[i+7]:= PByte(longword(@Key)+((i+7) mod Size))^;
xKey[i+7]:= PByte(pointer(@Key)+((i+7) mod Size))^;
Inc(i,8);
end;
j:= 0;

View File

@ -167,7 +167,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
A:= PDword(@InData)^ + KeyData[0];
B:= PDword(longword(@InData)+4)^ + KeyData[1];
B:= PDword(pointer(@InData)+4)^ + KeyData[1];
for i:= 1 to NUMROUNDS do
begin
A:= A xor B;
@ -176,7 +176,7 @@ begin
B:= LRot32(B,A)+KeyData[(2*i)+1];
end;
PDword(@OutData)^:= A;
PDword(longword(@OutData)+4)^:= B;
PDword(pointer(@OutData)+4)^:= B;
end;
procedure TDCP_rc5.DecryptECB(const InData; var OutData);
@ -187,7 +187,7 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
A:= PDword(@InData)^;
B:= PDword(longword(@InData)+4)^;
B:= PDword(pointer(@InData)+4)^;
for i:= NUMROUNDS downto 1 do
begin
B:= RRot32(B-KeyData[(2*i)+1],A);
@ -196,7 +196,7 @@ begin
A:= A xor B;
end;
PDword(@OutData)^:= A - KeyData[0];
PDword(longword(@OutData)+4)^:= B - KeyData[1];
PDword(pointer(@OutData)+4)^:= B - KeyData[1];
end;
end.

View File

@ -173,9 +173,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
x0:= PDword(@InData)^;
x1:= PDword(longword(@InData)+4)^;
x2:= PDword(longword(@InData)+8)^;
x3:= PDword(longword(@InData)+12)^;
x1:= PDword(pointer(@InData)+4)^;
x2:= PDword(pointer(@InData)+8)^;
x3:= PDword(pointer(@InData)+12)^;
x1:= x1 + KeyData[0];
x3:= x3 + KeyData[1];
for i:= 1 to NUMROUNDS do
@ -189,9 +189,9 @@ begin
x0:= x0 + KeyData[(2*NUMROUNDS)+2];
x2:= x2 + KeyData[(2*NUMROUNDS)+3];
PDword(@OutData)^:= x0;
PDword(longword(@OutData)+4)^:= x1;
PDword(longword(@OutData)+8)^:= x2;
PDword(longword(@OutData)+12)^:= x3;
PDword(pointer(@OutData)+4)^:= x1;
PDword(pointer(@OutData)+8)^:= x2;
PDword(pointer(@OutData)+12)^:= x3;
end;
procedure TDCP_rc6.DecryptECB(const InData; var OutData);
@ -203,9 +203,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
x0:= PDword(@InData)^;
x1:= PDword(longword(@InData)+4)^;
x2:= PDword(longword(@InData)+8)^;
x3:= PDword(longword(@InData)+12)^;
x1:= PDword(pointer(@InData)+4)^;
x2:= PDword(pointer(@InData)+8)^;
x3:= PDword(pointer(@InData)+12)^;
x2:= x2 - KeyData[(2*NUMROUNDS)+3];
x0:= x0 - KeyData[(2*NUMROUNDS)+2];
for i:= NUMROUNDS downto 1 do
@ -219,9 +219,9 @@ begin
x3:= x3 - KeyData[1];
x1:= x1 - KeyData[0];
PDword(@OutData)^:= x0;
PDword(longword(@OutData)+4)^:= x1;
PDword(longword(@OutData)+8)^:= x2;
PDword(longword(@OutData)+12)^:= x3;
PDword(pointer(@OutData)+4)^:= x1;
PDword(pointer(@OutData)+8)^:= x2;
PDword(pointer(@OutData)+12)^:= x3;
end;
end.

View File

@ -236,9 +236,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
PDword(@a[0,0])^:= PDword(@InData)^;
PDword(@a[1,0])^:= PDword(dword(@InData)+4)^;
PDword(@a[2,0])^:= PDword(dword(@InData)+8)^;
PDword(@a[3,0])^:= PDword(dword(@InData)+12)^;
PDword(@a[1,0])^:= PDword(pointer(@InData)+4)^;
PDword(@a[2,0])^:= PDword(pointer(@InData)+8)^;
PDword(@a[3,0])^:= PDword(pointer(@InData)+12)^;
for r:= 0 to (numrounds-2) do
begin
PDWord(@tempb[0])^:= PDWord(@a[0])^ xor rk[r,0];
@ -288,9 +288,9 @@ begin
PDWord(@a[3])^:= PDWord(@a[3])^ xor rk[numrounds,3];
PDword(@OutData)^:= PDword(@a[0,0])^;
PDword(dword(@OutData)+4)^:= PDword(@a[1,0])^;
PDword(dword(@OutData)+8)^:= PDword(@a[2,0])^;
PDword(dword(@OutData)+12)^:= PDword(@a[3,0])^;
PDword(pointer(@OutData)+4)^:= PDword(@a[1,0])^;
PDword(pointer(@OutData)+8)^:= PDword(@a[2,0])^;
PDword(pointer(@OutData)+12)^:= PDword(@a[3,0])^;
end;
procedure TDCP_rijndael.DecryptECB(const InData; var OutData);
@ -302,9 +302,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
PDword(@a[0,0])^:= PDword(@InData)^;
PDword(@a[1,0])^:= PDword(dword(@InData)+4)^;
PDword(@a[2,0])^:= PDword(dword(@InData)+8)^;
PDword(@a[3,0])^:= PDword(dword(@InData)+12)^;
PDword(@a[1,0])^:= PDword(pointer(@InData)+4)^;
PDword(@a[2,0])^:= PDword(pointer(@InData)+8)^;
PDword(@a[3,0])^:= PDword(pointer(@InData)+12)^;
for r:= NumRounds downto 2 do
begin
PDWord(@tempb[0])^:= PDWord(@a[0])^ xor drk[r,0];
@ -353,9 +353,9 @@ begin
PDWord(@a[2])^:= PDWord(@a[2])^ xor drk[0,2];
PDWord(@a[3])^:= PDWord(@a[3])^ xor drk[0,3];
PDword(@OutData)^:= PDword(@a[0,0])^;
PDword(dword(@OutData)+4)^:= PDword(@a[1,0])^;
PDword(dword(@OutData)+8)^:= PDword(@a[2,0])^;
PDword(dword(@OutData)+12)^:= PDword(@a[3,0])^;
PDword(pointer(@OutData)+4)^:= PDword(@a[1,0])^;
PDword(pointer(@OutData)+8)^:= PDword(@a[2,0])^;
PDword(pointer(@OutData)+12)^:= PDword(@a[3,0])^;
end;

View File

@ -178,9 +178,9 @@ begin
raise EDCP_blockcipher.Create('Cipher not initialized');
a:= PDWord(@InData)^;
b:= PDWord(longword(@InData)+4)^;
c:= PDWord(longword(@InData)+8)^;
d:= PDWord(longword(@InData)+12)^;
b:= PDWord(pointer(@InData)+4)^;
c:= PDWord(pointer(@InData)+8)^;
d:= PDWord(pointer(@InData)+12)^;
i:= 0;
while i < 32 do
@ -217,10 +217,10 @@ begin
end;
a:= a xor l_key[128]; b:= b xor l_key[128+1]; c:= c xor l_key[128+2]; d:= d xor l_key[128+3];
PDWord(PtrUInt(@OutData)+ 0)^:= a;
PDWord(PtrUInt(@OutData)+ 4)^:= b;
PDWord(PtrUInt(@OutData)+ 8)^:= c;
PDWord(PtrUInt(@OutData)+12)^:= d;
PDWord(pointer(@OutData)+ 0)^:= a;
PDWord(pointer(@OutData)+ 4)^:= b;
PDWord(pointer(@OutData)+ 8)^:= c;
PDWord(pointer(@OutData)+12)^:= d;
end;
procedure TDCP_serpent.DecryptECB(const InData; var OutData);
@ -233,9 +233,9 @@ begin
raise EDCP_blockcipher.Create('Cipher not initialized');
a:= PDWord(@InData)^;
b:= PDWord(longword(@InData)+4)^;
c:= PDWord(longword(@InData)+8)^;
d:= PDWord(longword(@InData)+12)^;
b:= PDWord(pointer(@InData)+4)^;
c:= PDWord(pointer(@InData)+8)^;
d:= PDWord(pointer(@InData)+12)^;
i:= 32;
a:= a xor l_key[4*32]; b:= b xor l_key[4*32+1]; c:= c xor l_key[4*32+2]; d:= d xor l_key[4*32+3];
@ -272,10 +272,10 @@ begin
Dec(i,8);
end;
PDWord(PtrUInt(@OutData)+ 0)^:= a;
PDWord(PtrUInt(@OutData)+ 4)^:= b;
PDWord(PtrUInt(@OutData)+ 8)^:= c;
PDWord(PtrUInt(@OutData)+12)^:= d;
PDWord(pointer(@OutData)+ 0)^:= a;
PDWord(pointer(@OutData)+ 4)^:= b;
PDWord(pointer(@OutData)+ 8)^:= c;
PDWord(pointer(@OutData)+12)^:= d;
end;
end.

View File

@ -22,8 +22,8 @@
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************}
unit DCPtea;
unit DCPtea;
{$MODE Delphi}
interface
@ -52,7 +52,7 @@ implementation
{$R-}{$Q-}
const
Delta= $9e3779b9;
Delta: DWord = $9e3779b9;
Rounds= 32;
function SwapDword(a: dword): dword;
@ -115,7 +115,7 @@ begin
raise EDCP_blockcipher.Create('Cipher not initialized');
x:= SwapDWord(pdword(@InData)^);
y:= SwapDWord(pdword(longword(@InData)+4)^);
y:= SwapDWord(pdword(pointer(@InData)+4)^);
sum:= 0; a:= KeyData[0]; b:= KeyData[1]; c:= KeyData[2]; d:= KeyData[3];
for n:= 1 to Rounds do
begin
@ -124,7 +124,7 @@ begin
Inc(y,(x shl 4) + (c xor x) + (sum xor (x shr 5)) + d);
end;
pdword(@OutData)^:= SwapDWord(x);
pdword(longword(@OutData)+4)^:= SwapDWord(y);
pdword(pointer(@OutData)+4)^:= SwapDWord(y);
end;
procedure TDCP_tea.DecryptECB(const InData; var OutData);
@ -135,8 +135,12 @@ begin
raise EDCP_blockcipher.Create('Cipher not initialized');
x:= SwapDWord(pdword(@InData)^);
y:= SwapDWord(pdword(longword(@InData)+4)^);
sum:= Delta shl 5; a:= KeyData[0]; b:= KeyData[1]; c:= KeyData[2]; d:= KeyData[3];
y:= SwapDWord(pdword(pointer(@InData)+4)^);
sum:= Delta shl 5;
a:= KeyData[0];
b:= KeyData[1];
c:= KeyData[2];
d:= KeyData[3];
for n:= 1 to Rounds do
begin
Dec(y,(x shl 4) + (c xor x) + (sum xor (x shr 5)) + d);
@ -144,7 +148,7 @@ begin
Dec(sum,Delta);
end;
pdword(@OutData)^:= SwapDWord(x);
pdword(longword(@OutData)+4)^:= SwapDWord(y);
pdword(pointer(@OutData)+4)^:= SwapDWord(y);
end;
end.

View File

@ -457,9 +457,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
x[0]:= PDWord(@InData)^ xor SubKeys[INPUTWHITEN];
x[1]:= PDWord(longword(@InData)+4)^ xor SubKeys[INPUTWHITEN+1];
x[2]:= PDWord(longword(@InData)+8)^ xor SubKeys[INPUTWHITEN+2];
x[3]:= PDWord(longword(@InData)+12)^ xor SubKeys[INPUTWHITEN+3];
x[1]:= PDWord(pointer(@InData)+4)^ xor SubKeys[INPUTWHITEN+1];
x[2]:= PDWord(pointer(@InData)+8)^ xor SubKeys[INPUTWHITEN+2];
x[3]:= PDWord(pointer(@InData)+12)^ xor SubKeys[INPUTWHITEN+3];
i:= 0;
while i<= NUMROUNDS-2 do
begin
@ -482,10 +482,10 @@ begin
x[0]:= (x[0] shr 1) or (x[0] shl 31);
Inc(i,2);
end;
PDWord(PtrUInt(@OutData)+ 0)^:= x[2] xor SubKeys[OUTPUTWHITEN];
PDWord(PtrUInt(@OutData)+ 4)^:= x[3] xor SubKeys[OUTPUTWHITEN+1];
PDWord(PtrUInt(@OutData)+ 8)^:= x[0] xor SubKeys[OUTPUTWHITEN+2];
PDWord(PtrUInt(@OutData)+12)^:= x[1] xor SubKeys[OUTPUTWHITEN+3];
PDWord(pointer(@OutData)+ 0)^:= x[2] xor SubKeys[OUTPUTWHITEN];
PDWord(pointer(@OutData)+ 4)^:= x[3] xor SubKeys[OUTPUTWHITEN+1];
PDWord(pointer(@OutData)+ 8)^:= x[0] xor SubKeys[OUTPUTWHITEN+2];
PDWord(pointer(@OutData)+12)^:= x[1] xor SubKeys[OUTPUTWHITEN+3];
end;
procedure TDCP_twofish.DecryptECB(const InData; var OutData);
@ -497,9 +497,9 @@ begin
if not fInitialized then
raise EDCP_blockcipher.Create('Cipher not initialized');
X[2]:= PDWord(@InData)^ xor SubKeys[OUTPUTWHITEN];
X[3]:= PDWord(longword(@InData)+4)^ xor SubKeys[OUTPUTWHITEN+1];
X[0]:= PDWord(longword(@InData)+8)^ xor SubKeys[OUTPUTWHITEN+2];
X[1]:= PDWord(longword(@InData)+12)^ xor SubKeys[OUTPUTWHITEN+3];
X[3]:= PDWord(pointer(@InData)+4)^ xor SubKeys[OUTPUTWHITEN+1];
X[0]:= PDWord(pointer(@InData)+8)^ xor SubKeys[OUTPUTWHITEN+2];
X[1]:= PDWord(pointer(@InData)+12)^ xor SubKeys[OUTPUTWHITEN+3];
i:= NUMROUNDS-2;
while i>= 0 do
begin
@ -522,10 +522,10 @@ begin
x[3]:= (x[3] shr 1) or (x[3] shl 31);
Dec(i,2);
end;
PDWord(PtrUInt(@OutData)+ 0)^:= X[0] xor SubKeys[INPUTWHITEN];
PDWord(PtrUInt(@OutData)+ 4)^:= X[1] xor SubKeys[INPUTWHITEN+1];
PDWord(PtrUInt(@OutData)+ 8)^:= X[2] xor SubKeys[INPUTWHITEN+2];
PDWord(PtrUInt(@OutData)+12)^:= X[3] xor SubKeys[INPUTWHITEN+3];
PDWord(pointer(@OutData)+ 0)^:= X[0] xor SubKeys[INPUTWHITEN];
PDWord(pointer(@OutData)+ 4)^:= X[1] xor SubKeys[INPUTWHITEN+1];
PDWord(pointer(@OutData)+ 8)^:= X[2] xor SubKeys[INPUTWHITEN+2];
PDWord(pointer(@OutData)+12)^:= X[3] xor SubKeys[INPUTWHITEN+3];
end;
procedure PreCompMDS;

View File

@ -22,8 +22,8 @@
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************}
unit DCPtiger;
unit DCPtiger;
{$MODE Delphi}
interface

View File

@ -22,8 +22,8 @@
{* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
{* DEALINGS IN THE SOFTWARE. *}
{******************************************************************************}
unit DCPblockciphers;
unit DCPblockciphers;
{$MODE Delphi}
interface
@ -205,8 +205,8 @@ begin
XorBlock(p2^,CV,8);
EncryptECB(p2^,p2^);
Move(p2^,CV,8);
p1:= pointer(longword(p1) + 8);
p2:= pointer(longword(p2) + 8);
p1:= pointer(p1 + 8);
p2:= pointer(p2 + 8);
end;
if (Size mod 8)<> 0 then
begin
@ -233,8 +233,8 @@ begin
DecryptECB(p2^,p2^);
XorBlock(p2^,CV,8);
Move(Temp,CV,8);
p1:= pointer(longword(p1) + 8);
p2:= pointer(longword(p2) + 8);
p1:= pointer(p1 + 8);
p2:= pointer(p2 + 8);
end;
if (Size mod 8)<> 0 then
begin
@ -303,8 +303,8 @@ begin
Move(p1^,p2^,8);
XorBlock(p2^,CV,8);
Move(p2^,CV,8);
p1:= pointer(longword(p1) + 8);
p2:= pointer(longword(p2) + 8);
p1:= pointer(pointer(p1) + 8);
p2:= pointer(pointer(p2) + 8);
end;
if (Size mod 8)<> 0 then
begin
@ -331,8 +331,8 @@ begin
Move(p1^,p2^,8);
XorBlock(p2^,CV,8);
Move(Temp,CV,8);
p1:= pointer(longword(p1) + 8);
p2:= pointer(longword(p2) + 8);
p1:= pointer(pointer(p1) + 8);
p2:= pointer(pointer(p2) + 8);
end;
if (Size mod 8)<> 0 then
begin
@ -356,8 +356,8 @@ begin
EncryptECB(CV,CV);
Move(p1^,p2^,8);
XorBlock(p2^,CV,8);
p1:= pointer(longword(p1) + 8);
p2:= pointer(longword(p2) + 8);
p1:= pointer(p1 + 8);
p2:= pointer(p2 + 8);
end;
if (Size mod 8)<> 0 then
begin
@ -381,8 +381,8 @@ begin
EncryptECB(CV,CV);
Move(p1^,p2^,8);
XorBlock(p2^,CV,8);
p1:= pointer(longword(p1) + 8);
p2:= pointer(longword(p2) + 8);
p1:= pointer(p1 + 8);
p2:= pointer(p2 + 8);
end;
if (Size mod 8)<> 0 then
begin
@ -408,8 +408,8 @@ begin
IncCounter;
Move(p1^,p2^,8);
XorBlock(p2^,temp,8);
p1:= pointer(longword(p1) + 8);
p2:= pointer(longword(p2) + 8);
p1:= pointer(p1 + 8);
p2:= pointer(p2 + 8);
end;
if (Size mod 8)<> 0 then
begin
@ -436,8 +436,8 @@ begin
IncCounter;
Move(p1^,p2^,8);
XorBlock(p2^,temp,8);
p1:= pointer(longword(p1) + 8);
p2:= pointer(longword(p2) + 8);
p1:= pointer(p1 + 8);
p2:= pointer(p2 + 8);
end;
if (Size mod 8)<> 0 then
begin
@ -530,8 +530,8 @@ begin
XorBlock(p2^,CV,16);
EncryptECB(p2^,p2^);
Move(p2^,CV,16);
p1:= pointer(longword(p1) + 16);
p2:= pointer(longword(p2) + 16);
p1:= pointer(p1 + 16);
p2:= pointer(p2 + 16);
end;
if (Size mod 16)<> 0 then
begin
@ -558,8 +558,8 @@ begin
DecryptECB(p2^,p2^);
XorBlock(p2^,CV,16);
Move(Temp,CV,16);
p1:= pointer(longword(p1) + 16);
p2:= pointer(longword(p2) + 16);
p1:= pointer(p1 + 16);
p2:= pointer(p2 + 16);
end;
if (Size mod 16)<> 0 then
begin
@ -628,8 +628,8 @@ begin
Move(p1^,p2^,16);
XorBlock(p2^,CV,16);
Move(p2^,CV,16);
p1:= pointer(longword(p1) + 16);
p2:= pointer(longword(p2) + 16);
p1:= pointer(pointer(p1) + 16);
p2:= pointer(pointer(p2) + 16);
end;
if (Size mod 16)<> 0 then
begin
@ -656,8 +656,8 @@ begin
Move(p1^,p2^,16);
XorBlock(p2^,CV,16);
Move(Temp,CV,16);
p1:= pointer(longword(p1) + 16);
p2:= pointer(longword(p2) + 16);
p1:= pointer(pointer(p1) + 16);
p2:= pointer(pointer(p2) + 16);
end;
if (Size mod 16)<> 0 then
begin
@ -681,8 +681,8 @@ begin
EncryptECB(CV,CV);
Move(p1^,p2^,16);
XorBlock(p2^,CV,16);
p1:= pointer(longword(p1) + 16);
p2:= pointer(longword(p2) + 16);
p1:= pointer(p1 + 16);
p2:= pointer(p2 + 16);
end;
if (Size mod 16)<> 0 then
begin
@ -706,8 +706,8 @@ begin
EncryptECB(CV,CV);
Move(p1^,p2^,16);
XorBlock(p2^,CV,16);
p1:= pointer(longword(p1) + 16);
p2:= pointer(longword(p2) + 16);
p1:= pointer(p1 + 16);
p2:= pointer(p2 + 16);
end;
if (Size mod 16)<> 0 then
begin
@ -733,8 +733,8 @@ begin
IncCounter;
Move(p1^,p2^,16);
XorBlock(p2^,temp,16);
p1:= pointer(longword(p1) + 16);
p2:= pointer(longword(p2) + 16);
p1:= pointer(p1 + 16);
p2:= pointer(p2 + 16);
end;
if (Size mod 16)<> 0 then
begin
@ -761,8 +761,8 @@ begin
IncCounter;
Move(p1^,p2^,16);
XorBlock(p2^,temp,16);
p1:= pointer(longword(p1) + 16);
p2:= pointer(longword(p2) + 16);
p1:= pointer(p1 + 16);
p2:= pointer(p2 + 16);
end;
if (Size mod 16)<> 0 then
begin

View File

@ -28,7 +28,7 @@ unit DCPcrypt2;
interface
uses
Classes, Sysutils, DCPconst, DCPbase64;
Classes, Sysutils, DCPbase64;
//{$DEFINE DCP1COMPAT} { DCPcrypt v1.31 compatiblity mode - see documentation }
@ -36,15 +36,15 @@ uses
{ A few predefined types to help out }
type
{$IFNDEF FPC}
Pbyte= ^byte;
Pword= ^word;
Pdword= ^dword;
Pint64= ^int64;
{$IFNDEF FPC}
dword= longword;
{$ENDIF}
Pwordarray= ^Twordarray;
Twordarray= array[0..19383] of word;
{$ENDIF}
Pdwordarray= ^Tdwordarray;
Tdwordarray= array[0..8191] of dword;
@ -629,10 +629,14 @@ end;
{** Helpher functions *********************************************************}
procedure XorBlock(var InData1, InData2; Size: longword);
var
b1: PByteArray;
b2: PByteArray;
i: longword;
begin
for i:= 1 to Size do
Pbyte(longword(@InData1)+i-1)^:= Pbyte(longword(@InData1)+i-1)^ xor Pbyte(longword(@InData2)+i-1)^;
b1 := @InData1;
b2 := @InData2;
for i := 0 to size-1 do
b1[i] := b1[i] xor b2[i];
end;
end.