Ejemplo n.º 1
0
 /**
  * Sets the crc32 hash for one or multiple files
  *
  * @param  string|array $options
  * @return \Zend\Validator\File\Hash Provides a fluent interface
  */
 public function setHash($options)
 {
     if (!is_array($options)) {
         $options = array($options);
     }
     $options['algorithm'] = 'crc32';
     parent::setHash($options);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Sets the md5 hash for one or multiple files
  *
  * @param  string|array $options
  * @param  string       $algorithm (Deprecated) Algorithm to use, fixed to md5
  * @return \Zend\Validator\File\Hash Provides a fluent interface
  */
 public function setHash($options)
 {
     if (!is_array($options)) {
         $options = (array) $options;
     }
     $options['algorithm'] = 'md5';
     parent::setHash($options);
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Sets the password.
  *
  * Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
  *     {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2} or pbkdf1:
  *         $hash, $salt, $count, $dkLen
  *
  *         Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
  *
  * @see      Crypt/Hash.php
  *
  * @param String $password
  * @param        optional String $method
  *
  * @return Boolean
  * @access   public
  * @internal Could, but not must, extend by the child Crypt_* class
  */
 function setPassword($password, $method = 'pbkdf2')
 {
     $key = '';
     switch ($method) {
         default:
             // 'pbkdf2' or 'pbkdf1'
             $func_args = func_get_args();
             // Hash function
             $hash = isset($func_args[2]) ? $func_args[2] : 'sha1';
             // WPA and WPA2 use the SSID as the salt
             $salt = isset($func_args[3]) ? $func_args[3] : $this->password_default_salt;
             // RFC2898#section-4.2 uses 1,000 iterations by default
             // WPA and WPA2 use 4,096.
             $count = isset($func_args[4]) ? $func_args[4] : 1000;
             // Keylength
             if (isset($func_args[5])) {
                 $dkLen = $func_args[5];
             } else {
                 $dkLen = $method == 'pbkdf1' ? 2 * $this->password_key_size : $this->password_key_size;
             }
             switch (true) {
                 case $method == 'pbkdf1':
                     $hashObj = new Hash();
                     $hashObj->setHash($hash);
                     if ($dkLen > $hashObj->getLength()) {
                         user_error('Derived key too long');
                         return false;
                     }
                     $t = $password . $salt;
                     for ($i = 0; $i < $count; ++$i) {
                         $t = $hashObj->hash($t);
                     }
                     $key = substr($t, 0, $dkLen);
                     $this->setKey(substr($key, 0, $dkLen >> 1));
                     $this->setIV(substr($key, $dkLen >> 1));
                     return true;
                     // Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
                 // Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
                 case !function_exists('hash_pbkdf2'):
                 case !function_exists('hash_algos'):
                 case !in_array($hash, hash_algos()):
                     $i = 1;
                     while (strlen($key) < $dkLen) {
                         $hmac = new Hash();
                         $hmac->setHash($hash);
                         $hmac->setKey($password);
                         $f = $u = $hmac->hash($salt . pack('N', $i++));
                         for ($j = 2; $j <= $count; ++$j) {
                             $u = $hmac->hash($u);
                             $f ^= $u;
                         }
                         $key .= $f;
                     }
                     $key = substr($key, 0, $dkLen);
                     break;
                 default:
                     $key = hash_pbkdf2($hash, $password, $salt, $count, $dkLen, true);
             }
     }
     $this->setKey($key);
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Sets the password.
  *
  * Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
  *     {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
  *         $hash, $salt, $method
  *     Set $dkLen by calling setKeyLength()
  *
  * @param String $password
  * @param optional String $method
  * @access public
  */
 function setPassword($password, $method = 'pbkdf2')
 {
     $key = '';
     switch ($method) {
         default:
             // 'pbkdf2'
             list(, , $hash, $salt, $count) = func_get_args();
             if (!isset($hash)) {
                 $hash = 'sha1';
             }
             // WPA and WPA2 use the SSID as the salt
             if (!isset($salt)) {
                 $salt = 'phpseclib';
             }
             // RFC2898#section-4.2 uses 1,000 iterations by default
             // WPA and WPA2 use 4,096.
             if (!isset($count)) {
                 $count = 1000;
             }
             $i = 1;
             while (strlen($key) < $this->key_size) {
                 // $dkLen == $this->key_size
                 //$dk.= $this->_pbkdf($password, $salt, $count, $i++);
                 $hmac = new Hash();
                 $hmac->setHash($hash);
                 $hmac->setKey($password);
                 $f = $u = $hmac->hash($salt . pack('N', $i++));
                 for ($j = 2; $j <= $count; $j++) {
                     $u = $hmac->hash($u);
                     $f ^= $u;
                 }
                 $key .= $f;
             }
     }
     $this->setKey(substr($key, 0, $this->key_size));
 }
Ejemplo n.º 5
0
 /**
  * Sets the password.
  *
  * Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
  *     {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
  *         $hash, $salt, $method
  *
  * @param String $password
  * @param optional String $method
  * @access public
  */
 function setPassword($password, $method = 'pbkdf2')
 {
     $key = '';
     switch ($method) {
         default:
             // 'pbkdf2'
             list(, , $hash, $salt, $count) = func_get_args();
             if (!isset($hash)) {
                 $hash = 'sha1';
             }
             // WPA and WPA2 use the SSID as the salt
             if (!isset($salt)) {
                 $salt = 'phpseclib';
             }
             // RFC2898#section-4.2 uses 1,000 iterations by default
             // WPA and WPA2 use 4,096.
             if (!isset($count)) {
                 $count = 1000;
             }
             if (!class_exists('Crypt_Hash')) {
                 require_once 'Crypt/Hash.php';
             }
             $i = 1;
             while (strlen($key) < 24) {
                 // $dkLen == 24
                 $hmac = new Hash();
                 $hmac->setHash($hash);
                 $hmac->setKey($password);
                 $f = $u = $hmac->hash($salt . pack('N', $i++));
                 for ($j = 2; $j <= $count; $j++) {
                     $u = $hmac->hash($u);
                     $f ^= $u;
                 }
                 $key .= $f;
             }
     }
     $this->setKey($key);
 }
Ejemplo n.º 6
0
 /**
  * Sets the password.
  *
  * Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
  *     {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
  *         $hash, $salt, $count, $dkLen
  *
  *         Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
  *
  * Note: Could, but not must, extend by the child * class
  *
  * @see Crypt/Hash.php
  * @param String $password
  * @param optional String $method
  * @access public
  */
 function setPassword($password, $method = 'pbkdf2')
 {
     $key = '';
     switch ($method) {
         default:
             // 'pbkdf2'
             $func_args = func_get_args();
             // Hash function
             $hash = isset($func_args[2]) ? $func_args[2] : 'sha1';
             // WPA and WPA2 use the SSID as the salt
             $salt = isset($func_args[3]) ? $func_args[3] : $this->password_default_salt;
             // RFC2898#section-4.2 uses 1,000 iterations by default
             // WPA and WPA2 use 4,096.
             $count = isset($func_args[4]) ? $func_args[4] : 1000;
             // Keylength
             $dkLen = isset($func_args[5]) ? $func_args[5] : $this->password_key_size;
             // Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
             switch (true) {
                 case !function_exists('hash_pbkdf2'):
                 case !function_exists('hash_algos'):
                 case !in_array($hash, hash_algos()):
                     $i = 1;
                     while (strlen($key) < $dkLen) {
                         $hmac = new Hash();
                         $hmac->setHash($hash);
                         $hmac->setKey($password);
                         $f = $u = $hmac->_hash($salt . pack('N', $i++));
                         for ($j = 2; $j <= $count; ++$j) {
                             $u = $hmac->_hash($u);
                             $f ^= $u;
                         }
                         $key .= $f;
                     }
                     $key = substr($key, 0, $dkLen);
                     break;
                 default:
                     $key = hash_pbkdf2($hash, $password, $salt, $count, $dkLen, true);
             }
     }
     $this->setKey($key);
 }