From a983412ea96dc920d3ee4c025bcdc29069b01735 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 13 May 2017 23:18:42 -0500 Subject: [PATCH] Crypt: fix OpenSSL engine on <= PHP 5.3.6 --- phpseclib/Crypt/Blowfish.php | 3 +++ phpseclib/Crypt/RC4.php | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 5be5ce3a..17c8e7e8 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -390,6 +390,9 @@ class Crypt_Blowfish extends Crypt_Base function isValidEngine($engine) { if ($engine == CRYPT_ENGINE_OPENSSL) { + if (version_compare(PHP_VERSION, '5.3.7') < 0 && $this->key_length != 16) { + return false; + } if ($this->key_length < 16) { return false; } diff --git a/phpseclib/Crypt/RC4.php b/phpseclib/Crypt/RC4.php index 62145548..7cec2e77 100644 --- a/phpseclib/Crypt/RC4.php +++ b/phpseclib/Crypt/RC4.php @@ -190,7 +190,23 @@ class Crypt_RC4 extends Crypt_Base function isValidEngine($engine) { if ($engine == CRYPT_ENGINE_OPENSSL) { - $this->cipher_name_openssl = 'rc4-40'; + if (version_compare(PHP_VERSION, '5.3.7') >= 0) { + $this->cipher_name_openssl = 'rc4-40'; + } else { + switch (strlen($this->key)) { + case 5: + $this->cipher_name_openssl = 'rc4-40'; + break; + case 8: + $this->cipher_name_openssl = 'rc4-64'; + break; + case 16: + $this->cipher_name_openssl = 'rc4'; + break; + default: + return false; + } + } } return parent::isValidEngine($engine);