Browse Source

* PChar -> PAnsiChar

Michaël Van Canneyt 2 years ago
parent
commit
d661e7288b

+ 6 - 6
packages/hash/examples/crctest.pas

@@ -8,8 +8,8 @@ uses
   crc;
 
 const
-  testseq1: string = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGTVIRGATTSYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
-  testseq2: string = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGDVIRGATTHYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
+  testseq1: RawByteString = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGTVIRGATTSYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
+  testseq2: RawByteString = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGDVIRGATTHYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
 
   test1_crc128: u128 = (lo:14444300186948028230; hi:0);
   test2_crc128: u128 = (lo:3310614217963326015; hi:0);
@@ -19,13 +19,13 @@ const
   test2_crc32: longword = 1264209917;
 
 
-function IntToStr128(v: u128): string;
+function IntToStr128(v: u128): RawByteString;
 begin
   result := 'todo';
 end;
 
 
-procedure perform_crc32(const name, testcase: string; result: longword);
+procedure perform_crc32(const name, testcase: RawByteString; result: longword);
 var
   crc: longword;
 begin
@@ -39,7 +39,7 @@ begin
     writeln('failed (got=',crc,',expected=',result,')');
 end;
 
-procedure perform_crc64(const name, testcase: string; result: qword);
+procedure perform_crc64(const name, testcase: RawByteString; result: qword);
 var
   crc: qword;
 begin
@@ -53,7 +53,7 @@ begin
     writeln('failed (got=',crc,',expected=',result,')');
 end;
 
-procedure perform_crc128(const name, testcase: string; result: u128);
+procedure perform_crc128(const name, testcase: RawByteString; result: u128);
 var
   crc: u128;
 begin

+ 22 - 3
packages/hash/examples/hsha1.pp

@@ -1,15 +1,34 @@
 // See some samples in: http://en.wikipedia.org/wiki/Hash-based_message_authentication_code
 program hsha1;
 
-{$mode objfpc}{$H+}
+{$mode objfpc}
+{$H+}
 
 uses
+{$ifdef unix}
+  cwstring,
+{$endif}
   HMAC;
 
+var
+  S : String;
+
 begin
   // for HMAC_SHA1("", "") = 0xfbdb1d1b18aa6c08324b7d64b71fb76370690e1d
-  WriteLn('Example 1: ', HMACSHA1Print(HMACSHA1Digest('', '')));
+  S:=HMACSHA1Print(HMACSHA1Digest('', ''));
+  WriteLn('Example 1: ', S);
+  if (S<>'fbdb1d1b18aa6c08324b7d64b71fb76370690e1d') then
+    begin
+    Writeln('Failed 1');
+    Halt(1);
+    end;
   // for HMAC_SHA1("key", "The quick brown fox jumps over the lazy dog") = 0xde7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9
-  WriteLn('Example 2: ', HMACSHA1('key', 'The quick brown fox jumps over the lazy dog'));
+  S:=HMACSHA1('key', 'The quick brown fox jumps over the lazy dog');
+  WriteLn('Example 2: ', S);
+  if (S<>'de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9') then
+    begin
+    Writeln('Failed 2');
+    Halt(2);
+    end;
 end.
 

+ 6 - 3
packages/hash/examples/md5performancetest.pas

@@ -3,16 +3,19 @@ program md5performancetest;
 {$mode objfpc}{$H+}
 
 uses
-  {$IFDEF UNIX}{$IFDEF UseCThreads}
+  {$IFDEF UNIX}
+  cwstring,
+  {$IFDEF UseCThreads}
   cthreads,
-  {$ENDIF}{$ENDIF}
+  {$ENDIF}
+  {$ENDIF}
   SysUtils,Classes,md5,dateutils;
 
 var
   StartTime: TDateTime;
   EndTime: TDateTime;
   i: integer;
-  s,ss: string;
+  s,ss: RawByteString;
 begin
   writeln('MD5 of a million "a" symbols');
   Writeln('x86 only: compile md5 unit with -dMD5SLOW to use unoptimized original version');

