]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 1 Feb 2025 23:32:03 +0000 (00:32 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 1 Feb 2025 23:32:03 +0000 (00:32 +0100)
- added commented-out debug lines
- $salt can no longer be false (boolean) by default as PHP is stricter now,
  let's take and check on an empty string instead

framework/main/classes/scrypt/class_Scrypt.php

index 66683e9c905f7f8f8a76cc5216be730bcee94c35..8f0039179e363f23348ef533df1c013016bc7564 100644 (file)
@@ -62,6 +62,8 @@ abstract class Scrypt extends BaseFrameworkSystem
      */
     protected static function strlen (string $str): int
     {
+        // Trace message
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('[%s:%d]: str=%s - CALLED!', __METHOD__, __LINE__, $str));
         static $isShadowed = null;
 
         if ($isShadowed === null) {
@@ -69,6 +71,7 @@ abstract class Scrypt extends BaseFrameworkSystem
                 ini_get('mbstring.func_overload') & 2;
         }
 
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('[%s:%d]: isShadowed=%d', __METHOD__, __LINE__, (int) $isShadowed));
         if ($isShadowed) {
             return mb_strlen($str, '8bit');
         } else {
@@ -83,8 +86,11 @@ abstract class Scrypt extends BaseFrameworkSystem
      *
      * @return string The salt
      */
-    public static function generateScryptSalt (int $length = 8): str
+    public static function generateScryptSalt (int $length = 8): string
     {
+        // Trace message
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('[%s:%d]: length=%d - CALLED!', __METHOD__, __LINE__, $length));
+
         $buffer = '';
         $buffer_valid = false;
         if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
@@ -122,8 +128,10 @@ abstract class Scrypt extends BaseFrameworkSystem
                 }
             }
         }
+
         $salt = str_replace(array('+', '$'), array('.', ''), base64_encode($buffer));
 
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('[%s:%d]: salt=%s - EXIT!', __METHOD__, __LINE__, $salt));
         return $salt;
     }
 
@@ -140,6 +148,8 @@ abstract class Scrypt extends BaseFrameworkSystem
      */
     public static function hashScrypt (string $password, string $salt = '', int $N = 16384, int $r = 8, int $p = 1): string
     {
+        // Trace message
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('[%s:%d]: password=%s,salt=%s,N=%d,r=%d,p=%d - CALLED!', __METHOD__, __LINE__, $password, $salt, $N, $r, $p));
         if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
             // Feature has been disabled
             throw new InvalidArgumentException('Feature "scrypt" disabled.');
@@ -157,15 +167,19 @@ abstract class Scrypt extends BaseFrameworkSystem
             throw new InvalidArgumentException('Parameter r is too large');
         }
 
-        if ($salt === false) {
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('[%s:%d]: salt=%s - BEFORE!', __METHOD__, __LINE__, $salt))
+        if ($salt === '') {
             $salt = self::generateScryptSalt();
         } else {
             // Remove dollar signs from the salt, as we use that as a separator.
             $salt = str_replace(array('+', '$'), array('.', ''), base64_encode($salt));
         }
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('[%s:%d]: salt=%s - AFTER!', __METHOD__, __LINE__, $salt))
 
         $hash = scrypt($password, $salt, $N, $r, $p, self::$_keyLength);
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('[%s:%d]: hash=%s', __METHOD__, __LINE__, $hash))
 
+        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('[%s:%d]: %d$%d$%d$%s$%s - CALLED!', __METHOD__, __LINE__, $N, $r, $p, $salt, $hash));
         return $N . '$' . $r . '$' . $p . '$' . $salt . '$' . $hash;
     }