mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-02-03 20:38:29 +00:00
setengine changes per bantu
This commit is contained in:
parent
9b7d006edb
commit
3f3e0cac98
@ -53,7 +53,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
* @access private
|
* @access public
|
||||||
* @see Crypt_Base::encrypt()
|
* @see Crypt_Base::encrypt()
|
||||||
* @see Crypt_Base::decrypt()
|
* @see Crypt_Base::decrypt()
|
||||||
* @internal This constants are for internal use only
|
* @internal This constants are for internal use only
|
||||||
@ -1587,6 +1587,8 @@ class Crypt_Base
|
|||||||
case CRYPT_ENGINE_INTERNAL:
|
case CRYPT_ENGINE_INTERNAL:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1640,17 +1642,20 @@ class Crypt_Base
|
|||||||
*/
|
*/
|
||||||
function _setEngine()
|
function _setEngine()
|
||||||
{
|
{
|
||||||
switch (true) {
|
$this->engine = null;
|
||||||
case $this->isValidEngine($this->preferredEngine):
|
|
||||||
|
$candidateEngines = array(
|
||||||
|
$this->preferredEngine,
|
||||||
|
CRYPT_ENGINE_MCRYPT,
|
||||||
|
CRYPT_ENGINE_OPENSSL
|
||||||
|
);
|
||||||
|
foreach ($candidateEngines as $engine) {
|
||||||
|
if ($this->isValidEngine($engine)) {
|
||||||
$this->engine = $this->preferredEngine;
|
$this->engine = $this->preferredEngine;
|
||||||
break;
|
break;
|
||||||
case $this->isValidEngine(CRYPT_ENGINE_OPENSSL):
|
}
|
||||||
$this->engine = CRYPT_ENGINE_OPENSSL;
|
}
|
||||||
break;
|
if (!$this->engine) {
|
||||||
case $this->isValidEngine(CRYPT_ENGINE_MCRYPT):
|
|
||||||
$this->engine = CRYPT_ENGINE_MCRYPT;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$this->engine = CRYPT_ENGINE_INTERNAL;
|
$this->engine = CRYPT_ENGINE_INTERNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1732,7 +1737,7 @@ class Crypt_Base
|
|||||||
* @see setIV()
|
* @see setIV()
|
||||||
* @see disableContinuousBuffer()
|
* @see disableContinuousBuffer()
|
||||||
* @access private
|
* @access private
|
||||||
* @internal _setup() is called always before(!) en/decryption.
|
* @internal _setup() is always called before en/decryption.
|
||||||
* @internal Could, but not must, extend by the child Crypt_* class
|
* @internal Could, but not must, extend by the child Crypt_* class
|
||||||
*/
|
*/
|
||||||
function _setup()
|
function _setup()
|
||||||
@ -2512,14 +2517,12 @@ class Crypt_Base
|
|||||||
* @param $bytes
|
* @param $bytes
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
function _trapdoor($bytes)
|
function _hashInlineCryptFunction($bytes)
|
||||||
{
|
{
|
||||||
if (!defined('CRYPT_BASE_WHIRLPOOL_AVAILABLE')) {
|
if (!defined('CRYPT_BASE_WHIRLPOOL_AVAILABLE')) {
|
||||||
define('CRYPT_BASE_WHIRLPOOL_AVAILABLE', (bool)(extension_loaded('hash') && in_array('whirlpool', hash_algos())));
|
define('CRYPT_BASE_WHIRLPOOL_AVAILABLE', (bool)(extension_loaded('hash') && in_array('whirlpool', hash_algos())));
|
||||||
}
|
}
|
||||||
|
|
||||||
// return pack('H*', md5($bytes) . sha1($bytes) . (CRYPT_BASE_WHIRLPOOL_AVAILABLE ? hash('whirlpool', $bytes) : '')); // Alternative
|
|
||||||
|
|
||||||
$result = '';
|
$result = '';
|
||||||
$hash = $bytes;
|
$hash = $bytes;
|
||||||
|
|
||||||
|
@ -546,10 +546,10 @@ class Crypt_Blowfish extends Crypt_Base
|
|||||||
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
|
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
|
||||||
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
|
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
|
||||||
|
|
||||||
// Generation of a uniqe hash for our generated code
|
// Generation of a unique hash for our generated code
|
||||||
$code_hash = "Crypt_Blowfish, {$this->mode}";
|
$code_hash = "Crypt_Blowfish, {$this->mode}";
|
||||||
if ($gen_hi_opt_code) {
|
if ($gen_hi_opt_code) {
|
||||||
$code_hash = str_pad($code_hash, 32) . $this->_trapdoor($this->key);
|
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($lambda_functions[$code_hash])) {
|
if (!isset($lambda_functions[$code_hash])) {
|
||||||
|
@ -1394,7 +1394,7 @@ class Crypt_DES extends Crypt_Base
|
|||||||
// After max 10 hi-optimized functions, we create generic
|
// After max 10 hi-optimized functions, we create generic
|
||||||
// (still very fast.. but not ultra) functions for each $mode/$des_rounds
|
// (still very fast.. but not ultra) functions for each $mode/$des_rounds
|
||||||
// Currently 2 * 5 generic functions will be then max. possible.
|
// Currently 2 * 5 generic functions will be then max. possible.
|
||||||
$code_hash = str_pad($code_hash, 32) . $this->_trapdoor($this->key);
|
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is there a re-usable $lambda_functions in there? If not, we have to create it.
|
// Is there a re-usable $lambda_functions in there? If not, we have to create it.
|
||||||
|
@ -642,7 +642,7 @@ class Crypt_RC2 extends Crypt_Base
|
|||||||
// Generation of a uniqe hash for our generated code
|
// Generation of a uniqe hash for our generated code
|
||||||
$code_hash = "Crypt_RC2, {$this->mode}";
|
$code_hash = "Crypt_RC2, {$this->mode}";
|
||||||
if ($gen_hi_opt_code) {
|
if ($gen_hi_opt_code) {
|
||||||
$code_hash = str_pad($code_hash, 32) . $this->_trapdoor($this->key);
|
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is there a re-usable $lambda_functions in there?
|
// Is there a re-usable $lambda_functions in there?
|
||||||
|
@ -960,7 +960,7 @@ class Crypt_Rijndael extends Crypt_Base
|
|||||||
// Generation of a uniqe hash for our generated code
|
// Generation of a uniqe hash for our generated code
|
||||||
$code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}";
|
$code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}";
|
||||||
if ($gen_hi_opt_code) {
|
if ($gen_hi_opt_code) {
|
||||||
$code_hash = str_pad($code_hash, 32) . $this->_trapdoor($this->key);
|
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($lambda_functions[$code_hash])) {
|
if (!isset($lambda_functions[$code_hash])) {
|
||||||
|
@ -746,7 +746,7 @@ class Crypt_Twofish extends Crypt_Base
|
|||||||
// Generation of a uniqe hash for our generated code
|
// Generation of a uniqe hash for our generated code
|
||||||
$code_hash = "Crypt_Twofish, {$this->mode}";
|
$code_hash = "Crypt_Twofish, {$this->mode}";
|
||||||
if ($gen_hi_opt_code) {
|
if ($gen_hi_opt_code) {
|
||||||
$code_hash = str_pad($code_hash, 32) . $this->_trapdoor($this->key);
|
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($lambda_functions[$code_hash])) {
|
if (!isset($lambda_functions[$code_hash])) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user