2
0
Эх сурвалжийг харах

* applied patch from Paul te Bokkel

peter 25 жил өмнө
parent
commit
0ade264ed1
1 өөрчлөгдсөн 24 нэмэгдсэн , 30 устгасан
  1. 24 30
      fcl/inc/idea.pp

+ 24 - 30
fcl/inc/idea.pp

@@ -11,7 +11,10 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
  **********************************************************************}
+
+{$ifdef fpc}
 {$mode objfpc}
+{$endif}
 
 UNIT IDEA;
 
@@ -103,8 +106,10 @@ Const
   SNoReadAllowed = 'Reading from encryption stream not allowed';
   SNoWriteAllowed = 'Writing to decryption stream not allowed';
 
+{$ifdef fpc}
 Type
-  PByte = ^Byte;
+  PChar = ^Byte;
+{$endif}
 
 PROCEDURE mul(VAR a:Word; b: Word);
 VAR p: LongInt;
@@ -153,7 +158,6 @@ PROCEDURE EnKeyIdea(userkey: ideacryptkey; VAR z: ideakey);
 VAR zi,i,j: integer;
 BEGIN
   FOR j := 0 TO 7 DO z[j] := userkey[j];
-  i := 0;
   zi := 0;
   i := 0;
   FOR j := 8 TO keylen-1 DO BEGIN
@@ -163,20 +167,18 @@ BEGIN
     i := i AND 7;
   END;
   FOR i := 0 TO 7 DO userkey[i] := 0;
-  zi := 0;
 END;
 
 PROCEDURE DeKeyIdea(z: IDEAKey; VAR dk: ideakey);
 VAR j: Integer;
     t1,t2,t3: Word;
     p: IDEAKey;
-    ip,it,idk: Integer;
+    ip: Integer;
     iz: Integer;
 BEGIN
   iz := 0;
   ip := keylen;
   FOR j := 0 TO keylen - 1 DO p[j] := 0;
-  idk := 0;
   t1 := inv(z[iz]);   Inc(iz);
   t2 := not(z[iz])+1; Inc(iz);
   t3 := not(z[iz])+1; Inc(iz);
@@ -202,7 +204,7 @@ BEGIN
   t1 := inv(z[iz]);   Inc(iz);
   t2 := Not(z[iz])+1; Inc(iz);
   t3 := Not(z[iz])+1; Inc(iz);
-  Dec(ip); p[ip] := inv(z[iz]); Inc(iz);
+  Dec(ip); p[ip] := inv(z[iz]);
   Dec(ip); p[ip] := t3;
   Dec(ip); p[ip] := t2;
   Dec(ip); p[ip] := t1;
@@ -211,13 +213,6 @@ BEGIN
     p[j] := 0;
   END;
   FOR j := 0 TO 51 DO z[j] := 0;
-  t1 := 0;
-  t2 := 0;
-  t3 := 0;
-  ip := 0;
-  it := 0;
-  idk := 0;
-  iz := 0;
 END;
 
 PROCEDURE CipherIdea(input: ideacryptdata; VAR outdata: ideacryptdata; z:
@@ -255,19 +250,13 @@ BEGIN
   outdata[3] := x4;
   FOR r := 0 TO 3 DO input[r] := 0;
   FOR r := 0 TO 51 DO z[r] := 0;
-  x1 := 0;
-  x2 := 0;
-  x3 := 0;
-  x4 := 0;
-  t1 := 0;
-  t2 := 0;
-  zi := 0;
 END;
 
 constructor TIDEAEncryptStream.Create(AKey : ideakey; Dest: TStream);
 
 begin
-  FKey:=Key;
+  inherited Create;
+  FKey:=AKey;
   FDest:=Dest;
   FBufPos:=0;
   Fpos:=0;
@@ -289,10 +278,12 @@ Var
 begin
   If FBufPos>0 then
     begin
-    // Fill with spaces.
-    FillChar(PByte(@FData)[FBufPos],SizeOf(FData)-FBufPos,' ');
+    // Fill with nulls
+    FillChar(PChar(@FData)[FBufPos],SizeOf(FData)-FBufPos,#0);
     CipherIdea(Fdata,OutData,FKey);
     FDest.Write(OutData,SizeOf(OutData));
+    // fixed: Manual flush and then free will now work
+    FBufPos := 0;
     end;
 end;
 
@@ -315,7 +306,7 @@ begin
     MVsize:=Count;
     If Mvsize>SizeOf(Fdata)-FBufPos then
       mvsize:=SizeOf(FData)-FBufPos;
-    Move(Pbyte(@Buffer)[Result],PByte(@FData)[FBufPos],MVSize);
+    Move(PChar(@Buffer)[Result],PChar(@FData)[FBufPos],MVSize);
     If FBufPos+mvSize=Sizeof(FData) then
       begin
       // Empty buffer.
@@ -346,7 +337,7 @@ constructor TIDEADeCryptStream.Create(AKey : ideakey; Src: TStream);
 
 begin
   inherited Create;
-  FKey:=Key;
+  FKey:=AKey;
   FPos:=0;
   FBufPos:=SizeOf(Fdata);
   FSrc:=Src;
@@ -373,7 +364,7 @@ begin
       mvSize:=Sizeof(FData)-FBufPos;
       If MvSize>count then
         mvsize:=Count;
-      Move(PByte(@FData)[FBufPos],Pbyte(@Buffer)[Result],MVSize);
+      Move(PChar(@FData)[FBufPos],PChar(@Buffer)[Result],MVSize);
       Dec(Count,mvsize);
       Inc(Result,mvsize);
       inc(fBufPos,mvsize);
@@ -385,8 +376,8 @@ begin
       If mvsize>0 then
         begin
         If MvSize<SizeOf(InData) Then
-          // Fill with spaces
-          FillChar(PByte(@InData)[mvsize],SizeOf(InData)-mvsize,' ');
+          // Fill with nulls
+          FillChar(PChar(@InData)[mvsize],SizeOf(InData)-mvsize,#0);
         CipherIdea(InData,FData,FKey);
         FBufPos:=0;
         end
@@ -399,7 +390,7 @@ end;
 
 function TIDEADeCryptStream.Write(const Buffer; Count: Longint): Longint;
 begin
-  Raise EIDEAError.Create(SNoReadAllowed);
+  Raise EIDEAError.Create(SNoWriteAllowed);
 end;
 
 function TIDEADeCryptStream.Seek(Offset: Longint; Origin: Word): Longint;
@@ -425,7 +416,10 @@ END.
 
 {
   $Log$
-  Revision 1.1.2.1  2000-07-30 18:11:37  peter
+  Revision 1.1.2.2  2000-08-04 21:27:17  peter
+    * applied patch from Paul te Bokkel
+
+  Revision 1.1.2.1  2000/07/30 18:11:37  peter
   *** empty log message ***
 
   Revision 1.1  2000/07/13 06:31:30  michael