From 53e005c1f4d5b841c3123f6f775b775630c7b4b7 Mon Sep 17 00:00:00 2001 From: NHellFire Date: Sun, 11 Feb 2018 07:22:36 +0000 Subject: [PATCH] Use OpenSSL for blowfish when available (fixes #58) --- lib/functions.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/functions.php b/lib/functions.php index 7ce6b68..3470c7c 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -745,6 +745,11 @@ function blowfish_encrypt($data,$secret=null) { if (! trim($secret)) return $data; + if (! empty($data) && function_exists('openssl_encrypt') && in_array('bf-ecb', openssl_get_cipher_methods())) { + $keylen = openssl_cipher_iv_length('bf-ecb') * 2; + return openssl_encrypt($data, 'bf-ecb', substr($secret,0,$keylen)); + } + if (function_exists('mcrypt_module_open') && ! empty($data)) { $td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_ECB,''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_DEV_URANDOM); @@ -801,6 +806,11 @@ function blowfish_decrypt($encdata,$secret=null) { if (! trim($secret)) return $encdata; + if (! empty($encdata) && function_exists('openssl_encrypt') && in_array('bf-ecb', openssl_get_cipher_methods())) { + $keylen = openssl_cipher_iv_length('bf-ecb') * 2; + return trim(openssl_decrypt($encdata, 'bf-ecb', substr($secret,0,$keylen))); + } + if (function_exists('mcrypt_module_open') && ! empty($encdata)) { $td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_ECB,''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_DEV_URANDOM);