Browse Source

fcl-hash: fixed HexStrToBytes

mattias 3 years ago
parent
commit
67905957cb
1 changed files with 4 additions and 6 deletions
  1. 4 6
      packages/fcl-hash/src/fphashutils.pp

+ 4 - 6
packages/fcl-hash/src/fphashutils.pp

@@ -123,7 +123,7 @@ Var
 begin
 begin
   Len:=Length(aHexStr);
   Len:=Length(aHexStr);
   aBytes:=[];
   aBytes:=[];
-  SetLength(aBytes, Len div 2);
+  SetLength(aBytes, (Len+1) div 2);
   if Len=0 then Exit;
   if Len=0 then Exit;
   P := PAnsiChar(aHexStr);
   P := PAnsiChar(aHexStr);
   PResult := PByte(aBytes);
   PResult := PByte(aBytes);
@@ -160,9 +160,9 @@ var
 
 
 begin
 begin
   aHexStr:='';
   aHexStr:='';
-  SetLength(aHexStr,aSize*2);
   if aSize=0 then
   if aSize=0 then
     exit;
     exit;
+  SetLength(aHexStr,aSize*2);
   PB:=aBytes;
   PB:=aBytes;
   PC:=PChar(aHexStr);
   PC:=PChar(aHexStr);
   for I:=0 to aSize-1 do
   for I:=0 to aSize-1 do
@@ -385,9 +385,7 @@ begin
   Result := rs1 xor rs2 xor result;
   Result := rs1 xor rs2 xor result;
 end;
 end;
 
 
-
 function CryptoGetRandomBytes(Buffer: PByte; const Count: Integer): Boolean;
 function CryptoGetRandomBytes(Buffer: PByte; const Count: Integer): Boolean;
-
 var
 var
   I, Remainder, Rounds: Integer;
   I, Remainder, Rounds: Integer;
   Lecuyer: TLecuyer;
   Lecuyer: TLecuyer;
@@ -402,8 +400,8 @@ begin
   if Remainder > 0 then
   if Remainder > 0 then
   begin
   begin
     R := Lecuyer.Next;
     R := Lecuyer.Next;
-    Move(R, PByteArray(Buffer)[Rounds*SizeOf(UInt32)], Remainder);
-    R:=R+R;// Silence compiler warning
+    Move(R, Buffer[Rounds*SizeOf(UInt32)], Remainder);
+    R:=R-R;// Silence compiler warning
   end;
   end;
 end;
 end;