diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 3a94a743..54d28593 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -288,7 +288,7 @@ class Blowfish extends BlockCipher /** * Default Constructor. * - * @param int|string $mode + * @param string $mode * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ @@ -296,7 +296,7 @@ class Blowfish extends BlockCipher { parent::__construct($mode); - if ($mode == self::MODE_STREAM) { + if ($this->mode == self::MODE_STREAM) { throw new \InvalidArgumentException('Block ciphers cannot be ran in stream mode'); } } diff --git a/phpseclib/Crypt/Common/SymmetricKey.php b/phpseclib/Crypt/Common/SymmetricKey.php index 80de0fc2..28041d3d 100644 --- a/phpseclib/Crypt/Common/SymmetricKey.php +++ b/phpseclib/Crypt/Common/SymmetricKey.php @@ -602,23 +602,21 @@ abstract class SymmetricKey * * - gcm * - * @param string|int $mode + * @param string $mode * @access public * @throws BadModeException if an invalid / unsupported mode is provided */ public function __construct($mode) { - if (!is_int($mode) || !in_array($mode, self::MODE_MAP, true)) { - $mode = strtolower($mode); - // necessary because of 5.6 compatibility; we can't do isset(self::MODE_MAP[$mode]) in 5.6 - $map = self::MODE_MAP; - if (!isset($map[$mode])) { - throw new BadModeException('No valid mode has been specified'); - } - - $mode = self::MODE_MAP[$mode]; + $mode = strtolower($mode); + // necessary because of 5.6 compatibility; we can't do isset(self::MODE_MAP[$mode]) in 5.6 + $map = self::MODE_MAP; + if (!isset($map[$mode])) { + throw new BadModeException('No valid mode has been specified'); } + $mode = self::MODE_MAP[$mode]; + // $mode dependent settings switch ($mode) { case self::MODE_ECB: diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index 2a55a276..40c0f947 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -584,7 +584,7 @@ class DES extends BlockCipher /** * Default Constructor. * - * @param int|string $mode + * @param string $mode * @access public * @throws BadModeException if an invalid / unsupported mode is provided */ @@ -592,7 +592,7 @@ class DES extends BlockCipher { parent::__construct($mode); - if ($mode == self::MODE_STREAM) { + if ($this->mode == self::MODE_STREAM) { throw new BadModeException('Block ciphers cannot be ran in stream mode'); } } diff --git a/phpseclib/Crypt/RC2.php b/phpseclib/Crypt/RC2.php index 425532bc..317d4380 100644 --- a/phpseclib/Crypt/RC2.php +++ b/phpseclib/Crypt/RC2.php @@ -265,7 +265,7 @@ class RC2 extends BlockCipher /** * Default Constructor. * - * @param int|string $mode + * @param string $mode * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ @@ -273,7 +273,7 @@ class RC2 extends BlockCipher { parent::__construct($mode); - if ($mode == self::MODE_STREAM) { + if ($this->mode == self::MODE_STREAM) { throw new BadModeException('Block ciphers cannot be ran in stream mode'); } } diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index 0483bf8b..58aa80e0 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -168,7 +168,7 @@ class Rijndael extends BlockCipher /** * Default Constructor. * - * @param int|string $mode + * @param string $mode * @access public * @throws \InvalidArgumentException if an invalid / unsupported mode is provided */ @@ -176,7 +176,7 @@ class Rijndael extends BlockCipher { parent::__construct($mode); - if ($mode == self::MODE_STREAM) { + if ($this->mode == self::MODE_STREAM) { throw new BadModeException('Block ciphers cannot be ran in stream mode'); } } diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index 32c3c9ca..aa1f5216 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -138,7 +138,7 @@ class TripleDES extends DES * * @see \phpseclib\Crypt\DES::__construct() * @see \phpseclib\Crypt\Common\SymmetricKey::__construct() - * @param int|string $mode + * @param string $mode * @access public */ public function __construct($mode) @@ -147,7 +147,6 @@ class TripleDES extends DES // In case of self::MODE_3CBC, we init as CRYPT_DES_MODE_CBC // and additional flag us internally as 3CBC case '3cbc': - $mode = self::MODE_3CBC; parent::__construct('cbc'); $this->mode_3cbc = true; @@ -168,6 +167,10 @@ class TripleDES extends DES // If not 3CBC, we init as usual default: parent::__construct($mode); + + if ($this->mode == self::MODE_STREAM) { + throw new BadModeException('Block ciphers cannot be ran in stream mode'); + } } } diff --git a/phpseclib/Crypt/Twofish.php b/phpseclib/Crypt/Twofish.php index 32d7c000..f9f1dce3 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -374,7 +374,7 @@ class Twofish extends BlockCipher /** * Default Constructor. * - * @param int|string $mode + * @param string $mode * @access public * @throws BadModeException if an invalid / unsupported mode is provided */ @@ -382,7 +382,7 @@ class Twofish extends BlockCipher { parent::__construct($mode); - if ($mode == self::MODE_STREAM) { + if ($this->mode == self::MODE_STREAM) { throw new BadModeException('Block ciphers cannot be ran in stream mode'); } }