use Org\Mxchange\CoreFramework\Feature\FrameworkFeature;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* This file contains a 'core-d' version of the example helper classes for the
* php-scrypt extension. It has been renamed from scrypt.php to this name so the
* As with all cryptographic code; it is recommended that you use a tried and
* tested library which uses this library; rather than rolling your own.
*
- * PHP version 5
+ * PHP version 8
*
* @category Security
* @package Scrypt
*/
abstract class Scrypt extends BaseFrameworkSystem
{
-
/**
*
* @var int The key length
*
* @return int
*/
- protected static function strlen ($str) {
+ protected static function strlen (string $str): int
+ {
static $isShadowed = null;
if ($isShadowed === null) {
*
* @return string The salt
*/
- public static function generateScryptSalt ($length = 8)
+ public static function generateScryptSalt (int $length = 8): str
{
$buffer = '';
$buffer_valid = false;
*
* @return string The hashed password
*/
- public static function hashScrypt ($password, $salt = false, $N = 16384, $r = 8, $p = 1)
+ public static function hashScrypt (string $password, string $salt = '', int $N = 16384, int $r = 8, int $p = 1): str
{
if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
// Feature has been disabled
- throw new \InvalidArgumentException('Feature "scrypt" disabled.');
+ throw new InvalidArgumentException('Feature "scrypt" disabled.');
}
if ($N == 0 || ($N & ($N - 1)) != 0) {
- throw new \InvalidArgumentException('N must be > 0 and a power of 2');
+ throw new InvalidArgumentException('N must be > 0 and a power of 2');
}
if ($N > PHP_INT_MAX / 128 / $r) {
- throw new \InvalidArgumentException('Parameter N is too large');
+ throw new InvalidArgumentException('Parameter N is too large');
}
if ($r > PHP_INT_MAX / 128 / $p) {
- throw new \InvalidArgumentException('Parameter r is too large');
+ throw new InvalidArgumentException('Parameter r is too large');
}
if ($salt === false) {
*
* @return boolean If the clear text matches
*/
- public static function checkScrypt ($password, $hash)
+ public static function checkScrypt (string $password, string $hash): bool
{
// Is there actually a hash?
if (!$hash) {
if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
// Feature has been disabled
- throw new \InvalidArgumentException('Feature "scrypt" disabled.');
+ throw new InvalidArgumentException('Feature "scrypt" disabled.');
}
list ($N, $r, $p, $salt, $hash) = explode('$', $hash);
*
* @return boolean If the two strings match.
*/
- public static function compareScryptHashes ($expected, $actual)
+ public static function compareScryptHashes (string $expected, string $actual): bool
{
$expected = (string) $expected;
$actual = (string) $actual;
return ($result === 0);
}
+
}