From a78d7df66031ee1be64cfab2f8a4ea29f6be182a Mon Sep 17 00:00:00 2001 From: Jim Wigginton Date: Mon, 4 Aug 2008 17:59:12 +0000 Subject: [PATCH] - if padding is disabled and the length of the text-to-be-encrypted isn't a multiple of the block size, padding will be automatically enabled git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@19 21d32557-59b3-4da0-833f-c5933fad653e --- phpseclib/Crypt/DES.php | 11 +++++++++-- phpseclib/Crypt/TripleDES.php | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index d3d0a01e..dc829d7e 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -53,7 +53,7 @@ * @author Jim Wigginton * @copyright MMVII Jim Wigginton * @license http://www.gnu.org/licenses/lgpl.txt - * @version $Id: DES.php,v 1.4 2008-03-31 00:49:09 terrafrost Exp $ + * @version $Id: DES.php,v 1.5 2008-08-04 17:59:12 terrafrost Exp $ * @link http://phpseclib.sourceforge.net */ @@ -496,13 +496,20 @@ class Crypt_DES { * Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize (8). * 8 - (strlen($text) & 7) bytes are added, each of which is equal to chr(8 - (strlen($text) & 7) * + * If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless + * and padding will, hence forth, be enabled. + * * @see Crypt_DES::_unpad() * @access private */ function _pad($text) { if (!$this->padding) { - return $text; + if (strlen($text) & 7 == 0) { + return $text; + } else { + $this->padding = true; + } } $length = 8 - (strlen($text) & 7); diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index 1b269e2f..51ef0441 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -47,7 +47,7 @@ * @author Jim Wigginton * @copyright MMVII Jim Wigginton * @license http://www.gnu.org/licenses/lgpl.txt - * @version $Id: TripleDES.php,v 1.3 2007-07-25 21:56:14 terrafrost Exp $ + * @version $Id: TripleDES.php,v 1.4 2008-08-04 17:59:12 terrafrost Exp $ * @link http://phpseclib.sourceforge.net */ @@ -552,13 +552,20 @@ class Crypt_TripleDES { * Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize (8). * 8 - (strlen($text) & 7) bytes are added, each of which is equal to chr(8 - (strlen($text) & 7) * + * If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless + * and padding will, hence forth, be enabled. + * * @see Crypt_TripleDES::_unpad() * @access private */ function _pad($text) { if (!$this->padding) { - return $text; + if (strlen($text) & 7 == 0) { + return $text; + } else { + $this->padding = true; + } } $length = 8 - (strlen($text) & 7);