+ 3 - 0
packages/hash/examples/mdtest.pas

@@ -18,6 +18,9 @@ program mdtest;
 {$mode objfpc}{$h+}
 
 uses
+{$ifdef unix}
+  cwstring,
+{$endif}
   SysUtils, md5;
 
 const

+ 1 - 1
packages/hash/examples/sha1performancetest.pas

@@ -12,7 +12,7 @@ var
   StartTime: TDateTime;
   EndTime: TDateTime;
   i: integer;
-  s,ss: string;
+  s,ss: RawByteString;
 begin
   writeln('MD5 of a million "a" symbols');
   Writeln('compile sha unit with -dSHA1SLOW to use unoptimized original version');

+ 11 - 4
packages/hash/examples/sha1test.pp

@@ -1,12 +1,19 @@
 program sha1test;
-{$mode objfpc}{$h+}
 
-uses SysUtils, sha1;
+{$mode objfpc}
+{$h+}
+
+uses 
+  {$ifdef unix}
+  cwstring,
+  {$endif}
+  SysUtils, sha1;
 
 function performTest: cardinal;
+
 // Runs test and returns result code (0=success)
 var
-  s, sdig: string;
+  s, sdig: rawbytestring;
   i: integer;
   ctx: TSHA1Context;
   d: TSHA1Digest;
@@ -25,7 +32,7 @@ begin
   for i := 1 to 1000 do s[i] := 'a';
   SHA1Init(ctx);
   for i := 0 to 999 do
-    SHA1Update(ctx, PChar(s)^, 1000);
+    SHA1Update(ctx, PAnsiChar(s)^, 1000);
   SHA1Final(ctx, d);
   sdig := SHA1Print(d);
   if sdig <> '34aa973cd4c4daa4f61eeb2bdbad27316534016f' then

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

@@ -388,7 +388,7 @@ begin
   get_crc64_table :=  {const} PQWord(@crc64_table);
 end;
 
