From 492562e0344e49dd8465482aa1ca4645c0df8c4f Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 8 Mar 2019 08:34:33 -0600 Subject: [PATCH 1/3] Hash: fix issues with _computeKey --- phpseclib/Crypt/Hash.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index 1042463f..41a49a8e 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -216,7 +216,7 @@ class Crypt_Hash * * @access private */ - function _computeKey() + function _computeKey($mode) { if ($this->key === false) { $this->computedKey = false; @@ -332,7 +332,7 @@ class Crypt_Hash default: $this->hash = MHASH_SHA1; } - $this->_computeKey(); + $this->_computeKey(CRYPT_HASH_MODE_MHASH); return; case CRYPT_HASH_MODE_HASH: switch ($hash) { @@ -349,7 +349,7 @@ class Crypt_Hash default: $this->hash = 'sha1'; } - $this->_computeKey(); + $this->_computeKey(CRYPT_HASH_MODE_HASH); return; } @@ -375,7 +375,7 @@ class Crypt_Hash $this->ipad = str_repeat(chr(0x36), $this->b); $this->opad = str_repeat(chr(0x5C), $this->b); - $this->_computeKey(); + $this->_computeKey(CRYPT_HASH_MODE_INTERNAL); } /** From e706c549c107b177593f00bf29e1af1a0bb881d2 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 8 Mar 2019 08:36:16 -0600 Subject: [PATCH 2/3] Hash: adjustments for 2.0 branch --- phpseclib/Crypt/Hash.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index 42a0a8a0..d89fd2d7 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -203,13 +203,13 @@ class Hash } switch ($mode) { - case CRYPT_HASH_MODE_MHASH: + case self::MODE_MHASH: $this->computedKey = mhash($this->hash, $this->key); break; - case CRYPT_HASH_MODE_HASH: + case self::MODE_HASH: $this->computedKey = hash($this->hash, $this->key, true); break; - case CRYPT_HASH_MODE_INTERNAL: + case self::MODE_INTERNAL: $this->computedKey = call_user_func($this->hash, $this->key); } } @@ -306,7 +306,7 @@ class Hash default: $this->hash = MHASH_SHA1; } - $this->_computeKey(CRYPT_HASH_MODE_MHASH); + $this->_computeKey(self::MODE_MHASH); return; case self::MODE_HASH: switch ($hash) { @@ -323,7 +323,7 @@ class Hash default: $this->hash = 'sha1'; } - $this->_computeKey(CRYPT_HASH_MODE_HASH); + $this->_computeKey(self::MODE_HASH); return; } @@ -349,7 +349,7 @@ class Hash $this->ipad = str_repeat(chr(0x36), $this->b); $this->opad = str_repeat(chr(0x5C), $this->b); - $this->_computeKey(CRYPT_HASH_MODE_INTERNAL); + $this->_computeKey(self::MODE_INTERNAL); } /** From 84e232924988f27caa7611321a1d2401d6d0c142 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 9 Mar 2019 17:08:59 -0600 Subject: [PATCH 3/3] Hash: fix issues with the mode --- phpseclib/Crypt/Hash.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index 1042463f..a998b5b2 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -153,6 +153,15 @@ class Crypt_Hash */ var $ipad; + /** + * Engine + * + * @see self::setHash() + * @var string + * @access private + */ + var $engine; + /** * Default Constructor. * @@ -228,7 +237,7 @@ class Crypt_Hash return; } - switch ($mode) { + switch ($this->engine) { case CRYPT_HASH_MODE_MHASH: $this->computedKey = mhash($this->hash, $this->key); break; @@ -308,18 +317,18 @@ class Crypt_Hash switch ($hash) { case 'md2': - $mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_HASH && in_array('md2', hash_algos()) ? + $this->engine = CRYPT_HASH_MODE == CRYPT_HASH_MODE_HASH && in_array('md2', hash_algos()) ? CRYPT_HASH_MODE_HASH : CRYPT_HASH_MODE_INTERNAL; break; case 'sha384': case 'sha512': - $mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_MHASH ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE; + $this->engine = CRYPT_HASH_MODE == CRYPT_HASH_MODE_MHASH ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE; break; default: - $mode = CRYPT_HASH_MODE; + $this->engine = CRYPT_HASH_MODE; } - switch ($mode) { + switch ($this->engine) { case CRYPT_HASH_MODE_MHASH: switch ($hash) { case 'md5': @@ -387,10 +396,8 @@ class Crypt_Hash */ function hash($text) { - $mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE; - if (!empty($this->key) || is_string($this->key)) { - switch ($mode) { + switch ($this->engine) { case CRYPT_HASH_MODE_MHASH: $output = mhash($this->hash, $text, $this->computedKey); break; @@ -407,7 +414,7 @@ class Crypt_Hash $output = call_user_func($this->hash, $output); // step 7 } } else { - switch ($mode) { + switch ($this->engine) { case CRYPT_HASH_MODE_MHASH: $output = mhash($this->hash, $text); break;