This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
<?php
/**
* The base abstract factory used by all PasswordLib factories
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib;
/**
* The base abstract factory used by all PasswordLib factories
*
* @category PHPPasswordLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
abstract class AbstractFactory {
/**
* Register a type with the factory by name
*
* This is an internal method to check if a provided class name implements
* an interface, and if it does to append that class to an internal array
* by name.
*
* @param string $type The name of the variable to store the class
* @param string $implements The interface to validate against
* @param string $name The name of this particular class
* @param string $class The fully qualified class name
* @param boolean $instantiate Should the class be stored instantiated
*
* @return void
* @throws InvalidArgumentException If class does not implement interface
*/
protected function registerType(
$type,
$implements,
$name,
$class,
$instantiate = false
) {
$name = strtolower($name);
$refl = new \ReflectionClass($class);
if (!$refl->implementsInterface($implements)) {
$message = sprintf('Class must implement %s', $implements);
throw new \InvalidArgumentException($message);
}
if ($instantiate) {
$class = new $class;
}
$this->{$type}[$name] = $class;
}
/**
* Load a set of classes from a directory into the factory
*
* @param string $directory The directory to search for classes in
* @param string $namespace The namespace prefix for any found classes
* @param string $callback The callback with which to register the class
*
* @return void
*/
protected function loadFiles($directory, $namespace, $callback) {
foreach (new \DirectoryIterator($directory) as $file) {
$filename = $file->getBasename();
if ($file->isFile() && substr($filename, -4) == '.php') {
$name = substr($filename, 0, -4);
$class = $namespace . $name;
call_user_func($callback, $name, $class);
}
}
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* A Utility class for converting between raw binary strings and a given
* list of characters
*
* PHP version 5.3
*
* @category PHPSecurityLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib;
/**
* A Utility class for converting between raw binary strings and a given
* list of characters
*
* @category PHPSecurityLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
class BaseConverter {
/**
* Convert from a raw binary string to a string of characters
*
* @param string $string The string to convert from
* @param string $characters The list of characters to convert to
*
* @return string The converted string
*/
public static function convertFromBinary($string, $characters) {
if ($string === '' || empty($characters)) {
return '';
}
$string = str_split($string);
$callback = function($str) {
return ord($str);
};
$string = array_map($callback, $string);
$converted = static::baseConvert($string, 256, strlen($characters));
$callback = function ($num) use ($characters) {
return $characters[$num];
};
$ret = implode('', array_map($callback, $converted));
return $ret;
}
/**
* Convert to a raw binary string from a string of characters
*
* @param string $string The string to convert from
* @param string $characters The list of characters to convert to
*
* @return string The converted string
*/
public static function convertToBinary($string, $characters) {
if (empty($string) || empty($characters)) {
return '';
}
$string = str_split($string);
$callback = function($str) use ($characters) {
return strpos($characters, $str);
};
$string = array_map($callback, $string);
$converted = static::baseConvert($string, strlen($characters), 256);
$callback = function ($num) {
return chr($num);
};
return implode('', array_map($callback, $converted));
}
/**
* Convert an array of input blocks to another numeric base
*
* This function was modified from an implementation found on StackOverflow.
* Special Thanks to @KeithRandall for supplying the implementation.
*
* @param int[] $source The source number, as an array
* @param int $srcBase The source base as an integer
* @param int $dstBase The destination base as an integer
*
* @see http://codegolf.stackexchange.com/questions/1620/arb/1626#1626
* @return int[] An array of integers in the encoded base
*/
public static function baseConvert(array $source, $srcBase, $dstBase) {
if ($dstBase < 2) {
$message = sprintf('Invalid Destination Base: %d', $dstBase);
throw new \InvalidArgumentException($message);
}
$result = array();
$count = count($source);
while ($count) {
$itMax = $count;
$remainder = $count = $loop = 0;
while($loop < $itMax) {
$dividend = $source[$loop++] + $remainder * $srcBase;
$remainder = $dividend % $dstBase;
$res = ($dividend - $remainder) / $dstBase;
if ($count || $res) {
$source[$count++] = $res;
}
}
$result[] = $remainder;
}
return array_reverse($result);
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* A class for arbitrary precision math functions
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib;
/**
* A class for arbitrary precision math functions
*
* @category PHPPasswordLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
abstract class BigMath {
/**
* Get an instance of the big math class
*
* This is NOT a singleton. It simply loads the proper strategy
* given the current server configuration
*
* @return \PasswordLib\Core\BigMath A big math instance
*/
public static function createFromServerConfiguration() {
//@codeCoverageIgnoreStart
if (extension_loaded('gmp')) {
return new \SecurityLib\BigMath\GMP();
} elseif (extension_loaded('bcmath')) {
return new \SecurityLib\BigMath\BCMath();
} else {
return new \SecurityLib\BigMath\PHPMath();
}
//@codeCoverageIgnoreEnd
}
/**
* Add two numbers together
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return A base-10 string of the sum of the two arguments
*/
abstract public function add($left, $right);
/**
* Subtract two numbers
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return A base-10 string of the difference of the two arguments
*/
abstract public function subtract($left, $right);
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* A class for arbitrary precision math functions implemented using bcmath
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Core
* @subpackage BigMath
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib\BigMath;
/**
* A class for arbitrary precision math functions implemented using bcmath
*
* @category PHPPasswordLib
* @package Core
* @subpackage BigMath
*/
class BCMath extends \SecurityLib\BigMath {
/**
* Add two numbers together
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return A base-10 string of the sum of the two arguments
*/
public function add($left, $right) {
return bcadd($left, $right, 0);
}
/**
* Subtract two numbers
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return A base-10 string of the difference of the two arguments
*/
public function subtract($left, $right) {
return bcsub($left, $right);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* A class for arbitrary precision math functions implemented using GMP
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Core
* @subpackage BigMath
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib\BigMath;
/**
* A class for arbitrary precision math functions implemented using GMP
*
* @category PHPPasswordLib
* @package Core
* @subpackage BigMath
*/
class GMP extends \SecurityLib\BigMath {
/**
* Add two numbers together
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return A base-10 string of the sum of the two arguments
*/
public function add($left, $right) {
return gmp_strval(gmp_add($left, $right));
}
/**
* Subtract two numbers
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return A base-10 string of the difference of the two arguments
*/
public function subtract($left, $right) {
return gmp_strval(gmp_sub($left, $right));
}
}

View File

@@ -0,0 +1,170 @@
<?php
/**
* A class for arbitrary precision math functions implemented in PHP
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Core
* @subpackage BigMath
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib\BigMath;
use SecurityLib\BaseConverter;
/**
* A class for arbitrary precision math functions implemented in PHP
*
* @category PHPPasswordLib
* @package Core
* @subpackage BigMath
*/
class PHPMath extends \SecurityLib\BigMath {
/**
* Add two numbers together
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return A base-10 string of the sum of the two arguments
*/
public function add($left, $right) {
if (empty($left)) {
return $right;
} elseif (empty($right)) {
return $left;
}
$negative = '';
if ($left[0] == '-' && $right[0] == '-') {
$negative = '-';
$left = substr($left, 1);
$right = substr($right, 1);
} elseif ($left[0] == '-') {
return $this->subtract($right, substr($left, 1));
} elseif ($right[0] == '-') {
return $this->subtract($left, substr($right, 1));
}
$left = $this->normalize($left);
$right = $this->normalize($right);
$result = BaseConverter::convertFromBinary(
$this->addBinary($left, $right),
'0123456789'
);
return $negative . $result;
}
/**
* Subtract two numbers
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return A base-10 string of the difference of the two arguments
*/
public function subtract($left, $right) {
if (empty($left)) {
return $right;
} elseif (empty($right)) {
return $left;
} elseif ($right[0] == '-') {
return $this->add($left, substr($right, 1));
} elseif ($left[0] == '-') {
return '-' . $this->add(ltrim($left, '-'), $right);
}
$left = $this->normalize($left);
$right = $this->normalize($right);
$results = $this->subtractBinary($left, $right);
$result = BaseConverter::convertFromBinary($results[1], '0123456789');
return $results[0] . $result;
}
/**
* Add two binary strings together
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return string The binary result
*/
protected function addBinary($left, $right) {
$len = max(strlen($left), strlen($right));
$left = str_pad($left, $len, chr(0), STR_PAD_LEFT);
$right = str_pad($right, $len, chr(0), STR_PAD_LEFT);
$result = '';
$carry = 0;
for ($i = 0; $i < $len; $i++) {
$sum = ord($left[$len - $i - 1])
+ ord($right[$len - $i - 1])
+ $carry;
$result .= chr($sum % 256);
$carry = $sum >> 8;
}
while ($carry) {
$result .= chr($carry % 256);
$carry >>= 8;
}
return strrev($result);
}
/**
* Subtract two binary strings using 256's compliment
*
* @param string $left The left argument
* @param string $right The right argument
*
* @return string The binary result
*/
protected function subtractBinary($left, $right) {
$len = max(strlen($left), strlen($right));
$left = str_pad($left, $len, chr(0), STR_PAD_LEFT);
$right = str_pad($right, $len, chr(0), STR_PAD_LEFT);
$right = $this->compliment($right);
$result = $this->addBinary($left, $right);
if (strlen($result) > $len) {
// Positive Result
$carry = substr($result, 0, -1 * $len);
$result = substr($result, strlen($carry));
return array(
'',
$this->addBinary($result, $carry)
);
}
return array('-', $this->compliment($result));
}
/**
* Take the 256 base compliment
*
* @param string $string The binary string to compliment
*
* @return string The complimented string
*/
protected function compliment($string) {
$result = '';
$len = strlen($string);
for ($i = 0; $i < $len; $i++) {
$result .= chr(255 - ord($string[$i]));
}
return $result;
}
/**
* Transform a string number into a binary string using base autodetection
*
* @param string $string The string to transform
*
* @return string The binary transformed number
*/
protected function normalize($string) {
return BaseConverter::convertToBinary(
$string,
'0123456789'
);
}
}

View File

@@ -0,0 +1,117 @@
<?php
/**
* The Enum base class for Enum functionality
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib;
use \ReflectionObject;
/**
* The Enum base class for Enum functionality
*
* This is based off of the SplEnum class implementation (which is only available
* as a PECL extension in 5.3)
*
* @see http://www.php.net/manual/en/class.splenum.php
* @category PHPPasswordLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
abstract class Enum {
/**
* A default value of null is provided. Override this to set your own default
*/
const __DEFAULT = null;
/**
* @var string The name of the constant this instance is using
*/
protected $name = '';
/**
* @var scalar The value of the constant this instance is using.
*/
protected $value = '';
/**
* Creates a new value of the Enum type
*
* @param mixed $value The value this instance represents
* @param boolean $strict Not Implemented at this time
*
* @return void
* @throws UnexpectedValueException If the value is not a constant
*/
public function __construct($value = null, $strict = false) {
if (is_null($value)) {
$value = static::__DEFAULT;
}
$validValues = $this->getConstList();
$this->name = array_search($value, $validValues);
if (!$this->name) {
throw new \UnexpectedValueException(
'Value not a const in enum ' . get_class($this)
);
}
$this->value = $value;
}
/**
* Cast the current object to a string and return its value
*
* @return mixed the current value of the instance
*/
public function __toString() {
return (string) $this->value;
}
/**
* Compare two enums using numeric comparison
*
* @param Enum $arg The enum to compare this instance to
*
* @return int 0 if same, 1 if the argument is greater, -1 else
*/
public function compare(Enum $arg) {
if ($this->value == $arg->value) {
return 0;
} elseif ($this->value > $arg->value) {
return -1;
} else {
return 1;
}
}
/**
* Returns all constants (including values) as an associative array
*
* @param boolean $include_default Include the __default magic value?
*
* @return array All of the constants found against this instance
*/
public function getConstList($include_default = false) {
static $constCache = array();
$class = get_class($this);
if (!isset($constCache[$class])) {
$reflector = new ReflectionObject($this);
$constCache[$class] = $reflector->getConstants();
}
if (!$include_default) {
$constants = $constCache[$class];
unset($constants['__DEFAULT']);
return $constants;
}
return $constCache[$class];
}
}

View File

@@ -0,0 +1,360 @@
<?php
/**
* A hash utility data mapper class
*
* This class's purpose is to store information about hash algorithms that is
* otherwise unavailable during runtime. Some information is available (such
* as the output size), but is included anyway for performance and completeness
* reasons.
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Hash
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib;
/**
* A hash utility data mapper class
*
* This class's purpose is to store information about hash algorithms that is
* otherwise unavailable during runtime. Some information is available (such
* as the output size), but is included anyway for performance and completeness
* reasons.
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Hash
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
class Hash {
/**
* This array contains information about each hash function available to PHP
* at the present time. Block sizes are not available from functions, so they
* must be hard coded.
*
* The "secure" indicates the strength of the hash and whether or not any known
* cryptographic attacks exist for the hash function. This will only apply when
* using the hash functions for situations that require cryptographic strength
* such as message signing. For other uses the insecure ones can have valid
* uses.
*
* @var array An array of information about each supported hash function
*/
protected static $hashInfo = array(
'md2' => array(
'HashSize' => 128,
'BlockSize' => 128,
'secure' => false,
),
'md4' => array(
'HashSize' => 128,
'BlockSize' => 512,
'secure' => false,
),
'md5' => array(
'HashSize' => 128,
'BlockSize' => 512,
'secure' => false,
),
'sha1' => array(
'HashSize' => 160,
'BlockSize' => 512,
'secure' => false,
),
'sha224' => array(
'HashSize' => 224,
'BlockSize' => 512,
'secure' => true,
),
'sha256' => array(
'HashSize' => 256,
'BlockSize' => 512,
'secure' => true,
),
'sha384' => array(
'HashSize' => 384,
'BlockSize' => 1024,
'secure' => true,
),
'sha512' => array(
'HashSize' => 512,
'BlockSize' => 1024,
'secure' => true,
),
'ripemd128' => array(
'HashSize' => 128,
'BlockSize' => 512,
'secure' => true,
),
'ripemd160' => array(
'HashSize' => 160,
'BlockSize' => 512,
'secure' => true,
),
'ripemd256' => array(
'HashSize' => 256,
'BlockSize' => 512,
'secure' => true,
),
'ripemd320' => array(
'HashSize' => 320,
'BlockSize' => 512,
'secure' => true,
),
'whirlpool' => array(
'HashSize' => 512,
'BlockSize' => 512,
'secure' => true,
),
'tiger128,3' => array(
'HashSize' => 128,
'BlockSize' => 512,
'secure' => true,
),
'tiger160,3' => array(
'HashSize' => 160,
'BlockSize' => 512,
'secure' => true,
),
'tiger192,3' => array(
'HashSize' => 192,
'BlockSize' => 512,
'secure' => true,
),
'tiger128,4' => array(
'HashSize' => 128,
'BlockSize' => 512,
'secure' => true,
),
'tiger160,4' => array(
'HashSize' => 160,
'BlockSize' => 512,
'secure' => true,
),
'tiger192,4' => array(
'HashSize' => 192,
'BlockSize' => 512,
'secure' => true,
),
'snefru' => array(
'HashSize' => 256,
'BlockSize' => 512,
'secure' => false,
),
'snefru256' => array(
'HashSize' => 256,
'BlockSize' => 512,
'secure' => false,
),
'gost' => array(
'HashSize' => 256,
'BlockSize' => 256,
'secure' => false,
),
'adler32' => array(
'HashSize' => 32,
'BlockSize' => 16,
'secure' => false,
),
'crc32' => array(
'HashSize' => 32,
'BlockSize' => 32,
'secure' => false,
),
'crc32b' => array(
'HashSize' => 32,
'BlockSize' => 32,
'secure' => false,
),
'salsa10' => array(
'HashSize' => 512,
'BlockSize' => 512,
'secure' => true,
),
'salsa20' => array(
'HashSize' => 512,
'BlockSize' => 512,
'secure' => true,
),
'haval128,3' => array(
'HashSize' => 128,
'BlockSize' => 1024,
'secure' => false,
),
'haval160,3' => array(
'HashSize' => 160,
'BlockSize' => 1024,
'secure' => false,
),
'haval192,3' => array(
'HashSize' => 192,
'BlockSize' => 1024,
'secure' => false,
),
'haval224,3' => array(
'HashSize' => 224,
'BlockSize' => 1024,
'secure' => false,
),
'haval256,3' => array(
'HashSize' => 256,
'BlockSize' => 1024,
'secure' => false,
),
'haval128,4' => array(
'HashSize' => 128,
'BlockSize' => 1024,
'secure' => false,
),
'haval160,4' => array(
'HashSize' => 160,
'BlockSize' => 1024,
'secure' => false,
),
'haval192,4' => array(
'HashSize' => 192,
'BlockSize' => 1024,
'secure' => false,
),
'haval224,4' => array(
'HashSize' => 224,
'BlockSize' => 1024,
'secure' => false,
),
'haval256,4' => array(
'HashSize' => 256,
'BlockSize' => 1024,
'secure' => false,
),
'haval128,5' => array(
'HashSize' => 128,
'BlockSize' => 1024,
'secure' => false,
),
'haval160,5' => array(
'HashSize' => 160,
'BlockSize' => 1024,
'secure' => false,
),
'haval192,5' => array(
'HashSize' => 192,
'BlockSize' => 1024,
'secure' => false,
),
'haval224,5' => array(
'HashSize' => 224,
'BlockSize' => 1024,
'secure' => false,
),
'haval256,5' => array(
'HashSize' => 256,
'BlockSize' => 1024,
'secure' => false,
),
'joaat' => array(
'HashSize' => 32,
'BlockSize' => 64,
'secure' => false,
),
'fnv132' => array(
'HashSize' => 32,
'BlockSize' => 32,
'secure' => false,
),
'fnv164' => array(
'HashSize' => 64,
'BlockSize' => 64,
'secure' => false,
),
);
/**
* Get the block size of the specified function in bytes
*
* @param string $hash The hash function to look up
*
* @return int The number of bytes in the block function
*/
public static function getBlockSize($hash) {
return static::getBlockSizeInBits($hash) / 8;
}
/**
* Get the block size of the specified function in bits
*
* @param string $hash The hash function to look up
*
* @return int The number of bits in the block function
*/
public static function getBlockSizeInBits($hash) {
if (isset(static::$hashInfo[$hash]['BlockSize'])) {
return static::$hashInfo[$hash]['BlockSize'];
}
return 0;
}
/**
* Get the output size of the specified function in bytes
*
* @param string $hash The hash function to look up
*
* @return int The number of bytes outputted by the hash function
*/
public static function getHashSize($hash) {
return static::getHashSizeInBits($hash) / 8;
}
/**
* Get the output size of the specified function in bits
*
* @param string $hash The hash function to look up
*
* @return int The number of bits outputted by the hash function
*/
public static function getHashSizeInBits($hash) {
if (isset(static::$hashInfo[$hash]['HashSize'])) {
return static::$hashInfo[$hash]['HashSize'];
}
return 0;
}
/**
* Check to see if the hash function specified is available
*
* @param string $hash The hash function to look up
*
* @return boolean If the hash function is available in this version of PHP
*/
public static function isAvailable($hash) {
return in_array($hash, hash_algos());
}
/**
* Check to see if the specified hash function is secure enough for
* cryptographic uses
*
* The "secure" indicates the strength of the hash and whether or not any known
* cryptographic attacks exist for the hash function. This will only apply when
* using the hash functions for situations that require cryptographic strength
* such as message signing. For other uses the insecure ones can have valid
* uses.
*
* @param string $hash The hash function to look up
*
* @return bolean If the function is secure
*/
public static function isSecure($hash) {
if (isset(static::$hashInfo[$hash])) {
return static::$hashInfo[$hash]['secure'];
}
return false;
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* The strength FlyweightEnum class
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib;
/**
* The strength FlyweightEnum class
*
* All mixing strategies must extend this class
*
* @category PHPPasswordLib
* @package Core
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
*/
class Strength extends Enum {
/**
* We provide a default value of VeryLow so that we don't accidentally over
* state the strength if we forget to pass in a value...
*/
const __DEFAULT = self::VERYLOW;
/**
* This represents Non-Cryptographic strengths. It should not be used any time
* that security or confidentiality is at stake
*/
const VERYLOW = 1;
/**
* This represents the bottom line of Cryptographic strengths. It may be used
* for low security uses where some strength is required.
*/
const LOW = 3;
/**
* This is the general purpose Cryptographical strength. It should be suitable
* for all uses except the most sensitive.
*/
const MEDIUM = 5;
/**
* This is the highest strength available. It should not be used unless the
* high strength is needed, due to hardware constraints (and entropy
* limitations).
*/
const HIGH = 7;
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* The Mixer strategy interface.
*
* All mixing strategies must implement this interface
*
* PHP version 5.3
*
* @category PHPPasswordLib
* @package Hash
* @author Anthony Ferrara <ircmaxell@ircmaxell.com>
* @copyright 2011 The Authors
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version Build @@version@@
*/
namespace SecurityLib;
/**
* The Utility trait.
*
* Contains methods used internally to this library.
*
* @category PHPPasswordLib
* @package Random
* @author Scott Arciszewski <scott@arciszewski.me>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @codeCoverageIgnore
*/
abstract class Util {
/**
* Return the length of a string, even in the presence of
* mbstring.func_overload
*
* @param string $string the string we're measuring
* @return int
*/
public static function safeStrlen($string)
{
if (\function_exists('mb_strlen')) {
return \mb_strlen($string, '8bit');
}
return \strlen($string);
}
/**
* Return a string contained within a string, even in the presence of
* mbstring.func_overload
*
* @param string $string The string we're searching
* @param int $start What offset should we begin
* @param int|null $length How long should the substring be?
* (default: the remainder)
* @return string
*/
public static function safeSubstr($string, $start = 0, $length = null)
{
if (\function_exists('mb_substr')) {
return \mb_substr($string, $start, $length, '8bit');
} elseif ($length !== null) {
return \substr($string, $start, $length);
}
return \substr($string, $start);
}
}

View File

@@ -0,0 +1,13 @@
{
"name": "SecurityLib/Core",
"description": "Common implementations",
"keywords": ["security"],
"license": "MIT",
"require": {
"php": ">=5.3"
},
"autoload": {
"psr-0": { "SecurityLib\\SecurityLib": "" }
},
"target-dir": "SecurityLib\\SecurityLib"
}