SSH2: add twofish support

This commit is contained in:
terrafrost 2013-05-03 01:45:09 -05:00
parent 3ac29adff1
commit 2c43e9151c

View File

@ -112,6 +112,13 @@ if (!class_exists('Crypt_AES')) {
require_once('Crypt/AES.php'); require_once('Crypt/AES.php');
} }
/**
* Include Crypt_Twofish
*/
if (!class_exists('Crypt_Twofish')) {
require_once('Crypt/Twofish.php');
}
/**#@+ /**#@+
* Execution Bitmap Masks * Execution Bitmap Masks
* *
@ -966,24 +973,36 @@ class Net_SSH2 {
); );
static $encryption_algorithms = array( static $encryption_algorithms = array(
/*
// from <http://tools.ietf.org/html/rfc4345#section-4>: // from <http://tools.ietf.org/html/rfc4345#section-4>:
'arcfour256', 'arcfour256',
'arcfour128', 'arcfour128',
'arcfour', // OPTIONAL the ARCFOUR stream cipher with a 128-bit key 'arcfour', // OPTIONAL the ARCFOUR stream cipher with a 128-bit key
'aes128-cbc', // RECOMMENDED AES with a 128-bit key // CTR modes from <http://tools.ietf.org/html/rfc4344#section-4>:
'aes192-cbc', // OPTIONAL AES with a 192-bit key 'aes128-ctr', // RECOMMENDED AES (Rijndael) in SDCTR mode, with 128-bit key
'aes256-cbc', // OPTIONAL AES in CBC mode, with a 256-bit key 'aes192-ctr', // RECOMMENDED AES with 192-bit key
'aes256-ctr', // RECOMMENDED AES with 256-bit key
// from <http://tools.ietf.org/html/rfc4344#section-4>: 'twofish128-ctr', // OPTIONAL Twofish in SDCTR mode, with 128-bit key
'aes128-ctr', // RECOMMENDED AES (Rijndael) in SDCTR mode, with 128-bit key 'twofish192-ctr', // OPTIONAL Twofish with 192-bit key
'aes192-ctr', // RECOMMENDED AES with 192-bit key 'twofish256-ctr', // OPTIONAL Twofish with 256-bit key
'aes256-ctr', // RECOMMENDED AES with 256-bit key
'3des-ctr', // RECOMMENDED Three-key 3DES in SDCTR mode
'3des-cbc', // REQUIRED three-key 3DES in CBC mode 'aes128-cbc', // RECOMMENDED AES with a 128-bit key
'none' // OPTIONAL no encryption; NOT RECOMMENDED 'aes192-cbc', // OPTIONAL AES with a 192-bit key
'aes256-cbc', // OPTIONAL AES in CBC mode, with a 256-bit key
*/
'twofish128-cbc', // OPTIONAL Twofish with a 128-bit key
'twofish192-cbc', // OPTIONAL Twofish with a 192-bit key
'twofish256-cbc',
'twofish-cbc', // OPTIONAL alias for "twofish256-cbc"
// (this is being retained for historical reasons)
'3des-ctr', // RECOMMENDED Three-key 3DES in SDCTR mode
'3des-cbc', // REQUIRED three-key 3DES in CBC mode
'none' // OPTIONAL no encryption; NOT RECOMMENDED
); );
static $mac_algorithms = array( static $mac_algorithms = array(
@ -1092,14 +1111,21 @@ class Net_SSH2 {
break; break;
case 'aes256-cbc': case 'aes256-cbc':
case 'aes256-ctr': case 'aes256-ctr':
case 'twofish-cbc':
case 'twofish256-cbc':
case 'twofish256-ctr':
$decryptKeyLength = 32; // eg. 256 / 8 $decryptKeyLength = 32; // eg. 256 / 8
break; break;
case 'aes192-cbc': case 'aes192-cbc':
case 'aes192-ctr': case 'aes192-ctr':
case 'twofish192-cbc':
case 'twofish192-ctr':
$decryptKeyLength = 24; // eg. 192 / 8 $decryptKeyLength = 24; // eg. 192 / 8
break; break;
case 'aes128-cbc': case 'aes128-cbc':
case 'aes128-ctr': case 'aes128-ctr':
case 'twofish128-cbc':
case 'twofish128-ctr':
$decryptKeyLength = 16; // eg. 128 / 8 $decryptKeyLength = 16; // eg. 128 / 8
break; break;
case 'arcfour': case 'arcfour':
@ -1123,14 +1149,21 @@ class Net_SSH2 {
switch ($encrypt) { switch ($encrypt) {
case '3des-cbc': case '3des-cbc':
case '3des-ctr': case '3des-ctr':
case 'twofish-cbc':
case 'twofish256-cbc':
case 'twofish256-ctr':
$encryptKeyLength = 24; $encryptKeyLength = 24;
break; break;
case 'aes256-cbc': case 'aes256-cbc':
case 'aes256-ctr': case 'aes256-ctr':
case 'twofish192-cbc':
case 'twofish192-ctr':
$encryptKeyLength = 32; $encryptKeyLength = 32;
break; break;
case 'aes192-cbc': case 'aes192-cbc':
case 'aes192-ctr': case 'aes192-ctr':
case 'twofish128-cbc':
case 'twofish128-ctr':
$encryptKeyLength = 24; $encryptKeyLength = 24;
break; break;
case 'aes128-cbc': case 'aes128-cbc':
@ -1307,6 +1340,19 @@ class Net_SSH2 {
$this->encrypt = new Crypt_AES(CRYPT_AES_MODE_CTR); $this->encrypt = new Crypt_AES(CRYPT_AES_MODE_CTR);
$this->encrypt_block_size = 16; // eg. 128 / 8 $this->encrypt_block_size = 16; // eg. 128 / 8
break; break;
case 'twofish128-cbc':
case 'twofish192-cbc':
case 'twofish256-cbc':
case 'twofish-cbc':
$this->encrypt = new Crypt_Twofish();
$this->decrypt_block_size = 16;
break;
case 'twofish128-ctr':
case 'twofish192-ctr':
case 'twofish256-ctr':
$this->encrypt = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
$this->decrypt_block_size = 16;
break;
case 'arcfour': case 'arcfour':
case 'arcfour128': case 'arcfour128':
case 'arcfour256': case 'arcfour256':
@ -1335,6 +1381,19 @@ class Net_SSH2 {
$this->decrypt = new Crypt_AES(CRYPT_AES_MODE_CTR); $this->decrypt = new Crypt_AES(CRYPT_AES_MODE_CTR);
$this->decrypt_block_size = 16; $this->decrypt_block_size = 16;
break; break;
case 'twofish128-cbc':
case 'twofish192-cbc':
case 'twofish256-cbc':
case 'twofish-cbc':
$this->decrypt = new Crypt_Twofish();
$this->decrypt_block_size = 16;
break;
case 'twofish128-ctr':
case 'twofish192-ctr':
case 'twofish256-ctr':
$this->decrypt = new Crypt_Twofish(CRYPT_TWOFISH_MODE_CTR);
$this->decrypt_block_size = 16;
break;
case 'arcfour': case 'arcfour':
case 'arcfour128': case 'arcfour128':
case 'arcfour256': case 'arcfour256':
@ -3223,4 +3282,4 @@ class Net_SSH2 {
} }
return $this->exit_status; return $this->exit_status;
} }
} }