From d91158f6ef741f7f548091b0ee32ecac33f0207f Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 4 Oct 2015 21:06:17 -0500 Subject: [PATCH] rename key_size -> key_length --- phpseclib/Crypt/AES.php | 6 +++--- phpseclib/Crypt/Base.php | 15 +++------------ phpseclib/Crypt/Blowfish.php | 16 ++++++++-------- phpseclib/Crypt/DES.php | 12 ++++++------ phpseclib/Crypt/RC2.php | 4 ++-- phpseclib/Crypt/RC4.php | 10 +++++----- phpseclib/Crypt/Rijndael.php | 34 +++++++++++++++++----------------- phpseclib/Crypt/TripleDES.php | 14 +++++++------- phpseclib/Crypt/Twofish.php | 15 ++++++++++++--- 9 files changed, 63 insertions(+), 63 deletions(-) diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 4d6b2794..5653bfbe 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -183,13 +183,13 @@ class Crypt_AES extends Crypt_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 3e99a6b7..6d0022fc 100644 --- a/phpseclib/Crypt/Base.php +++ b/phpseclib/Crypt/Base.php @@ -385,15 +385,6 @@ class Crypt_Base */ var $cipher_name_openssl_ecb; - /** - * The default password key_size used by setPassword() - * - * @see Crypt_Base::setPassword() - * @var int - * @access private - */ - var $password_key_size = 32; - /** * The default salt used by setPassword() * @@ -583,7 +574,7 @@ class Crypt_Base */ function getKeyLength() { - return $this->key_size << 3; + return $this->key_length << 3; } /** @@ -661,7 +652,7 @@ class Crypt_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) { @@ -1935,7 +1926,7 @@ class Crypt_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 8af33d40..25907e7b 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -344,17 +344,17 @@ class Crypt_Blowfish extends Crypt_Base var $kl; /** - * The Key Length + * The Key Length (in bytes) * * @see 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. @@ -367,11 +367,11 @@ class Crypt_Blowfish extends Crypt_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); @@ -390,7 +390,7 @@ class Crypt_Blowfish extends Crypt_Base function isValidEngine($engine) { if ($engine == CRYPT_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 98fd9394..b3b6fce8 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -140,13 +140,13 @@ class Crypt_DES extends Crypt_Base var $block_size = 8; /** - * Key Length + * Key Length (in bytes) * * @see Crypt_Base::setKeyLength() * @var int * @access private */ - var $key_size = 8; + var $key_length = 8; /** * The namespace used by the cipher for its constants. @@ -209,7 +209,7 @@ class Crypt_DES extends Crypt_Base * @var string * @access private */ - var $key_size_max = 8; + var $key_length_max = 8; /** * The Key Schedule @@ -663,7 +663,7 @@ class Crypt_DES extends Crypt_Base */ function isValidEngine($engine) { - if ($this->key_size_max == 8) { + if ($this->key_length_max == 8) { if ($engine == CRYPT_ENGINE_OPENSSL) { $this->cipher_name_openssl_ecb = 'des-ecb'; $this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode(); @@ -692,8 +692,8 @@ class Crypt_DES extends Crypt_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 121a426a..42acdbc5 100644 --- a/phpseclib/Crypt/RC2.php +++ b/phpseclib/Crypt/RC2.php @@ -148,13 +148,13 @@ class Crypt_RC2 extends Crypt_Base var $skip_key_adjustment = true; /** - * Key Length + * Key Length (in bytes) * * @see Crypt_RC2::setKeyLength() * @var int * @access private */ - var $key_size = 16; // = 128 bits + var $key_length = 16; // = 128 bits /** * The namespace used by the cipher for its constants. diff --git a/phpseclib/Crypt/RC4.php b/phpseclib/Crypt/RC4.php index 3ad16836..f18a0e3a 100644 --- a/phpseclib/Crypt/RC4.php +++ b/phpseclib/Crypt/RC4.php @@ -99,13 +99,13 @@ class Crypt_RC4 extends Crypt_Base var $block_size = 0; /** - * Key Length + * Key Length (in bytes) * * @see Crypt_RC4::setKeyLength() * @var int * @access private */ - var $key_size = 128; // = 1024 bits + var $key_length = 128; // = 1024 bits /** * The namespace used by the cipher for its constants. @@ -232,11 +232,11 @@ class Crypt_RC4 extends Crypt_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 7bd01903..5f0ac6ae 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -139,9 +139,9 @@ class Crypt_Rijndael extends Crypt_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. * 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 Crypt_Base::cipher_name_mcrypt @@ -194,17 +194,17 @@ class Crypt_Rijndael extends Crypt_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 @@ -293,19 +293,19 @@ class Crypt_Rijndael extends Crypt_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); @@ -351,12 +351,12 @@ class Crypt_Rijndael extends Crypt_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 CRYPT_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; } @@ -575,13 +575,13 @@ class Crypt_Rijndael extends Crypt_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 70c5f250..585e2a42 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -95,13 +95,13 @@ define('CRYPT_DES_MODE_CBC3', CRYPT_MODE_CBC3); class Crypt_TripleDES extends Crypt_DES { /** - * Key Length + * Key Length (in bytes) * * @see Crypt_TripleDES::setKeyLength() * @var int * @access private */ - var $key_size = 24; + var $key_length = 24; /** * The default salt used by setPassword() @@ -150,7 +150,7 @@ class Crypt_TripleDES extends Crypt_DES * @var string * @access private */ - var $key_size_max = 24; + var $key_length_max = 24; /** * Internal flag whether using CRYPT_DES_MODE_3CBC or not @@ -278,13 +278,13 @@ class Crypt_TripleDES extends Crypt_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); @@ -307,7 +307,7 @@ class Crypt_TripleDES extends Crypt_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 c332a3e5..06cb0bb7 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -432,6 +432,15 @@ class Crypt_Twofish extends Crypt_Base */ var $kl; + /** + * The Key Length (in bytes) + * + * @see Crypt_Twofish::setKeyLength() + * @var int + * @access private + */ + var $key_length = 16; + /** * Sets the key length. * @@ -444,13 +453,13 @@ class Crypt_Twofish extends Crypt_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);