Namespaced Crypt Package

This commit is contained in:
Clint Nelissen 2014-12-16 16:16:54 -08:00
parent 6c1695c9a2
commit fe742e18d7
33 changed files with 636 additions and 799 deletions

View File

@ -7,21 +7,21 @@
*
* PHP versions 4 and 5
*
* If {@link Crypt_AES::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
* {@link Crypt_AES::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
* it'll be null-padded to 192-bits and 192 bits will be the key length until {@link Crypt_AES::setKey() setKey()}
* If {@link \phpseclib\Crypt\AES::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
* {@link \phpseclib\Crypt\AES::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
* it'll be null-padded to 192-bits and 192 bits will be the key length until {@link \phpseclib\Crypt\AES::setKey() setKey()}
* is called, again, at which point, it'll be recalculated.
*
* Since Crypt_AES extends Crypt_Rijndael, some functions are available to be called that, in the context of AES, don't
* make a whole lot of sense. {@link Crypt_AES::setBlockLength() setBlockLength()}, for instance. Calling that function,
* Since \phpseclib\Crypt\AES extends \phpseclib\Crypt\Rijndael, some functions are available to be called that, in the context of AES, don't
* make a whole lot of sense. {@link \phpseclib\Crypt\AES::setBlockLength() setBlockLength()}, for instance. Calling that function,
* however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
*
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/AES.php';
* include 'vendor/autoload.php';
*
* $aes = new Crypt_AES();
* $aes = new \phpseclib\Crypt\AES();
*
* $aes->setKey('abcdefghijklmnop');
*
@ -36,33 +36,30 @@
* </code>
*
* @category Crypt
* @package Crypt_AES
* @package AES
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2008 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Crypt_Rijndael
*/
if (!class_exists('Crypt_Rijndael')) {
include_once 'Rijndael.php';
}
namespace phpseclib\Crypt;
use phpseclib\Crypt\Rijndael;
/**
* Pure-PHP implementation of AES.
*
* @package Crypt_AES
* @package AES
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class Crypt_AES extends Crypt_Rijndael
class AES extends Rijndael
{
/**
* The namespace used by the cipher for its constants.
*
* @see Crypt_Base::const_namespace
* @see \phpseclib\Crypt\Base::const_namespace
* @var String
* @access private
*/
@ -71,9 +68,9 @@ class Crypt_AES extends Crypt_Rijndael
/**
* Dummy function
*
* Since Crypt_AES extends Crypt_Rijndael, this function is, technically, available, but it doesn't do anything.
* Since \phpseclib\Crypt\AES extends \phpseclib\Crypt\Rijndael, this function is, technically, available, but it doesn't do anything.
*
* @see Crypt_Rijndael::setBlockLength()
* @see \phpseclib\Crypt\Rijndael::setBlockLength()
* @access public
* @param Integer $length
*/
@ -88,7 +85,7 @@ class Crypt_AES extends Crypt_Rijndael
* Valid key lengths are 128, 192, and 256. If the length is less than 128, it will be rounded up to
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
*
* @see Crypt_Rijndael:setKeyLength()
* @see \phpseclib\Crypt\Rijndael:setKeyLength()
* @access public
* @param Integer $length
*/
@ -109,7 +106,7 @@ class Crypt_AES extends Crypt_Rijndael
*
* Rijndael supports five different key lengths, AES only supports three.
*
* @see Crypt_Rijndael:setKey()
* @see \phpseclib\Crypt\Rijndael:setKey()
* @see setKeyLength()
* @access public
* @param String $key

View File

@ -1,14 +1,14 @@
<?php
/**
* Base Class for all Crypt_* cipher classes
* Base Class for all \phpseclib\Crypt\* cipher classes
*
* PHP versions 4 and 5
*
* Internally for phpseclib developers:
* If you plan to add a new cipher class, please note following rules:
*
* - The new Crypt_* cipher class should extend Crypt_Base
* - The new \phpseclib\Crypt\* cipher class should extend \phpseclib\Crypt\Base
*
* - Following methods are then required to be overridden/overloaded:
*
@ -20,13 +20,13 @@
*
* - All other methods are optional to be overridden/overloaded
*
* - Look at the source code of the current ciphers how they extend Crypt_Base
* - Look at the source code of the current ciphers how they extend \phpseclib\Crypt\Base
* and take one of them as a start up for the new cipher class.
*
* - Please read all the other comments/notes/hints here also for each class var/method
*
* @category Crypt
* @package Crypt_Base
* @package Base
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright 2007 Jim Wigginton
@ -34,20 +34,24 @@
* @link http://phpseclib.sourceforge.net
*/
namespace phpseclib\Crypt;
use phpseclib\Crypt\Hash;
/**
* Base Class for all Crypt_* cipher classes
* Base Class for all \phpseclib\Crypt\* cipher classes
*
* @package Crypt_Base
* @package Base
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @access public
*/
class Crypt_Base
class Base
{
/**#@+
* @access public
* @see Crypt_Base::encrypt()
* @see Crypt_Base::decrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\Base::decrypt()
*/
/**
* Encrypt / decrypt using the Counter mode.
@ -90,7 +94,7 @@ class Crypt_Base
/**#@+
* @access private
* @see Crypt_Base::__construct()
* @see \phpseclib\Crypt\Base::__construct()
*/
/**
* Base value for the internal implementation $engine switch
@ -105,7 +109,7 @@ class Crypt_Base
/**
* The Encryption Mode
*
* @see Crypt_Base::__construct()
* @see \phpseclib\Crypt\Base::__construct()
* @var Integer
* @access private
*/
@ -122,7 +126,7 @@ class Crypt_Base
/**
* The Key
*
* @see Crypt_Base::setKey()
* @see \phpseclib\Crypt\Base::setKey()
* @var String
* @access private
*/
@ -131,7 +135,7 @@ class Crypt_Base
/**
* The Initialization Vector
*
* @see Crypt_Base::setIV()
* @see \phpseclib\Crypt\Base::setIV()
* @var String
* @access private
*/
@ -140,8 +144,8 @@ class Crypt_Base
/**
* A "sliding" Initialization Vector
*
* @see Crypt_Base::enableContinuousBuffer()
* @see Crypt_Base::_clearBuffers()
* @see \phpseclib\Crypt\Base::enableContinuousBuffer()
* @see \phpseclib\Crypt\Base::_clearBuffers()
* @var String
* @access private
*/
@ -150,8 +154,8 @@ class Crypt_Base
/**
* A "sliding" Initialization Vector
*
* @see Crypt_Base::enableContinuousBuffer()
* @see Crypt_Base::_clearBuffers()
* @see \phpseclib\Crypt\Base::enableContinuousBuffer()
* @see \phpseclib\Crypt\Base::_clearBuffers()
* @var String
* @access private
*/
@ -160,7 +164,7 @@ class Crypt_Base
/**
* Continuous Buffer status
*
* @see Crypt_Base::enableContinuousBuffer()
* @see \phpseclib\Crypt\Base::enableContinuousBuffer()
* @var Boolean
* @access private
*/
@ -169,8 +173,8 @@ class Crypt_Base
/**
* Encryption buffer for CTR, OFB and CFB modes
*
* @see Crypt_Base::encrypt()
* @see Crypt_Base::_clearBuffers()
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\Base::_clearBuffers()
* @var Array
* @access private
*/
@ -179,8 +183,8 @@ class Crypt_Base
/**
* Decryption buffer for CTR, OFB and CFB modes
*
* @see Crypt_Base::decrypt()
* @see Crypt_Base::_clearBuffers()
* @see \phpseclib\Crypt\Base::decrypt()
* @see \phpseclib\Crypt\Base::_clearBuffers()
* @var Array
* @access private
*/
@ -192,7 +196,7 @@ class Crypt_Base
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
*
* @see Crypt_Base::encrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @var Resource
* @access private
*/
@ -204,7 +208,7 @@ class Crypt_Base
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
*
* @see Crypt_Base::decrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @var Resource
* @access private
*/
@ -213,8 +217,8 @@ class Crypt_Base
/**
* Does the enmcrypt resource need to be (re)initialized?
*
* @see Crypt_Twofish::setKey()
* @see Crypt_Twofish::setIV()
* @see \phpseclib\Crypt\Twofish::setKey()
* @see \phpseclib\Crypt\Twofish::setIV()
* @var Boolean
* @access private
*/
@ -223,8 +227,8 @@ class Crypt_Base
/**
* Does the demcrypt resource need to be (re)initialized?
*
* @see Crypt_Twofish::setKey()
* @see Crypt_Twofish::setIV()
* @see \phpseclib\Crypt\Twofish::setKey()
* @see \phpseclib\Crypt\Twofish::setIV()
* @var Boolean
* @access private
*/
@ -241,9 +245,9 @@ class Crypt_Base
* use a separate ECB-mode mcrypt resource.
*
* @link http://phpseclib.sourceforge.net/cfb-demo.phps
* @see Crypt_Base::encrypt()
* @see Crypt_Base::decrypt()
* @see Crypt_Base::_setupMcrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @see \phpseclib\Crypt\Base::_setupMcrypt()
* @var Resource
* @access private
*/
@ -265,7 +269,7 @@ class Crypt_Base
* which, typically, depends on the complexity
* on its internaly Key-expanding algorithm.
*
* @see Crypt_Base::encrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @var Integer
* @access private
*/
@ -285,7 +289,7 @@ class Crypt_Base
/**
* Padding status
*
* @see Crypt_Base::enablePadding()
* @see \phpseclib\Crypt\Base::enablePadding()
* @var Boolean
* @access private
*/
@ -294,7 +298,7 @@ class Crypt_Base
/**
* Is the mode one that is paddable?
*
* @see Crypt_Base::__construct()
* @see \phpseclib\Crypt\Base::__construct()
* @var Boolean
* @access private
*/
@ -314,8 +318,8 @@ class Crypt_Base
* If possible, self::ENGINE_MCRYPT will be used for each cipher.
* Otherwise self::ENGINE_INTERNAL
*
* @see Crypt_Base::encrypt()
* @see Crypt_Base::decrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @var Integer
* @access private
*/
@ -328,7 +332,7 @@ class Crypt_Base
*
* @link http://www.php.net/mcrypt_module_open
* @link http://www.php.net/mcrypt_list_algorithms
* @see Crypt_Base::_setupMcrypt()
* @see \phpseclib\Crypt\Base::_setupMcrypt()
* @var String
* @access private
*/
@ -337,7 +341,7 @@ class Crypt_Base
/**
* The default password key_size used by setPassword()
*
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::setPassword()
* @var Integer
* @access private
*/
@ -346,7 +350,7 @@ class Crypt_Base
/**
* The default salt used by setPassword()
*
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::setPassword()
* @var String
* @access private
*/
@ -366,10 +370,10 @@ class Crypt_Base
* for each cipher.
*
* Example:
* $aes = new Crypt_AES(Crypt_AES::MODE_CFB); // $aes will operate in cfb mode
* $aes = new Crypt_AES(self::MODE_CFB); // identical
* $aes = new \phpseclib\Crypt\AES(\phpseclib\Crypt\AES::MODE_CFB); // $aes will operate in cfb mode
* $aes = new \phpseclib\Crypt\AES(self::MODE_CFB); // identical
*
* @see Crypt_Base::__construct()
* @see \phpseclib\Crypt\Base::__construct()
* @var String
* @access private
*/
@ -381,10 +385,10 @@ class Crypt_Base
* Used by encrypt() / decrypt()
* only if $engine == self::ENGINE_INTERNAL
*
* @see Crypt_Base::encrypt()
* @see Crypt_Base::decrypt()
* @see Crypt_Base::_setupInlineCrypt()
* @see Crypt_Base::$use_inline_crypt
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @see \phpseclib\Crypt\Base::$use_inline_crypt
* @var Callback
* @access private
*/
@ -393,9 +397,9 @@ class Crypt_Base
/**
* Holds whether performance-optimized $inline_crypt() can/should be used.
*
* @see Crypt_Base::encrypt()
* @see Crypt_Base::decrypt()
* @see Crypt_Base::inline_crypt
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @see \phpseclib\Crypt\Base::inline_crypt
* @var mixed
* @access private
*/
@ -480,10 +484,10 @@ class Crypt_Base
/**
* Sets the initialization vector. (optional)
*
* SetIV is not required when self::MODE_ECB (or ie for AES: Crypt_AES::MODE_ECB) is being used. If not explicitly set, it'll be assumed
* SetIV is not required when self::MODE_ECB (or ie for AES: \phpseclib\Crypt\AES::MODE_ECB) is being used. If not explicitly set, it'll be assumed
* to be all zero's.
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @access public
* @param String $iv
@ -508,7 +512,7 @@ class Crypt_Base
*
* If the key is not explicitly set, it'll be assumed to be all null bytes.
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @access public
* @param String $key
@ -528,7 +532,7 @@ class Crypt_Base
*
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @see Crypt/Hash.php
* @param String $password
@ -563,10 +567,7 @@ class Crypt_Base
switch (true) {
case $method == 'pbkdf1':
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$hashObj = new Crypt_Hash();
$hashObj = new Hash();
$hashObj->setHash($hash);
if ($dkLen > $hashObj->getLength()) {
user_error('Derived key too long');
@ -586,12 +587,9 @@ class Crypt_Base
case !function_exists('hash_pbkdf2'):
case !function_exists('hash_algos'):
case !in_array($hash, hash_algos()):
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$i = 1;
while (strlen($key) < $dkLen) {
$hmac = new Crypt_Hash();
$hmac = new Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
@ -627,9 +625,9 @@ class Crypt_Base
* strlen($plaintext) will still need to be a multiple of the block size, however, arbitrary values can be added to make it that
* length.
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @see Crypt_Base::decrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @access public
* @param String $plaintext
* @return String $cipertext
@ -855,9 +853,9 @@ class Crypt_Base
* If strlen($ciphertext) is not a multiple of the block size, null bytes will be added to the end of the string until
* it is.
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @see Crypt_Base::encrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @access public
* @param String $ciphertext
* @return String $plaintext
@ -1073,7 +1071,7 @@ class Crypt_Base
* away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is
* transmitted separately)
*
* @see Crypt_Base::disablePadding()
* @see \phpseclib\Crypt\Base::disablePadding()
* @access public
*/
function enablePadding()
@ -1084,7 +1082,7 @@ class Crypt_Base
/**
* Do not pad packets.
*
* @see Crypt_Base::enablePadding()
* @see \phpseclib\Crypt\Base::enablePadding()
* @access public
*/
function disablePadding()
@ -1121,14 +1119,14 @@ class Crypt_Base
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
*
* Put another way, when the continuous buffer is enabled, the state of the Crypt_*() object changes after each
* Put another way, when the continuous buffer is enabled, the state of the \phpseclib\Crypt\*() object changes after each
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them),
* however, they are also less intuitive and more likely to cause you problems.
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @see Crypt_Base::disableContinuousBuffer()
* @see \phpseclib\Crypt\Base::disableContinuousBuffer()
* @access public
*/
function enableContinuousBuffer()
@ -1145,9 +1143,9 @@ class Crypt_Base
*
* The default behavior.
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @see Crypt_Base::enableContinuousBuffer()
* @see \phpseclib\Crypt\Base::enableContinuousBuffer()
* @access public
*/
function disableContinuousBuffer()
@ -1166,7 +1164,7 @@ class Crypt_Base
/**
* Encrypts a block
*
* Note: Must extend by the child Crypt_* class
* Note: Must extend by the child \phpseclib\Crypt\* class
*
* @access private
* @param String $in
@ -1180,7 +1178,7 @@ class Crypt_Base
/**
* Decrypts a block
*
* Note: Must extend by the child Crypt_* class
* Note: Must extend by the child \phpseclib\Crypt\* class
*
* @access private
* @param String $in
@ -1196,9 +1194,9 @@ class Crypt_Base
*
* Only used if $engine == self::ENGINE_INTERNAL
*
* Note: Must extend by the child Crypt_* class
* Note: Must extend by the child \phpseclib\Crypt\* class
*
* @see Crypt_Base::_setup()
* @see \phpseclib\Crypt\Base::_setup()
* @access private
*/
function _setupKey()
@ -1225,7 +1223,7 @@ class Crypt_Base
*
* Internally: _setup() is called always before(!) en/decryption.
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @see setKey()
* @see setIV()
@ -1260,7 +1258,7 @@ class Crypt_Base
* - First run of encrypt() / decrypt()
*
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @see setKey()
* @see setIV()
@ -1309,7 +1307,7 @@ class Crypt_Base
* If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless
* and padding will, hence forth, be enabled.
*
* @see Crypt_Base::_unpad()
* @see \phpseclib\Crypt\Base::_unpad()
* @param String $text
* @access private
* @return String
@ -1338,7 +1336,7 @@ class Crypt_Base
* If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong
* and false will be returned.
*
* @see Crypt_Base::_pad()
* @see \phpseclib\Crypt\Base::_pad()
* @param String $text
* @access private
* @return String
@ -1365,7 +1363,7 @@ class Crypt_Base
* after disableContinuousBuffer() or on cipher $engine (re)init
* ie after setKey() or setIV()
*
* Note: Could, but not must, extend by the child Crypt_* class
* Note: Could, but not must, extend by the child \phpseclib\Crypt\* class
*
* @access public
*/
@ -1402,8 +1400,8 @@ class Crypt_Base
* Encrypt the output of this and XOR it against the ciphertext / plaintext to get the
* plaintext / ciphertext in CTR mode.
*
* @see Crypt_Base::decrypt()
* @see Crypt_Base::encrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @param String $iv
* @param Integer $length
* @access private
@ -1481,7 +1479,7 @@ class Crypt_Base
* - short (as good as possible)
*
* Note: - _setupInlineCrypt() is using _createInlineCryptFunction() to create the full callback function code.
* - In case of using inline crypting, _setupInlineCrypt() must extend by the child Crypt_* class.
* - In case of using inline crypting, _setupInlineCrypt() must extend by the child \phpseclib\Crypt\* class.
* - The following variable names are reserved:
* - $_* (all variable names prefixed with an underscore)
* - $self (object reference to it self. Do not use $this, but $self instead)
@ -1489,19 +1487,19 @@ class Crypt_Base
* - The callback function should not use the 'return' statement, but en/decrypt'ing the content of $in only
*
*
* @see Crypt_Base::_setup()
* @see Crypt_Base::_createInlineCryptFunction()
* @see Crypt_Base::encrypt()
* @see Crypt_Base::decrypt()
* @see \phpseclib\Crypt\Base::_setup()
* @see \phpseclib\Crypt\Base::_createInlineCryptFunction()
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @access private
*/
function _setupInlineCrypt()
{
// If a Crypt_* class providing inline crypting it must extend _setupInlineCrypt()
// If a \phpseclib\Crypt\* class providing inline crypting it must extend _setupInlineCrypt()
// If, for any reason, an extending Crypt_Base() Crypt_* class
// If, for any reason, an extending \phpseclib\Crypt\Base() \phpseclib\Crypt\* class
// not using inline crypting then it must be ensured that: $this->use_inline_crypt = false
// ie in the class var declaration of $use_inline_crypt in general for the Crypt_* class,
// ie in the class var declaration of $use_inline_crypt in general for the \phpseclib\Crypt\* class,
// in the constructor at object instance-time
// or, if it's runtime-specific, at runtime
@ -1598,7 +1596,7 @@ class Crypt_Base
* +----------------------------------------------------------------------------------------------+
* </code>
*
* See also the Crypt_*::_setupInlineCrypt()'s for
* See also the \phpseclib\Crypt\*::_setupInlineCrypt()'s for
* productive inline $cipher_code's how they works.
*
* Structure of:
@ -1612,9 +1610,9 @@ class Crypt_Base
* );
* </code>
*
* @see Crypt_Base::_setupInlineCrypt()
* @see Crypt_Base::encrypt()
* @see Crypt_Base::decrypt()
* @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @param Array $cipher_code
* @access private
* @return String (the name of the created callback function)

View File

@ -14,9 +14,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/Blowfish.php';
* include 'vendor/autoload.php';
*
* $blowfish = new Crypt_Blowfish();
* $blowfish = new \phpseclib\Crypt\Blowfish();
*
* $blowfish->setKey('12345678901234567890123456789012');
*
@ -27,7 +27,7 @@
* </code>
*
* @category Crypt
* @package Crypt_Blowfish
* @package Blowfish
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright 2007 Jim Wigginton
@ -35,29 +35,24 @@
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Crypt_Base
*
* Base cipher class
*/
if (!class_exists('Crypt_Base')) {
include_once 'Base.php';
}
namespace phpseclib\Crypt;
use phpseclib\Crypt\Base;
/**
* Pure-PHP implementation of Blowfish.
*
* @package Crypt_Blowfish
* @package Blowfish
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @access public
*/
class Crypt_Blowfish extends Crypt_Base
class Blowfish extends Base
{
/**
* Block Length of the cipher
*
* @see Crypt_Base::block_size
* @see \phpseclib\Crypt\Base::block_size
* @var Integer
* @access private
*/
@ -66,8 +61,8 @@ class Crypt_Blowfish extends Crypt_Base
/**
* The default password key_size used by setPassword()
*
* @see Crypt_Base::password_key_size
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::password_key_size
* @see \phpseclib\Crypt\Base::setPassword()
* @var Integer
* @access private
*/
@ -76,7 +71,7 @@ class Crypt_Blowfish extends Crypt_Base
/**
* The namespace used by the cipher for its constants.
*
* @see Crypt_Base::const_namespace
* @see \phpseclib\Crypt\Base::const_namespace
* @var String
* @access private
*/
@ -85,7 +80,7 @@ class Crypt_Blowfish extends Crypt_Base
/**
* The mcrypt specific name of the cipher
*
* @see Crypt_Base::cipher_name_mcrypt
* @see \phpseclib\Crypt\Base::cipher_name_mcrypt
* @var String
* @access private
*/
@ -94,7 +89,7 @@ class Crypt_Blowfish extends Crypt_Base
/**
* Optimizing value while CFB-encrypting
*
* @see Crypt_Base::cfb_init_len
* @see \phpseclib\Crypt\Base::cfb_init_len
* @var Integer
* @access private
*/
@ -308,7 +303,7 @@ class Crypt_Blowfish extends Crypt_Base
* If the key is not explicitly set, or empty, it'll be assumed a 128 bits key to be all null bytes.
*
* @access public
* @see Crypt_Base::setKey()
* @see \phpseclib\Crypt\Base::setKey()
* @param String $key
*/
function setKey($key)
@ -327,7 +322,7 @@ class Crypt_Blowfish extends Crypt_Base
/**
* Setup the key (expansion)
*
* @see Crypt_Base::_setupKey()
* @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@ -455,12 +450,12 @@ class Crypt_Blowfish extends Crypt_Base
/**
* Setup the performance-optimized function for de/encrypt()
*
* @see Crypt_Base::_setupInlineCrypt()
* @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
{
$lambda_functions =& Crypt_Blowfish::_getLambdaFunctions();
$lambda_functions =& self::_getLambdaFunctions();
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
@ -468,10 +463,10 @@ class Crypt_Blowfish extends Crypt_Base
switch (true) {
case $gen_hi_opt_code:
$code_hash = md5(str_pad("Crypt_Blowfish, {$this->mode}, ", 32, "\0") . $this->key);
$code_hash = md5(str_pad("Blowfish, {$this->mode}, ", 32, "\0") . $this->key);
break;
default:
$code_hash = "Crypt_Blowfish, {$this->mode}";
$code_hash = "Blowfish, {$this->mode}";
}
if (!isset($lambda_functions[$code_hash])) {

View File

@ -16,9 +16,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/DES.php';
* include 'vendor/autoload.php';
*
* $des = new Crypt_DES();
* $des = new \phpseclib\Crypt\DES();
*
* $des->setKey('abcdefgh');
*
@ -33,35 +33,30 @@
* </code>
*
* @category Crypt
* @package Crypt_DES
* @package DES
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Crypt_Base
*
* Base cipher class
*/
if (!class_exists('Crypt_Base')) {
include_once 'Base.php';
}
namespace phpseclib\Crypt;
use phpseclib\Crypt\Base;
/**
* Pure-PHP implementation of DES.
*
* @package Crypt_DES
* @package DES
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class Crypt_DES extends Crypt_Base
class DES extends Base
{
/**#@+
* @access private
* @see Crypt_DES::_setupKey()
* @see Crypt_DES::_processBlock()
* @see \phpseclib\Crypt\DES::_setupKey()
* @see \phpseclib\Crypt\DES::_processBlock()
*/
/**
* Contains $keys[self::ENCRYPT]
@ -76,7 +71,7 @@ class Crypt_DES extends Crypt_Base
/**
* Block Length of the cipher
*
* @see Crypt_Base::block_size
* @see \phpseclib\Crypt\Base::block_size
* @var Integer
* @access private
*/
@ -85,7 +80,7 @@ class Crypt_DES extends Crypt_Base
/**
* The Key
*
* @see Crypt_Base::key
* @see \phpseclib\Crypt\Base::key
* @see setKey()
* @var String
* @access private
@ -95,8 +90,8 @@ class Crypt_DES extends Crypt_Base
/**
* The default password key_size used by setPassword()
*
* @see Crypt_Base::password_key_size
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::password_key_size
* @see \phpseclib\Crypt\Base::setPassword()
* @var Integer
* @access private
*/
@ -105,7 +100,7 @@ class Crypt_DES extends Crypt_Base
/**
* The namespace used by the cipher for its constants.
*
* @see Crypt_Base::const_namespace
* @see \phpseclib\Crypt\Base::const_namespace
* @var String
* @access private
*/
@ -114,7 +109,7 @@ class Crypt_DES extends Crypt_Base
/**
* The mcrypt specific name of the cipher
*
* @see Crypt_Base::cipher_name_mcrypt
* @see \phpseclib\Crypt\Base::cipher_name_mcrypt
* @var String
* @access private
*/
@ -123,7 +118,7 @@ class Crypt_DES extends Crypt_Base
/**
* Optimizing value while CFB-encrypting
*
* @see Crypt_Base::cfb_init_len
* @see \phpseclib\Crypt\Base::cfb_init_len
* @var Integer
* @access private
*/
@ -134,8 +129,8 @@ class Crypt_DES extends Crypt_Base
*
* Used only if $engine == self::ENGINE_INTERNAL
*
* @see Crypt_DES::_setupKey()
* @see Crypt_DES::_processBlock()
* @see \phpseclib\Crypt\DES::_setupKey()
* @see \phpseclib\Crypt\DES::_processBlock()
* @var Integer
* @access private
*/
@ -144,7 +139,7 @@ class Crypt_DES extends Crypt_Base
/**
* max possible size of $key
*
* @see Crypt_DES::setKey()
* @see \phpseclib\Crypt\DES::setKey()
* @var String
* @access private
*/
@ -153,7 +148,7 @@ class Crypt_DES extends Crypt_Base
/**
* The Key Schedule
*
* @see Crypt_DES::_setupKey()
* @see \phpseclib\Crypt\DES::_setupKey()
* @var Array
* @access private
*/
@ -166,8 +161,8 @@ class Crypt_DES extends Crypt_Base
* with each byte containing all bits in the same state as the
* corresponding bit in the index value.
*
* @see Crypt_DES::_processBlock()
* @see Crypt_DES::_setupKey()
* @see \phpseclib\Crypt\DES::_processBlock()
* @see \phpseclib\Crypt\DES::_setupKey()
* @var Array
* @access private
*/
@ -601,7 +596,7 @@ class Crypt_DES extends Crypt_Base
*
* If the key is not explicitly set, it'll be assumed to be all zero's.
*
* @see Crypt_Base::setKey()
* @see \phpseclib\Crypt\Base::setKey()
* @access public
* @param String $key
*/
@ -620,9 +615,9 @@ class Crypt_DES extends Crypt_Base
/**
* Encrypts a block
*
* @see Crypt_Base::_encryptBlock()
* @see Crypt_Base::encrypt()
* @see Crypt_DES::encrypt()
* @see \phpseclib\Crypt\Base::_encryptBlock()
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\DES::encrypt()
* @access private
* @param String $in
* @return String
@ -635,9 +630,9 @@ class Crypt_DES extends Crypt_Base
/**
* Decrypts a block
*
* @see Crypt_Base::_decryptBlock()
* @see Crypt_Base::decrypt()
* @see Crypt_DES::decrypt()
* @see \phpseclib\Crypt\Base::_decryptBlock()
* @see \phpseclib\Crypt\Base::decrypt()
* @see \phpseclib\Crypt\DES::decrypt()
* @access private
* @param String $in
* @return String
@ -654,8 +649,8 @@ class Crypt_DES extends Crypt_Base
* {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general
* idea of what this function does.
*
* @see Crypt_DES::_encryptBlock()
* @see Crypt_DES::_decryptBlock()
* @see \phpseclib\Crypt\DES::_encryptBlock()
* @see \phpseclib\Crypt\DES::_decryptBlock()
* @access private
* @param String $block
* @param Integer $mode
@ -739,7 +734,7 @@ class Crypt_DES extends Crypt_Base
/**
* Creates the key schedule
*
* @see Crypt_Base::_setupKey()
* @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@ -1274,12 +1269,12 @@ class Crypt_DES extends Crypt_Base
/**
* Setup the performance-optimized function for de/encrypt()
*
* @see Crypt_Base::_setupInlineCrypt()
* @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
{
$lambda_functions =& Crypt_DES::_getLambdaFunctions();
$lambda_functions =& self::_getLambdaFunctions();
// Engine configuration for:
// - DES ($des_rounds == 1) or
@ -1295,13 +1290,13 @@ class Crypt_DES extends Crypt_Base
case $gen_hi_opt_code:
// For hi-optimized code, we create for each combination of
// $mode, $des_rounds and $this->key its own encrypt/decrypt function.
$code_hash = md5(str_pad("Crypt_DES, $des_rounds, {$this->mode}, ", 32, "\0") . $this->key);
$code_hash = md5(str_pad("DES, $des_rounds, {$this->mode}, ", 32, "\0") . $this->key);
break;
default:
// After max 10 hi-optimized functions, we create generic
// (still very fast.. but not ultra) functions for each $mode/$des_rounds
// Currently 2 * 5 generic functions will be then max. possible.
$code_hash = "Crypt_DES, $des_rounds, {$this->mode}";
$code_hash = "DES, $des_rounds, {$this->mode}";
}
// Is there a re-usable $lambda_functions in there? If not, we have to create it.

View File

@ -7,7 +7,7 @@
*
* md2, md5, md5-96, sha1, sha1-96, sha256, sha256-96, sha384, and sha512, sha512-96
*
* If {@link Crypt_Hash::setKey() setKey()} is called, {@link Crypt_Hash::hash() hash()} will return the HMAC as opposed to
* If {@link \phpseclib\Crypt\Hash::setKey() setKey()} is called, {@link \phpseclib\Crypt\Hash::hash() hash()} will return the HMAC as opposed to
* the hash. If no valid algorithm is provided, sha1 will be used.
*
* PHP versions 4 and 5
@ -18,9 +18,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/Hash.php';
* include 'vendor/autoload.php';
*
* $hash = new Crypt_Hash('sha1');
* $hash = new \phpseclib\Crypt\Hash('sha1');
*
* $hash->setKey('abcdefg');
*
@ -29,27 +29,29 @@
* </code>
*
* @category Crypt
* @package Crypt_Hash
* @package Hash
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
use \phpseclib\Math\BigInteger;
namespace phpseclib\Crypt;
use phpseclib\Math\BigInteger;
/**
* Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
*
* @package Crypt_Hash
* @package Hash
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class Crypt_Hash
class Hash
{
/**#@+
* @access private
* @see Crypt_Hash::__construct()
* @see \phpseclib\Crypt\Hash::__construct()
*/
/**
* Toggles the internal implementation
@ -68,7 +70,7 @@ class Crypt_Hash
/**
* Hash Parameter
*
* @see Crypt_Hash::setHash()
* @see \phpseclib\Crypt\Hash::setHash()
* @var Integer
* @access private
*/
@ -77,7 +79,7 @@ class Crypt_Hash
/**
* Byte-length of compression blocks / key (Internal HMAC)
*
* @see Crypt_Hash::setAlgorithm()
* @see \phpseclib\Crypt\Hash::setAlgorithm()
* @var Integer
* @access private
*/
@ -86,7 +88,7 @@ class Crypt_Hash
/**
* Byte-length of hash output (Internal HMAC)
*
* @see Crypt_Hash::setHash()
* @see \phpseclib\Crypt\Hash::setHash()
* @var Integer
* @access private
*/
@ -95,7 +97,7 @@ class Crypt_Hash
/**
* Hash Algorithm
*
* @see Crypt_Hash::setHash()
* @see \phpseclib\Crypt\Hash::setHash()
* @var String
* @access private
*/
@ -104,7 +106,7 @@ class Crypt_Hash
/**
* Key
*
* @see Crypt_Hash::setKey()
* @see \phpseclib\Crypt\Hash::setKey()
* @var String
* @access private
*/
@ -113,7 +115,7 @@ class Crypt_Hash
/**
* Outer XOR (Internal HMAC)
*
* @see Crypt_Hash::setKey()
* @see \phpseclib\Crypt\Hash::setKey()
* @var String
* @access private
*/
@ -122,7 +124,7 @@ class Crypt_Hash
/**
* Inner XOR (Internal HMAC)
*
* @see Crypt_Hash::setKey()
* @see \phpseclib\Crypt\Hash::setKey()
* @var String
* @access private
*/
@ -132,7 +134,7 @@ class Crypt_Hash
* Default Constructor.
*
* @param optional String $hash
* @return Crypt_Hash
* @return \phpseclib\Crypt\Hash
* @access public
*/
function __construct($hash = 'sha1')
@ -721,7 +723,7 @@ class Crypt_Hash
}
// Produce the final hash value (big-endian)
// (Crypt_Hash::hash() trims the output for hashes but not for HMACs. as such, we trim the output here)
// (\phpseclib\Crypt\Hash::hash() trims the output for hashes but not for HMACs. as such, we trim the output here)
$temp = $hash[0]->toBytes() . $hash[1]->toBytes() . $hash[2]->toBytes() . $hash[3]->toBytes() .
$hash[4]->toBytes() . $hash[5]->toBytes();
if ($this->l != 48) {

View File

@ -14,9 +14,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/RC2.php';
* include 'vendor/autoload.php';
*
* $rc2 = new Crypt_RC2();
* $rc2 = new \phpseclib\Crypt\RC2();
*
* $rc2->setKey('abcdefgh');
*
@ -27,33 +27,28 @@
* </code>
*
* @category Crypt
* @package Crypt_RC2
* @package RC2
* @author Patrick Monnerat <pm@datasphere.ch>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Crypt_Base
*
* Base cipher class
*/
if (!class_exists('Crypt_Base')) {
include_once 'Base.php';
}
namespace phpseclib\Crypt;
use phpseclib\Crypt\Base;
/**
* Pure-PHP implementation of RC2.
*
* @package Crypt_RC2
* @package RC2
* @access public
*/
class Crypt_RC2 extends Crypt_Base
class RC2 extends Base
{
/**
* Block Length of the cipher
*
* @see Crypt_Base::block_size
* @see \phpseclib\Crypt\Base::block_size
* @var Integer
* @access private
*/
@ -62,7 +57,7 @@ class Crypt_RC2 extends Crypt_Base
/**
* The Key
*
* @see Crypt_Base::key
* @see \phpseclib\Crypt\Base::key
* @see setKey()
* @var String
* @access private
@ -72,8 +67,8 @@ class Crypt_RC2 extends Crypt_Base
/**
* The default password key_size used by setPassword()
*
* @see Crypt_Base::password_key_size
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::password_key_size
* @see \phpseclib\Crypt\Base::setPassword()
* @var Integer
* @access private
*/
@ -82,7 +77,7 @@ class Crypt_RC2 extends Crypt_Base
/**
* The namespace used by the cipher for its constants.
*
* @see Crypt_Base::const_namespace
* @see \phpseclib\Crypt\Base::const_namespace
* @var String
* @access private
*/
@ -91,7 +86,7 @@ class Crypt_RC2 extends Crypt_Base
/**
* The mcrypt specific name of the cipher
*
* @see Crypt_Base::cipher_name_mcrypt
* @see \phpseclib\Crypt\Base::cipher_name_mcrypt
* @var String
* @access private
*/
@ -100,7 +95,7 @@ class Crypt_RC2 extends Crypt_Base
/**
* Optimizing value while CFB-encrypting
*
* @see Crypt_Base::cfb_init_len
* @see \phpseclib\Crypt\Base::cfb_init_len
* @var Integer
* @access private
*/
@ -109,8 +104,8 @@ class Crypt_RC2 extends Crypt_Base
/**
* The key length in bits.
*
* @see Crypt_RC2::setKeyLength()
* @see Crypt_RC2::setKey()
* @see \phpseclib\Crypt\RC2::setKeyLength()
* @see \phpseclib\Crypt\RC2::setKey()
* @var Integer
* @access private
* @internal Should be in range [1..1024].
@ -121,7 +116,7 @@ class Crypt_RC2 extends Crypt_Base
/**
* The Key Schedule
*
* @see Crypt_RC2::_setupKey()
* @see \phpseclib\Crypt\RC2::_setupKey()
* @var Array
* @access private
*/
@ -131,7 +126,7 @@ class Crypt_RC2 extends Crypt_Base
* Key expansion randomization table.
* Twice the same 256-value sequence to save a modulus in key expansion.
*
* @see Crypt_RC2::setKey()
* @see \phpseclib\Crypt\RC2::setKey()
* @var Array
* @access private
*/
@ -205,7 +200,7 @@ class Crypt_RC2 extends Crypt_Base
/**
* Inverse key expansion randomization table.
*
* @see Crypt_RC2::setKey()
* @see \phpseclib\Crypt\RC2::setKey()
* @var Array
* @access private
*/
@ -251,23 +246,23 @@ class Crypt_RC2 extends Crypt_Base
*
* $mode could be:
*
* - Crypt_Base::MODE_ECB
* - \phpseclib\Crypt\Base::MODE_ECB
*
* - Crypt_Base::MODE_CBC
* - \phpseclib\Crypt\Base::MODE_CBC
*
* - Crypt_Base::MODE_CTR
* - \phpseclib\Crypt\Base::MODE_CTR
*
* - Crypt_Base::MODE_CFB
* - \phpseclib\Crypt\Base::MODE_CFB
*
* - Crypt_Base::MODE_OFB
* - \phpseclib\Crypt\Base::MODE_OFB
*
* If not explicitly set, Crypt_Base::MODE_CBC will be used.
* If not explicitly set, \phpseclib\Crypt\Base::MODE_CBC will be used.
*
* @see Crypt_Base::__construct()
* @see \phpseclib\Crypt\Base::__construct()
* @param optional Integer $mode
* @access public
*/
function __construct($mode = Crypt_Base::MODE_CBC)
function __construct($mode = Base::MODE_CBC)
{
parent::__construct($mode);
$this->setKey('');
@ -278,7 +273,7 @@ class Crypt_RC2 extends Crypt_Base
*
* Valid key lengths are 1 to 1024.
* Calling this function after setting the key has no effect until the next
* Crypt_RC2::setKey() call.
* \phpseclib\Crypt\RC2::setKey() call.
*
* @access public
* @param Integer $length in bits
@ -301,7 +296,7 @@ class Crypt_RC2 extends Crypt_Base
* If the key is not explicitly set, it'll be assumed to be a single
* null byte.
*
* @see Crypt_Base::setKey()
* @see \phpseclib\Crypt\Base::setKey()
* @access public
* @param String $key
* @param Integer $t1 optional Effective key length in bits.
@ -348,8 +343,8 @@ class Crypt_RC2 extends Crypt_Base
/**
* Encrypts a block
*
* @see Crypt_Base::_encryptBlock()
* @see Crypt_Base::encrypt()
* @see \phpseclib\Crypt\Base::_encryptBlock()
* @see \phpseclib\Crypt\Base::encrypt()
* @access private
* @param String $in
* @return String
@ -393,8 +388,8 @@ class Crypt_RC2 extends Crypt_Base
/**
* Decrypts a block
*
* @see Crypt_Base::_decryptBlock()
* @see Crypt_Base::decrypt()
* @see \phpseclib\Crypt\Base::_decryptBlock()
* @see \phpseclib\Crypt\Base::decrypt()
* @access private
* @param String $in
* @return String
@ -438,12 +433,12 @@ class Crypt_RC2 extends Crypt_Base
/**
* Creates the key schedule
*
* @see Crypt_Base::_setupKey()
* @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
{
// Key has already been expanded in Crypt_RC2::setKey():
// Key has already been expanded in \phpseclib\Crypt\RC2::setKey():
// Only the first value must be altered.
$l = unpack('Ca/Cb/v*', $this->key);
array_unshift($l, $this->pitable[$l['a']] | ($l['b'] << 8));
@ -455,12 +450,12 @@ class Crypt_RC2 extends Crypt_Base
/**
* Setup the performance-optimized function for de/encrypt()
*
* @see Crypt_Base::_setupInlineCrypt()
* @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
{
$lambda_functions = &Crypt_RC2::_getLambdaFunctions();
$lambda_functions =& self::_getLambdaFunctions();
// The first 10 generated $lambda_functions will use the $keys hardcoded as integers
// for the mixing rounds, for better inline crypt performance [~20% faster].
@ -472,7 +467,7 @@ class Crypt_RC2 extends Crypt_Base
}
}
$code_hash = md5(str_pad("Crypt_RC2, {$this->mode}, ", 32, "\0") . implode(',', $keys));
$code_hash = md5(str_pad("RC2, {$this->mode}, ", 32, "\0") . implode(',', $keys));
// Is there a re-usable $lambda_functions in there?
// If not, we have to create it.

View File

@ -18,9 +18,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/RC4.php';
* include 'vendor/autoload.php';
*
* $rc4 = new Crypt_RC4();
* $rc4 = new \phpseclib\Crypt\RC4();
*
* $rc4->setKey('abcdefgh');
*
@ -35,34 +35,29 @@
* </code>
*
* @category Crypt
* @package Crypt_RC4
* @package RC4
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Crypt_Base
*
* Base cipher class
*/
if (!class_exists('Crypt_Base')) {
include_once 'Base.php';
}
namespace phpseclib\Crypt;
use phpseclib\Crypt\Base;
/**
* Pure-PHP implementation of RC4.
*
* @package Crypt_RC4
* @package RC4
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class Crypt_RC4 extends Crypt_Base
class RC4 extends Base
{
/**#@+
* @access private
* @see Crypt_RC4::_crypt()
* @see \phpseclib\Crypt\RC4::_crypt()
*/
const ENCRYPT = 0;
const DECRYPT = 1;
@ -74,7 +69,7 @@ class Crypt_RC4 extends Crypt_Base
* RC4 is a stream cipher
* so we the block_size to 0
*
* @see Crypt_Base::block_size
* @see \phpseclib\Crypt\Base::block_size
* @var Integer
* @access private
*/
@ -83,8 +78,8 @@ class Crypt_RC4 extends Crypt_Base
/**
* The default password key_size used by setPassword()
*
* @see Crypt_Base::password_key_size
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::password_key_size
* @see \phpseclib\Crypt\Base::setPassword()
* @var Integer
* @access private
*/
@ -93,7 +88,7 @@ class Crypt_RC4 extends Crypt_Base
/**
* The namespace used by the cipher for its constants.
*
* @see Crypt_Base::const_namespace
* @see \phpseclib\Crypt\Base::const_namespace
* @var String
* @access private
*/
@ -102,7 +97,7 @@ class Crypt_RC4 extends Crypt_Base
/**
* The mcrypt specific name of the cipher
*
* @see Crypt_Base::cipher_name_mcrypt
* @see \phpseclib\Crypt\Base::cipher_name_mcrypt
* @var String
* @access private
*/
@ -111,7 +106,7 @@ class Crypt_RC4 extends Crypt_Base
/**
* Holds whether performance-optimized $inline_crypt() can/should be used.
*
* @see Crypt_Base::inline_crypt
* @see \phpseclib\Crypt\Base::inline_crypt
* @var mixed
* @access private
*/
@ -120,7 +115,7 @@ class Crypt_RC4 extends Crypt_Base
/**
* The Key
*
* @see Crypt_RC4::setKey()
* @see \phpseclib\Crypt\RC4::setKey()
* @var String
* @access private
*/
@ -129,7 +124,7 @@ class Crypt_RC4 extends Crypt_Base
/**
* The Key Stream for decryption and encryption
*
* @see Crypt_RC4::setKey()
* @see \phpseclib\Crypt\RC4::setKey()
* @var Array
* @access private
*/
@ -140,13 +135,13 @@ class Crypt_RC4 extends Crypt_Base
*
* Determines whether or not the mcrypt extension should be used.
*
* @see Crypt_Base::__construct()
* @return Crypt_RC4
* @see \phpseclib\Crypt\Base::__construct()
* @return \phpseclib\Crypt\RC4
* @access public
*/
function __construct()
{
parent::__construct(Crypt_Base::MODE_STREAM);
parent::__construct(Base::MODE_STREAM);
}
/**
@ -165,7 +160,7 @@ class Crypt_RC4 extends Crypt_Base
* {@link http://en.wikipedia.org/wiki/Related_key_attack http://en.wikipedia.org/wiki/Related_key_attack}
*
* @param String $iv
* @see Crypt_RC4::setKey()
* @see \phpseclib\Crypt\RC4::setKey()
* @access public
*/
function setIV($iv)
@ -179,7 +174,7 @@ class Crypt_RC4 extends Crypt_Base
* be used. If no key is explicitly set, it'll be assumed to be a single null byte.
*
* @access public
* @see Crypt_Base::setKey()
* @see \phpseclib\Crypt\Base::setKey()
* @param String $key
*/
function setKey($key)
@ -190,15 +185,15 @@ class Crypt_RC4 extends Crypt_Base
/**
* Encrypts a message.
*
* @see Crypt_Base::decrypt()
* @see Crypt_RC4::_crypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @see \phpseclib\Crypt\RC4::_crypt()
* @access public
* @param String $plaintext
* @return String $ciphertext
*/
function encrypt($plaintext)
{
if ($this->engine == Crypt_Base::ENGINE_MCRYPT) {
if ($this->engine == Base::ENGINE_MCRYPT) {
return parent::encrypt($plaintext);
}
return $this->_crypt($plaintext, self::ENCRYPT);
@ -210,15 +205,15 @@ class Crypt_RC4 extends Crypt_Base
* $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)).
* At least if the continuous buffer is disabled.
*
* @see Crypt_Base::encrypt()
* @see Crypt_RC4::_crypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @see \phpseclib\Crypt\RC4::_crypt()
* @access public
* @param String $ciphertext
* @return String $plaintext
*/
function decrypt($ciphertext)
{
if ($this->engine == Crypt_Base::ENGINE_MCRYPT) {
if ($this->engine == Base::ENGINE_MCRYPT) {
return parent::decrypt($ciphertext);
}
return $this->_crypt($ciphertext, self::DECRYPT);
@ -228,7 +223,7 @@ class Crypt_RC4 extends Crypt_Base
/**
* Setup the key (expansion)
*
* @see Crypt_Base::_setupKey()
* @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@ -255,8 +250,8 @@ class Crypt_RC4 extends Crypt_Base
/**
* Encrypts or decrypts a message.
*
* @see Crypt_RC4::encrypt()
* @see Crypt_RC4::decrypt()
* @see \phpseclib\Crypt\RC4::encrypt()
* @see \phpseclib\Crypt\RC4::decrypt()
* @access private
* @param String $text
* @param Integer $mode

View File

@ -8,9 +8,9 @@
* Here's an example of how to encrypt and decrypt text with this library:
* <code>
* <?php
* include 'Crypt/RSA.php';
* include 'vendor/autoload.php';
*
* $rsa = new Crypt_RSA();
* $rsa = new \phpseclib\Crypt\RSA();
* extract($rsa->createKey());
*
* $plaintext = 'terrafrost';
@ -26,9 +26,9 @@
* Here's an example of how to create signatures and verify signatures with this library:
* <code>
* <?php
* include 'Crypt/RSA.php';
* include 'vendor/autoload.php';
*
* $rsa = new Crypt_RSA();
* $rsa = new \phpseclib\Crypt\RSA();
* extract($rsa->createKey());
*
* $plaintext = 'terrafrost';
@ -42,36 +42,37 @@
* </code>
*
* @category Crypt
* @package Crypt_RSA
* @package RSA
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2009 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
use \phpseclib\Crypt\Random;
use \phpseclib\Math\BigInteger;
namespace phpseclib\Crypt;
/**
* Include Crypt_Hash
*/
if (!class_exists('Crypt_Hash')) {
include_once 'Hash.php';
}
use phpseclib\Crypt\AES;
use phpseclib\Crypt\Base;
use phpseclib\Crypt\DES;
use phpseclib\Crypt\Hash;
use phpseclib\Crypt\Random;
use phpseclib\Crypt\RSA;
use phpseclib\Crypt\TripleDES;
use phpseclib\Math\BigInteger;
/**
* Pure-PHP PKCS#1 compliant implementation of RSA.
*
* @package Crypt_RSA
* @package RSA
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class Crypt_RSA
class RSA
{
/**#@+
* @access public
* @see Crypt_RSA::encrypt()
* @see Crypt_RSA::decrypt()
* @see \phpseclib\Crypt\RSA::encrypt()
* @see \phpseclib\Crypt\RSA::decrypt()
*/
/**
* Use {@link http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding Optimal Asymmetric Encryption Padding}
@ -79,8 +80,8 @@ class Crypt_RSA
*
* Uses sha1 by default.
*
* @see Crypt_RSA::setHash()
* @see Crypt_RSA::setMGFHash()
* @see \phpseclib\Crypt\RSA::setHash()
* @see \phpseclib\Crypt\RSA::setMGFHash()
*/
const ENCRYPTION_OAEP = 1;
/**
@ -94,17 +95,17 @@ class Crypt_RSA
/**#@+
* @access public
* @see Crypt_RSA::sign()
* @see Crypt_RSA::verify()
* @see Crypt_RSA::setHash()
* @see \phpseclib\Crypt\RSA::sign()
* @see \phpseclib\Crypt\RSA::verify()
* @see \phpseclib\Crypt\RSA::setHash()
*/
/**
* Use the Probabilistic Signature Scheme for signing
*
* Uses sha1 by default.
*
* @see Crypt_RSA::setSaltLength()
* @see Crypt_RSA::setMGFHash()
* @see \phpseclib\Crypt\RSA::setSaltLength()
* @see \phpseclib\Crypt\RSA::setMGFHash()
*/
const SIGNATURE_PSS = 1;
/**
@ -118,7 +119,7 @@ class Crypt_RSA
/**#@+
* @access private
* @see Crypt_RSA::createKey()
* @see \phpseclib\Crypt\RSA::createKey()
*/
/**
* ASN1 Integer
@ -144,7 +145,7 @@ class Crypt_RSA
/**#@+
* @access private
* @see Crypt_RSA::__construct()
* @see \phpseclib\Crypt\RSA::__construct()
*/
/**
* To use the pure-PHP implementation
@ -160,8 +161,8 @@ class Crypt_RSA
/**#@+
* @access public
* @see Crypt_RSA::createKey()
* @see Crypt_RSA::setPrivateKeyFormat()
* @see \phpseclib\Crypt\RSA::createKey()
* @see \phpseclib\Crypt\RSA::setPrivateKeyFormat()
*/
/**
* PKCS#1 formatted private key
@ -185,8 +186,8 @@ class Crypt_RSA
/**#@+
* @access public
* @see Crypt_RSA::createKey()
* @see Crypt_RSA::setPublicKeyFormat()
* @see \phpseclib\Crypt\RSA::createKey()
* @see \phpseclib\Crypt\RSA::setPublicKeyFormat()
*/
/**
* Raw public key
@ -332,7 +333,7 @@ class Crypt_RSA
/**
* Hash function
*
* @var Crypt_Hash
* @var \phpseclib\Crypt\Hash
* @access private
*/
var $hash;
@ -356,7 +357,7 @@ class Crypt_RSA
/**
* Hash function for the Mask Generation Function
*
* @var Crypt_Hash
* @var \phpseclib\Crypt\Hash
* @access private
*/
var $mgfHash;
@ -407,7 +408,7 @@ class Crypt_RSA
* For use with parsing XML formatted keys. PHP's XML Parser functions use utilized - instead of PHP's DOM functions -
* because PHP's XML Parser functions work on PHP4 whereas PHP's DOM functions - although surperior - don't.
*
* @see Crypt_RSA::_start_element_handler()
* @see \phpseclib\Crypt\RSA::_start_element_handler()
* @var Array
* @access private
*/
@ -418,8 +419,8 @@ class Crypt_RSA
*
* For use with parsing XML formatted keys.
*
* @see Crypt_RSA::_character_handler()
* @see Crypt_RSA::_stop_element_handler()
* @see \phpseclib\Crypt\RSA::_character_handler()
* @see \phpseclib\Crypt\RSA::_stop_element_handler()
* @var Mixed
* @access private
*/
@ -429,7 +430,7 @@ class Crypt_RSA
* OpenSSL configuration file name.
*
* Set to null to use system configuration file.
* @see Crypt_RSA::createKey()
* @see \phpseclib\Crypt\RSA::createKey()
* @var Mixed
* @Access public
*/
@ -447,10 +448,10 @@ class Crypt_RSA
* The constructor
*
* If you want to make use of the openssl extension, you'll need to set the mode manually, yourself. The reason
* Crypt_RSA doesn't do it is because OpenSSL doesn't fail gracefully. openssl_pkey_new(), in particular, requires
* \phpseclib\Crypt\RSA doesn't do it is because OpenSSL doesn't fail gracefully. openssl_pkey_new(), in particular, requires
* openssl.cnf be present somewhere and, unfortunately, the only real way to find out is too late.
*
* @return Crypt_RSA
* @return \phpseclib\Crypt\RSA
* @access public
*/
function __construct()
@ -505,10 +506,10 @@ class Crypt_RSA
$this->zero = new BigInteger();
$this->one = new BigInteger(1);
$this->hash = new Crypt_Hash('sha1');
$this->hash = new Hash('sha1');
$this->hLen = $this->hash->getLength();
$this->hashName = 'sha1';
$this->mgfHash = new Crypt_Hash('sha1');
$this->mgfHash = new Hash('sha1');
$this->mgfHLen = $this->mgfHash->getLength();
}
@ -519,7 +520,7 @@ class Crypt_RSA
* - 'privatekey': The private key.
* - 'publickey': The public key.
* - 'partialkey': A partially computed key (if the execution time exceeded $timeout).
* Will need to be passed back to Crypt_RSA::createKey() as the third parameter for further processing.
* Will need to be passed back to \phpseclib\Crypt\RSA::createKey() as the third parameter for further processing.
*
* @access public
* @param optional Integer $bits
@ -767,9 +768,6 @@ class Crypt_RSA
} else {
$private.= Random::string(16 - (strlen($private) & 15));
$source.= pack('Na*', strlen($private), $private);
if (!class_exists('Crypt_AES')) {
include_once 'Crypt/AES.php';
}
$sequence = 0;
$symkey = '';
while (strlen($symkey) < 32) {
@ -777,7 +775,7 @@ class Crypt_RSA
$symkey.= pack('H*', sha1($temp));
}
$symkey = substr($symkey, 0, 32);
$crypto = new Crypt_AES();
$crypto = new AES();
$crypto->setKey($symkey);
$crypto->disablePadding();
@ -788,10 +786,7 @@ class Crypt_RSA
$private = base64_encode($private);
$key.= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n";
$key.= chunk_split($private, 64);
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$hash = new Crypt_Hash('sha1');
$hash = new Hash('sha1');
$hash->setKey(pack('H*', sha1($hashkey)));
$key.= 'Private-MAC: ' . bin2hex($hash->hash($source)) . "\r\n";
@ -834,10 +829,7 @@ class Crypt_RSA
$salt = Random::string(8);
$iterationCount = 2048;
if (!class_exists('Crypt_DES')) {
include_once 'Crypt/DES.php';
}
$crypto = new Crypt_DES();
$crypto = new DES();
$crypto->setPassword($this->password, 'pbkdf1', 'md5', $salt, $iterationCount);
$RSAPrivateKey = $crypto->encrypt($RSAPrivateKey);
@ -874,10 +866,7 @@ class Crypt_RSA
$iv = Random::string(8);
$symkey = pack('H*', md5($this->password . $iv)); // symkey is short for symmetric key
$symkey.= substr(pack('H*', md5($symkey . $this->password . $iv)), 0, 8);
if (!class_exists('Crypt_TripleDES')) {
include_once 'Crypt/TripleDES.php';
}
$des = new Crypt_TripleDES();
$des = new TripleDES();
$des->setKey($symkey);
$des->setIV($iv);
$iv = strtoupper(bin2hex($iv));
@ -1048,36 +1037,21 @@ class Crypt_RSA
}
switch ($matches[1]) {
case 'AES-256-CBC':
if (!class_exists('Crypt_AES')) {
include_once 'Crypt/AES.php';
}
$crypto = new Crypt_AES();
$crypto = new AES();
break;
case 'AES-128-CBC':
if (!class_exists('Crypt_AES')) {
include_once 'Crypt/AES.php';
}
$symkey = substr($symkey, 0, 16);
$crypto = new Crypt_AES();
$crypto = new AES();
break;
case 'DES-EDE3-CFB':
if (!class_exists('Crypt_TripleDES')) {
include_once 'Crypt/TripleDES.php';
}
$crypto = new Crypt_TripleDES(Crypt_TripleDES::MODE_CFB);
$crypto = new TripleDES(Base::MODE_CFB);
break;
case 'DES-EDE3-CBC':
if (!class_exists('Crypt_TripleDES')) {
include_once 'Crypt/TripleDES.php';
}
$symkey = substr($symkey, 0, 24);
$crypto = new Crypt_TripleDES();
$crypto = new TripleDES();
break;
case 'DES-CBC':
if (!class_exists('Crypt_DES')) {
include_once 'Crypt/DES.php';
}
$crypto = new Crypt_DES();
$crypto = new DES();
break;
default:
return false;
@ -1153,10 +1127,7 @@ class Crypt_RSA
return false;
}
if (!class_exists('Crypt_DES')) {
include_once 'Crypt/DES.php';
}
$crypto = new Crypt_DES();
$crypto = new DES();
$crypto->setPassword($this->password, 'pbkdf1', 'md5', $salt, $iterationCount);
$key = $crypto->decrypt($key);
if ($key === false) {
@ -1334,9 +1305,6 @@ class Crypt_RSA
switch ($encryption) {
case 'aes256-cbc':
if (!class_exists('Crypt_AES')) {
include_once 'Crypt/AES.php';
}
$symkey = '';
$sequence = 0;
while (strlen($symkey) < 32) {
@ -1344,7 +1312,7 @@ class Crypt_RSA
$symkey.= pack('H*', sha1($temp));
}
$symkey = substr($symkey, 0, 32);
$crypto = new Crypt_AES();
$crypto = new AES();
}
if ($encryption != 'none') {
@ -1486,7 +1454,7 @@ class Crypt_RSA
*/
function loadKey($key, $type = false)
{
if (is_object($key) && strtolower(get_class($key)) == 'crypt_rsa') {
if (is_object($key) && get_class($key) == 'phpseclib\Crypt\RSA') {
$this->privateKeyFormat = $key->privateKeyFormat;
$this->publicKeyFormat = $key->publicKeyFormat;
$this->k = $key->k;
@ -1500,10 +1468,10 @@ class Crypt_RSA
$this->comment = $key->comment;
if (is_object($key->hash)) {
$this->hash = new Crypt_Hash($key->hash->getHash());
$this->hash = new Hash($key->hash->getHash());
}
if (is_object($key->mgfHash)) {
$this->mgfHash = new Crypt_Hash($key->mgfHash->getHash());
$this->mgfHash = new Hash($key->mgfHash->getHash());
}
if (is_object($key->modulus)) {
@ -1694,7 +1662,7 @@ class Crypt_RSA
return true;
}
$rsa = new Crypt_RSA();
$rsa = new RSA();
if (!$rsa->loadKey($key, $type)) {
return false;
}
@ -1799,7 +1767,7 @@ class Crypt_RSA
*/
function __clone()
{
$key = new Crypt_RSA();
$key = new RSA();
$key->loadKey($this);
return $key;
}
@ -1923,7 +1891,7 @@ class Crypt_RSA
*/
function setHash($hash)
{
// Crypt_Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
// \phpseclib\Crypt\Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
switch ($hash) {
case 'md2':
case 'md5':
@ -1931,11 +1899,11 @@ class Crypt_RSA
case 'sha256':
case 'sha384':
case 'sha512':
$this->hash = new Crypt_Hash($hash);
$this->hash = new Hash($hash);
$this->hashName = $hash;
break;
default:
$this->hash = new Crypt_Hash('sha1');
$this->hash = new Hash('sha1');
$this->hashName = 'sha1';
}
$this->hLen = $this->hash->getLength();
@ -1952,7 +1920,7 @@ class Crypt_RSA
*/
function setMGFHash($hash)
{
// Crypt_Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
// \phpseclib\Crypt\Hash supports algorithms that PKCS#1 doesn't support. md5-96 and sha1-96, for example.
switch ($hash) {
case 'md2':
case 'md5':
@ -1960,10 +1928,10 @@ class Crypt_RSA
case 'sha256':
case 'sha384':
case 'sha512':
$this->mgfHash = new Crypt_Hash($hash);
$this->mgfHash = new Hash($hash);
break;
default:
$this->mgfHash = new Crypt_Hash('sha1');
$this->mgfHash = new Hash('sha1');
}
$this->mgfHLen = $this->mgfHash->getLength();
}
@ -2426,7 +2394,7 @@ class Crypt_RSA
* to be 2 regardless of which key is used. For compatibility purposes, we'll just check to make sure the
* second byte is 2 or less. If it is, we'll accept the decrypted string as valid.
*
* As a consequence of this, a private key encrypted ciphertext produced with Crypt_RSA may not decrypt
* As a consequence of this, a private key encrypted ciphertext produced with \phpseclib\Crypt\RSA may not decrypt
* with a strictly PKCS#1 v1.5 compliant RSA implementation. Public key encrypted ciphertext's should but
* not private key encrypted ciphertext's.
*

View File

@ -8,9 +8,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/Random.php';
* include 'vendor/autoload.php';
*
* echo bin2hex(Random::string(8));
* echo bin2hex(\phpseclib\Crypt\Random::string(8));
* ?>
* </code>
*
@ -24,6 +24,14 @@
namespace phpseclib\Crypt;
use phpseclib\Crypt\AES;
use phpseclib\Crypt\Base;
use phpseclib\Crypt\Blowfish;
use phpseclib\Crypt\DES;
use phpseclib\Crypt\RC4;
use phpseclib\Crypt\TripleDES;
use phpseclib\Crypt\Twofish;
/**
* Pure-PHP Random Number Generator
*
@ -172,41 +180,23 @@ class Random
//
// http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Designs_based_on_cryptographic_primitives
switch (true) {
case stream_resolve_include_path('Crypt/AES.php'):
if (!class_exists('Crypt_AES')) {
include_once 'AES.php';
}
$crypto = new Crypt_AES(Crypt_AES::MODE_CTR);
case class_exists('\phpseclib\Crypt\AES'):
$crypto = new AES(Base::MODE_CTR);
break;
case stream_resolve_include_path('Crypt/Twofish.php'):
if (!class_exists('Crypt_Twofish')) {
include_once 'Twofish.php';
}
$crypto = new Crypt_Twofish(Crypt_Twofish::MODE_CTR);
case class_exists('\phpseclib\Crypt\Twofish'):
$crypto = new Twofish(Base::MODE_CTR);
break;
case stream_resolve_include_path('Crypt/Blowfish.php'):
if (!class_exists('Crypt_Blowfish')) {
include_once 'Blowfish.php';
}
$crypto = new Crypt_Blowfish(Crypt_Blowfish::MODE_CTR);
case class_exists('\phpseclib\Crypt\Blowfish'):
$crypto = new Blowfish(Base::MODE_CTR);
break;
case stream_resolve_include_path('Crypt/TripleDES.php'):
if (!class_exists('Crypt_TripleDES')) {
include_once 'TripleDES.php';
}
$crypto = new Crypt_TripleDES(Crypt_TripleDES::MODE_CTR);
case class_exists('\phpseclib\Crypt\TripleDES'):
$crypto = new TripleDES(Base::MODE_CTR);
break;
case stream_resolve_include_path('Crypt/DES.php'):
if (!class_exists('Crypt_DES')) {
include_once 'DES.php';
}
$crypto = new Crypt_DES(Crypt_DES::MODE_CTR);
case class_exists('\phpseclib\Crypt\DES'):
$crypto = new DES(Base::MODE_CTR);
break;
case stream_resolve_include_path('Crypt/RC4.php'):
if (!class_exists('Crypt_RC4')) {
include_once 'RC4.php';
}
$crypto = new Crypt_RC4();
case class_exists('\phpseclib\Crypt\RC4'):
$crypto = new RC4();
break;
default:
user_error(__CLASS__ . ' requires at least one symmetric cipher be loaded');

View File

@ -7,11 +7,11 @@
*
* PHP versions 4 and 5
*
* If {@link Crypt_Rijndael::setBlockLength() setBlockLength()} isn't called, it'll be assumed to be 128 bits. If
* {@link Crypt_Rijndael::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
* {@link Crypt_Rijndael::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's
* If {@link \phpseclib\Crypt\Rijndael::setBlockLength() setBlockLength()} isn't called, it'll be assumed to be 128 bits. If
* {@link \phpseclib\Crypt\Rijndael::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
* {@link \phpseclib\Crypt\Rijndael::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's
* 136-bits it'll be null-padded to 192-bits and 192 bits will be the key length until
* {@link Crypt_Rijndael::setKey() setKey()} is called, again, at which point, it'll be recalculated.
* {@link \phpseclib\Crypt\Rijndael::setKey() setKey()} is called, again, at which point, it'll be recalculated.
*
* Not all Rijndael implementations may support 160-bits or 224-bits as the block length / key length. mcrypt, for example,
* does not. AES, itself, only supports block lengths of 128 and key lengths of 128, 192, and 256.
@ -28,9 +28,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/Rijndael.php';
* include 'vendor/autoload.php';
*
* $rijndael = new Crypt_Rijndael();
* $rijndael = new \phpseclib\Crypt\Rijndael();
*
* $rijndael->setKey('abcdefghijklmnop');
*
@ -45,36 +45,31 @@
* </code>
*
* @category Crypt
* @package Crypt_Rijndael
* @package Rijndael
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2008 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Crypt_Base
*
* Base cipher class
*/
if (!class_exists('Crypt_Base')) {
include_once 'Base.php';
}
namespace phpseclib\Crypt;
use phpseclib\Crypt\Base;
/**
* Pure-PHP implementation of Rijndael.
*
* @package Crypt_Rijndael
* @package Rijndael
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class Crypt_Rijndael extends Crypt_Base
class Rijndael extends Base
{
/**
* The default password key_size used by setPassword()
*
* @see Crypt_Base::password_key_size
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::password_key_size
* @see \phpseclib\Crypt\Base::setPassword()
* @var Integer
* @access private
*/
@ -83,7 +78,7 @@ class Crypt_Rijndael extends Crypt_Base
/**
* The namespace used by the cipher for its constants.
*
* @see Crypt_Base::const_namespace
* @see \phpseclib\Crypt\Base::const_namespace
* @var String
* @access private
*/
@ -93,12 +88,12 @@ 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.
* Crypt_Rijndael determines automatically whether mcrypt is useable
* \phpseclib\Crypt\Rijndael determines automatically whether mcrypt is useable
* or not for the current $block_size/$key_size.
* In case of, $cipher_name_mcrypt will be set dynamically at run time accordingly.
*
* @see Crypt_Base::cipher_name_mcrypt
* @see Crypt_Base::engine
* @see \phpseclib\Crypt\Base::cipher_name_mcrypt
* @see \phpseclib\Crypt\Base::engine
* @see _setupEngine()
* @var String
* @access private
@ -108,8 +103,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* The default salt used by setPassword()
*
* @see Crypt_Base::password_default_salt
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::password_default_salt
* @see \phpseclib\Crypt\Base::setPassword()
* @var String
* @access private
*/
@ -211,8 +206,8 @@ class Crypt_Rijndael extends Crypt_Base
* precomputed tables can be used in the mixColumns phase. in that example, they're assigned t0...t3, so
* those are the names we'll use.
*
* @see Crypt_Rijndael:_encryptBlock()
* @see Crypt_Rijndael:_decryptBlock()
* @see \phpseclib\Crypt\Rijndael:_encryptBlock()
* @see \phpseclib\Crypt\Rijndael:_decryptBlock()
* @var Array
* @access private
*/
@ -254,8 +249,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Precomputed mixColumns table
*
* @see Crypt_Rijndael:_encryptBlock()
* @see Crypt_Rijndael:_decryptBlock()
* @see \phpseclib\Crypt\Rijndael:_encryptBlock()
* @see \phpseclib\Crypt\Rijndael:_decryptBlock()
* @var Array
* @access private
*/
@ -297,8 +292,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Precomputed mixColumns table
*
* @see Crypt_Rijndael:_encryptBlock()
* @see Crypt_Rijndael:_decryptBlock()
* @see \phpseclib\Crypt\Rijndael:_encryptBlock()
* @see \phpseclib\Crypt\Rijndael:_decryptBlock()
* @var Array
* @access private
*/
@ -340,8 +335,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Precomputed mixColumns table
*
* @see Crypt_Rijndael:_encryptBlock()
* @see Crypt_Rijndael:_decryptBlock()
* @see \phpseclib\Crypt\Rijndael:_encryptBlock()
* @see \phpseclib\Crypt\Rijndael:_decryptBlock()
* @var Array
* @access private
*/
@ -383,8 +378,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Precomputed invMixColumns table
*
* @see Crypt_Rijndael:_encryptBlock()
* @see Crypt_Rijndael:_decryptBlock()
* @see \phpseclib\Crypt\Rijndael:_encryptBlock()
* @see \phpseclib\Crypt\Rijndael:_decryptBlock()
* @var Array
* @access private
*/
@ -426,8 +421,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Precomputed invMixColumns table
*
* @see Crypt_Rijndael:_encryptBlock()
* @see Crypt_Rijndael:_decryptBlock()
* @see \phpseclib\Crypt\Rijndael:_encryptBlock()
* @see \phpseclib\Crypt\Rijndael:_decryptBlock()
* @var Array
* @access private
*/
@ -469,8 +464,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Precomputed invMixColumns table
*
* @see Crypt_Rijndael:_encryptBlock()
* @see Crypt_Rijndael:_decryptBlock()
* @see \phpseclib\Crypt\Rijndael:_encryptBlock()
* @see \phpseclib\Crypt\Rijndael:_decryptBlock()
* @var Array
* @access private
*/
@ -512,8 +507,8 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Precomputed invMixColumns table
*
* @see Crypt_Rijndael:_encryptBlock()
* @see Crypt_Rijndael:_decryptBlock()
* @see \phpseclib\Crypt\Rijndael:_encryptBlock()
* @see \phpseclib\Crypt\Rijndael:_decryptBlock()
* @var Array
* @access private
*/
@ -555,7 +550,7 @@ class Crypt_Rijndael extends Crypt_Base
/**
* The SubByte S-Box
*
* @see Crypt_Rijndael::_encryptBlock()
* @see \phpseclib\Crypt\Rijndael::_encryptBlock()
* @var Array
* @access private
*/
@ -581,7 +576,7 @@ class Crypt_Rijndael extends Crypt_Base
/**
* The inverse SubByte S-Box
*
* @see Crypt_Rijndael::_decryptBlock()
* @see \phpseclib\Crypt\Rijndael::_decryptBlock()
* @var Array
* @access private
*/
@ -616,7 +611,7 @@ class Crypt_Rijndael extends Crypt_Base
*
* Note: 160/224-bit keys must explicitly set by setKeyLength(), otherwise they will be round/pad up to 192/256 bits.
*
* @see Crypt_Base:setKey()
* @see \phpseclib\Crypt\Base:setKey()
* @see setKeyLength()
* @access public
* @param String $key
@ -717,10 +712,10 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Setup the fastest possible $engine
*
* Determines if the mcrypt (Crypt_Base::ENGINE_MCRYPT) $engine available
* Determines if the mcrypt (\phpseclib\Crypt\Base::ENGINE_MCRYPT) $engine available
* and usable for the current $block_size and $key_size.
*
* If not, the slower Crypt_Base::ENGINE_INTERNAL $engine will be set.
* If not, the slower \phpseclib\Crypt\Base::ENGINE_INTERNAL $engine will be set.
*
* @see setKey()
* @see setKeyLength()
@ -729,7 +724,7 @@ class Crypt_Rijndael extends Crypt_Base
*/
function _setupEngine()
{
if (constant('CRYPT_' . $this->const_namespace . '_MODE') == Crypt_Base::ENGINE_INTERNAL) {
if (constant('CRYPT_' . $this->const_namespace . '_MODE') == Base::ENGINE_INTERNAL) {
// No mcrypt support at all for rijndael
return;
}
@ -741,10 +736,10 @@ class Crypt_Rijndael extends Crypt_Base
switch (true) {
case $this->key_size % 8: // mcrypt is not usable for 160/224-bit keys, only for 128/192/256-bit keys
case !in_array($cipher_name_mcrypt, mcrypt_list_algorithms()): // $cipher_name_mcrypt is not available for the current $block_size
$engine = Crypt_Base::ENGINE_INTERNAL;
$engine = Base::ENGINE_INTERNAL;
break;
default:
$engine = Crypt_Base::ENGINE_MCRYPT;
$engine = Base::ENGINE_MCRYPT;
}
if ($this->engine == $engine && $this->cipher_name_mcrypt == $cipher_name_mcrypt) {
@ -772,9 +767,9 @@ class Crypt_Rijndael extends Crypt_Base
}
/**
* Setup the Crypt_Base::ENGINE_MCRYPT $engine
* Setup the \phpseclib\Crypt\Base::ENGINE_MCRYPT $engine
*
* @see Crypt_Base::_setupMcrypt()
* @see \phpseclib\Crypt\Base::_setupMcrypt()
* @access private
*/
function _setupMcrypt()
@ -979,7 +974,7 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Setup the key (expansion)
*
* @see Crypt_Base::_setupKey()
* @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@ -1111,7 +1106,7 @@ class Crypt_Rijndael extends Crypt_Base
/**
* Setup the performance-optimized function for de/encrypt()
*
* @see Crypt_Base::_setupInlineCrypt()
* @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
@ -1120,7 +1115,7 @@ class Crypt_Rijndael extends Crypt_Base
// So here we are'nt under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt().
// However...the here generated function- $code, stored as php callback in $this->inline_crypt, must work as fast as even possible.
$lambda_functions =& Crypt_Rijndael::_getLambdaFunctions();
$lambda_functions =& self::_getLambdaFunctions();
// The first 10 generated $lambda_functions will use the key-words hardcoded for better performance.
// For memory reason we limit those ultra-optimized functions.
@ -1139,7 +1134,7 @@ class Crypt_Rijndael extends Crypt_Base
$init_decrypt = '$dw = $self->dw;';
}
$code_hash = md5(str_pad("Crypt_Rijndael, {$this->mode}, {$this->block_size}, ", 32, "\0") . implode(',', $w));
$code_hash = md5(str_pad("Rijndael, {$this->mode}, {$this->block_size}, ", 32, "\0") . implode(',', $w));
if (!isset($lambda_functions[$code_hash])) {
$Nr = $this->Nr;

View File

@ -10,9 +10,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/TripleDES.php';
* include 'vendor/autoload.php';
*
* $des = new Crypt_TripleDES();
* $des = new \phpseclib\Crypt\TripleDES();
*
* $des->setKey('abcdefghijklmnopqrstuvwx');
*
@ -27,28 +27,26 @@
* </code>
*
* @category Crypt
* @package Crypt_TripleDES
* @package TripleDES
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Crypt_DES
*/
if (!class_exists('Crypt_DES')) {
include_once 'DES.php';
}
namespace phpseclib\Crypt;
use phpseclib\Crypt\Base;
use phpseclib\Crypt\DES;
/**
* Pure-PHP implementation of Triple DES.
*
* @package Crypt_TripleDES
* @package TripleDES
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
class Crypt_TripleDES extends Crypt_DES
class TripleDES extends DES
{
/**
@ -61,16 +59,16 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Encrypt / decrypt using outer chaining
*
* Outer chaining is used by SSH-2 and when the mode is set to Crypt_Base::MODE_CBC.
* Outer chaining is used by SSH-2 and when the mode is set to \phpseclib\Crypt\Base::MODE_CBC.
*/
const MODE_CBC3 = Crypt_Base::MODE_CBC;
const MODE_CBC3 = Base::MODE_CBC;
/**
* The default password key_size used by setPassword()
*
* @see Crypt_DES::password_key_size
* @see Crypt_Base::password_key_size
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\DES::password_key_size
* @see \phpseclib\Crypt\Base::password_key_size
* @see \phpseclib\Crypt\Base::setPassword()
* @var Integer
* @access private
*/
@ -79,8 +77,8 @@ class Crypt_TripleDES extends Crypt_DES
/**
* The default salt used by setPassword()
*
* @see Crypt_Base::password_default_salt
* @see Crypt_Base::setPassword()
* @see \phpseclib\Crypt\Base::password_default_salt
* @see \phpseclib\Crypt\Base::setPassword()
* @var String
* @access private
*/
@ -89,8 +87,8 @@ class Crypt_TripleDES extends Crypt_DES
/**
* The namespace used by the cipher for its constants.
*
* @see Crypt_DES::const_namespace
* @see Crypt_Base::const_namespace
* @see \phpseclib\Crypt\DES::const_namespace
* @see \phpseclib\Crypt\Base::const_namespace
* @var String
* @access private
*/
@ -99,8 +97,8 @@ class Crypt_TripleDES extends Crypt_DES
/**
* The mcrypt specific name of the cipher
*
* @see Crypt_DES::cipher_name_mcrypt
* @see Crypt_Base::cipher_name_mcrypt
* @see \phpseclib\Crypt\DES::cipher_name_mcrypt
* @see \phpseclib\Crypt\Base::cipher_name_mcrypt
* @var String
* @access private
*/
@ -109,7 +107,7 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Optimizing value while CFB-encrypting
*
* @see Crypt_Base::cfb_init_len
* @see \phpseclib\Crypt\Base::cfb_init_len
* @var Integer
* @access private
*/
@ -118,8 +116,8 @@ class Crypt_TripleDES extends Crypt_DES
/**
* max possible size of $key
*
* @see Crypt_TripleDES::setKey()
* @see Crypt_DES::setKey()
* @see \phpseclib\Crypt\TripleDES::setKey()
* @see \phpseclib\Crypt\DES::setKey()
* @var String
* @access private
*/
@ -134,7 +132,7 @@ class Crypt_TripleDES extends Crypt_DES
var $mode_3cbc;
/**
* The Crypt_DES objects
* The \phpseclib\Crypt\DES objects
*
* Used only if $mode_3cbc === true
*
@ -150,42 +148,42 @@ class Crypt_TripleDES extends Crypt_DES
*
* $mode could be:
*
* - Crypt_Base::MODE_ECB
* - \phpseclib\Crypt\Base::MODE_ECB
*
* - Crypt_Base::MODE_CBC
* - \phpseclib\Crypt\Base::MODE_CBC
*
* - Crypt_Base::MODE_CTR
* - \phpseclib\Crypt\Base::MODE_CTR
*
* - Crypt_Base::MODE_CFB
* - \phpseclib\Crypt\Base::MODE_CFB
*
* - Crypt_Base::MODE_OFB
* - \phpseclib\Crypt\Base::MODE_OFB
*
* - self::MODE_3CBC
* - \phpseclib\Crypt\TripleDES::MODE_3CBC
*
* If not explicitly set, Crypt_Base::MODE_CBC will be used.
* If not explicitly set, \phpseclib\Crypt\Base::MODE_CBC will be used.
*
* @see Crypt_DES::__construct()
* @see Crypt_Base::__construct()
* @see \phpseclib\Crypt\DES::__construct()
* @see \phpseclib\Crypt\Base::__construct()
* @param optional Integer $mode
* @access public
*/
function __construct($mode = Crypt_Base::MODE_CBC)
function __construct($mode = Base::MODE_CBC)
{
switch ($mode) {
// In case of self::MODE_3CBC, we init as CRYPT_DES_MODE_CBC
// and additional flag us internally as 3CBC
case self::MODE_3CBC:
parent::__construct(Crypt_Base::MODE_CBC);
parent::__construct(Base::MODE_CBC);
$this->mode_3cbc = true;
// This three $des'es will do the 3CBC work (if $key > 64bits)
$this->des = array(
new Crypt_DES(Crypt_Base::MODE_CBC),
new Crypt_DES(Crypt_Base::MODE_CBC),
new Crypt_DES(Crypt_Base::MODE_CBC),
new DES(Base::MODE_CBC),
new DES(Base::MODE_CBC),
new DES(Base::MODE_CBC),
);
// we're going to be doing the padding, ourselves, so disable it in the Crypt_DES objects
// we're going to be doing the padding, ourselves, so disable it in the \phpseclib\Crypt\DES objects
$this->des[0]->disablePadding();
$this->des[1]->disablePadding();
$this->des[2]->disablePadding();
@ -199,10 +197,10 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Sets the initialization vector. (optional)
*
* SetIV is not required when Crypt_Base::MODE_ECB is being used. If not explicitly set, it'll be assumed
* SetIV is not required when \phpseclib\Crypt\Base::MODE_ECB is being used. If not explicitly set, it'll be assumed
* to be all zero's.
*
* @see Crypt_Base::setIV()
* @see \phpseclib\Crypt\Base::setIV()
* @access public
* @param String $iv
*/
@ -227,8 +225,8 @@ class Crypt_TripleDES extends Crypt_DES
* If the key is not explicitly set, it'll be assumed to be all null bytes.
*
* @access public
* @see Crypt_DES::setKey()
* @see Crypt_Base::setKey()
* @see \phpseclib\Crypt\DES::setKey()
* @see \phpseclib\Crypt\Base::setKey()
* @param String $key
*/
function setKey($key)
@ -258,7 +256,7 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Encrypts a message.
*
* @see Crypt_Base::encrypt()
* @see \phpseclib\Crypt\Base::encrypt()
* @access public
* @param String $plaintext
* @return String $cipertext
@ -285,7 +283,7 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Decrypts a message.
*
* @see Crypt_Base::decrypt()
* @see \phpseclib\Crypt\Base::decrypt()
* @access public
* @param String $ciphertext
* @return String $plaintext
@ -336,13 +334,13 @@ class Crypt_TripleDES extends Crypt_DES
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
*
* Put another way, when the continuous buffer is enabled, the state of the Crypt_DES() object changes after each
* Put another way, when the continuous buffer is enabled, the state of the \phpseclib\Crypt\DES() object changes after each
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them),
* however, they are also less intuitive and more likely to cause you problems.
*
* @see Crypt_Base::enableContinuousBuffer()
* @see Crypt_TripleDES::disableContinuousBuffer()
* @see \phpseclib\Crypt\Base::enableContinuousBuffer()
* @see \phpseclib\Crypt\TripleDES::disableContinuousBuffer()
* @access public
*/
function enableContinuousBuffer()
@ -360,8 +358,8 @@ class Crypt_TripleDES extends Crypt_DES
*
* The default behavior.
*
* @see Crypt_Base::disableContinuousBuffer()
* @see Crypt_TripleDES::enableContinuousBuffer()
* @see \phpseclib\Crypt\Base::disableContinuousBuffer()
* @see \phpseclib\Crypt\TripleDES::enableContinuousBuffer()
* @access public
*/
function disableContinuousBuffer()
@ -377,8 +375,8 @@ class Crypt_TripleDES extends Crypt_DES
/**
* Creates the key schedule
*
* @see Crypt_DES::_setupKey()
* @see Crypt_Base::_setupKey()
* @see \phpseclib\Crypt\DES::_setupKey()
* @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()

View File

@ -14,9 +14,9 @@
* Here's a short example of how to use this library:
* <code>
* <?php
* include 'Crypt/Twofish.php';
* include 'vendor/autoload.php';
*
* $twofish = new Crypt_Twofish();
* $twofish = new \phpseclib\Crypt\Twofish();
*
* $twofish->setKey('12345678901234567890123456789012');
*
@ -27,7 +27,7 @@
* </code>
*
* @category Crypt
* @package Crypt_Twofish
* @package Twofish
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @copyright 2007 Jim Wigginton
@ -35,29 +35,24 @@
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Crypt_Base
*
* Base cipher class
*/
if (!class_exists('Crypt_Base')) {
include_once 'Base.php';
}
namespace phpseclib\Crypt;
use phpseclib\Crypt\Base;
/**
* Pure-PHP implementation of Twofish.
*
* @package Crypt_Twofish
* @package Twofish
* @author Jim Wigginton <terrafrost@php.net>
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
* @access public
*/
class Crypt_Twofish extends Crypt_Base
class Twofish extends Base
{
/**
* The namespace used by the cipher for its constants.
*
* @see Crypt_Base::const_namespace
* @see \phpseclib\Crypt\Base::const_namespace
* @var String
* @access private
*/
@ -66,7 +61,7 @@ class Crypt_Twofish extends Crypt_Base
/**
* The mcrypt specific name of the cipher
*
* @see Crypt_Base::cipher_name_mcrypt
* @see \phpseclib\Crypt\Base::cipher_name_mcrypt
* @var String
* @access private
*/
@ -75,7 +70,7 @@ class Crypt_Twofish extends Crypt_Base
/**
* Optimizing value while CFB-encrypting
*
* @see Crypt_Base::cfb_init_len
* @see \phpseclib\Crypt\Base::cfb_init_len
* @var Integer
* @access private
*/
@ -385,7 +380,7 @@ class Crypt_Twofish extends Crypt_Base
* If the key is not explicitly set, it'll be assumed a 128 bits key to be all null bytes.
*
* @access public
* @see Crypt_Base::setKey()
* @see \phpseclib\Crypt\Base::setKey()
* @param String $key
*/
function setKey($key)
@ -410,7 +405,7 @@ class Crypt_Twofish extends Crypt_Base
/**
* Setup the key (expansion)
*
* @see Crypt_Base::_setupKey()
* @see \phpseclib\Crypt\Base::_setupKey()
* @access private
*/
function _setupKey()
@ -675,22 +670,22 @@ class Crypt_Twofish extends Crypt_Base
/**
* Setup the performance-optimized function for de/encrypt()
*
* @see Crypt_Base::_setupInlineCrypt()
* @see \phpseclib\Crypt\Base::_setupInlineCrypt()
* @access private
*/
function _setupInlineCrypt()
{
$lambda_functions =& Crypt_Twofish::_getLambdaFunctions();
$lambda_functions =& self::_getLambdaFunctions();
// Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one.
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
switch (true) {
case $gen_hi_opt_code:
$code_hash = md5(str_pad("Crypt_Twofish, {$this->mode}, ", 32, "\0") . $this->key);
$code_hash = md5(str_pad("Twofish, {$this->mode}, ", 32, "\0") . $this->key);
break;
default:
$code_hash = "Crypt_Twofish, {$this->mode}";
$code_hash = "Twofish, {$this->mode}";
}
if (!isset($lambda_functions[$code_hash])) {

View File

@ -206,7 +206,7 @@ class ASN1
*/
function decodeBER($encoded)
{
if (is_object($encoded) && strtolower(get_class($encoded)) == 'file_asn1_element') {
if (is_object($encoded) && get_class($encoded) === 'phpseclib\File\ASN1\Element') {
$encoded = $encoded->element;
}
@ -779,7 +779,7 @@ class ASN1
*/
function _encode_der($source, $mapping, $idx = null, $special = array())
{
if (is_object($source) && strtolower(get_class($source)) == 'file_asn1_element') {
if (is_object($source) && get_class($source) === 'phpseclib\File\ASN1\Element') {
return $source->element;
}

View File

@ -26,7 +26,8 @@
namespace phpseclib\File;
use Crypt_RSA; // This should get removed after the Crypt package has been fully namespaced
use phpseclib\Crypt\Hash;
use phpseclib\Crypt\RSA;
use phpseclib\File\ASN1;
use phpseclib\File\ASN1\Element;
use phpseclib\Math\BigInteger;
@ -2105,10 +2106,7 @@ class X509
{
switch ($publicKeyAlgorithm) {
case 'rsaEncryption':
if (!class_exists('Crypt_RSA')) {
include_once 'Crypt/RSA.php';
}
$rsa = new Crypt_RSA();
$rsa = new RSA();
$rsa->loadKey($publicKey);
switch ($signatureAlgorithm) {
@ -2120,7 +2118,7 @@ class X509
case 'sha384WithRSAEncryption':
case 'sha512WithRSAEncryption':
$rsa->setHash(preg_replace('#WithRSAEncryption$#', '', $signatureAlgorithm));
$rsa->setSignatureMode(Crypt_RSA::SIGNATURE_PKCS1);
$rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
if (!@$rsa->verify($signatureSubject, $signature)) {
return false;
}
@ -2508,10 +2506,7 @@ class X509
return $result;
case self::DN_HASH:
$dn = $this->getDN(self::DN_CANON, $dn);
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$hash = new Crypt_Hash('sha1');
$hash = new Hash('sha1');
$hash = $hash->hash($dn);
extract(unpack('Vhash', $hash));
return strtolower(bin2hex(pack('N', $hash)));
@ -2721,7 +2716,7 @@ class X509
/**
* Set public key
*
* Key needs to be a Crypt_RSA object
* Key needs to be a \phpseclib\Crypt\RSA object
*
* @param Object $key
* @access public
@ -2736,7 +2731,7 @@ class X509
/**
* Set private key
*
* Key needs to be a Crypt_RSA object
* Key needs to be a \phpseclib\Crypt\RSA object
*
* @param Object $key
* @access public
@ -2762,7 +2757,7 @@ class X509
/**
* Gets the public key
*
* Returns a Crypt_RSA object or a false.
* Returns a \phpseclib\Crypt\RSA object or a false.
*
* @access public
* @return Mixed
@ -2789,10 +2784,7 @@ class X509
switch ($keyinfo['algorithm']['algorithm']) {
case 'rsaEncryption':
if (!class_exists('Crypt_RSA')) {
include_once 'Crypt/RSA.php';
}
$publicKey = new Crypt_RSA();
$publicKey = new RSA();
$publicKey->loadKey($key);
$publicKey->setPublicKey();
break;
@ -2862,10 +2854,7 @@ class X509
switch ($algorithm) {
case 'rsaEncryption':
if (!class_exists('Crypt_RSA')) {
include_once 'Crypt/RSA.php';
}
$this->publicKey = new Crypt_RSA();
$this->publicKey = new RSA();
$this->publicKey->loadKey($key);
$this->publicKey->setPublicKey();
break;
@ -2988,10 +2977,7 @@ class X509
switch ($algorithm) {
case 'rsaEncryption':
if (!class_exists('Crypt_RSA')) {
include_once 'Crypt/RSA.php';
}
$this->publicKey = new Crypt_RSA();
$this->publicKey = new RSA();
$this->publicKey->loadKey($key);
$this->publicKey->setPublicKey();
break;
@ -3615,8 +3601,8 @@ class X509
*/
function _sign($key, $signatureAlgorithm)
{
switch (strtolower(get_class($key))) {
case 'crypt_rsa':
switch (get_class($key)) {
case 'phpseclib\Crypt\RSA':
switch ($signatureAlgorithm) {
case 'md2WithRSAEncryption':
case 'md5WithRSAEncryption':
@ -3626,7 +3612,7 @@ class X509
case 'sha384WithRSAEncryption':
case 'sha512WithRSAEncryption':
$key->setHash(preg_replace('#WithRSAEncryption$#', '', $signatureAlgorithm));
$key->setSignatureMode(Crypt_RSA::SIGNATURE_PKCS1);
$key->setSignatureMode(RSA::SIGNATURE_PKCS1);
$this->currentCert['signature'] = base64_encode("\0" . $key->sign($this->signatureSubject));
return $this->currentCert;
@ -4176,7 +4162,7 @@ class X509
return $this->computeKeyIdentifier($key['certificationRequestInfo']['subjectPKInfo']['subjectPublicKey'], $method);
case !is_object($key):
return false;
case strtolower(get_class($key)) == 'file_asn1_element':
case get_class($key) === 'phpseclib\File\ASN1\Element':
// Assume the element is a bitstring-packed key.
$asn1 = new ASN1();
$decoded = $asn1->decodeBER($key->element);
@ -4189,10 +4175,7 @@ class X509
}
$raw = base64_decode($raw);
// If the key is private, compute identifier from its corresponding public key.
if (!class_exists('Crypt_RSA')) {
include_once 'Crypt/RSA.php';
}
$key = new Crypt_RSA();
$key = new RSA();
if (!$key->loadKey($raw)) {
return false; // Not an unencrypted RSA key.
}
@ -4201,7 +4184,7 @@ class X509
}
$key = $raw; // Is a public key.
break;
case strtolower(get_class($key)) == 'file_x509':
case get_class($key) === 'phpseclib\File\X509':
if (isset($key->publicKey)) {
return $this->computeKeyIdentifier($key->publicKey, $method);
}
@ -4212,8 +4195,8 @@ class X509
return $this->computeKeyIdentifier($key->currentCert, $method);
}
return false;
default: // Should be a key object (i.e.: Crypt_RSA).
$key = $key->getPublicKey(Crypt_RSA::PUBLIC_FORMAT_PKCS1);
default: // Should be a key object (i.e.: \phpseclib\Crypt\RSA).
$key = $key->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1);
break;
}
@ -4221,10 +4204,7 @@ class X509
$key = $this->_extractBER($key);
// Now we have the key string: compute its sha-1 sum.
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$hash = new Crypt_Hash('sha1');
$hash = new Hash('sha1');
$hash = $hash->hash($key);
if ($method == 2) {
@ -4247,14 +4227,14 @@ class X509
return false;
}
switch (strtolower(get_class($this->publicKey))) {
case 'crypt_rsa':
switch (get_class($this->publicKey)) {
case 'phpseclib\Crypt\RSA':
// the following two return statements do the same thing. i dunno.. i just prefer the later for some reason.
// the former is a good example of how to do fuzzing on the public key
//return new Element(base64_decode(preg_replace('#-.+-|[\r\n]#', '', $this->publicKey->getPublicKey())));
return array(
'algorithm' => array('algorithm' => 'rsaEncryption'),
'subjectPublicKey' => $this->publicKey->getPublicKey(Crypt_RSA::PUBLIC_FORMAT_PKCS1)
'subjectPublicKey' => $this->publicKey->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1)
);
default:
return false;

View File

@ -41,7 +41,7 @@
* </code>
*
* @category Math
* @package Math_BigInteger
* @package BigInteger
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2006 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
@ -50,13 +50,13 @@
namespace phpseclib\Math;
use \phpseclib\Crypt\Random;
use phpseclib\Crypt\Random;
/**
* Pure-PHP arbitrary precision integer arithmetic library. Supports base-2, base-10, base-16, and base-256
* numbers.
*
* @package Math_BigInteger
* @package BigInteger
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
@ -3024,7 +3024,7 @@ class BigInteger
/**
* Generates a random BigInteger
*
* Byte length is equal to $length. Uses Crypt\Random if it's loaded and mt_rand if it's not.
* Byte length is equal to $length. Uses \phpseclib\Crypt\Random if it's loaded and mt_rand if it's not.
*
* @param Integer $length
* @return \phpseclib\Math\BigInteger
@ -3032,7 +3032,7 @@ class BigInteger
*/
function _random_number_helper($size)
{
if (class_exists('phpseclib\Crypt\Random')) {
if (class_exists('\phpseclib\Crypt\Random')) {
$random = Random::string($size);
} else {
$random = '';

View File

@ -193,7 +193,7 @@ class Stream
if (isset($context[$scheme]['password'])) {
$pass = $context[$scheme]['password'];
}
if (isset($context[$scheme]['privkey']) && is_object($context[$scheme]['privkey']) && get_Class($context[$scheme]['privkey']) == 'Crypt_RSA') {
if (isset($context[$scheme]['privkey']) && is_object($context[$scheme]['privkey']) && get_class($context[$scheme]['privkey']) == 'phpseclib\Crypt\RSA') {
$pass = $context[$scheme]['privkey'];
}
@ -201,7 +201,7 @@ class Stream
return false;
}
// casting $pass to a string is necessary in the event that it's a Crypt_RSA object
// casting $pass to a string is necessary in the event that it's a \phpseclib\Crypt\RSA object
if (isset(self::$instances[$host][$port][$user][(string) $pass])) {
$this->sftp = self::$instances[$host][$port][$user][(string) $pass];
} else {

View File

@ -48,12 +48,9 @@
namespace phpseclib\Net;
// These should be removed once the Crypt package is fully namespaced
use Crypt_DES;
use Crypt_TripleDES;
// End unnecessary Use Statements
use phpseclib\Crypt\DES;
use phpseclib\Crypt\Random;
use phpseclib\Crypt\TripleDES;
use phpseclib\Math\BigInteger;
/**
@ -661,31 +658,22 @@ class SSH1
switch ($cipher) {
//case self::CIPHER_NONE:
// $this->crypto = new Crypt_Null();
// $this->crypto = new \phpseclib\Crypt\Null();
// break;
case self::CIPHER_DES:
if (!class_exists('Crypt_DES')) {
include_once 'Crypt/DES.php';
}
$this->crypto = new Crypt_DES();
$this->crypto = new DES();
$this->crypto->disablePadding();
$this->crypto->enableContinuousBuffer();
$this->crypto->setKey(substr($session_key, 0, 8));
break;
case self::CIPHER_3DES:
if (!class_exists('Crypt_TripleDES')) {
include_once 'Crypt/TripleDES.php';
}
$this->crypto = new Crypt_TripleDES(Crypt_TripleDES::MODE_3CBC);
$this->crypto = new TripleDES(TripleDES::MODE_3CBC);
$this->crypto->disablePadding();
$this->crypto->enableContinuousBuffer();
$this->crypto->setKey(substr($session_key, 0, 24));
break;
//case self::CIPHER_RC4:
// if (!class_exists('Crypt_RC4')) {
// include_once 'Crypt/RC4.php';
// }
// $this->crypto = new Crypt_RC4();
// $this->crypto = new RC4();
// $this->crypto->enableContinuousBuffer();
// $this->crypto->setKey(substr($session_key, 0, 16));
// break;
@ -1323,13 +1311,9 @@ class SSH1
function _rsa_crypt($m, $key)
{
/*
if (!class_exists('Crypt_RSA')) {
include_once 'Crypt/RSA.php';
}
$rsa = new Crypt_RSA();
$rsa->loadKey($key, Crypt_RSA::PUBLIC_FORMAT_RAW);
$rsa->setEncryptionMode(Crypt_RSA::ENCRYPTION_PKCS1);
$rsa = new RSA();
$rsa->loadKey($key, RSA::PUBLIC_FORMAT_RAW);
$rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1);
return $rsa->encrypt($m);
*/

View File

@ -22,10 +22,9 @@
*
* <code>
* <?php
* include 'Crypt/RSA.php';
* include 'vendor/autoload.php';
*
* $key = new Crypt_RSA();
* $key = new \phpseclib\Crypt\RSA();
* //$key->setPassword('whatever');
* $key->loadKey(file_get_contents('privatekey'));
*
@ -50,19 +49,16 @@
namespace phpseclib\Net;
// These should be removed once the Crypt package is fully namespaced
use Crypt_Blowfish;
use Crypt_Hash;
use Crypt_RC4;
use Crypt_Rijndael;
use Crypt_RSA;
use Crypt_TripleDES;
use Crypt_Twofish;
// End unnecessary Use Statements
use phpseclib\Crypt\Base;
use phpseclib\Crypt\Blowfish;
use phpseclib\Crypt\Hash;
use phpseclib\Crypt\Random;
// Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
use phpseclib\Math\BigInteger;
use phpseclib\Crypt\RC4;
use phpseclib\Crypt\Rijndael;
use phpseclib\Crypt\RSA;
use phpseclib\Crypt\TripleDES;
use phpseclib\Crypt\Twofish;
use phpseclib\Math\BigInteger; // Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
/**
* Pure-PHP implementation of SSHv2.
@ -850,10 +846,6 @@ class SSH2
*/
function __construct($host, $port = 22, $timeout = 10)
{
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$this->message_numbers = array(
1 => 'NET_SSH2_MSG_DISCONNECT',
2 => 'NET_SSH2_MSG_IGNORE',
@ -1123,31 +1115,31 @@ class SSH2
//'none' // OPTIONAL no encryption; NOT RECOMMENDED
);
if (stream_resolve_include_path('Crypt/RC4.php') === false) {
if (class_exists('\phpseclib\Crypt\RC4') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('arcfour256', 'arcfour128', 'arcfour')
);
}
if (stream_resolve_include_path('Crypt/Rijndael.php') === false) {
if (class_exists('\phpseclib\Crypt\Rijndael') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc')
);
}
if (stream_resolve_include_path('Crypt/Twofish.php') === false) {
if (class_exists('\phpseclib\Crypt\Twofish') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('twofish128-ctr', 'twofish192-ctr', 'twofish256-ctr', 'twofish128-cbc', 'twofish192-cbc', 'twofish256-cbc', 'twofish-cbc')
);
}
if (stream_resolve_include_path('Crypt/Blowfish.php') === false) {
if (class_exists('\phpseclib\Crypt\Blowfish') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('blowfish-ctr', 'blowfish-cbc')
);
}
if (stream_resolve_include_path('Crypt/TripleDES.php') === false) {
if (class_exists('\phpseclib\Crypt\TripleDES') === false) {
$encryption_algorithms = array_diff(
$encryption_algorithms,
array('3des-ctr', '3des-cbc')
@ -1374,7 +1366,7 @@ class SSH2
// the generator field element is 2 (decimal) and the hash function is sha1.
$g = new BigInteger(2);
$prime = new BigInteger($prime, 16);
$kexHash = new Crypt_Hash('sha1');
$kexHash = new Hash('sha1');
//$q = $p->bitwise_rightShift(1);
/* To increase the speed of the key exchange, both client and server may
@ -1479,156 +1471,102 @@ class SSH2
switch ($encrypt) {
case '3des-cbc':
if (!class_exists('Crypt_TripleDES')) {
include_once 'Crypt/TripleDES.php';
}
$this->encrypt = new Crypt_TripleDES();
$this->encrypt = new TripleDES();
// $this->encrypt_block_size = 64 / 8 == the default
break;
case '3des-ctr':
if (!class_exists('Crypt_TripleDES')) {
include_once 'Crypt/TripleDES.php';
}
$this->encrypt = new Crypt_TripleDES(Crypt_Base::MODE_CTR);
$this->encrypt = new TripleDES(Base::MODE_CTR);
// $this->encrypt_block_size = 64 / 8 == the default
break;
case 'aes256-cbc':
case 'aes192-cbc':
case 'aes128-cbc':
if (!class_exists('Crypt_Rijndael')) {
include_once 'Crypt/Rijndael.php';
}
$this->encrypt = new Crypt_Rijndael();
$this->encrypt = new Rijndael();
$this->encrypt_block_size = 16; // eg. 128 / 8
break;
case 'aes256-ctr':
case 'aes192-ctr':
case 'aes128-ctr':
if (!class_exists('Crypt_Rijndael')) {
include_once 'Crypt/Rijndael.php';
}
$this->encrypt = new Crypt_Rijndael(Crypt_Base::MODE_CTR);
$this->encrypt = new Rijndael(Base::MODE_CTR);
$this->encrypt_block_size = 16; // eg. 128 / 8
break;
case 'blowfish-cbc':
if (!class_exists('Crypt_Blowfish')) {
include_once 'Crypt/Blowfish.php';
}
$this->encrypt = new Crypt_Blowfish();
$this->encrypt = new Blowfish();
$this->encrypt_block_size = 8;
break;
case 'blowfish-ctr':
if (!class_exists('Crypt_Blowfish')) {
include_once 'Crypt/Blowfish.php';
}
$this->encrypt = new Crypt_Blowfish(Crypt_Base::MODE_CTR);
$this->encrypt = new Blowfish(Base::MODE_CTR);
$this->encrypt_block_size = 8;
break;
case 'twofish128-cbc':
case 'twofish192-cbc':
case 'twofish256-cbc':
case 'twofish-cbc':
if (!class_exists('Crypt_Twofish')) {
include_once 'Crypt/Twofish.php';
}
$this->encrypt = new Crypt_Twofish();
$this->encrypt = new Twofish();
$this->encrypt_block_size = 16;
break;
case 'twofish128-ctr':
case 'twofish192-ctr':
case 'twofish256-ctr':
if (!class_exists('Crypt_Twofish')) {
include_once 'Crypt/Twofish.php';
}
$this->encrypt = new Crypt_Twofish(Crypt_Base::MODE_CTR);
$this->encrypt = new Twofish(Base::MODE_CTR);
$this->encrypt_block_size = 16;
break;
case 'arcfour':
case 'arcfour128':
case 'arcfour256':
if (!class_exists('Crypt_RC4')) {
include_once 'Crypt/RC4.php';
}
$this->encrypt = new Crypt_RC4();
$this->encrypt = new RC4();
break;
case 'none';
//$this->encrypt = new Crypt_Null();
//$this->encrypt = new Null();
}
switch ($decrypt) {
case '3des-cbc':
if (!class_exists('Crypt_TripleDES')) {
include_once 'Crypt/TripleDES.php';
}
$this->decrypt = new Crypt_TripleDES();
$this->decrypt = new TripleDES();
break;
case '3des-ctr':
if (!class_exists('Crypt_TripleDES')) {
include_once 'Crypt/TripleDES.php';
}
$this->decrypt = new Crypt_TripleDES(Crypt_Base::MODE_CTR);
$this->decrypt = new TripleDES(Base::MODE_CTR);
break;
case 'aes256-cbc':
case 'aes192-cbc':
case 'aes128-cbc':
if (!class_exists('Crypt_Rijndael')) {
include_once 'Crypt/Rijndael.php';
}
$this->decrypt = new Crypt_Rijndael();
$this->decrypt = new Rijndael();
$this->decrypt_block_size = 16;
break;
case 'aes256-ctr':
case 'aes192-ctr':
case 'aes128-ctr':
if (!class_exists('Crypt_Rijndael')) {
include_once 'Crypt/Rijndael.php';
}
$this->decrypt = new Crypt_Rijndael(Crypt_Base::MODE_CTR);
$this->decrypt = new Rijndael(Base::MODE_CTR);
$this->decrypt_block_size = 16;
break;
case 'blowfish-cbc':
if (!class_exists('Crypt_Blowfish')) {
include_once 'Crypt/Blowfish.php';
}
$this->decrypt = new Crypt_Blowfish();
$this->decrypt = new Blowfish();
$this->decrypt_block_size = 8;
break;
case 'blowfish-ctr':
if (!class_exists('Crypt_Blowfish')) {
include_once 'Crypt/Blowfish.php';
}
$this->decrypt = new Crypt_Blowfish(Crypt_Base::MODE_CTR);
$this->decrypt = new Blowfish(Base::MODE_CTR);
$this->decrypt_block_size = 8;
break;
case 'twofish128-cbc':
case 'twofish192-cbc':
case 'twofish256-cbc':
case 'twofish-cbc':
if (!class_exists('Crypt_Twofish')) {
include_once 'Crypt/Twofish.php';
}
$this->decrypt = new Crypt_Twofish();
$this->decrypt = new Twofish();
$this->decrypt_block_size = 16;
break;
case 'twofish128-ctr':
case 'twofish192-ctr':
case 'twofish256-ctr':
if (!class_exists('Crypt_Twofish')) {
include_once 'Crypt/Twofish.php';
}
$this->decrypt = new Crypt_Twofish(Crypt_Base::MODE_CTR);
$this->decrypt = new Twofish(Base::MODE_CTR);
$this->decrypt_block_size = 16;
break;
case 'arcfour':
case 'arcfour128':
case 'arcfour256':
if (!class_exists('Crypt_RC4')) {
include_once 'Crypt/RC4.php';
}
$this->decrypt = new Crypt_RC4();
$this->decrypt = new RC4();
break;
case 'none';
//$this->decrypt = new Crypt_Null();
//$this->decrypt = new Null();
}
$keyBytes = pack('Na*', strlen($keyBytes), $keyBytes);
@ -1690,23 +1628,23 @@ class SSH2
$createKeyLength = 0; // ie. $mac_algorithms[$i] == 'none'
switch ($mac_algorithms[$i]) {
case 'hmac-sha2-256':
$this->hmac_create = new Crypt_Hash('sha256');
$this->hmac_create = new Hash('sha256');
$createKeyLength = 32;
break;
case 'hmac-sha1':
$this->hmac_create = new Crypt_Hash('sha1');
$this->hmac_create = new Hash('sha1');
$createKeyLength = 20;
break;
case 'hmac-sha1-96':
$this->hmac_create = new Crypt_Hash('sha1-96');
$this->hmac_create = new Hash('sha1-96');
$createKeyLength = 20;
break;
case 'hmac-md5':
$this->hmac_create = new Crypt_Hash('md5');
$this->hmac_create = new Hash('md5');
$createKeyLength = 16;
break;
case 'hmac-md5-96':
$this->hmac_create = new Crypt_Hash('md5-96');
$this->hmac_create = new Hash('md5-96');
$createKeyLength = 16;
}
@ -1720,27 +1658,27 @@ class SSH2
$this->hmac_size = 0;
switch ($mac_algorithms[$i]) {
case 'hmac-sha2-256':
$this->hmac_check = new Crypt_Hash('sha256');
$this->hmac_check = new Hash('sha256');
$checkKeyLength = 32;
$this->hmac_size = 32;
break;
case 'hmac-sha1':
$this->hmac_check = new Crypt_Hash('sha1');
$this->hmac_check = new Hash('sha1');
$checkKeyLength = 20;
$this->hmac_size = 20;
break;
case 'hmac-sha1-96':
$this->hmac_check = new Crypt_Hash('sha1-96');
$this->hmac_check = new Hash('sha1-96');
$checkKeyLength = 20;
$this->hmac_size = 12;
break;
case 'hmac-md5':
$this->hmac_check = new Crypt_Hash('md5');
$this->hmac_check = new Hash('md5');
$checkKeyLength = 16;
$this->hmac_size = 16;
break;
case 'hmac-md5-96':
$this->hmac_check = new Crypt_Hash('md5-96');
$this->hmac_check = new Hash('md5-96');
$checkKeyLength = 16;
$this->hmac_size = 12;
}
@ -1777,7 +1715,7 @@ class SSH2
/**
* Login
*
* The $password parameter can be a plaintext password, a Crypt_RSA object or an array
* The $password parameter can be a plaintext password, a \phpseclib\Crypt\RSA object or an array
*
* @param String $username
* @param Mixed $password
@ -1867,10 +1805,9 @@ class SSH2
return !is_string($password) && !is_array($password) ? false : $this->_keyboard_interactive_process($password);
}
// although PHP5's get_class() preserves the case, PHP4's does not
if (is_object($password)) {
switch (get_class($password)) {
case 'Crypt_RSA':
case 'phpseclib\Crypt\RSA':
return $this->_privatekey_login($username, $password);
case 'phpseclib\System\SSH\Agent':
return $this->_ssh_agent_login($username, $password);
@ -2134,7 +2071,7 @@ class SSH2
* Login with an RSA private key
*
* @param String $username
* @param Crypt_RSA $password
* @param \phpseclib\Crypt\RSA $password
* @return Boolean
* @access private
* @internal It might be worthwhile, at some point, to protect against {@link http://tools.ietf.org/html/rfc4251#section-9.3.9 traffic analysis}
@ -2143,7 +2080,7 @@ class SSH2
function _privatekey_login($username, $privatekey)
{
// see http://tools.ietf.org/html/rfc4253#page-15
$publickey = $privatekey->getPublicKey(Crypt_RSA::PUBLIC_FORMAT_RAW);
$publickey = $privatekey->getPublicKey(RSA::PUBLIC_FORMAT_RAW);
if ($publickey === false) {
return false;
}
@ -2193,7 +2130,7 @@ class SSH2
}
$packet = $part1 . chr(1) . $part2;
$privatekey->setSignatureMode(Crypt_RSA::SIGNATURE_PKCS1);
$privatekey->setSignatureMode(RSA::SIGNATURE_PKCS1);
$signature = $privatekey->sign(pack('Na*a*', strlen($this->session_id), $this->session_id, $packet));
$signature = pack('Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($signature), $signature);
$packet.= pack('Na*', strlen($signature), $signature);
@ -3747,13 +3684,9 @@ class SSH2
$temp = unpack('Nlength', $this->_string_shift($signature, 4));
$signature = $this->_string_shift($signature, $temp['length']);
if (!class_exists('Crypt_RSA')) {
include_once 'Crypt/RSA.php';
}
$rsa = new Crypt_RSA();
$rsa->setSignatureMode(Crypt_RSA::SIGNATURE_PKCS1);
$rsa->loadKey(array('e' => $e, 'n' => $n), Crypt_RSA::PUBLIC_FORMAT_RAW);
$rsa = new RSA();
$rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
$rsa->loadKey(array('e' => $e, 'n' => $n), RSA::PUBLIC_FORMAT_RAW);
if (!$rsa->verify($this->exchange_hash, $signature)) {
user_error('Bad server signature');
return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);

View File

@ -7,7 +7,6 @@
* Here are some examples of how to use this library:
* <code>
* <?php
* include 'System/SSH/Agent.php';
* include 'vendor/autoload.php';
*
* $agent = new \phpseclib\System\SSH\Agent();
@ -33,7 +32,7 @@
namespace phpseclib\System\SSH;
use Crypt_RSA; //This should be removed once the Crypt package is fully namespaced
use phpseclib\Crypt\RSA;
use phpseclib\System\SSH\Agent\Identity;
/**
@ -138,10 +137,7 @@ class Agent
$key_type = substr($key_blob, 4, $length);
switch ($key_type) {
case 'ssh-rsa':
if (!class_exists('Crypt_RSA')) {
include_once 'Crypt/RSA.php';
}
$key = new Crypt_RSA();
$key = new RSA();
$key->loadKey('ssh-rsa ' . base64_encode($key_blob) . ' ' . $key_comment);
break;
case 'ssh-dss':

View File

@ -21,7 +21,7 @@ use phpseclib\System\SSH\Agent;
* Pure-PHP ssh-agent client identity object
*
* Instantiation should only be performed by \phpseclib\System\SSH\Agent class.
* This could be thought of as implementing an interface that Crypt_RSA
* This could be thought of as implementing an interface that phpseclib\Crypt\RSA
* implements. ie. maybe a Net_SSH_Auth_PublicKey interface or something.
* The methods in this interface would be getPublicKey, setSignatureMode
* and sign since those are the methods phpseclib looks for to perform
@ -36,7 +36,7 @@ class Identity
/**
* Key Object
*
* @var Crypt_RSA
* @var \phpseclib\Crypt\RSA
* @access private
* @see \phpseclib\System\SSH\Agent\Identity::getPublicKey()
*/
@ -77,7 +77,7 @@ class Identity
*
* Called by \phpseclib\System\SSH\Agent::requestIdentities()
*
* @param Crypt_RSA $key
* @param \phpseclib\Crypt\RSA $key
* @access private
*/
function setPublicKey($key)
@ -118,7 +118,7 @@ class Identity
* Set Signature Mode
*
* Doesn't do anything as ssh-agent doesn't let you pick and choose the signature mode. ie.
* ssh-agent's only supported mode is Crypt_RSA::SIGNATURE_PKCS1
* ssh-agent's only supported mode is \phpseclib\Crypt\RSA::SIGNATURE_PKCS1
*
* @param Integer $mode
* @access public

View File

@ -6,6 +6,7 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Base;
use phpseclib\Net\SFTP;
class Functional_Net_SFTPLargeFileTest extends PhpseclibFunctionalTestCase
@ -19,13 +20,13 @@ class Functional_Net_SFTPLargeFileTest extends PhpseclibFunctionalTestCase
self::markTestSkipped('This test depends on mcrypt for performance.');
}
parent::setUpBeforeClass();
self::ensureConstant('CRYPT_AES_MODE', Crypt_Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_BLOWFISH_MODE', Crypt_Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_DES_MODE', Crypt_Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_RC2_MODE', Crypt_Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_RC4_MODE', Crypt_Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_RIJNDAEL_MODE', Crypt_Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_TWOFISH_MODE', Crypt_Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_AES_MODE', Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_BLOWFISH_MODE', Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_DES_MODE', Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_RC2_MODE', Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_RC4_MODE', Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_RIJNDAEL_MODE', Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_TWOFISH_MODE', Base::ENGINE_MCRYPT);
}
public function setUp()

View File

@ -5,6 +5,9 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Hash;
use phpseclib\Math\BigInteger;
abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase
{
static public function setUpBeforeClass()
@ -13,19 +16,19 @@ abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase
if (extension_loaded('gmp')) {
self::ensureConstant(
'MATH_BIGINTEGER_MODE',
\phpseclib\Math\BigInteger::MODE_GMP
BigInteger::MODE_GMP
);
} elseif (extension_loaded('bcmath')) {
self::ensureConstant(
'MATH_BIGINTEGER_MODE',
\phpseclib\Math\BigInteger::MODE_BCMATH
BigInteger::MODE_BCMATH
);
} else {
self::markTestSkipped(
'Should have gmp or bcmath extension for functional test.'
);
}
self::ensureConstant('CRYPT_HASH_MODE', Crypt_Hash::MODE_HASH);
self::ensureConstant('CRYPT_HASH_MODE', Hash::MODE_HASH);
self::reRequireFile('Math/BigInteger.php');
self::reRequireFile('Crypt/Hash.php');
}

View File

@ -5,13 +5,15 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Base;
class Unit_Crypt_AES_InternalTest extends Unit_Crypt_AES_TestCase
{
static public function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::ensureConstant('CRYPT_AES_MODE', Crypt_AES::ENGINE_INTERNAL);
self::ensureConstant('CRYPT_RIJNDAEL_MODE', Crypt_Rijndael::ENGINE_INTERNAL);
self::ensureConstant('CRYPT_AES_MODE', Base::ENGINE_INTERNAL);
self::ensureConstant('CRYPT_RIJNDAEL_MODE', Base::ENGINE_INTERNAL);
}
}

View File

@ -5,6 +5,8 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Base;
class Unit_Crypt_AES_McryptTest extends Unit_Crypt_AES_TestCase
{
static public function setUpBeforeClass()
@ -15,7 +17,7 @@ class Unit_Crypt_AES_McryptTest extends Unit_Crypt_AES_TestCase
parent::setUpBeforeClass();
self::ensureConstant('CRYPT_AES_MODE', Crypt_AES::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_RIJNDAEL_MODE', Crypt_Rijndael::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_AES_MODE', Base::ENGINE_MCRYPT);
self::ensureConstant('CRYPT_RIJNDAEL_MODE', Base::ENGINE_MCRYPT);
}
}

View File

@ -5,6 +5,10 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\AES;
use phpseclib\Crypt\Base;
use phpseclib\Crypt\Rijndael;
require_once 'Crypt/AES.php';
abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
@ -25,9 +29,9 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
public function continuousBufferCombos()
{
$modes = array(
'Crypt_AES::MODE_CTR',
'Crypt_AES::MODE_OFB',
'Crypt_AES::MODE_CFB',
Base::MODE_CTR,
Base::MODE_OFB,
Base::MODE_CFB,
);
$plaintexts = array(
'',
@ -63,7 +67,7 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
*/
public function testEncryptDecryptWithContinuousBuffer($mode, $plaintext, $iv, $key)
{
$aes = new Crypt_AES(constant($mode));
$aes = new AES($mode);
$aes->enableContinuousBuffer();
$aes->setIV($iv);
$aes->setKey($key);
@ -84,7 +88,7 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
// this test case is from the following URL:
// https://web.archive.org/web/20070209120224/http://fp.gladman.plus.com/cryptography_technology/rijndael/aesdvec.zip
$aes = new Crypt_Rijndael();
$aes = new Rijndael();
$aes->disablePadding();
$aes->setKey(pack('H*', '2b7e151628aed2a6abf7158809cf4f3c762e7160')); // 160-bit key. Valid in Rijndael.
$ciphertext = $aes->encrypt(pack('H*', '3243f6a8885a308d313198a2e0370734'));
@ -98,7 +102,7 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
{
// same as the above - just with a different ciphertext
$aes = new Crypt_AES();
$aes = new AES();
$aes->disablePadding();
$aes->setKey(pack('H*', '2b7e151628aed2a6abf7158809cf4f3c762e7160')); // 160-bit key. AES should null pad to 192-bits
$ciphertext = $aes->encrypt(pack('H*', '3243f6a8885a308d313198a2e0370734'));

View File

@ -5,11 +5,13 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Hash;
class Unit_Crypt_Hash_MD5Test extends Unit_Crypt_Hash_TestCase
{
public function getInstance()
{
return new Crypt_Hash('md5');
return new Hash('md5');
}
/**

View File

@ -5,11 +5,13 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Hash;
class Unit_Crypt_Hash_SHA256Test extends Unit_Crypt_Hash_TestCase
{
public function getInstance()
{
return new Crypt_Hash('sha256');
return new Hash('sha256');
}
/**

View File

@ -5,11 +5,13 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Hash;
class Unit_Crypt_Hash_SHA256_96Test extends Unit_Crypt_Hash_SHA256Test
{
public function getInstance()
{
return new Crypt_Hash('sha256-96');
return new Hash('sha256-96');
}
/**

View File

@ -5,11 +5,13 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Hash;
class Unit_Crypt_Hash_SHA512Test extends Unit_Crypt_Hash_TestCase
{
public function getInstance()
{
return new Crypt_Hash('sha512');
return new Hash('sha512');
}
/**

View File

@ -5,11 +5,13 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
use phpseclib\Crypt\Hash;
class Unit_Crypt_Hash_SHA512_96Test extends Unit_Crypt_Hash_SHA512Test
{
public function getInstance()
{
return new Crypt_Hash('sha512-96');
return new Hash('sha512-96');
}
/**

View File

@ -5,27 +5,27 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'Crypt/Hash.php';
use phpseclib\Crypt\Hash;
abstract class Unit_Crypt_Hash_TestCase extends PhpseclibTestCase
{
static public function setUpBeforeClass()
{
if (!defined('CRYPT_HASH_MODE')) {
define('CRYPT_HASH_MODE', Crypt_Hash::MODE_INTERNAL);
define('CRYPT_HASH_MODE', Hash::MODE_INTERNAL);
}
}
public function setUp()
{
if (defined('CRYPT_HASH_MODE') && CRYPT_HASH_MODE !== Crypt_Hash::MODE_INTERNAL) {
if (defined('CRYPT_HASH_MODE') && CRYPT_HASH_MODE !== Hash::MODE_INTERNAL) {
$this->markTestSkipped(
'Skipping test because CRYPT_HASH_MODE is not defined as Crypt_Hash::MODE_INTERNAL.'
'Skipping test because CRYPT_HASH_MODE is not defined as \phpseclib\Crypt\Hash::MODE_INTERNAL.'
);
}
}
protected function assertHashesTo(Crypt_Hash $hash, $message, $expected)
protected function assertHashesTo(Hash $hash, $message, $expected)
{
$this->assertEquals(
strtolower($expected),
@ -34,7 +34,7 @@ abstract class Unit_Crypt_Hash_TestCase extends PhpseclibTestCase
);
}
protected function assertHMACsTo(Crypt_Hash $hash, $key, $message, $expected)
protected function assertHMACsTo(Hash $hash, $key, $message, $expected)
{
$hash->setKey($key);

View File

@ -5,13 +5,13 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
require_once 'Crypt/RSA.php' ;
use phpseclib\Crypt\RSA;
class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
{
public function testBadKey()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = 'zzzzzzzzzzzzzz';
@ -20,7 +20,7 @@ class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
public function testPKCS1Key()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = '-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
@ -42,7 +42,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
public function testPKCS1SpacesKey()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = '-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
@ -65,7 +65,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
public function testPKCS1NoHeaderKey()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = 'MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5
@ -85,7 +85,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
public function testPKCS1NoWhitespaceNoHeaderKey()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = 'MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp' .
'wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5' .
@ -105,7 +105,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
public function testRawPKCS1Key()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = 'MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp' .
'wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5' .
@ -126,7 +126,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
public function testLoadPKCS8PrivateKey()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$rsa->setPassword('password');
$key = '-----BEGIN ENCRYPTED PRIVATE KEY-----
@ -165,7 +165,7 @@ xryZaRDVmtMuf/OZBQ==
public function testSavePKCS8PrivateKey()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = '-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp
@ -184,7 +184,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$this->assertTrue($rsa->loadKey($key));
$key = $rsa->getPrivateKey(Crypt_RSA::PRIVATE_FORMAT_PKCS8);
$key = $rsa->getPrivateKey(RSA::PRIVATE_FORMAT_PKCS8);
$this->assertInternalType('string', $key);
$this->assertTrue($rsa->loadKey($key));
@ -192,7 +192,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
public function testPubKey1()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = '-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa
@ -210,7 +210,7 @@ Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
public function testPubKey2()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = '-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA61BjmfXGEvWmegnBGSuS
@ -229,7 +229,7 @@ ZQIDAQAB
public function testSSHPubKey()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4e' .
'CZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMS' .
@ -243,7 +243,7 @@ ZQIDAQAB
public function testSetPrivate()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = '-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa
@ -267,7 +267,7 @@ Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
*/
public function testUnsignedXML()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = '<RSAKeyValue>
<Modulus>v5OxcEgxPUfa701NpxnScCmlRkbwSGBiTWobHkIWZEB+AlRTHaVoZg/D8l6YzR7VdQidG6gF+nuUMjY75dBXgY/XcyVq0Hccf1jTfgARuNuq4GGG3hnCJVi2QsOgcf9R7TeXn+p1RKIhjQoWCiEQeEBTotNbJhcabNcPGSEJw+s=</Modulus>
@ -276,7 +276,7 @@ Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
$rsa->loadKey($key);
$rsa->setPublicKey();
$newkey = $rsa->getPublicKey(Crypt_RSA::PUBLIC_FORMAT_XML);
$newkey = $rsa->getPublicKey(RSA::PUBLIC_FORMAT_XML);
$this->assertSame(preg_replace('#\s#', '', $key), preg_replace('#\s#', '', $newkey));
}
@ -286,7 +286,7 @@ Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
*/
public function testSignedPKCS1()
{
$rsa = new Crypt_RSA();
$rsa = new RSA();
$key = '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/k7FwSDE9R9rvTU2nGdJwKaVG

View File

@ -6,8 +6,7 @@
*/
use phpseclib\File\X509;
require_once 'Crypt/RSA.php';
use phpseclib\Crypt\RSA;
class Unit_File_X509_SPKACTest extends PhpseclibTestCase
{
@ -47,7 +46,7 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase
public function testSaveSPKAC()
{
$privKey = new Crypt_RSA();
$privKey = new RSA();
extract($privKey->createKey());
$privKey->loadKey($privatekey);