-{void crc64(char *seq, char *res)
+{void crc64(AnsiChar *seq, AnsiChar *res)
 
     int i, j, low, high;
     unsigned long long crc = INITIALCRC64, part;

+ 28 - 28
packages/hash/src/hmac.pp

@@ -25,15 +25,15 @@ type
   THMACMD5Digest = TMD5Digest;
   THMACSHA1Digest = TSHA1Digest;
 
-function HMACMD5Digest(const AKey, AMessage: string): THMACMD5Digest;
+function HMACMD5Digest(const AKey, AMessage: RawByteString): THMACMD5Digest;
 function HMACMD5Print(const ADigest: THMACMD5Digest): string; inline;
 function HMACMD5Match(const ADigest1, ADigest2: THMACMD5Digest): boolean; inline;
-function HMACMD5(const AKey, AMessage: string): string; inline;
+function HMACMD5(const AKey, AMessage: RawByteString): string; inline;
 
-function HMACSHA1Digest(const AKey, AMessage: string): THMACSHA1Digest;
+function HMACSHA1Digest(const AKey, AMessage: RawByteString): THMACSHA1Digest;
 function HMACSHA1Print(const ADigest: THMACSHA1Digest): string; inline;
 function HMACSHA1Match(const ADigest1, ADigest2: THMACSHA1Digest): boolean; inline;
-function HMACSHA1(const AKey, AMessage: string): string; inline;
+function HMACSHA1(const AKey, AMessage: RawByteString): string; inline;
 
 implementation
 
@@ -43,10 +43,10 @@ const
   SHA1_BLOCK_SIZE = 64;
   SHA1_BLOCK_COUNT = 20;
 
-function MD5Raw(var ABuffer; const ABufferLength: PtrUInt): string;
+function MD5Raw(var ABuffer; const ABufferLength: PtrUInt): RawByteString;
 var
   I: Byte;
-  VDest: PChar;
+  VDest: PAnsiChar;
   VDigest: TMD5Digest;
   VContext: TMD5Context;
 begin
@@ -57,17 +57,17 @@ begin
   VDest := Pointer(Result);
   for I := 0 to MD5_BLOCK_COUNT - 1 do
   begin
-    VDest^ := Char(VDigest[I]);
+    VDest^ := AnsiChar(VDigest[I]);
     Inc(VDest);
   end;
 end;
 
-function HMACMD5Digest(const AKey, AMessage: string): THMACMD5Digest;
+function HMACMD5Digest(const AKey, AMessage: RawByteString): THMACMD5Digest;
 var
   I: Byte;
   VLength: PtrUInt;
-  PKey, POPad, PIPad: PChar;
-  VKey, VOPad, VIPad: string;
+  PKey, POPad, PIPad: PAnsiChar;
+  VKey, VOPad, VIPad: RawByteString;
 begin
   VLength := Length(AKey);
   if VLength > MD5_BLOCK_SIZE then
@@ -83,16 +83,16 @@ begin
     VKey := AKey + VKey;
   end;
   SetLength(VOPad, MD5_BLOCK_SIZE);
-  POPad := PChar(VOPad);
+  POPad := PAnsiChar(VOPad);
   FillChar(POPad^, MD5_BLOCK_SIZE, $5c);
   SetLength(VIPad, MD5_BLOCK_SIZE);
-  PIPad := PChar(VIPad);
+  PIPad := PAnsiChar(VIPad);
   FillChar(PIPad^, MD5_BLOCK_SIZE, $36);
-  PKey := PChar(VKey);
+  PKey := PAnsiChar(VKey);
   for I := 1 to VLength do
   begin
-    POPad^ := Char(Ord(POPad^) xor Ord(PKey^));
-    PIPad^ := Char(Ord(PIPad^) xor Ord(PKey^));
+    POPad^ := AnsiChar(Ord(POPad^) xor Ord(PKey^));
+    PIPad^ := AnsiChar(Ord(PIPad^) xor Ord(PKey^));
     Inc(POPad);
     Inc(PIPad);
     Inc(PKey);
@@ -111,15 +111,15 @@ begin
   Result := MD5Match(ADigest1, ADigest2);
 end;
 
-function HMACMD5(const AKey, AMessage: string): string;
+function HMACMD5(const AKey, AMessage: RawByteString): string;
 begin
   Result := HMACMD5Print(HMACMD5Digest(AKey, AMessage));
 end;
 
-function SHA1Raw(const ABuffer; const ABufferLength: PtrUInt): string;
+function SHA1Raw(const ABuffer; const ABufferLength: PtrUInt): RawByteString;
 var
   I: Byte;
-  VDest: PChar;
+  VDest: PAnsiChar;
   VDigest: TSHA1Digest;
   VContext: TSHA1Context;
 begin
@@ -130,17 +130,17 @@ begin
   VDest := Pointer(Result);
   for I := 0 to SHA1_BLOCK_COUNT - 1 do
   begin
-    VDest^ := Char(VDigest[I]);
+    VDest^ := AnsiChar(VDigest[I]);
     Inc(VDest);
   end;
 end;
 
-function HMACSHA1Digest(const AKey, AMessage: string): THMACSHA1Digest;
+function HMACSHA1Digest(const AKey, AMessage: RawByteString): THMACSHA1Digest;
 var
   I: Byte;
   VLength: PtrUInt;
-  PKey, POPad, PIPad: PChar;
-  VKey, VOPad, VIPad: string;
+  PKey, POPad, PIPad: PAnsiChar;
+  VKey, VOPad, VIPad: RawBytestring;
 begin
   // Set up masking block from key.
   VLength := Length(AKey);
@@ -156,18 +156,18 @@ begin
     FillChar(Pointer(VKey)^, SHA1_BLOCK_SIZE - VLength, #0);
     VKey := AKey + VKey; // VKEY now has length SHA1_BLOCK_SIZE
   end;
-  PKey := PChar(VKey);
+  PKey := PAnsiChar(VKey);
   // Padding blocks
   SetLength(VOPad, SHA1_BLOCK_SIZE);
-  POPad := PChar(VOPad);
+  POPad := PAnsiChar(VOPad);
   FillChar(POPad^, SHA1_BLOCK_SIZE, $5c);
   SetLength(VIPad, SHA1_BLOCK_SIZE);
-  PIPad := PChar(VIPad);
+  PIPad := PAnsiChar(VIPad);
   FillChar(PIPad^, SHA1_BLOCK_SIZE, $36);
   for I := 1 to SHA1_BLOCK_SIZE do
   begin
-    POPad^ := Char(Ord(POPad^) xor Ord(PKey^));
-    PIPad^ := Char(Ord(PIPad^) xor Ord(PKey^));
+    POPad^ := AnsiChar(Ord(POPad^) xor Ord(PKey^));
+    PIPad^ := AnsiChar(Ord(PIPad^) xor Ord(PKey^));
     Inc(POPad);
     Inc(PIPad);
     Inc(PKey);
@@ -186,7 +186,7 @@ begin
   Result := SHA1Match(ADigest1, ADigest2);
 end;
 
-function HMACSHA1(const AKey, AMessage: string): string;
+function HMACSHA1(const AKey, AMessage: RawByteString): string;
 begin
   Result := HMACSHA1Print(HMACSHA1Digest(AKey, AMessage));
 end;

+ 11 - 11
packages/hash/src/md5.pp

@@ -122,7 +122,7 @@ procedure MDFinal(var Context: TMDContext; out Digest: TMDDigest);
  * Auxilary functions
  ******************************************************************************)
 
-function MDString(const S: String; const Version: TMDVersion): TMDDigest;
+function MDString(const S: RawByteString; const Version: TMDVersion): TMDDigest;
 function MDBuffer(var Buf; const BufLen: PtrUInt; const Version: TMDVersion): TMDDigest;
 function MDFile(const Filename: RawByteString; const Version: TMDVersion; const Bufsize: PtrUInt = MDDefBufSize): TMDDigest;
 function MDFile(const Filename: UnicodeString; const Version: TMDVersion; const Bufsize: PtrUInt = MDDefBufSize): TMDDigest;
@@ -156,17 +156,17 @@ procedure MD5Final(var Context: TMD5Context; out Digest: TMD5Digest); external n
  * Dedicated auxilary functions
  ******************************************************************************)
 
-function MD2String(const S: String): TMD2Digest; inline;
+function MD2String(const S: RawByteString): TMD2Digest; inline;
 function MD2Buffer(var Buf; const BufLen: PtrUInt): TMD2Digest;
 function MD2File(const Filename: RawByteString; const Bufsize: PtrUInt = MDDefBufSize): TMD2Digest; overload; inline;
 function MD2File(const Filename: UnicodeString; const Bufsize: PtrUInt = MDDefBufSize): TMD2Digest; overload; inline;
 
-function MD4String(const S: String): TMD4Digest; inline;
+function MD4String(const S: RawByteString): TMD4Digest; inline;
 function MD4Buffer(var Buf; const BufLen: PtrUInt): TMD4Digest;
 function MD4File(const Filename: RawByteString; const Bufsize: PtrUInt = MDDefBufSize): TMD4Digest; inline;
 function MD4File(const Filename: UnicodeString; const Bufsize: PtrUInt = MDDefBufSize): TMD4Digest; inline;
 
-function MD5String(const S: String): TMD5Digest; inline;
+function MD5String(const S: RawByteString): TMD5Digest; inline;
 function MD5Buffer(var Buf; const BufLen: PtrUInt): TMD5Digest;
 function MD5File(const Filename: RawByteString; const Bufsize: PtrUInt = MDDefBufSize): TMD5Digest; inline;
 function MD5File(const Filename: UnicodeString; const Bufsize: PtrUInt = MDDefBufSize): TMD5Digest; inline;
@@ -650,12 +650,12 @@ begin
   FillChar(Context, SizeOf(TMDContext), 0);
 end;
 
-function MDString(const S: String; const Version: TMDVersion): TMDDigest;
+function MDString(const S: RawByteString; const Version: TMDVersion): TMDDigest;
 var
   Context: TMDContext;
 begin
   MDInit(Context, Version);
-  MDUpdate(Context, PChar(S)^, length(S));
+  MDUpdate(Context, PAnsiChar(S)^, length(S));
   MDFinal(Context, Result);
 end;
 
@@ -671,7 +671,7 @@ end;
 function MDFile(const Filename: RawByteString; const Version: TMDVersion; const BufSize: PtrUInt): TMDDigest;
 var
   F: File;
-  Buf: Pchar;
+  Buf: PAnsiChar;
   Context: TMDContext;
   Count: Cardinal;
   ofm: Longint;
@@ -704,7 +704,7 @@ end;
 function MDFile(const Filename: UnicodeString; const Version: TMDVersion; const BufSize: PtrUInt): TMDDigest;
 var
   F: File;
-  Buf: Pchar;
+  Buf: PAnsiChar;
   Context: TMDContext;
   Count: Cardinal;
   ofm: Longint;
@@ -770,7 +770,7 @@ begin
   MDInit(Context, MD_VERSION_5);
 end;
 
-function MD2String(const S: String): TMD2Digest;
+function MD2String(const S: RawByteString): TMD2Digest;
 begin
   Result := MDString(S, MD_VERSION_2);
 end;
@@ -790,7 +790,7 @@ begin
   Result := MDFile(Filename, MD_VERSION_2, Bufsize);
 end;
 
-function MD4String(const S: String): TMD4Digest;
+function MD4String(const S: RawByteString): TMD4Digest;
 begin
   Result := MDString(S, MD_VERSION_4);
 end;
@@ -810,7 +810,7 @@ begin
   Result := MDFile(Filename, MD_VERSION_4, Bufsize);
 end;
 
-function MD5String(const S: String): TMD5Digest;
+function MD5String(const S: RawByteString): TMD5Digest;
 begin
   Result := MDString(S, MD_VERSION_5);
 end;

+ 6 - 6
packages/hash/src/ntlm.pas

@@ -23,8 +23,8 @@ uses
   Math, Strings, md5;
 
 
-function LMGenerate(const Password: PChar): TMDDigest;
-function NTGenerate(const Password: PChar): TMDDigest;
+function LMGenerate(const Password: PAnsiChar): TMDDigest;
+function NTGenerate(const Password: PAnsiChar): TMDDigest;
 
 implementation
 
@@ -331,7 +331,7 @@ begin
 end;*)
 
 
