CS adjustment

This commit is contained in:
Hans-Jürgen Petrich 2013-05-25 11:22:25 +07:00
parent 995c09cb67
commit 5429504aee
7 changed files with 55 additions and 13 deletions

View File

@ -156,10 +156,15 @@ class Crypt_AES extends Crypt_Rijndael {
* Determines whether or not the mcrypt extension should be used. * Determines whether or not the mcrypt extension should be used.
* *
* $mode could be: * $mode could be:
*
* - CRYPT_AES_MODE_ECB * - CRYPT_AES_MODE_ECB
*
* - CRYPT_AES_MODE_CBC * - CRYPT_AES_MODE_CBC
*
* - CRYPT_AES_MODE_CTR * - CRYPT_AES_MODE_CTR
*
* - CRYPT_AES_MODE_CFB * - CRYPT_AES_MODE_CFB
*
* - CRYPT_AES_MODE_OFB * - CRYPT_AES_MODE_OFB
* *
* If not explictly set, CRYPT_AES_MODE_CBC will be used. * If not explictly set, CRYPT_AES_MODE_CBC will be used.

View File

@ -407,11 +407,17 @@ class Crypt_Base {
* Determines whether or not the mcrypt extension should be used. * Determines whether or not the mcrypt extension should be used.
* *
* $mode could be: * $mode could be:
*
* - CRYPT_MODE_ECB * - CRYPT_MODE_ECB
*
* - CRYPT_MODE_CBC * - CRYPT_MODE_CBC
*
* - CRYPT_MODE_CTR * - CRYPT_MODE_CTR
*
* - CRYPT_MODE_CFB * - CRYPT_MODE_CFB
*
* - CRYPT_MODE_OFB * - CRYPT_MODE_OFB
*
* (or the alias constants of the choosen cipher, for example for AES: CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC ...) * (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. * If not explictly set, CRYPT_MODE_CBC will be used.
@ -608,7 +614,7 @@ class Crypt_Base {
$this->enchanged = false; $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 // 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. // rewritten CFB implementation the above outputs the same thing twice.
if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) { if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) {
@ -737,7 +743,7 @@ class Crypt_Base {
break; break;
case CRYPT_MODE_CFB: case CRYPT_MODE_CFB:
// cfb loosely routines inspired by openssl's: // 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) { if ($this->continuousBuffer) {
$iv = &$this->encryptIV; $iv = &$this->encryptIV;
$pos = &$buffer['pos']; $pos = &$buffer['pos'];
@ -876,7 +882,7 @@ class Crypt_Base {
} }
if ($this->paddable) { 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." // "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)); $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 * _mcryptSetup() will be called each time if $changed === true
* typically this happens when using one or more of following public methods: * typically this happens when using one or more of following public methods:
*
* - setKey() * - setKey()
*
* - setIV() * - setIV()
*
* - disableContinuousBuffer() * - disableContinuousBuffer()
*
* - First run of encrypt() / decrypt() * - First run of encrypt() / decrypt()
* *
*
* Note: Could, but not must, extend by the child Crypt_* class * Note: Could, but not must, extend by the child Crypt_* class
* *
* @see setKey() * @see setKey()

View File

@ -375,10 +375,15 @@ class Crypt_Blowfish extends Crypt_Base {
* Determines whether or not the mcrypt extension should be used. * Determines whether or not the mcrypt extension should be used.
* *
* $mode could be: * $mode could be:
*
* - CRYPT_BLOWFISH_MODE_ECB * - CRYPT_BLOWFISH_MODE_ECB
*
* - CRYPT_BLOWFISH_MODE_CBC * - CRYPT_BLOWFISH_MODE_CBC
*
* - CRYPT_BLOWFISH_MODE_CTR * - CRYPT_BLOWFISH_MODE_CTR
*
* - CRYPT_BLOWFISH_MODE_CFB * - CRYPT_BLOWFISH_MODE_CFB
*
* - CRYPT_BLOWFISH_MODE_OFB * - CRYPT_BLOWFISH_MODE_OFB
* *
* If not explictly set, CRYPT_BLOWFISH_MODE_CBC will be used. * If not explictly set, CRYPT_BLOWFISH_MODE_CBC will be used.
@ -593,7 +598,7 @@ class Crypt_Blowfish extends Crypt_Base {
$init_crypt = ' $init_crypt = '
list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"]; list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"];
list(' . implode(',', $p) . ') = $self->bctx["p"]; list(' . implode(',', $p) . ') = $self->bctx["p"];
'; ';
} }

View File

@ -669,10 +669,15 @@ class Crypt_DES extends Crypt_Base {
* Determines whether or not the mcrypt extension should be used. * Determines whether or not the mcrypt extension should be used.
* *
* $mode could be: * $mode could be:
*
* - CRYPT_DES_MODE_ECB * - CRYPT_DES_MODE_ECB
*
* - CRYPT_DES_MODE_CBC * - CRYPT_DES_MODE_CBC
*
* - CRYPT_DES_MODE_CTR * - CRYPT_DES_MODE_CTR
*
* - CRYPT_DES_MODE_CFB * - CRYPT_DES_MODE_CFB
*
* - CRYPT_DES_MODE_OFB * - CRYPT_DES_MODE_OFB
* *
* If not explictly set, CRYPT_DES_MODE_CBC will be used. * 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); $sbox6 = array_map("intval", $this->sbox6);
$sbox7 = array_map("intval", $this->sbox7); $sbox7 = array_map("intval", $this->sbox7);
$sbox8 = array_map("intval", $this->sbox8); $sbox8 = array_map("intval", $this->sbox8);
/* Merge $shuffle with $[inv]ipmap */ /* Merge $shuffle with $[inv]ipmap */
for ($i = 0; $i < 256; ++$i) { for ($i = 0; $i < 256; ++$i) {
$shuffleip[] = $this->shuffle[$this->ipmap[$i]]; $shuffleip[] = $this->shuffle[$this->ipmap[$i]];
$shuffleinvip[] = $this->shuffle[$this->invipmap[$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 // Generation of a uniqe hash for our generated code
switch (true) { switch (true) {
case $gen_hi_opt_code: 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. // $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); $code_hash = md5(str_pad("Crypt_DES, $des_rounds, {$this->mode}, ", 32, "\0") . $this->key);
break; break;
default: 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 // (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}"; $code_hash = "Crypt_DES, $des_rounds, {$this->mode}";
} }
@ -1422,7 +1427,7 @@ class Crypt_DES extends Crypt_Base {
switch (true) { switch (true) {
case $gen_hi_opt_code: case $gen_hi_opt_code:
// In Hi-optimized code mode, we use our [3]DES key schedule as hardcoded integers. // 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. // That is the extra performance boost.
$k = array( $k = array(
CRYPT_DES_ENCRYPT => $this->keys[CRYPT_DES_ENCRYPT], CRYPT_DES_ENCRYPT => $this->keys[CRYPT_DES_ENCRYPT],
@ -1470,7 +1475,7 @@ class Crypt_DES extends Crypt_Base {
$l = $in[1]; $l = $in[1];
$r = $in[2]; $r = $in[2];
'; ';
$l = '$l'; $l = '$l';
$r = '$r'; $r = '$r';
@ -1481,10 +1486,10 @@ class Crypt_DES extends Crypt_Base {
// start of "the Feistel (F) function" - see the following URL: // start of "the Feistel (F) function" - see the following URL:
// http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png
// Merge key schedule. // Merge key schedule.
$crypt_block[$c].= ' $crypt_block[$c].= '
$b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . '; $b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . ';
$b2 = ((' . $r . ' >> 31) & 0x00000001) ^ (' . $r . ' << 1) ^ ' . $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] ^ $l . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^
$sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^ $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^
$sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^ $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^

View File

@ -666,10 +666,15 @@ class Crypt_Rijndael extends Crypt_Base {
* Determines whether or not the mcrypt extension should be used. * Determines whether or not the mcrypt extension should be used.
* *
* $mode could be: * $mode could be:
*
* - CRYPT_RIJNDAEL_MODE_ECB * - CRYPT_RIJNDAEL_MODE_ECB
*
* - CRYPT_RIJNDAEL_MODE_CBC * - CRYPT_RIJNDAEL_MODE_CBC
*
* - CRYPT_RIJNDAEL_MODE_CTR * - CRYPT_RIJNDAEL_MODE_CTR
*
* - CRYPT_RIJNDAEL_MODE_CFB * - CRYPT_RIJNDAEL_MODE_CFB
*
* - CRYPT_RIJNDAEL_MODE_OFB * - CRYPT_RIJNDAEL_MODE_OFB
* *
* If not explictly set, CRYPT_RIJNDAEL_MODE_CBC will be used. * If not explictly set, CRYPT_RIJNDAEL_MODE_CBC will be used.

View File

@ -81,7 +81,7 @@ define('CRYPT_DES_MODE_CBC3', CRYPT_DES_MODE_CBC);
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @version 0.1.0 * @version 0.1.0
* @access public * @access public
* @package Crypt_TerraDES * @package Crypt_TripleDES
*/ */
class Crypt_TripleDES extends Crypt_DES { 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. * Determines whether or not the mcrypt extension should be used.
* *
* $mode could be: * $mode could be:
*
* - CRYPT_DES_MODE_ECB * - CRYPT_DES_MODE_ECB
*
* - CRYPT_DES_MODE_CBC * - CRYPT_DES_MODE_CBC
*
* - CRYPT_DES_MODE_CTR * - CRYPT_DES_MODE_CTR
*
* - CRYPT_DES_MODE_CFB * - CRYPT_DES_MODE_CFB
*
* - CRYPT_DES_MODE_OFB * - CRYPT_DES_MODE_OFB
*
* - CRYPT_DES_MODE_3CBC * - CRYPT_DES_MODE_3CBC
* *
* If not explictly set, CRYPT_DES_MODE_CBC will be used. * If not explictly set, CRYPT_DES_MODE_CBC will be used.

View File

@ -454,10 +454,15 @@ class Crypt_Twofish extends Crypt_Base {
* Determines whether or not the mcrypt extension should be used. * Determines whether or not the mcrypt extension should be used.
* *
* $mode could be: * $mode could be:
*
* - CRYPT_TWOFISH_MODE_ECB * - CRYPT_TWOFISH_MODE_ECB
*
* - CRYPT_TWOFISH_MODE_CBC * - CRYPT_TWOFISH_MODE_CBC
*
* - CRYPT_TWOFISH_MODE_CTR * - CRYPT_TWOFISH_MODE_CTR
*
* - CRYPT_TWOFISH_MODE_CFB * - CRYPT_TWOFISH_MODE_CFB
*
* - CRYPT_TWOFISH_MODE_OFB * - CRYPT_TWOFISH_MODE_OFB
* *
* If not explictly set, CRYPT_TWOFISH_MODE_CBC will be used. * If not explictly set, CRYPT_TWOFISH_MODE_CBC will be used.