Browse Source

* completed md5.pp fixes (forgot to uncomment some code pieces)
* readded get_crc_table to keep backward compatibility. it is aliased now to get_crc32_table

git-svn-id: trunk@12578 -

ivost 16 years ago
parent
commit
cd00ccbb6d
2 changed files with 10 additions and 46 deletions
  1. 2 1
      packages/hash/src/crc.pas
  2. 8 45
      packages/hash/src/md5.pp

+ 2 - 1
packages/hash/src/crc.pas

@@ -49,6 +49,7 @@ function crc32(crc: cardinal; buf: Pbyte; len: cardinal): cardinal;
 }
 }
 
 
 function get_crc32_table: Pcardinal;  { can be used by asm versions of crc32() }
 function get_crc32_table: Pcardinal;  { can be used by asm versions of crc32() }
+function get_crc_table: Pcardinal; external name 'get_crc32_table';
 
 
 
 
 
 
@@ -199,7 +200,7 @@ const
 { =========================================================================
 { =========================================================================
   This function can be used by asm versions of crc32() }
   This function can be used by asm versions of crc32() }
 
 
-function get_crc32_table : {const} Pcardinal;
+function get_crc32_table : {const} Pcardinal; [public,alias:'get_crc32_table'];
 begin
 begin
 {$ifdef DYNAMIC_CRC_TABLE}
 {$ifdef DYNAMIC_CRC_TABLE}
   if (crc32_table_empty) then
   if (crc32_table_empty) then

+ 8 - 45
packages/hash/src/md5.pp

@@ -51,9 +51,10 @@ type
   TMD5Digest = TMDDigest;
   TMD5Digest = TMDDigest;
 
 
   PMDContext = ^TMDContext;
   PMDContext = ^TMDContext;
+  TMDHashFunc = procedure(Context: PMDContext; Buffer: Pointer);
   TMDContext = record
   TMDContext = record
     Version : TMDVersion;
     Version : TMDVersion;
-    Hash    : procedure(Context: PMDContext; Buffer: Pointer);
+    Hash    : TMDHashFunc;
     Align   : PtrUInt;
     Align   : PtrUInt;
     State   : array[0..3] of Cardinal;
     State   : array[0..3] of Cardinal;
     BufCnt  : QWord;
     BufCnt  : QWord;
@@ -363,10 +364,10 @@ begin
 
 
     MD_VERSION_4, MD_VERSION_5:
     MD_VERSION_4, MD_VERSION_5:
       begin
       begin
-        {if Version = MD_VERSION_4 then
-          Context.Hash := @MD4Transform
+        if Version = MD_VERSION_4 then
+          Context.Hash := TMDHashFunc(@MD4Transform)
         else
         else
-          Context.Hash := @MD5Transform;}
+          Context.Hash := TMDHashFunc(@MD5Transform);
         Context.Align := 64;
         Context.Align := 64;
         Context.State[0] := $67452301;
         Context.State[0] := $67452301;
         Context.State[1] := $efcdab89;
         Context.State[1] := $efcdab89;
@@ -379,7 +380,7 @@ begin
     MD_VERSION_2:
     MD_VERSION_2:
       begin
       begin
         Context.Align := 16;
         Context.Align := 16;
-        //Context.Hash := @@MD2Transform
+        Context.Hash := TMDHashFunc(@MD2Transform)
       end;
       end;
 
 
   end;
   end;
@@ -414,11 +415,7 @@ begin
     // 1.2 If buffer contains "Align" bytes, transform it
     // 1.2 If buffer contains "Align" bytes, transform it
     if Context.BufCnt = Align then
     if Context.BufCnt = Align then
     begin
     begin
-      case Context.Version of
-        MD_VERSION_2: MD2Transform(Context, @Context.Buffer);
-        MD_VERSION_4: MD4Transform(Context, @Context.Buffer);
-        MD_VERSION_5: MD5Transform(Context, @Context.Buffer);
-      end;
+      Context.Hash(@Context, @Context.Buffer);
       Context.BufCnt := 0;
       Context.BufCnt := 0;
     end;
     end;
   end;
   end;
@@ -427,11 +424,7 @@ begin
   Num := BufLen - Num;
   Num := BufLen - Num;
   while Num >= Align do
   while Num >= Align do
   begin
   begin
-    case Context.Version of
-      MD_VERSION_2: MD2Transform(Context, Src);
-      MD_VERSION_4: MD4Transform(Context, Src);
-      MD_VERSION_5: MD5Transform(Context, Src);
-    end;
+    Context.Hash(@Context, Src);
     Src := Pointer(PtrUInt(Src) + Align);
     Src := Pointer(PtrUInt(Src) + Align);
     Num := Num - Align;
     Num := Num - Align;
   end;
   end;
@@ -570,46 +563,16 @@ begin
   MDInit(Context, MD_VERSION_2);
   MDInit(Context, MD_VERSION_2);
 end;
 end;
 
 
-{procedure MD2Update(var Context: TMD2Context; var Buf; const BufLen: PtrUInt);
-begin
-  MDUpdate(Context, Buf, BufLen);
-end;
-
-procedure MD2Final(var Context: TMD2Context; var Digest: TMD2Digest);
-begin
-  MDFinal(Context, Digest);
-end;}
-
 procedure MD4Init(var Context: TMD4Context);
 procedure MD4Init(var Context: TMD4Context);
 begin
 begin
   MDInit(Context, MD_VERSION_4);
   MDInit(Context, MD_VERSION_4);
 end;
 end;
 
 
-{procedure MD4Update(var Context: TMD4Context; var Buf; const BufLen: PtrUInt);
-begin
-  MDUpdate(Context, Buf, BufLen);
-end;
-
-procedure MD4Final(var Context: TMD4Context; var Digest: TMD4Digest);
-begin
-  MDFinal(Context, Digest);
-end;}
-
 procedure MD5Init(var Context: TMD5Context);
 procedure MD5Init(var Context: TMD5Context);
 begin
 begin
   MDInit(Context, MD_VERSION_5);
   MDInit(Context, MD_VERSION_5);
 end;
 end;
 
 
-{procedure MD5Update(var Context: TMD5Context; var Buf; const BufLen: PtrUInt);
-begin
-  MDUpdate(Context, Buf, BufLen);
-end;
-
-procedure MD5Final(var Context: TMD5Context; var Digest: TMD5Digest);
-begin
-  MDFinal(Context, Digest);
-end;}
-
 function MD2String(const S: String): TMD2Digest;
 function MD2String(const S: String): TMD2Digest;
 begin
 begin
   Result := MDString(S, MD_VERSION_2);
   Result := MDString(S, MD_VERSION_2);