diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 6f0a66ec..5e7153b3 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -114,13 +114,13 @@ class AES extends Rijndael $length = strlen($key); switch (true) { case $length <= 16: - $this->key_size = 16; + $this->key_length = 16; break; case $length <= 24: - $this->key_size = 24; + $this->key_length = 24; break; default: - $this->key_size = 32; + $this->key_length = 32; } $this->_setEngine(); } diff --git a/phpseclib/Crypt/Base.php b/phpseclib/Crypt/Base.php index 520e18dc..b0224e32 100644 --- a/phpseclib/Crypt/Base.php +++ b/phpseclib/Crypt/Base.php @@ -378,15 +378,6 @@ abstract class Base */ var $cipher_name_openssl_ecb; - /** - * The default password key_size used by setPassword() - * - * @see \phpseclib\Crypt\Base::setPassword() - * @var int - * @access private - */ - var $password_key_size = 32; - /** * The default salt used by setPassword() * @@ -553,7 +544,7 @@ abstract class Base */ function getKeyLength() { - return $this->key_size << 3; + return $this->key_length << 3; } /** @@ -631,7 +622,7 @@ abstract class Base if (isset($func_args[5])) { $dkLen = $func_args[5]; } else { - $dkLen = $method == 'pbkdf1' ? 2 * $this->key_size : $this->key_size; + $dkLen = $method == 'pbkdf1' ? 2 * $this->key_length : $this->key_length; } switch (true) { @@ -1893,7 +1884,7 @@ abstract class Base $this->encryptIV = $this->decryptIV = str_pad(substr($this->iv, 0, $this->block_size), $this->block_size, "\0"); if (!$this->skip_key_adjustment) { - $this->key = str_pad(substr($this->key, 0, $this->key_size), $this->key_size, "\0"); + $this->key = str_pad(substr($this->key, 0, $this->key_length), $this->key_length, "\0"); } } diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 50505378..6d9df3d7 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -273,17 +273,17 @@ class Blowfish extends Base var $kl; /** - * The Key Length + * The Key Length (in bytes) * * @see \phpseclib\Crypt\Base::setKeyLength() * @var int * @access private * @internal The max value is 256 / 8 = 32, the min value is 128 / 8 = 16. Exists in conjunction with $Nk - * because the encryption / decryption / key schedule creation requires this number and not $key_size. We could - * derive this from $key_size or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu + * because the encryption / decryption / key schedule creation requires this number and not $key_length. We could + * derive this from $key_length or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu * of that, we'll just precompute it once. */ - var $key_size = 16; + var $key_length = 16; /** * Sets the key length. @@ -296,11 +296,11 @@ class Blowfish extends Base function setKeyLength($length) { if ($length < 32) { - $this->key_size = 7; + $this->key_length = 7; } elseif ($length > 448) { - $this->key_size = 56; + $this->key_length = 56; } else { - $this->key_size = $length >> 3; + $this->key_length = $length >> 3; } parent::setKeyLength($length); @@ -319,7 +319,7 @@ class Blowfish extends Base function isValidEngine($engine) { if ($engine == self::ENGINE_OPENSSL) { - if ($this->key_size != 16) { + if ($this->key_length != 16) { return false; } $this->cipher_name_openssl_ecb = 'bf-ecb'; diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index 4a56e26c..23f9045b 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -78,13 +78,13 @@ class DES extends Base var $block_size = 8; /** - * Key Length + * Key Length (in bytes) * * @see \phpseclib\Crypt\Base::setKeyLength() * @var int * @access private */ - var $key_size = 8; + var $key_length = 8; /** * The mcrypt specific name of the cipher @@ -138,7 +138,7 @@ class DES extends Base * @var string * @access private */ - var $key_size_max = 8; + var $key_length_max = 8; /** * The Key Schedule @@ -592,7 +592,7 @@ class DES extends Base */ function isValidEngine($engine) { - if ($this->key_size_max == 8) { + if ($this->key_length_max == 8) { if ($engine == self::ENGINE_OPENSSL) { $this->cipher_name_openssl_ecb = 'des-ecb'; $this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode(); @@ -621,8 +621,8 @@ class DES extends Base { // We check/cut here only up to max length of the key. // Key padding to the proper length will be done in _setupKey() - if (strlen($key) > $this->key_size_max) { - $key = substr($key, 0, $this->key_size_max); + if (strlen($key) > $this->key_length_max) { + $key = substr($key, 0, $this->key_length_max); } // Sets the key diff --git a/phpseclib/Crypt/RC2.php b/phpseclib/Crypt/RC2.php index 5f31e002..e6f920af 100644 --- a/phpseclib/Crypt/RC2.php +++ b/phpseclib/Crypt/RC2.php @@ -86,13 +86,13 @@ class RC2 extends Base var $skip_key_adjustment = true; /** - * Key Length + * Key Length (in bytes) * * @see \phpseclib\Crypt\RC2::setKeyLength() * @var int * @access private */ - var $key_size = 16; // = 128 bits + var $key_length = 16; // = 128 bits /** * The mcrypt specific name of the cipher diff --git a/phpseclib/Crypt/RC4.php b/phpseclib/Crypt/RC4.php index 1a6d3bc2..a5db1691 100644 --- a/phpseclib/Crypt/RC4.php +++ b/phpseclib/Crypt/RC4.php @@ -76,13 +76,13 @@ class RC4 extends Base var $block_size = 0; /** - * Key Length + * Key Length (in bytes) * * @see \phpseclib\Crypt\RC4::setKeyLength() * @var int * @access private */ - var $key_size = 128; // = 1024 bits + var $key_length = 128; // = 1024 bits /** * The mcrypt specific name of the cipher @@ -200,11 +200,11 @@ class RC4 extends Base function setKeyLength($length) { if ($length < 8) { - $this->key_size = 1; + $this->key_length = 1; } elseif ($length > 2048) { - $this->key_size = 248; + $this->key_length = 248; } else { - $this->key_size = $length >> 3; + $this->key_length = $length >> 3; } parent::setKeyLength($length); diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index 079bd52d..334eaf9d 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -68,9 +68,9 @@ class Rijndael extends Base /** * The mcrypt specific name of the cipher * - * Mcrypt is useable for 128/192/256-bit $block_size/$key_size. For 160/224 not. + * Mcrypt is useable for 128/192/256-bit $block_size/$key_length. For 160/224 not. * \phpseclib\Crypt\Rijndael determines automatically whether mcrypt is useable - * or not for the current $block_size/$key_size. + * or not for the current $block_size/$key_length. * In case of, $cipher_name_mcrypt will be set dynamically at run time accordingly. * * @see \phpseclib\Crypt\Base::cipher_name_mcrypt @@ -123,17 +123,17 @@ class Rijndael extends Base var $Nb = 4; /** - * The Key Length + * The Key Length (in bytes) * * @see setKeyLength() * @var int * @access private * @internal The max value is 256 / 8 = 32, the min value is 128 / 8 = 16. Exists in conjunction with $Nk - * because the encryption / decryption / key schedule creation requires this number and not $key_size. We could - * derive this from $key_size or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu + * because the encryption / decryption / key schedule creation requires this number and not $key_length. We could + * derive this from $key_length or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu * of that, we'll just precompute it once. */ - var $key_size = 16; + var $key_length = 16; /** * The Key Length divided by 32 @@ -194,19 +194,19 @@ class Rijndael extends Base { switch (true) { case $length <= 128: - $this->key_size = 16; + $this->key_length = 16; break; case $length <= 160: - $this->key_size = 20; + $this->key_length = 20; break; case $length <= 192: - $this->key_size = 24; + $this->key_length = 24; break; case $length <= 224: - $this->key_size = 28; + $this->key_length = 28; break; default: - $this->key_size = 32; + $this->key_length = 32; } parent::setKeyLength($length); @@ -252,12 +252,12 @@ class Rijndael extends Base if ($this->block_size != 16) { return false; } - $this->cipher_name_openssl_ecb = 'aes-' . ($this->key_size << 3) . '-ecb'; - $this->cipher_name_openssl = 'aes-' . ($this->key_size << 3) . '-' . $this->_openssl_translate_mode(); + $this->cipher_name_openssl_ecb = 'aes-' . ($this->key_length << 3) . '-ecb'; + $this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->_openssl_translate_mode(); break; case self::ENGINE_MCRYPT: $this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3); - if ($this->key_size % 8) { // is it a 160/224-bit key? + if ($this->key_length % 8) { // is it a 160/224-bit key? // mcrypt is not usable for them, only for 128/192/256-bit keys return false; } @@ -476,13 +476,13 @@ class Rijndael extends Base 0x7D000000, 0xFA000000, 0xEF000000, 0xC5000000, 0x91000000 ); - if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_size === $this->kl['key_size'] && $this->block_size === $this->kl['block_size']) { + if (isset($this->kl['key']) && $this->key === $this->kl['key'] && $this->key_length === $this->kl['key_length'] && $this->block_size === $this->kl['block_size']) { // already expanded return; } - $this->kl = array('key' => $this->key, 'key_size' => $this->key_size, 'block_size' => $this->block_size); + $this->kl = array('key' => $this->key, 'key_length' => $this->key_length, 'block_size' => $this->block_size); - $this->Nk = $this->key_size >> 2; + $this->Nk = $this->key_length >> 2; // see Rijndael-ammended.pdf#page=44 $this->Nr = max($this->Nk, $this->Nb) + 6; diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index d1389e3f..c5a0229e 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -64,13 +64,13 @@ class TripleDES extends DES const MODE_CBC3 = Base::MODE_CBC; /** - * Key Length + * Key Length (in bytes) * * @see \phpseclib\Crypt\TripleDES::setKeyLength() * @var int * @access private */ - var $key_size = 24; + var $key_length = 24; /** * The default salt used by setPassword() @@ -109,7 +109,7 @@ class TripleDES extends DES * @var string * @access private */ - var $key_size_max = 24; + var $key_length_max = 24; /** * Internal flag whether using self::MODE_3CBC or not @@ -237,13 +237,13 @@ class TripleDES extends DES $length >>= 3; switch (true) { case $length <= 8: - $this->key_size = 8; + $this->key_length = 8; break; case $length <= 16: - $this->key_size = 16; + $this->key_length = 16; break; default: - $this->key_size = 24; + $this->key_length = 24; } parent::setKeyLength($length); @@ -266,7 +266,7 @@ class TripleDES extends DES */ function setKey($key) { - $length = $this->explicit_key_length ? $this->key_size : strlen($key); + $length = $this->explicit_key_length ? $this->key_length : strlen($key); if ($length > 8) { $key = str_pad(substr($key, 0, 24), 24, chr(0)); // if $key is between 64 and 128-bits, use the first 64-bits as the last, per this: diff --git a/phpseclib/Crypt/Twofish.php b/phpseclib/Crypt/Twofish.php index 91033295..623e9a6a 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -361,6 +361,15 @@ class Twofish extends Base */ var $kl; + /** + * The Key Length (in bytes) + * + * @see Crypt_Twofish::setKeyLength() + * @var int + * @access private + */ + var $key_length = 16; + /** * Sets the key length. * @@ -373,13 +382,13 @@ class Twofish extends Base { switch (true) { case $length <= 128: - $this->key_size = 16; + $this->key_length = 16; break; case $length <= 192: - $this->key_size = 24; + $this->key_length = 24; break; default: - $this->key_size = 32; + $this->key_length = 32; } parent::setKeyLength($length);