-function LMGenerate(const Password: PChar): TMDDigest;
+function LMGenerate(const Password: PAnsiChar): TMDDigest;
 var
   dospwd: array[0..14] of Byte;
 begin
@@ -341,8 +341,8 @@ begin
   FillChar(dospwd, Sizeof(dospwd), 0);
 
   (* Password must be converted to DOS charset - null terminated, uppercase *)
-  StrLCopy(PChar(@dospwd[0]), PChar(@Password[0]), SizeOf(dospwd)-1);
-  StrUpper(PChar(@dospwd[0]));
+  StrLCopy(PAnsiChar(@dospwd[0]), PAnsiChar(@Password[0]), SizeOf(dospwd)-1);
+  StrUpper(PAnsiChar(@dospwd[0]));
 
   (* Only the first 14 chars are considered, password need not be null terminated *)
   E_P16(@dospwd[0], @Result);
@@ -351,7 +351,7 @@ begin
 end;
 
 
-function NTGenerate(const Password: PChar): TMDDigest;
+function NTGenerate(const Password: PAnsiChar): TMDDigest;
 var
   pos: Integer;
   wpwd: array[0..127] of WideChar;

+ 5 - 5
packages/hash/src/sha1.pp

@@ -41,7 +41,7 @@ procedure SHA1Update(var ctx: TSHA1Context; const Buf; BufLen: PtrUInt);
 procedure SHA1Final(var ctx: TSHA1Context; out Digest: TSHA1Digest);
 
 { auxiliary }
