Skip to content

Commit

Permalink
Fix div by 0 error on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Grieve committed Mar 11, 2024
1 parent 6d20976 commit cd2893b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions library/fsl/fsl_scrypt.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1017,11 +1017,15 @@ class function TScrypt.CheckPassword(const Passphrase: String; ExpectedHashStrin
if not scrypt.TryParseHashString(ExpectedHashString, {out}costFactor, blockSizeFactor, parallelizationFactor, salt, expected) then
raise EScryptException.Create(SCouldNotParsePassword);
try
{$IFNDEF FPC}
{$IFDEF FPC}
t1 := GetTickCount64;
{$ELSE}
QueryPerformanceCounter(t1);
{$ENDIF}
actual := scrypt.DeriveBytes(Passphrase, salt, costFactor, blockSizeFactor, ParallelizationFactor, Length(expected));
{$IFNDEF FPC}
{$IFDEF FPC}
t2 := GetTickCount64;
{$ELSE}
QueryPerformanceCounter(t2);
{$ENDIF}

Expand All @@ -1035,11 +1039,14 @@ class function TScrypt.CheckPassword(const Passphrase: String; ExpectedHashStrin
//Only advertise a rehash being needed if they got the correct password.
//Don't want someone blindly re-hashing with a bad password because they forgot to check the result,
//or because they decided to handle "PasswordRehashNeeded" first.
{$IFNDEF FPC}
{$IFDEF FPC}
freq := 1;
{$ELSE}
if QueryPerformanceFrequency(freq) then
begin
freq := freq * 1000; // ms
{$ENDIF}
duration := (t2-t1)/freq * 1000; //ms
duration := (t2-t1)/freq;
if duration < 250 then
PasswordRehashNeeded := True;
{$IFNDEF FPC}
Expand Down

0 comments on commit cd2893b

Please sign in to comment.