summaryrefslogtreecommitdiff
path: root/packages/hash
diff options
context:
space:
mode:
authorivost <ivost@3ad0048d-3df7-0310-abae-a5850022a9f2>2009-01-20 18:45:56 +0000
committerivost <ivost@3ad0048d-3df7-0310-abae-a5850022a9f2>2009-01-20 18:45:56 +0000
commit09795827effb8e2529dd9b089f6d9775d34ca86c (patch)
tree8db42c87863a097cd9d8ec7b2ed758bdeb41cc04 /packages/hash
parent7a54bec9c760c97f276827a4db266b4008958bd0 (diff)
downloadfpc-09795827effb8e2529dd9b089f6d9775d34ca86c.tar.gz
* 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: http://svn.freepascal.org/svn/fpc/trunk@12578 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/hash')
-rw-r--r--packages/hash/src/crc.pas3
-rw-r--r--packages/hash/src/md5.pp53
2 files changed, 10 insertions, 46 deletions
diff --git a/packages/hash/src/crc.pas b/packages/hash/src/crc.pas
index 1cd33a7acd..64c7c5dd82 100644
--- a/packages/hash/src/crc.pas
+++ b/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_crc_table: Pcardinal; external name 'get_crc32_table';
@@ -199,7 +200,7 @@ const
{ =========================================================================
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
{$ifdef DYNAMIC_CRC_TABLE}
if (crc32_table_empty) then
diff --git a/packages/hash/src/md5.pp b/packages/hash/src/md5.pp
index 6934f5fe65..48e4ad71e5 100644
--- a/packages/hash/src/md5.pp
+++ b/packages/hash/src/md5.pp
@@ -51,9 +51,10 @@ type
TMD5Digest = TMDDigest;
PMDContext = ^TMDContext;
+ TMDHashFunc = procedure(Context: PMDContext; Buffer: Pointer);
TMDContext = record
Version : TMDVersion;
- Hash : procedure(Context: PMDContext; Buffer: Pointer);
+ Hash : TMDHashFunc;
Align : PtrUInt;
State : array[0..3] of Cardinal;
BufCnt : QWord;
@@ -363,10 +364,10 @@ begin
MD_VERSION_4, MD_VERSION_5:
begin
- {if Version = MD_VERSION_4 then
- Context.Hash := @MD4Transform
+ if Version = MD_VERSION_4 then
+ Context.Hash := TMDHashFunc(@MD4Transform)
else
- Context.Hash := @MD5Transform;}
+ Context.Hash := TMDHashFunc(@MD5Transform);
Context.Align := 64;
Context.State[0] := $67452301;
Context.State[1] := $efcdab89;
@@ -379,7 +380,7 @@ begin
MD_VERSION_2:
begin
Context.Align := 16;
- //Context.Hash := @@MD2Transform
+ Context.Hash := TMDHashFunc(@MD2Transform)
end;
end;
@@ -414,11 +415,7 @@ begin
// 1.2 If buffer contains "Align" bytes, transform it
if Context.BufCnt = Align then
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;
end;
end;
@@ -427,11 +424,7 @@ begin
Num := BufLen - Num;
while Num >= Align do
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);
Num := Num - Align;
end;
@@ -570,46 +563,16 @@ begin
MDInit(Context, MD_VERSION_2);
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);
begin
MDInit(Context, MD_VERSION_4);
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);
begin
MDInit(Context, MD_VERSION_5);
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;
begin
Result := MDString(S, MD_VERSION_2);