Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bug fix for backwards compat

git-svn-id: http://svn.php.net/repository/pear/packages/Crypt_CBC/trunk@81698 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 99c52ffe0eed8818676eddefed171eb839cfcc87 1 parent 8b67476
Colin Viebrock authored
Showing with 28 additions and 15 deletions.
  1. +24 −12 CBC.php
  2. +4 −3 package.xml
36 CBC.php
View
@@ -25,17 +25,15 @@
/**
* Class to emulate Perl's Crypt::CBC module
*
- * Blowfish support is not completely working, mainly because of a bug
- * discovered in libmcrypt (version 2.4.8 and earlier). If you are running
- * a later version of libmcrypt > 2.4.8, you can do Blowfish encryption
- * that is compatable with Perl. However, check the libmcrypt documenation
- * as to whether you should use 'BLOWFISH' or 'BLOWFISH-COMPAT' when
- * specifying the cipher.
- *
+ * Blowfish support that is compatable with Perl requires libmcrypt >= 2.4.9.
* If you are using libmcrypt <= 2.4.8, Blowfish encryption will work,
* but your data will not be readable by Perl scripts. It will work
* "internally" .. i.e. this class will be able to encode/decode the data.
*
+ * Blowfish support that is compatable with PHP applications using
+ * libmcrypt <= 2.4.8 requies you to use 'BLOWFISH-COMPAT' when
+ * specifying the cipher. Check the libmcrypt docs when in doubt.
+ *
* This class no longer works with libmcrypt 2.2.x versions.
*
* NOTE: the cipher names in this class may change depending on how
@@ -73,6 +71,12 @@ class Crypt_CBC extends PEAR {
var $TD;
/**
+ * crypt deinit function, for backwards compatability
+ * @var string
+ */
+ var $deinit_function;
+
+ /**
* blocksize of cipher
* @var string
*/
@@ -136,9 +140,17 @@ function Crypt_CBC ($key, $cipher='DES')
return $this->raiseError('mcrypt module is not compiled into PHP', null,
PEAR_ERROR_DIE, null, 'compile PHP using "--with-mcrypt"' );
}
- if (!function_exists('mcrypt_module_open') || !function_exists('mcrypt_generic_deinit')) {
- return $this->raiseError('libmcrypt/PHP version insufficient', null,
- PEAR_ERROR_DIE, null, 'this class only works with libmcrypt >= 2.4.x and later, and PHP >= 4.1.1' );
+ if (!function_exists('mcrypt_module_open')) {
+ return $this->raiseError('libmcrypt version insufficient', null,
+ PEAR_ERROR_DIE, null, 'this class requires libmcrypt >= 2.4.x, preferably >= 2.4.18' );
+ }
+ if (function_exists('mcrypt_generic_deinit')) {
+ $this->deinit_function = 'mcrypt_generic_deinit';
+ } else if (function_exists('mcrypt_generic_end')) {
+ $this->deinit_function = 'mcrypt_generic_end';
+ } else {
+ return $this->raiseError('PHP version insufficient', null,
+ PEAR_ERROR_DIE, null, 'this class requires PHP >= 4.0.2, preferably >= 4.1.1' );
}
@@ -238,7 +250,7 @@ function encrypt($clear)
$cblock = mcrypt_generic($this->TD, $iv^$block );
$iv = $cblock;
$crypt .= $cblock;
- mcrypt_generic_deinit($this->TD);
+ call_user_func($this->deinit_function, $this->TD);
}
$this->last_crypt = $crypt;
@@ -287,7 +299,7 @@ function decrypt($crypt) {
$block = $iv ^ mdecrypt_generic($this->TD, $cblock);
$iv = $cblock;
$clear .= $block;
- mcrypt_generic_deinit($this->TD);
+ call_user_func($this->deinit_function, $this->TD);
}
/* remove the padding from the end of the cleartext */
7 package.xml
View
@@ -18,12 +18,13 @@
</maintainer>
</maintainers>
<release>
- <version>0.2</version>
+ <version>0.3</version>
<state>stable</state>
<license>PHP 2.02</license>
- <date>2002-05-09</date>
+ <date>2002-05-10</date>
<notes>
- Bug fix for a pretty bad memory leak.
+ Previous bug fixed worked, but required PHP 4.2.0. The class has been changed
+ to allow for more backwards compatability (back to 4.0.2)
</notes>
<filelist>
<dir name="/" baseinstalldir="Crypt">
Please sign in to comment.
Something went wrong with that request. Please try again.