Skip to content

Commit 85f8c61

Browse files
committed
Fix for Setting of IV length for AEAD mode failed - closes #183
1 parent 1650d6a commit 85f8c61

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/functions.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,10 @@ function blowfish_encrypt($data,$secret=null) {
793793
return $data;
794794

795795
if (! empty($data) && function_exists('openssl_encrypt') && in_array(SESSION_CIPHER, openssl_get_cipher_methods())) {
796+
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(SESSION_CIPHER));
796797
$keylen = openssl_cipher_iv_length(SESSION_CIPHER) * 2;
797-
return openssl_encrypt($data, SESSION_CIPHER, substr($secret,0,$keylen));
798+
$encrypted = openssl_encrypt($data, SESSION_CIPHER, substr($secret,0,$keylen), $options=0, $iv, $tag);
799+
return base64_encode($encrypted . '::' . $iv . '::' . $tag);
798800
}
799801

800802
if (function_exists('mcrypt_module_open') && ! empty($data)) {
@@ -855,7 +857,8 @@ function blowfish_decrypt($encdata,$secret=null) {
855857

856858
if (! empty($encdata) && function_exists('openssl_encrypt') && in_array(SESSION_CIPHER, openssl_get_cipher_methods())) {
857859
$keylen = openssl_cipher_iv_length(SESSION_CIPHER) * 2;
858-
return trim(openssl_decrypt($encdata, SESSION_CIPHER, substr($secret,0,$keylen)));
860+
list($encryptedData, $iv, $tag) = explode('::', base64_decode($encdata), 3);
861+
return trim(openssl_decrypt($encryptedData, SESSION_CIPHER, substr($secret,0,$keylen), $options=0, $iv, $tag));
859862
}
860863

861864
if (function_exists('mcrypt_module_open') && ! empty($encdata)) {

0 commit comments

Comments
 (0)