From 5429504aee1851ae217c75cf20a08e31381b0363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Petrich?= Date: Sat, 25 May 2013 11:22:25 +0700 Subject: [PATCH] CS adjustment --- phpseclib/Crypt/AES.php | 5 +++++ phpseclib/Crypt/Base.php | 17 ++++++++++++++--- phpseclib/Crypt/Blowfish.php | 7 ++++++- phpseclib/Crypt/DES.php | 21 +++++++++++++-------- phpseclib/Crypt/Rijndael.php | 5 +++++ phpseclib/Crypt/TripleDES.php | 8 +++++++- phpseclib/Crypt/Twofish.php | 5 +++++ 7 files changed, 55 insertions(+), 13 deletions(-) diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 45a83f8f..6f65df32 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -156,10 +156,15 @@ class Crypt_AES extends Crypt_Rijndael { * Determines whether or not the mcrypt extension should be used. * * $mode could be: + * * - CRYPT_AES_MODE_ECB + * * - CRYPT_AES_MODE_CBC + * * - CRYPT_AES_MODE_CTR + * * - CRYPT_AES_MODE_CFB + * * - CRYPT_AES_MODE_OFB * * If not explictly set, CRYPT_AES_MODE_CBC will be used. diff --git a/phpseclib/Crypt/Base.php b/phpseclib/Crypt/Base.php index bd295298..2851c8b8 100644 --- a/phpseclib/Crypt/Base.php +++ b/phpseclib/Crypt/Base.php @@ -407,11 +407,17 @@ class Crypt_Base { * Determines whether or not the mcrypt extension should be used. * * $mode could be: + * * - CRYPT_MODE_ECB + * * - CRYPT_MODE_CBC + * * - CRYPT_MODE_CTR + * * - CRYPT_MODE_CFB + * * - CRYPT_MODE_OFB + * * (or the alias constants of the choosen cipher, for example for AES: CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC ...) * * If not explictly set, CRYPT_MODE_CBC will be used. @@ -608,7 +614,7 @@ class Crypt_Base { $this->enchanged = false; } - // re: http://phpseclib.sourceforge.net/cfb-demo.phps + // re: {@link http://phpseclib.sourceforge.net/cfb-demo.phps} // using mcrypt's default handing of CFB the above would output two different things. using phpseclib's // rewritten CFB implementation the above outputs the same thing twice. if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) { @@ -737,7 +743,7 @@ class Crypt_Base { break; case CRYPT_MODE_CFB: // cfb loosely routines inspired by openssl's: - // http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1 + // {@link http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1} if ($this->continuousBuffer) { $iv = &$this->encryptIV; $pos = &$buffer['pos']; @@ -876,7 +882,7 @@ class Crypt_Base { } if ($this->paddable) { - // we pad with chr(0) since that's what mcrypt_generic does. to quote from http://php.net/function.mcrypt-generic : + // we pad with chr(0) since that's what mcrypt_generic does. to quote from {@link http://www.php.net/function.mcrypt-generic}: // "The data is padded with "\0" to make sure the length of the data is n * blocksize." $ciphertext = str_pad($ciphertext, strlen($ciphertext) + ($block_size - strlen($ciphertext) % $block_size) % $block_size, chr(0)); } @@ -1193,11 +1199,16 @@ class Crypt_Base { * * _mcryptSetup() will be called each time if $changed === true * typically this happens when using one or more of following public methods: + * * - setKey() + * * - setIV() + * * - disableContinuousBuffer() + * * - First run of encrypt() / decrypt() * + * * Note: Could, but not must, extend by the child Crypt_* class * * @see setKey() diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 776b7804..0ead8192 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -375,10 +375,15 @@ class Crypt_Blowfish extends Crypt_Base { * Determines whether or not the mcrypt extension should be used. * * $mode could be: + * * - CRYPT_BLOWFISH_MODE_ECB + * * - CRYPT_BLOWFISH_MODE_CBC + * * - CRYPT_BLOWFISH_MODE_CTR + * * - CRYPT_BLOWFISH_MODE_CFB + * * - CRYPT_BLOWFISH_MODE_OFB * * If not explictly set, CRYPT_BLOWFISH_MODE_CBC will be used. @@ -593,7 +598,7 @@ class Crypt_Blowfish extends Crypt_Base { $init_crypt = ' list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"]; list(' . implode(',', $p) . ') = $self->bctx["p"]; - + '; } diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index 230fa56d..9bbc1048 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -669,10 +669,15 @@ class Crypt_DES extends Crypt_Base { * Determines whether or not the mcrypt extension should be used. * * $mode could be: + * * - CRYPT_DES_MODE_ECB + * * - CRYPT_DES_MODE_CBC + * * - CRYPT_DES_MODE_CTR + * * - CRYPT_DES_MODE_CFB + * * - CRYPT_DES_MODE_OFB * * If not explictly set, CRYPT_DES_MODE_CBC will be used. @@ -769,7 +774,7 @@ class Crypt_DES extends Crypt_Base { $sbox6 = array_map("intval", $this->sbox6); $sbox7 = array_map("intval", $this->sbox7); $sbox8 = array_map("intval", $this->sbox8); - /* Merge $shuffle with $[inv]ipmap */ + /* Merge $shuffle with $[inv]ipmap */ for ($i = 0; $i < 256; ++$i) { $shuffleip[] = $this->shuffle[$this->ipmap[$i]]; $shuffleinvip[] = $this->shuffle[$this->invipmap[$i]]; @@ -1387,14 +1392,14 @@ class Crypt_DES extends Crypt_Base { // Generation of a uniqe hash for our generated code switch (true) { case $gen_hi_opt_code: - // For hi-optimized code, we create for each combination of + // For hi-optimized code, we create for each combination of // $mode, $des_rounds and $this->key its own encrypt/decrypt function. $code_hash = md5(str_pad("Crypt_DES, $des_rounds, {$this->mode}, ", 32, "\0") . $this->key); break; default: - // After max 10 hi-optimized functions, we create generic + // After max 10 hi-optimized functions, we create generic // (still very fast.. but not ultra) functions for each $mode/$des_rounds - // Currently 2 * 5 generic functions will be then max. possible. + // Currently 2 * 5 generic functions will be then max. possible. $code_hash = "Crypt_DES, $des_rounds, {$this->mode}"; } @@ -1422,7 +1427,7 @@ class Crypt_DES extends Crypt_Base { switch (true) { case $gen_hi_opt_code: // In Hi-optimized code mode, we use our [3]DES key schedule as hardcoded integers. - // No futher initialisation of the $keys schedule is necessary. + // No futher initialisation of the $keys schedule is necessary. // That is the extra performance boost. $k = array( CRYPT_DES_ENCRYPT => $this->keys[CRYPT_DES_ENCRYPT], @@ -1470,7 +1475,7 @@ class Crypt_DES extends Crypt_Base { $l = $in[1]; $r = $in[2]; '; - + $l = '$l'; $r = '$r'; @@ -1481,10 +1486,10 @@ class Crypt_DES extends Crypt_Base { // start of "the Feistel (F) function" - see the following URL: // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png // Merge key schedule. - $crypt_block[$c].= ' + $crypt_block[$c].= ' $b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . '; $b2 = ((' . $r . ' >> 31) & 0x00000001) ^ (' . $r . ' << 1) ^ ' . $k[$c][++$ki] . ';' . - /* S-box indexing. */ + /* S-box indexing. */ $l . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^ $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^ $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^ diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index 6fec3a9d..c0194307 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -666,10 +666,15 @@ class Crypt_Rijndael extends Crypt_Base { * Determines whether or not the mcrypt extension should be used. * * $mode could be: + * * - CRYPT_RIJNDAEL_MODE_ECB + * * - CRYPT_RIJNDAEL_MODE_CBC + * * - CRYPT_RIJNDAEL_MODE_CTR + * * - CRYPT_RIJNDAEL_MODE_CFB + * * - CRYPT_RIJNDAEL_MODE_OFB * * If not explictly set, CRYPT_RIJNDAEL_MODE_CBC will be used. diff --git a/phpseclib/Crypt/TripleDES.php b/phpseclib/Crypt/TripleDES.php index 2c507352..448225d1 100644 --- a/phpseclib/Crypt/TripleDES.php +++ b/phpseclib/Crypt/TripleDES.php @@ -81,7 +81,7 @@ define('CRYPT_DES_MODE_CBC3', CRYPT_DES_MODE_CBC); * @author Jim Wigginton * @version 0.1.0 * @access public - * @package Crypt_TerraDES + * @package Crypt_TripleDES */ class Crypt_TripleDES extends Crypt_DES { /** @@ -168,11 +168,17 @@ class Crypt_TripleDES extends Crypt_DES { * Determines whether or not the mcrypt extension should be used. * * $mode could be: + * * - CRYPT_DES_MODE_ECB + * * - CRYPT_DES_MODE_CBC + * * - CRYPT_DES_MODE_CTR + * * - CRYPT_DES_MODE_CFB + * * - CRYPT_DES_MODE_OFB + * * - CRYPT_DES_MODE_3CBC * * If not explictly set, CRYPT_DES_MODE_CBC will be used. diff --git a/phpseclib/Crypt/Twofish.php b/phpseclib/Crypt/Twofish.php index 7fc07f8b..321e9583 100644 --- a/phpseclib/Crypt/Twofish.php +++ b/phpseclib/Crypt/Twofish.php @@ -454,10 +454,15 @@ class Crypt_Twofish extends Crypt_Base { * Determines whether or not the mcrypt extension should be used. * * $mode could be: + * * - CRYPT_TWOFISH_MODE_ECB + * * - CRYPT_TWOFISH_MODE_CBC + * * - CRYPT_TWOFISH_MODE_CTR + * * - CRYPT_TWOFISH_MODE_CFB + * * - CRYPT_TWOFISH_MODE_OFB * * If not explictly set, CRYPT_TWOFISH_MODE_CBC will be used.