optimizations

This commit is contained in:
Hans-Jürgen Petrich 2013-05-13 12:41:52 +07:00
parent c16de4f2d5
commit b242259d17
7 changed files with 125 additions and 131 deletions

View File

@ -69,13 +69,6 @@
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Math_BigInteger
*/
if (!class_exists('Math_BigInteger')) {
require_once('Math/BigInteger.php');
}
/**
* Include Crypt_Random
*/
@ -84,14 +77,14 @@ if (!class_exists('Math_BigInteger')) {
// call function_exists() a second time to stop the require_once from being called outside
// of the auto loader
if (!function_exists('crypt_random_string')) {
require_once('Crypt/Random.php');
require_once('Random.php');
}
/**
* Include Crypt_Hash
*/
if (!class_exists('Crypt_Hash')) {
require_once('Crypt/Hash.php');
require_once('Hash.php');
}
/**#@+
@ -469,6 +462,10 @@ class Crypt_RSA {
*/
function Crypt_RSA()
{
if (!class_exists('Math_BigInteger')) {
require_once('Math/BigInteger.php');
}
$this->configFile = CRYPT_RSA_OPENSSL_CONFIG;
if ( !defined('CRYPT_RSA_MODE') ) {

View File

@ -41,13 +41,6 @@
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Math_BigInteger
*/
if (!class_exists('Math_BigInteger')) {
require_once('Math/BigInteger.php');
}
/**#@+
* Tag Classes
*
@ -249,6 +242,17 @@ class File_ASN1 {
FILE_ASN1_TYPE_VISIBLE_STRING => 1,
);
function File_ASN1()
{
static $static_init = null;
if (!$static_init) {
$static_init = true;
if (!class_exists('Math_BigInteger')) {
require_once('Math/BigInteger.php');
}
}
}
/**
* Parse BER-encoding
*

View File

@ -48,7 +48,7 @@
* Include File_ASN1
*/
if (!class_exists('File_ASN1')) {
require_once('File/ASN1.php');
require_once('ASN1.php');
}
/**

View File

@ -58,7 +58,7 @@
* Include Net_SSH2
*/
if (!class_exists('Net_SSH2')) {
require_once('Net/SSH2.php');
require_once('SSH2.php');
}
/**#@+

View File

@ -34,13 +34,6 @@
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Net_SSH2
*/
if (!class_exists('Net_SFTP')) {
require_once('Net/SFTP.php');
}
/**
* SFTP Stream Wrapper
*
@ -134,6 +127,18 @@ class Net_SFTP_Stream {
*/
var $notification;
/**
* The Constructor
*
* @access public
*/
function Net_SFTP_Stream()
{
if (!class_exists('Net_SFTP')) {
require_once('Net/SFTP.php');
}
}
/**
* Path Parser
*
@ -756,4 +761,6 @@ class Net_SFTP_Stream {
}
}
stream_wrapper_register('sftp', 'Net_SFTP_Stream');
if (function_exists('stream_wrapper_register')) {
stream_wrapper_register('sftp', 'Net_SFTP_Stream');
}

View File

@ -66,52 +66,6 @@
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Math_BigInteger
*
* Used to do RSA encryption.
*/
if (!class_exists('Math_BigInteger')) {
require_once('Math/BigInteger.php');
}
/**
* Include Crypt_Null
*/
//require_once('Crypt/Null.php');
/**
* Include Crypt_DES
*/
if (!class_exists('Crypt_DES')) {
require_once('Crypt/DES.php');
}
/**
* Include Crypt_TripleDES
*/
if (!class_exists('Crypt_TripleDES')) {
require_once('Crypt/TripleDES.php');
}
/**
* Include Crypt_RC4
*/
if (!class_exists('Crypt_RC4')) {
require_once('Crypt/RC4.php');
}
/**
* Include Crypt_Random
*/
// the class_exists() will only be called if the crypt_random_string function hasn't been defined and
// will trigger a call to __autoload() if you're wanting to auto-load classes
// call function_exists() a second time to stop the require_once from being called outside
// of the auto loader
if (!function_exists('crypt_random_string') && !class_exists('Crypt_Random') && !function_exists('crypt_random_string')) {
require_once('Crypt/Random.php');
}
/**#@+
* Encryption Methods
*
@ -495,6 +449,19 @@ class Net_SSH1 {
*/
function Net_SSH1($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES)
{
if (!class_exists('Math_BigInteger')) {
require_once('Math/BigInteger.php');
}
// Include Crypt_Random
// the class_exists() will only be called if the crypt_random_string function hasn't been defined and
// will trigger a call to __autoload() if you're wanting to auto-load classes
// call function_exists() a second time to stop the require_once from being called outside
// of the auto loader
if (!function_exists('crypt_random_string') && !class_exists('Crypt_Random') && !function_exists('crypt_random_string')) {
require_once('Crypt/Random.php');
}
$this->protocol_flags = array(
1 => 'NET_SSH1_MSG_DISCONNECT',
2 => 'NET_SSH1_SMSG_PUBLIC_KEY',
@ -636,18 +603,27 @@ class Net_SSH1 {
// $this->crypto = new Crypt_Null();
// break;
case NET_SSH1_CIPHER_DES:
if (!class_exists('Crypt_DES')) {
require_once('Crypt/DES.php');
}
$this->crypto = new Crypt_DES();
$this->crypto->disablePadding();
$this->crypto->enableContinuousBuffer();
$this->crypto->setKey(substr($session_key, 0, 8));
break;
case NET_SSH1_CIPHER_3DES:
if (!class_exists('Crypt_TripleDES')) {
require_once('Crypt/TripleDES.php');
}
$this->crypto = new Crypt_TripleDES(CRYPT_DES_MODE_3CBC);
$this->crypto->disablePadding();
$this->crypto->enableContinuousBuffer();
$this->crypto->setKey(substr($session_key, 0, 24));
break;
//case NET_SSH1_CIPHER_RC4:
// if (!class_exists('Crypt_RC4')) {
// require_once('Crypt/RC4.php');
// }
// $this->crypto = new Crypt_RC4();
// $this->crypto->enableContinuousBuffer();
// $this->crypto->setKey(substr($session_key, 0, 16));

View File

@ -68,64 +68,6 @@
* @link http://phpseclib.sourceforge.net
*/
/**
* Include Math_BigInteger
*
* Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
*/
if (!class_exists('Math_BigInteger')) {
require_once('Math/BigInteger.php');
}
/**
* Include Crypt_Random
*/
if (!function_exists('crypt_random_string')) {
require_once('Crypt/Random.php');
}
/**
* Include Crypt_Hash
*/
if (!class_exists('Crypt_Hash')) {
require_once('Crypt/Hash.php');
}
/**
* Include Crypt_TripleDES
*/
if (!class_exists('Crypt_TripleDES')) {
require_once('Crypt/TripleDES.php');
}
/**
* Include Crypt_RC4
*/
if (!class_exists('Crypt_RC4')) {
require_once('Crypt/RC4.php');
}
/**
* Include Crypt_AES
*/
if (!class_exists('Crypt_AES')) {
require_once('Crypt/AES.php');
}
/**
* Include Crypt_Twofish
*/
if (!class_exists('Crypt_Twofish')) {
require_once('Crypt/Twofish.php');
}
/**
* Include Crypt_Blowfish
*/
if (!class_exists('Crypt_Blowfish')) {
require_once('Crypt/Blowfish.php');
}
/**#@+
* Execution Bitmap Masks
*
@ -791,6 +733,20 @@ class Net_SSH2 {
*/
function Net_SSH2($host, $port = 22, $timeout = 10)
{
// Include Math_BigInteger
// Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
if (!class_exists('Math_BigInteger')) {
require_once('Math/BigInteger.php');
}
if (!function_exists('crypt_random_string')) {
require_once('Crypt/Random.php');
}
if (!class_exists('Crypt_Hash')) {
require_once('Crypt/Hash.php');
}
$this->last_packet = strtok(microtime(), ' ') + strtok(''); // == microtime(true) in PHP5
$this->message_numbers = array(
1 => 'NET_SSH2_MSG_DISCONNECT',
@ -1334,30 +1290,48 @@ class Net_SSH2 {
switch ($encrypt) {
case '3des-cbc':
if (!class_exists('Crypt_TripleDES')) {
require_once('Crypt/TripleDES.php');
}
$this->encrypt = new Crypt_TripleDES();
// $this->encrypt_block_size = 64 / 8 == the default
break;
case '3des-ctr':
if (!class_exists('Crypt_TripleDES')) {
require_once('Crypt/TripleDES.php');
}
$this->encrypt = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
// $this->encrypt_block_size = 64 / 8 == the default
break;
case 'aes256-cbc':
case 'aes192-cbc':
case 'aes128-cbc':
if (!class_exists('Crypt_AES')) {
require_once('Crypt/AES.php');
}
$this->encrypt = new Crypt_AES();
$this->encrypt_block_size = 16; // eg. 128 / 8
break;
case 'aes256-ctr':
case 'aes192-ctr':
case 'aes128-ctr':
if (!class_exists('Crypt_AES')) {
require_once('Crypt/AES.php');
}
$this->encrypt = new Crypt_AES(CRYPT_AES_MODE_CTR);
$this->encrypt_block_size = 16; // eg. 128 / 8
break;
case 'blowfish-cbc':
if (!class_exists('Crypt_Blowfish')) {
require_once('Crypt/Blowfish.php');
}
$this->encrypt = new Crypt_Blowfish();
$this->encrypt_block_size = 8;
break;
case 'blowfish-ctr':
if (!class_exists('Crypt_Blowfish')) {
require_once('Crypt/Blowfish.php');
}
$this->encrypt = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR);
$this->encrypt_block_size = 8;
break;
@ -1365,18 +1339,27 @@ class Net_SSH2 {
case 'twofish192-cbc':
case 'twofish256-cbc':
case 'twofish-cbc':
if (!class_exists('Crypt_Twofish')) {
require_once('Crypt/Twofish.php');
}
$this->encrypt = new Crypt_Twofish();
$this->encrypt_block_size = 16;
break;
case 'twofish128-ctr':
case 'twofish192-ctr':
case 'twofish256-ctr':
if (!class_exists('Crypt_Twofish')) {
require_once('Crypt/Twofish.php');
}
$this->encrypt = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
$this->encrypt_block_size = 16;
break;
case 'arcfour':
case 'arcfour128':
case 'arcfour256':
if (!class_exists('Crypt_RC4')) {
require_once('Crypt/RC4.php');
}
$this->encrypt = new Crypt_RC4();
break;
case 'none';
@ -1385,28 +1368,46 @@ class Net_SSH2 {
switch ($decrypt) {
case '3des-cbc':
if (!class_exists('Crypt_TripleDES')) {
require_once('Crypt/TripleDES.php');
}
$this->decrypt = new Crypt_TripleDES();
break;
case '3des-ctr':
if (!class_exists('Crypt_TripleDES')) {
require_once('Crypt/TripleDES.php');
}
$this->decrypt = new Crypt_TripleDES(CRYPT_DES_MODE_CTR);
break;
case 'aes256-cbc':
case 'aes192-cbc':
case 'aes128-cbc':
if (!class_exists('Crypt_AES')) {
require_once('Crypt/AES.php');
}
$this->decrypt = new Crypt_AES();
$this->decrypt_block_size = 16;
break;
case 'aes256-ctr':
case 'aes192-ctr':
case 'aes128-ctr':
if (!class_exists('Crypt_AES')) {
require_once('Crypt/AES.php');
}
$this->decrypt = new Crypt_AES(CRYPT_AES_MODE_CTR);
$this->decrypt_block_size = 16;
break;
case 'blowfish-cbc':
if (!class_exists('Crypt_Blowfish')) {
require_once('Crypt/Blowfish.php');
}
$this->decrypt = new Crypt_Blowfish();
$this->decrypt_block_size = 8;
break;
case 'blowfish-ctr':
if (!class_exists('Crypt_Blowfish')) {
require_once('Crypt/Blowfish.php');
}
$this->decrypt = new Crypt_Blowfish(CRYPT_BLOWFISH_MODE_CTR);
$this->decrypt_block_size = 8;
break;
@ -1414,18 +1415,27 @@ class Net_SSH2 {
case 'twofish192-cbc':
case 'twofish256-cbc':
case 'twofish-cbc':
if (!class_exists('Crypt_Twofish')) {
require_once('Crypt/Twofish.php');
}
$this->decrypt = new Crypt_Twofish();
$this->decrypt_block_size = 16;
break;
case 'twofish128-ctr':
case 'twofish192-ctr':
case 'twofish256-ctr':
if (!class_exists('Crypt_Twofish')) {
require_once('Crypt/Twofish.php');
}
$this->decrypt = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
$this->decrypt_block_size = 16;
break;
case 'arcfour':
case 'arcfour128':
case 'arcfour256':
if (!class_exists('Crypt_RC4')) {
require_once('Crypt/RC4.php');
}
$this->decrypt = new Crypt_RC4();
break;
case 'none';