From cd2893be7efcb05e68e690ea62dd4a45829a8521 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 11 Mar 2024 15:21:04 +1100 Subject: [PATCH] Fix div by 0 error on linux --- library/fsl/fsl_scrypt.pas | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/library/fsl/fsl_scrypt.pas b/library/fsl/fsl_scrypt.pas index beb540da0..29835c063 100644 --- a/library/fsl/fsl_scrypt.pas +++ b/library/fsl/fsl_scrypt.pas @@ -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} @@ -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}