mirror of
https://github.com/danog/phpseclib.git
synced 2024-11-27 04:46:26 +01: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::decrypt()
|
||||
* @internal This constants are for internal use only
|
||||
@ -1587,6 +1587,8 @@ class Crypt_Base
|
||||
case CRYPT_ENGINE_INTERNAL:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1640,18 +1642,21 @@ class Crypt_Base
|
||||
*/
|
||||
function _setEngine()
|
||||
{
|
||||
switch (true) {
|
||||
case $this->isValidEngine($this->preferredEngine):
|
||||
$this->engine = null;
|
||||
|
||||
$candidateEngines = array(
|
||||
$this->preferredEngine,
|
||||
CRYPT_ENGINE_MCRYPT,
|
||||
CRYPT_ENGINE_OPENSSL
|
||||
);
|
||||
foreach ($candidateEngines as $engine) {
|
||||
if ($this->isValidEngine($engine)) {
|
||||
$this->engine = $this->preferredEngine;
|
||||
break;
|
||||
case $this->isValidEngine(CRYPT_ENGINE_OPENSSL):
|
||||
$this->engine = CRYPT_ENGINE_OPENSSL;
|
||||
break;
|
||||
case $this->isValidEngine(CRYPT_ENGINE_MCRYPT):
|
||||
$this->engine = CRYPT_ENGINE_MCRYPT;
|
||||
break;
|
||||
default:
|
||||
$this->engine = CRYPT_ENGINE_INTERNAL;
|
||||
}
|
||||
}
|
||||
if (!$this->engine) {
|
||||
$this->engine = CRYPT_ENGINE_INTERNAL;
|
||||
}
|
||||
|
||||
if ($this->engine != CRYPT_ENGINE_MCRYPT && $this->enmcrypt) {
|
||||
@ -1732,7 +1737,7 @@ class Crypt_Base
|
||||
* @see setIV()
|
||||
* @see disableContinuousBuffer()
|
||||
* @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
|
||||
*/
|
||||
function _setup()
|
||||
@ -2512,14 +2517,12 @@ class Crypt_Base
|
||||
* @param $bytes
|
||||
* @return String
|
||||
*/
|
||||
function _trapdoor($bytes)
|
||||
function _hashInlineCryptFunction($bytes)
|
||||
{
|
||||
if (!defined('CRYPT_BASE_WHIRLPOOL_AVAILABLE')) {
|
||||
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 = '';
|
||||
$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.
|
||||
$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}";
|
||||
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])) {
|
||||
|
@ -1394,7 +1394,7 @@ class Crypt_DES extends Crypt_Base
|
||||
// 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 = 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.
|
||||
|
@ -642,7 +642,7 @@ class Crypt_RC2 extends Crypt_Base
|
||||
// Generation of a uniqe hash for our generated code
|
||||
$code_hash = "Crypt_RC2, {$this->mode}";
|
||||
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?
|
||||
|
@ -960,7 +960,7 @@ class Crypt_Rijndael extends Crypt_Base
|
||||
// Generation of a uniqe hash for our generated code
|
||||
$code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}";
|
||||
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])) {
|
||||
|
@ -746,7 +746,7 @@ class Crypt_Twofish extends Crypt_Base
|
||||
// Generation of a uniqe hash for our generated code
|
||||
$code_hash = "Crypt_Twofish, {$this->mode}";
|
||||
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])) {
|
||||
|
Loading…
Reference in New Issue
Block a user