-function SHA1String(const S: String): TSHA1Digest;
+function SHA1String(const S: RawByteString): TSHA1Digest;
 function SHA1Buffer(const Buf; BufLen: PtrUInt): TSHA1Digest;
 function SHA1File(const Filename: String; const Bufsize: PtrUInt = 1024): TSHA1Digest;
 
@@ -241,12 +241,12 @@ begin
   FillChar(ctx, sizeof(TSHA1Context), 0);
 end;
 
-function SHA1String(const S: String): TSHA1Digest;
+function SHA1String(const S: RawByteString): TSHA1Digest;
 var
   Context: TSHA1Context;
 begin
   SHA1Init(Context);
-  SHA1Update(Context, PChar(S)^, length(S));
+  SHA1Update(Context, PAnsiChar(S)^, length(S));
   SHA1Final(Context, Result);
 end;
 
@@ -267,7 +267,7 @@ end;
 function SHA1File(const Filename: String; const Bufsize: PtrUInt): TSHA1Digest;
 var
   F: File;
-  Buf: Pchar;
+  Buf: PAnsiChar;
   Context: TSHA1Context;
   Count: Cardinal;
   ofm: Longint;
@@ -300,7 +300,7 @@ begin
 end;
 
 const
-  HexTbl: array[0..15] of char='0123456789abcdef';     // lowercase
+  HexTbl: array[0..15] of AnsiChar='0123456789abcdef';     // lowercase
 
 function SHA1Print(const Digest: TSHA1Digest): String;
 var

+ 15 - 15
packages/hash/src/unixcrypt.pas

@@ -9,30 +9,30 @@ interface
 uses
   ctypes;
 
-function crypt(const key: pchar; const salt: pchar): pchar; cdecl; external;
+function crypt(const key: PAnsiChar; const salt: PAnsiChar): PAnsiChar; cdecl; external;
 
 // salt helper functions
-function gen_des_salt: string;
-function gen_md5_salt: string;
+function gen_des_salt: RawByteString;
+function gen_md5_salt: RawByteString;
 
 // crypt helper functions
-function crypt_password(const key: string; const UseMD5: boolean): string;
-function validate_password(const key: string; const hash: string): boolean;
+function crypt_password(const key: RawByteString; const UseMD5: boolean): RawByteString;
+function validate_password(const key: RawByteString; const hash: RawByteString): boolean;
 
 implementation
 
 const
-  salt_chars: array[0..63] of char = (
+  salt_chars: array[0..63] of AnsiChar = (
     'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
     'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
     '0','1','2','3','4','5','6','7','8','9','.','/');
 
-function gen_des_salt: string;
+function gen_des_salt: RawByteString;
 begin
   Result := salt_chars[Random(64)] + salt_chars[Random(64)];
 end;
 
-function gen_md5_salt: string;
+function gen_md5_salt: RawByteString;
 var
   i: integer;
 begin
@@ -41,20 +41,20 @@ begin
     Result := Result + salt_chars[Random(64)];
 end;
 
-function crypt_password(const key: string; const UseMD5: boolean): string;
+function crypt_password(const key: RawByteString; const UseMD5: boolean): RawByteString;
 begin
   if UseMD5 then
-    Result := crypt(pchar(key), pchar(gen_md5_salt)) else
-    Result := crypt(pchar(key), pchar(gen_des_salt));
+    Result := crypt(PAnsiChar(key), PAnsiChar(gen_md5_salt)) else
+    Result := crypt(PAnsiChar(key), PAnsiChar(gen_des_salt));
 end;
 
-function validate_password(const key: string; const hash: string): boolean;
+function validate_password(const key: RawByteString; const hash: RawByteString): boolean;
 begin
   Result :=
   // MD5 compare
-    ((Length(hash) = 34) and (hash[1] = '$') and (hash[2] = '1') and (hash[3] = '$') and (hash[12] = '$') and (crypt(pchar(key), pchar(copy(hash, 1, 11))) = hash)) or
+    ((Length(hash) = 34) and (hash[1] = '$') and (hash[2] = '1') and (hash[3] = '$') and (hash[12] = '$') and (crypt(PAnsiChar(key), PAnsiChar(copy(hash, 1, 11))) = hash)) or
   // DES compare
-    ((Length(hash) = 13) and (crypt(pchar(key), pchar(copy(hash, 1, 2))) = hash));
+    ((Length(hash) = 13) and (crypt(PAnsiChar(key), PAnsiChar(copy(hash, 1, 2))) = hash));
 end;
 
-end.
+end.

+ 6 - 6
packages/hash/src/uuid.pas

@@ -93,10 +93,10 @@ function uuid_create(out uuid: uuid_t): boolean;
 procedure uuid_finalize(out state: uuid_state);
 
 { uuid_create_md5_from_name -- create a version 3 (MD5) UUID using a "name" from a "name space" }
-procedure uuid_create_md5_from_name(out uuid: uuid_t; const nsid: uuid_t; const name: string);
+procedure uuid_create_md5_from_name(out uuid: uuid_t; const nsid: uuid_t; const name: RawByteString);
 
 { uuid_create_sha1_from_name -- create a version 5 (SHA-1) UUID using a "name" from a "name space" }
-procedure uuid_create_sha1_from_name(out uuid: uuid_t; const nsid: uuid_t; const name: string);
+procedure uuid_create_sha1_from_name(out uuid: uuid_t; const nsid: uuid_t; const name: RawByteString);
 
 { uuid_compare --  Compare two UUID's "lexically" }
 function uuid_compare(const u1, u2: uuid_t): integer;
@@ -202,7 +202,7 @@ end;
 
 { uuid_create_md5_from_name }
 
-procedure uuid_create_md5_from_name(out uuid: uuid_t; const nsid: uuid_t; const name: string);
+procedure uuid_create_md5_from_name(out uuid: uuid_t; const nsid: uuid_t; const name: RawByteString);
 var
   net_nsid: uuid_t;
   c: TMDContext;
@@ -217,7 +217,7 @@ begin
 
   MDInit(c, MD_VERSION_5);
   MDUpdate(c, net_nsid, sizeof(net_nsid));
-  MDUpdate(c, pchar(name)^, Length(name));
+  MDUpdate(c, PAnsiChar(name)^, Length(name));
   MDFinal(c, hash);
 
   (* the hash is in network byte order at this point *)
@@ -227,7 +227,7 @@ end;
 
 { uuid_create_sha1_from_name }
 
-procedure uuid_create_sha1_from_name(out uuid: uuid_t; const nsid: uuid_t; const name: string);
+procedure uuid_create_sha1_from_name(out uuid: uuid_t; const nsid: uuid_t; const name: RawByteString);
 var
   net_nsid: uuid_t;
   c: TSHA1Context;
@@ -242,7 +242,7 @@ begin
 
   SHA1Init(c);
   SHA1Update(c, net_nsid, sizeof(net_nsid));
-  SHA1Update(c, pchar(name)^, Length(name));
+  SHA1Update(c, PAnsiChar(name)^, Length(name));
   SHA1Final(c, hash);
 
   (* the hash is in network byte order at this point *)

+ 3 - 0
packages/hash/tests/testhash.pp

@@ -5,6 +5,9 @@ program testhash;
 {$mode objfpc}
 
 uses
+{$ifdef unix}
+  cwstring,
+{$endif}
   consoletestrunner, utestshmac;
 
 var