@@ -693,9 +693,9 @@ |
||
693 | 693 | // Creates the inline-crypt function |
694 | 694 | $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( |
695 | 695 | array( |
696 | - 'init_crypt' => $init_crypt, |
|
697 | - 'encrypt_block' => $encrypt_block, |
|
698 | - 'decrypt_block' => $decrypt_block |
|
696 | + 'init_crypt' => $init_crypt, |
|
697 | + 'encrypt_block' => $encrypt_block, |
|
698 | + 'decrypt_block' => $decrypt_block |
|
699 | 699 | ) |
700 | 700 | ); |
701 | 701 | } |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | return false; |
296 | 296 | } |
297 | 297 | $this->cipher_name_openssl_ecb = 'rc2-ecb'; |
298 | - $this->cipher_name_openssl = 'rc2-' . $this->_openssl_translate_mode(); |
|
298 | + $this->cipher_name_openssl = 'rc2-'.$this->_openssl_translate_mode(); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | return parent::isValidEngine($engine); |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | function setKeyLength($length) |
316 | 316 | { |
317 | 317 | if ($length < 8 || $length > 1024) { |
318 | - throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported'); |
|
318 | + throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported'); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | $this->default_key_length = $this->current_key_length = $length; |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | } |
359 | 359 | |
360 | 360 | if ($t1 < 1 || $t1 > 1024) { |
361 | - throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported'); |
|
361 | + throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys between 1 and 1024 bits, inclusive, are supported'); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | $this->current_key_length = $t1; |
@@ -575,18 +575,18 @@ discard block |
||
575 | 575 | */ |
576 | 576 | function _setupInlineCrypt() |
577 | 577 | { |
578 | - $lambda_functions =& self::_getLambdaFunctions(); |
|
578 | + $lambda_functions = & self::_getLambdaFunctions(); |
|
579 | 579 | |
580 | 580 | // The first 10 generated $lambda_functions will use the $keys hardcoded as integers |
581 | 581 | // for the mixing rounds, for better inline crypt performance [~20% faster]. |
582 | 582 | // But for memory reason we have to limit those ultra-optimized $lambda_functions to an amount of 10. |
583 | 583 | // (Currently, for Crypt_RC2, one generated $lambda_function cost on php5.5@32bit ~60kb unfreeable mem and ~100kb on php5.5@64bit) |
584 | - $gen_hi_opt_code = (bool)(count($lambda_functions) < 10); |
|
584 | + $gen_hi_opt_code = (bool) (count($lambda_functions) < 10); |
|
585 | 585 | |
586 | 586 | // Generation of a unique hash for our generated code |
587 | 587 | $code_hash = "Crypt_RC2, {$this->mode}"; |
588 | 588 | if ($gen_hi_opt_code) { |
589 | - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); |
|
589 | + $code_hash = str_pad($code_hash, 32).$this->_hashInlineCryptFunction($this->key); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | // Is there a re-usable $lambda_functions in there? |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | default: |
602 | 602 | $keys = array(); |
603 | 603 | foreach ($this->keys as $k => $v) { |
604 | - $keys[$k] = '$keys[' . $k . ']'; |
|
604 | + $keys[$k] = '$keys['.$k.']'; |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | |
@@ -622,16 +622,16 @@ discard block |
||
622 | 622 | for (;;) { |
623 | 623 | // Mixing round. |
624 | 624 | $encrypt_block .= ' |
625 | - $r0 = (($r0 + ' . $keys[$j++] . ' + |
|
625 | + $r0 = (($r0 + ' . $keys[$j++].' + |
|
626 | 626 | ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF) << 1; |
627 | 627 | $r0 |= $r0 >> 16; |
628 | - $r1 = (($r1 + ' . $keys[$j++] . ' + |
|
628 | + $r1 = (($r1 + ' . $keys[$j++].' + |
|
629 | 629 | ((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF) << 2; |
630 | 630 | $r1 |= $r1 >> 16; |
631 | - $r2 = (($r2 + ' . $keys[$j++] . ' + |
|
631 | + $r2 = (($r2 + ' . $keys[$j++].' + |
|
632 | 632 | ((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF) << 3; |
633 | 633 | $r2 |= $r2 >> 16; |
634 | - $r3 = (($r3 + ' . $keys[$j++] . ' + |
|
634 | + $r3 = (($r3 + ' . $keys[$j++].' + |
|
635 | 635 | ((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF) << 5; |
636 | 636 | $r3 |= $r3 >> 16;'; |
637 | 637 | |
@@ -661,16 +661,16 @@ discard block |
||
661 | 661 | // R-mixing round. |
662 | 662 | $decrypt_block .= ' |
663 | 663 | $r3 = ($r3 | ($r3 << 16)) >> 5; |
664 | - $r3 = ($r3 - ' . $keys[--$j] . ' - |
|
664 | + $r3 = ($r3 - ' . $keys[--$j].' - |
|
665 | 665 | ((($r0 ^ $r1) & $r2) ^ $r0)) & 0xFFFF; |
666 | 666 | $r2 = ($r2 | ($r2 << 16)) >> 3; |
667 | - $r2 = ($r2 - ' . $keys[--$j] . ' - |
|
667 | + $r2 = ($r2 - ' . $keys[--$j].' - |
|
668 | 668 | ((($r3 ^ $r0) & $r1) ^ $r3)) & 0xFFFF; |
669 | 669 | $r1 = ($r1 | ($r1 << 16)) >> 2; |
670 | - $r1 = ($r1 - ' . $keys[--$j] . ' - |
|
670 | + $r1 = ($r1 - ' . $keys[--$j].' - |
|
671 | 671 | ((($r2 ^ $r3) & $r0) ^ $r2)) & 0xFFFF; |
672 | 672 | $r0 = ($r0 | ($r0 << 16)) >> 1; |
673 | - $r0 = ($r0 - ' . $keys[--$j] . ' - |
|
673 | + $r0 = ($r0 - ' . $keys[--$j].' - |
|
674 | 674 | ((($r1 ^ $r2) & $r3) ^ $r1)) & 0xFFFF;'; |
675 | 675 | |
676 | 676 | if ($j === $limit) { |
@@ -96,12 +96,12 @@ |
||
96 | 96 | session_start(); |
97 | 97 | |
98 | 98 | $v = (isset($_SERVER) ? self::safe_serialize($_SERVER) : '') . |
99 | - (isset($_POST) ? self::safe_serialize($_POST) : '') . |
|
100 | - (isset($_GET) ? self::safe_serialize($_GET) : '') . |
|
101 | - (isset($_COOKIE) ? self::safe_serialize($_COOKIE) : '') . |
|
102 | - self::safe_serialize($GLOBALS) . |
|
103 | - self::safe_serialize($_SESSION) . |
|
104 | - self::safe_serialize($_OLD_SESSION); |
|
99 | + (isset($_POST) ? self::safe_serialize($_POST) : '') . |
|
100 | + (isset($_GET) ? self::safe_serialize($_GET) : '') . |
|
101 | + (isset($_COOKIE) ? self::safe_serialize($_COOKIE) : '') . |
|
102 | + self::safe_serialize($GLOBALS) . |
|
103 | + self::safe_serialize($_SESSION) . |
|
104 | + self::safe_serialize($_OLD_SESSION); |
|
105 | 105 | $v = $seed = $_SESSION['seed'] = sha1($v, true); |
106 | 106 | if (!isset($_SESSION['count'])) { |
107 | 107 | $_SESSION['count'] = 0; |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | session_cache_limiter(''); |
96 | 96 | session_start(); |
97 | 97 | |
98 | - $v = (isset($_SERVER) ? self::safe_serialize($_SERVER) : '') . |
|
99 | - (isset($_POST) ? self::safe_serialize($_POST) : '') . |
|
100 | - (isset($_GET) ? self::safe_serialize($_GET) : '') . |
|
101 | - (isset($_COOKIE) ? self::safe_serialize($_COOKIE) : '') . |
|
102 | - self::safe_serialize($GLOBALS) . |
|
103 | - self::safe_serialize($_SESSION) . |
|
98 | + $v = (isset($_SERVER) ? self::safe_serialize($_SERVER) : ''). |
|
99 | + (isset($_POST) ? self::safe_serialize($_POST) : ''). |
|
100 | + (isset($_GET) ? self::safe_serialize($_GET) : ''). |
|
101 | + (isset($_COOKIE) ? self::safe_serialize($_COOKIE) : ''). |
|
102 | + self::safe_serialize($GLOBALS). |
|
103 | + self::safe_serialize($_SESSION). |
|
104 | 104 | self::safe_serialize($_OLD_SESSION); |
105 | 105 | $v = $seed = $_SESSION['seed'] = sha1($v, true); |
106 | 106 | if (!isset($_SESSION['count'])) { |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | // http://tools.ietf.org/html/rfc4253#section-7.2 |
134 | 134 | // |
135 | 135 | // see the is_string($crypto) part for an example of how to expand the keys |
136 | - $key = sha1($seed . 'A', true); |
|
137 | - $iv = sha1($seed . 'C', true); |
|
136 | + $key = sha1($seed.'A', true); |
|
137 | + $iv = sha1($seed.'C', true); |
|
138 | 138 | |
139 | 139 | // ciphers are used as per the nist.gov link below. also, see this link: |
140 | 140 | // |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $crypto = new RC4(); |
160 | 160 | break; |
161 | 161 | default: |
162 | - throw new \RuntimeException(__CLASS__ . ' requires at least one symmetric cipher be loaded'); |
|
162 | + throw new \RuntimeException(__CLASS__.' requires at least one symmetric cipher be loaded'); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | $crypto->setKey(substr($key, 0, $crypto->getKeyLength() >> 3)); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $i = $crypto->encrypt(microtime()); // strlen(microtime()) == 21 |
183 | 183 | $r = $crypto->encrypt($i ^ $v); // strlen($v) == 20 |
184 | 184 | $v = $crypto->encrypt($r ^ $i); // strlen($r) == 20 |
185 | - $result.= $r; |
|
185 | + $result .= $r; |
|
186 | 186 | } |
187 | 187 | return substr($result, 0, $length); |
188 | 188 | } |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | // subWord |
373 | 373 | for ($i = 0; $i < $Nb; ++$i) { |
374 | 374 | $state[$i] = $sbox[$state[$i] & 0x000000FF] | |
375 | - ($sbox[$state[$i] >> 8 & 0x000000FF] << 8) | |
|
376 | - ($sbox[$state[$i] >> 16 & 0x000000FF] << 16) | |
|
377 | - ($sbox[$state[$i] >> 24 & 0x000000FF] << 24); |
|
375 | + ($sbox[$state[$i] >> 8 & 0x000000FF] << 8) | |
|
376 | + ($sbox[$state[$i] >> 16 & 0x000000FF] << 16) | |
|
377 | + ($sbox[$state[$i] >> 24 & 0x000000FF] << 24); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | // shiftRows + addRoundKey |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | ($state[$j] & 0x00FF0000) ^ |
388 | 388 | ($state[$k] & 0x0000FF00) ^ |
389 | 389 | ($state[$l] & 0x000000FF) ^ |
390 | - $w[$i]; |
|
390 | + $w[$i]; |
|
391 | 391 | ++$i; |
392 | 392 | $j = ($j + 1) % $Nb; |
393 | 393 | $k = ($k + 1) % $Nb; |
@@ -475,9 +475,9 @@ discard block |
||
475 | 475 | ($state[$l] & 0x000000FF); |
476 | 476 | |
477 | 477 | $temp[$i] = $dw[$i] ^ ($isbox[$word & 0x000000FF] | |
478 | - ($isbox[$word >> 8 & 0x000000FF] << 8) | |
|
479 | - ($isbox[$word >> 16 & 0x000000FF] << 16) | |
|
480 | - ($isbox[$word >> 24 & 0x000000FF] << 24)); |
|
478 | + ($isbox[$word >> 8 & 0x000000FF] << 8) | |
|
479 | + ($isbox[$word >> 16 & 0x000000FF] << 16) | |
|
480 | + ($isbox[$word >> 24 & 0x000000FF] << 24)); |
|
481 | 481 | ++$i; |
482 | 482 | $j = ($j + 1) % $Nb; |
483 | 483 | $k = ($k + 1) % $Nb; |
@@ -625,9 +625,9 @@ discard block |
||
625 | 625 | } |
626 | 626 | |
627 | 627 | return $sbox[$word & 0x000000FF] | |
628 | - ($sbox[$word >> 8 & 0x000000FF] << 8) | |
|
629 | - ($sbox[$word >> 16 & 0x000000FF] << 16) | |
|
630 | - ($sbox[$word >> 24 & 0x000000FF] << 24); |
|
628 | + ($sbox[$word >> 8 & 0x000000FF] << 8) | |
|
629 | + ($sbox[$word >> 16 & 0x000000FF] << 16) | |
|
630 | + ($sbox[$word >> 24 & 0x000000FF] << 24); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
@@ -966,11 +966,11 @@ discard block |
||
966 | 966 | |
967 | 967 | $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( |
968 | 968 | array( |
969 | - 'init_crypt' => '', |
|
970 | - 'init_encrypt' => $init_encrypt, |
|
971 | - 'init_decrypt' => $init_decrypt, |
|
972 | - 'encrypt_block' => $encrypt_block, |
|
973 | - 'decrypt_block' => $decrypt_block |
|
969 | + 'init_crypt' => '', |
|
970 | + 'init_encrypt' => $init_encrypt, |
|
971 | + 'init_decrypt' => $init_decrypt, |
|
972 | + 'encrypt_block' => $encrypt_block, |
|
973 | + 'decrypt_block' => $decrypt_block |
|
974 | 974 | ) |
975 | 975 | ); |
976 | 976 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $this->key_length = $length >> 3; |
218 | 218 | break; |
219 | 219 | default: |
220 | - throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys of sizes 128, 160, 192, 224 or 256 bits are supported'); |
|
220 | + throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys of sizes 128, 160, 192, 224 or 256 bits are supported'); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | parent::setKeyLength($length); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | case 32: |
244 | 244 | break; |
245 | 245 | default: |
246 | - throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 20, 24, 28 or 32 are supported'); |
|
246 | + throw new \LengthException('Key of size '.strlen($key).' not supported by this algorithm. Only keys of sizes 16, 20, 24, 28 or 32 are supported'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | parent::setKey($key); |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | case 256: |
268 | 268 | break; |
269 | 269 | default: |
270 | - throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys of sizes 128, 160, 192, 224 or 256 bits are supported'); |
|
270 | + throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys of sizes 128, 160, 192, 224 or 256 bits are supported'); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | $this->Nb = $length >> 5; |
@@ -293,11 +293,11 @@ discard block |
||
293 | 293 | if ($this->block_size != 16) { |
294 | 294 | return false; |
295 | 295 | } |
296 | - $this->cipher_name_openssl_ecb = 'aes-' . ($this->key_length << 3) . '-ecb'; |
|
297 | - $this->cipher_name_openssl = 'aes-' . ($this->key_length << 3) . '-' . $this->_openssl_translate_mode(); |
|
296 | + $this->cipher_name_openssl_ecb = 'aes-'.($this->key_length << 3).'-ecb'; |
|
297 | + $this->cipher_name_openssl = 'aes-'.($this->key_length << 3).'-'.$this->_openssl_translate_mode(); |
|
298 | 298 | break; |
299 | 299 | case self::ENGINE_MCRYPT: |
300 | - $this->cipher_name_mcrypt = 'rijndael-' . ($this->block_size << 3); |
|
300 | + $this->cipher_name_mcrypt = 'rijndael-'.($this->block_size << 3); |
|
301 | 301 | if ($this->key_length % 8) { // is it a 160/224-bit key? |
302 | 302 | // mcrypt is not usable for them, only for 128/192/256-bit keys |
303 | 303 | return false; |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | while ($i < $Nb) { |
359 | 359 | $temp[$i] = $t0[$state[$i] >> 24 & 0x000000FF] ^ |
360 | 360 | $t1[$state[$j] >> 16 & 0x000000FF] ^ |
361 | - $t2[$state[$k] >> 8 & 0x000000FF] ^ |
|
362 | - $t3[$state[$l] & 0x000000FF] ^ |
|
361 | + $t2[$state[$k] >> 8 & 0x000000FF] ^ |
|
362 | + $t3[$state[$l] & 0x000000FF] ^ |
|
363 | 363 | $w[++$wc]; |
364 | 364 | ++$i; |
365 | 365 | $j = ($j + 1) % $Nb; |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | |
372 | 372 | // subWord |
373 | 373 | for ($i = 0; $i < $Nb; ++$i) { |
374 | - $state[$i] = $sbox[$state[$i] & 0x000000FF] | |
|
375 | - ($sbox[$state[$i] >> 8 & 0x000000FF] << 8) | |
|
374 | + $state[$i] = $sbox[$state[$i] & 0x000000FF] | |
|
375 | + ($sbox[$state[$i] >> 8 & 0x000000FF] << 8) | |
|
376 | 376 | ($sbox[$state[$i] >> 16 & 0x000000FF] << 16) | |
377 | 377 | ($sbox[$state[$i] >> 24 & 0x000000FF] << 24); |
378 | 378 | } |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | while ($i < $Nb) { |
452 | 452 | $temp[$i] = $dt0[$state[$i] >> 24 & 0x000000FF] ^ |
453 | 453 | $dt1[$state[$j] >> 16 & 0x000000FF] ^ |
454 | - $dt2[$state[$k] >> 8 & 0x000000FF] ^ |
|
455 | - $dt3[$state[$l] & 0x000000FF] ^ |
|
454 | + $dt2[$state[$k] >> 8 & 0x000000FF] ^ |
|
455 | + $dt3[$state[$l] & 0x000000FF] ^ |
|
456 | 456 | $dw[++$wc]; |
457 | 457 | ++$i; |
458 | 458 | $j = ($j + 1) % $Nb; |
@@ -474,8 +474,8 @@ discard block |
||
474 | 474 | ($state[$k] & 0x0000FF00) | |
475 | 475 | ($state[$l] & 0x000000FF); |
476 | 476 | |
477 | - $temp[$i] = $dw[$i] ^ ($isbox[$word & 0x000000FF] | |
|
478 | - ($isbox[$word >> 8 & 0x000000FF] << 8) | |
|
477 | + $temp[$i] = $dw[$i] ^ ($isbox[$word & 0x000000FF] | |
|
478 | + ($isbox[$word >> 8 & 0x000000FF] << 8) | |
|
479 | 479 | ($isbox[$word >> 16 & 0x000000FF] << 16) | |
480 | 480 | ($isbox[$word >> 24 & 0x000000FF] << 24)); |
481 | 481 | ++$i; |
@@ -582,8 +582,8 @@ discard block |
||
582 | 582 | $dw = $this->_subWord($this->w[$row][$j]); |
583 | 583 | $temp[$j] = $dt0[$dw >> 24 & 0x000000FF] ^ |
584 | 584 | $dt1[$dw >> 16 & 0x000000FF] ^ |
585 | - $dt2[$dw >> 8 & 0x000000FF] ^ |
|
586 | - $dt3[$dw & 0x000000FF]; |
|
585 | + $dt2[$dw >> 8 & 0x000000FF] ^ |
|
586 | + $dt3[$dw & 0x000000FF]; |
|
587 | 587 | $j++; |
588 | 588 | } |
589 | 589 | $this->dw[$row] = $temp; |
@@ -621,11 +621,11 @@ discard block |
||
621 | 621 | { |
622 | 622 | static $sbox; |
623 | 623 | if (empty($sbox)) { |
624 | - list(, , , , $sbox) = $this->_getTables(); |
|
624 | + list(,,,, $sbox) = $this->_getTables(); |
|
625 | 625 | } |
626 | 626 | |
627 | - return $sbox[$word & 0x000000FF] | |
|
628 | - ($sbox[$word >> 8 & 0x000000FF] << 8) | |
|
627 | + return $sbox[$word & 0x000000FF] | |
|
628 | + ($sbox[$word >> 8 & 0x000000FF] << 8) | |
|
629 | 629 | ($sbox[$word >> 16 & 0x000000FF] << 16) | |
630 | 630 | ($sbox[$word >> 24 & 0x000000FF] << 24); |
631 | 631 | } |
@@ -684,9 +684,9 @@ discard block |
||
684 | 684 | )); |
685 | 685 | |
686 | 686 | foreach ($t3 as $t3i) { |
687 | - $t0[] = (($t3i << 24) & 0xFF000000) | (($t3i >> 8) & 0x00FFFFFF); |
|
687 | + $t0[] = (($t3i << 24) & 0xFF000000) | (($t3i >> 8) & 0x00FFFFFF); |
|
688 | 688 | $t1[] = (($t3i << 16) & 0xFFFF0000) | (($t3i >> 16) & 0x0000FFFF); |
689 | - $t2[] = (($t3i << 8) & 0xFFFFFF00) | (($t3i >> 24) & 0x000000FF); |
|
689 | + $t2[] = (($t3i << 8) & 0xFFFFFF00) | (($t3i >> 24) & 0x000000FF); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | $tables = array( |
@@ -768,9 +768,9 @@ discard block |
||
768 | 768 | )); |
769 | 769 | |
770 | 770 | foreach ($dt3 as $dt3i) { |
771 | - $dt0[] = (($dt3i << 24) & 0xFF000000) | (($dt3i >> 8) & 0x00FFFFFF); |
|
771 | + $dt0[] = (($dt3i << 24) & 0xFF000000) | (($dt3i >> 8) & 0x00FFFFFF); |
|
772 | 772 | $dt1[] = (($dt3i << 16) & 0xFFFF0000) | (($dt3i >> 16) & 0x0000FFFF); |
773 | - $dt2[] = (($dt3i << 8) & 0xFFFFFF00) | (($dt3i >> 24) & 0x000000FF); |
|
773 | + $dt2[] = (($dt3i << 8) & 0xFFFFFF00) | (($dt3i >> 24) & 0x000000FF); |
|
774 | 774 | }; |
775 | 775 | |
776 | 776 | $tables = array( |
@@ -815,17 +815,17 @@ discard block |
||
815 | 815 | // So here we are'nt under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt(). |
816 | 816 | // However...the here generated function- $code, stored as php callback in $this->inline_crypt, must work as fast as even possible. |
817 | 817 | |
818 | - $lambda_functions =& self::_getLambdaFunctions(); |
|
818 | + $lambda_functions = & self::_getLambdaFunctions(); |
|
819 | 819 | |
820 | 820 | // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. |
821 | 821 | // (Currently, for Crypt_Rijndael/AES, one generated $lambda_function cost on php5.5@32bit ~80kb unfreeable mem and ~130kb on php5.5@64bit) |
822 | 822 | // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one. |
823 | - $gen_hi_opt_code = (bool)(count($lambda_functions) < 10); |
|
823 | + $gen_hi_opt_code = (bool) (count($lambda_functions) < 10); |
|
824 | 824 | |
825 | 825 | // Generation of a uniqe hash for our generated code |
826 | 826 | $code_hash = "Crypt_Rijndael, {$this->mode}, {$this->Nr}, {$this->Nb}"; |
827 | 827 | if ($gen_hi_opt_code) { |
828 | - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); |
|
828 | + $code_hash = str_pad($code_hash, 32).$this->_hashInlineCryptFunction($this->key); |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | if (!isset($lambda_functions[$code_hash])) { |
@@ -839,8 +839,8 @@ discard block |
||
839 | 839 | break; |
840 | 840 | default: |
841 | 841 | for ($i = 0, $cw = count($this->w); $i < $cw; ++$i) { |
842 | - $w[] = '$w[' . $i . ']'; |
|
843 | - $dw[] = '$dw[' . $i . ']'; |
|
842 | + $w[] = '$w['.$i.']'; |
|
843 | + $dw[] = '$dw['.$i.']'; |
|
844 | 844 | } |
845 | 845 | $init_encrypt = '$w = $self->w;'; |
846 | 846 | $init_decrypt = '$dw = $self->dw;'; |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | $c = $this->c; |
852 | 852 | |
853 | 853 | // Generating encrypt code: |
854 | - $init_encrypt.= ' |
|
854 | + $init_encrypt .= ' |
|
855 | 855 | static $tables; |
856 | 856 | if (empty($tables)) { |
857 | 857 | $tables = &$self->_getTables(); |
@@ -877,9 +877,9 @@ discard block |
||
877 | 877 | for ($round = 1; $round < $Nr; ++$round) { |
878 | 878 | list($s, $e) = array($e, $s); |
879 | 879 | for ($i = 0; $i < $Nb; ++$i) { |
880 | - $encrypt_block.= |
|
880 | + $encrypt_block .= |
|
881 | 881 | '$'.$e.$i.' = |
882 | - $t0[($'.$s.$i .' >> 24) & 0xff] ^ |
|
882 | + $t0[($'.$s.$i.' >> 24) & 0xff] ^ |
|
883 | 883 | $t1[($'.$s.(($i + $c[1]) % $Nb).' >> 16) & 0xff] ^ |
884 | 884 | $t2[($'.$s.(($i + $c[2]) % $Nb).' >> 8) & 0xff] ^ |
885 | 885 | $t3[ $'.$s.(($i + $c[3]) % $Nb).' & 0xff] ^ |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | |
890 | 890 | // Finalround: subWord + shiftRows + addRoundKey |
891 | 891 | for ($i = 0; $i < $Nb; ++$i) { |
892 | - $encrypt_block.= |
|
892 | + $encrypt_block .= |
|
893 | 893 | '$'.$e.$i.' = |
894 | 894 | $sbox[ $'.$e.$i.' & 0xff] | |
895 | 895 | ($sbox[($'.$e.$i.' >> 8) & 0xff] << 8) | |
@@ -898,8 +898,8 @@ discard block |
||
898 | 898 | } |
899 | 899 | $encrypt_block .= '$in = pack("N*"'."\n"; |
900 | 900 | for ($i = 0; $i < $Nb; ++$i) { |
901 | - $encrypt_block.= ', |
|
902 | - ($'.$e.$i .' & '.((int)0xFF000000).') ^ |
|
901 | + $encrypt_block .= ', |
|
902 | + ($'.$e.$i.' & '.((int) 0xFF000000).') ^ |
|
903 | 903 | ($'.$e.(($i + $c[1]) % $Nb).' & 0x00FF0000 ) ^ |
904 | 904 | ($'.$e.(($i + $c[2]) % $Nb).' & 0x0000FF00 ) ^ |
905 | 905 | ($'.$e.(($i + $c[3]) % $Nb).' & 0x000000FF ) ^ |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | $encrypt_block .= ');'; |
909 | 909 | |
910 | 910 | // Generating decrypt code: |
911 | - $init_decrypt.= ' |
|
911 | + $init_decrypt .= ' |
|
912 | 912 | static $invtables; |
913 | 913 | if (empty($invtables)) { |
914 | 914 | $invtables = &$self->_getInvTables(); |
@@ -934,9 +934,9 @@ discard block |
||
934 | 934 | for ($round = 1; $round < $Nr; ++$round) { |
935 | 935 | list($s, $e) = array($e, $s); |
936 | 936 | for ($i = 0; $i < $Nb; ++$i) { |
937 | - $decrypt_block.= |
|
937 | + $decrypt_block .= |
|
938 | 938 | '$'.$e.$i.' = |
939 | - $dt0[($'.$s.$i .' >> 24) & 0xff] ^ |
|
939 | + $dt0[($'.$s.$i.' >> 24) & 0xff] ^ |
|
940 | 940 | $dt1[($'.$s.(($Nb + $i - $c[1]) % $Nb).' >> 16) & 0xff] ^ |
941 | 941 | $dt2[($'.$s.(($Nb + $i - $c[2]) % $Nb).' >> 8) & 0xff] ^ |
942 | 942 | $dt3[ $'.$s.(($Nb + $i - $c[3]) % $Nb).' & 0xff] ^ |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | |
947 | 947 | // Finalround: subWord + shiftRows + addRoundKey |
948 | 948 | for ($i = 0; $i < $Nb; ++$i) { |
949 | - $decrypt_block.= |
|
949 | + $decrypt_block .= |
|
950 | 950 | '$'.$e.$i.' = |
951 | 951 | $isbox[ $'.$e.$i.' & 0xff] | |
952 | 952 | ($isbox[($'.$e.$i.' >> 8) & 0xff] << 8) | |
@@ -955,8 +955,8 @@ discard block |
||
955 | 955 | } |
956 | 956 | $decrypt_block .= '$in = pack("N*"'."\n"; |
957 | 957 | for ($i = 0; $i < $Nb; ++$i) { |
958 | - $decrypt_block.= ', |
|
959 | - ($'.$e.$i. ' & '.((int)0xFF000000).') ^ |
|
958 | + $decrypt_block .= ', |
|
959 | + ($'.$e.$i.' & '.((int) 0xFF000000).') ^ |
|
960 | 960 | ($'.$e.(($Nb + $i - $c[1]) % $Nb).' & 0x00FF0000 ) ^ |
961 | 961 | ($'.$e.(($Nb + $i - $c[2]) % $Nb).' & 0x0000FF00 ) ^ |
962 | 962 | ($'.$e.(($Nb + $i - $c[3]) % $Nb).' & 0x000000FF ) ^ |
@@ -37,7 +37,7 @@ |
||
37 | 37 | { |
38 | 38 | $length = ord(Strings::shift($string)); |
39 | 39 | if ($length & 0x80) { // definite length, long form |
40 | - $length&= 0x7F; |
|
40 | + $length &= 0x7F; |
|
41 | 41 | $temp = Strings::shift($string, $length); |
42 | 42 | list(, $length) = unpack('N', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4)); |
43 | 43 | } |
@@ -38,35 +38,35 @@ |
||
38 | 38 | */ |
39 | 39 | class Cipher_AES_256 extends Cipher_Rijndael_128 |
40 | 40 | { |
41 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
42 | - const BYTES_BLOCK = 16; // 128 bits; |
|
41 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
42 | + const BYTES_BLOCK = 16; // 128 bits; |
|
43 | 43 | |
44 | - /** @type integer BITS_KEY The size of the key, in bytes */ |
|
45 | - const BYTES_KEY = 32; // 256 bits; |
|
44 | + /** @type integer BITS_KEY The size of the key, in bytes */ |
|
45 | + const BYTES_KEY = 32; // 256 bits; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Constructor |
|
49 | - * Sets the key used for encryption. |
|
50 | - * |
|
51 | - * @param string $key string containing the user supplied encryption key |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function __construct($key) |
|
55 | - { |
|
56 | - // Setup AES by calling the second constructor in Rijndael_128 |
|
57 | - // The block size is set here too, since all AES implementations use 128 bit blocks |
|
58 | - parent::__construct1(PHP_Crypt::CIPHER_AES_256, $key, self::BYTES_KEY); |
|
59 | - } |
|
47 | + /** |
|
48 | + * Constructor |
|
49 | + * Sets the key used for encryption. |
|
50 | + * |
|
51 | + * @param string $key string containing the user supplied encryption key |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function __construct($key) |
|
55 | + { |
|
56 | + // Setup AES by calling the second constructor in Rijndael_128 |
|
57 | + // The block size is set here too, since all AES implementations use 128 bit blocks |
|
58 | + parent::__construct1(PHP_Crypt::CIPHER_AES_256, $key, self::BYTES_KEY); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Destructor |
|
64 | - * |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function __destruct() |
|
68 | - { |
|
69 | - parent::__destruct(); |
|
70 | - } |
|
62 | + /** |
|
63 | + * Destructor |
|
64 | + * |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function __destruct() |
|
68 | + { |
|
69 | + parent::__destruct(); |
|
70 | + } |
|
71 | 71 | } |
72 | 72 | ?> |
@@ -46,219 +46,219 @@ |
||
46 | 46 | */ |
47 | 47 | class Cipher_Enigma extends Cipher |
48 | 48 | { |
49 | - const MASK = 0377; |
|
50 | - |
|
51 | - /** @type integer ROTORSZ The size of $t1,$t2,$t3,$deck */ |
|
52 | - const ROTORSZ = 256; |
|
53 | - |
|
54 | - /** @type array $t1 An array of chars, ROTORSZ size */ |
|
55 | - private $t1 = array(); |
|
56 | - |
|
57 | - /** @type array $t2 An array of chars, ROTORSZ size */ |
|
58 | - private $t2 = array(); |
|
59 | - |
|
60 | - /** @type array $t3 An array of chars, ROTORSZ size */ |
|
61 | - private $t3 = array(); |
|
62 | - |
|
63 | - /** @type array $deck An array of chars, ROTORSZ size */ |
|
64 | - private $deck = array(); |
|
65 | - |
|
66 | - private $n1 = 0; |
|
67 | - private $n2 = 0; |
|
68 | - private $nr1 = 0; |
|
69 | - private $nr2 = 0; |
|
70 | - |
|
71 | - /** @type string $xkey Stores the modified key */ |
|
72 | - private $xkey = ""; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Constructor |
|
77 | - * |
|
78 | - * @param string $key The key used for Encryption/Decryption |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public function __construct($key) |
|
82 | - { |
|
83 | - parent::__construct(PHP_Crypt::CIPHER_ENIGMA, $key, strlen($key)); |
|
84 | - |
|
85 | - $this->createKey(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Destructor |
|
91 | - * |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function __destruct() |
|
95 | - { |
|
96 | - parent::__destruct(); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Encrypt plain text data using Enigma |
|
102 | - * |
|
103 | - * @param string $str A plain text string of any length |
|
104 | - * @return boolean Returns true |
|
105 | - */ |
|
106 | - public function encrypt(&$str) |
|
107 | - { |
|
108 | - $this->operation(parent::ENCRYPT); |
|
109 | - return $this->enigma($str); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Decrypt an Enigma encrypted string |
|
115 | - * |
|
116 | - * @param string $str A Enigma encrypted string |
|
117 | - * @return boolean Returns true |
|
118 | - */ |
|
119 | - public function decrypt(&$str) |
|
120 | - { |
|
121 | - $this->operation(parent::DECRYPT); |
|
122 | - return $this->enigma($str); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Peforms the actual Enigma encryption/decryption. Since |
|
128 | - * the algorithm is the same for both, we do it all in |
|
129 | - * this one function |
|
130 | - * |
|
131 | - * @param string $str A string to encrypt or decrypt |
|
132 | - * @return boolean Returns true |
|
133 | - */ |
|
134 | - private function enigma(&$str) |
|
135 | - { |
|
136 | - // zero out the counters |
|
137 | - $this->n1 = 0; |
|
138 | - $this->n2 = 0; |
|
139 | - $this->nr1 = 0; |
|
140 | - $this->nr2 = 0; |
|
141 | - |
|
142 | - $max = strlen($str); |
|
143 | - for($j = 0; $j < $max; ++$j) |
|
144 | - { |
|
145 | - $i = ord($str[$j]); |
|
146 | - $this->nr1 = $this->n1; |
|
147 | - |
|
148 | - $pos1 = ($i + $this->nr1) & self::MASK; |
|
149 | - $pos3 = ($this->t1[$pos1] + $this->nr2) & self::MASK; |
|
150 | - $pos2 = ($this->t3[$pos3] - $this->nr2) & self::MASK; |
|
151 | - $i = $this->t2[$pos2] - $this->nr1; |
|
152 | - |
|
153 | - $str[$j] = chr($i); |
|
154 | - $this->n1++; |
|
155 | - |
|
156 | - if($this->n1 == self::ROTORSZ) |
|
157 | - { |
|
158 | - $this->n1 = 0; |
|
159 | - $this->n2++; |
|
160 | - |
|
161 | - if($this->n2 == self::ROTORSZ) |
|
162 | - $this->n2 = 0; |
|
163 | - |
|
164 | - $this->nr2 = $this->n2; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - return true; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * The code for this function was translated to PHP from mcrypt's enigma.c, |
|
174 | - * I was not able to find sufficient documentation to create my own |
|
175 | - * version of this function. |
|
176 | - * Enigma requires a 13 byte key, this function will |
|
177 | - * lengthen the key to get it to 13 bytes long if it's short. It also |
|
178 | - * Sets $deck, and $t1, $t2, $t3 which I think are the Enigma rotors. |
|
179 | - * |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - private function createKey() |
|
183 | - { |
|
184 | - $this->deck = array(); |
|
185 | - $this->t1 = array(); |
|
186 | - $this->t2 = array_fill(0, self::ROTORSZ, 0); |
|
187 | - $this->t3 = $this->t2; |
|
188 | - $this->xkey = $this->key(); |
|
189 | - $klen = $this->keySize(); |
|
190 | - |
|
191 | - // get the key to exactly 13 bytes if it's less than 13 |
|
192 | - if($klen < 13) |
|
193 | - $this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT); |
|
194 | - |
|
195 | - $seed = 123; |
|
196 | - for($i = 0; $i < 13; ++$i) |
|
197 | - $seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i; |
|
198 | - |
|
199 | - // sets $t1 and $deck |
|
200 | - for($i = 0; $i < self::ROTORSZ; ++$i) |
|
201 | - { |
|
202 | - $this->t1[] = $i; |
|
203 | - $this->deck[] = $i; |
|
204 | - } |
|
205 | - |
|
206 | - // sets $t3 |
|
207 | - for($i = 0; $i < self::ROTORSZ; ++$i) |
|
208 | - { |
|
209 | - // make sure the return values are 32 bit |
|
210 | - $seed = 5 * parent::sInt32($seed) + ord($this->xkey[$i % 13]); |
|
211 | - $seed = parent::sInt32($seed); |
|
212 | - |
|
213 | - // force the returned value to be an unsigned int |
|
214 | - //$random = parent::uint32($seed % 65521); |
|
215 | - $random = parent::uInt($seed % 65521); |
|
216 | - |
|
217 | - $k = self::ROTORSZ - 1 - $i; |
|
218 | - $ic = ($random & self::MASK) % ($k + 1); |
|
219 | - |
|
220 | - // make sure the returned value is an unsigned int |
|
221 | - $random = parent::uInt($random >> 8); |
|
222 | - |
|
223 | - $temp = $this->t1[$k]; |
|
224 | - $this->t1[$k] = $this->t1[$ic]; |
|
225 | - $this->t1[$ic] = $temp; |
|
226 | - if($this->t3[$k] != 0) |
|
227 | - continue; |
|
228 | - |
|
229 | - $ic = ($random & self::MASK) % $k; |
|
230 | - while($this->t3[$ic] != 0) |
|
231 | - $ic = ($ic + 1) % $k; |
|
232 | - |
|
233 | - $this->t3[$k] = $ic; |
|
234 | - $this->t3[$ic] = $k; |
|
235 | - } |
|
236 | - |
|
237 | - // sets $t2 |
|
238 | - for($i = 0; $i < self::ROTORSZ; ++$i) |
|
239 | - { |
|
240 | - $pos = $this->t1[$i] & self::MASK; |
|
241 | - $this->t2[$pos] = $i; |
|
242 | - } |
|
243 | - |
|
244 | - // now convert $t1, $t2, $t3, $deck values to signed chars, |
|
245 | - // PHP's chr() function returns an unsigned char, so we have |
|
246 | - // to use use our own |
|
247 | - $this->t1 = array_map("parent::sChar", $this->t1); |
|
248 | - $this->t2 = array_map("parent::sChar", $this->t2); |
|
249 | - $this->t3 = array_map("parent::sChar", $this->t3); |
|
250 | - $this->deck = array_map("parent::sChar", $this->deck); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * Indicates this is a stream cipher |
|
256 | - * |
|
257 | - * @return integer Returns Cipher::STREAM |
|
258 | - */ |
|
259 | - public function type() |
|
260 | - { |
|
261 | - return parent::STREAM; |
|
262 | - } |
|
49 | + const MASK = 0377; |
|
50 | + |
|
51 | + /** @type integer ROTORSZ The size of $t1,$t2,$t3,$deck */ |
|
52 | + const ROTORSZ = 256; |
|
53 | + |
|
54 | + /** @type array $t1 An array of chars, ROTORSZ size */ |
|
55 | + private $t1 = array(); |
|
56 | + |
|
57 | + /** @type array $t2 An array of chars, ROTORSZ size */ |
|
58 | + private $t2 = array(); |
|
59 | + |
|
60 | + /** @type array $t3 An array of chars, ROTORSZ size */ |
|
61 | + private $t3 = array(); |
|
62 | + |
|
63 | + /** @type array $deck An array of chars, ROTORSZ size */ |
|
64 | + private $deck = array(); |
|
65 | + |
|
66 | + private $n1 = 0; |
|
67 | + private $n2 = 0; |
|
68 | + private $nr1 = 0; |
|
69 | + private $nr2 = 0; |
|
70 | + |
|
71 | + /** @type string $xkey Stores the modified key */ |
|
72 | + private $xkey = ""; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Constructor |
|
77 | + * |
|
78 | + * @param string $key The key used for Encryption/Decryption |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public function __construct($key) |
|
82 | + { |
|
83 | + parent::__construct(PHP_Crypt::CIPHER_ENIGMA, $key, strlen($key)); |
|
84 | + |
|
85 | + $this->createKey(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Destructor |
|
91 | + * |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function __destruct() |
|
95 | + { |
|
96 | + parent::__destruct(); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Encrypt plain text data using Enigma |
|
102 | + * |
|
103 | + * @param string $str A plain text string of any length |
|
104 | + * @return boolean Returns true |
|
105 | + */ |
|
106 | + public function encrypt(&$str) |
|
107 | + { |
|
108 | + $this->operation(parent::ENCRYPT); |
|
109 | + return $this->enigma($str); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Decrypt an Enigma encrypted string |
|
115 | + * |
|
116 | + * @param string $str A Enigma encrypted string |
|
117 | + * @return boolean Returns true |
|
118 | + */ |
|
119 | + public function decrypt(&$str) |
|
120 | + { |
|
121 | + $this->operation(parent::DECRYPT); |
|
122 | + return $this->enigma($str); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Peforms the actual Enigma encryption/decryption. Since |
|
128 | + * the algorithm is the same for both, we do it all in |
|
129 | + * this one function |
|
130 | + * |
|
131 | + * @param string $str A string to encrypt or decrypt |
|
132 | + * @return boolean Returns true |
|
133 | + */ |
|
134 | + private function enigma(&$str) |
|
135 | + { |
|
136 | + // zero out the counters |
|
137 | + $this->n1 = 0; |
|
138 | + $this->n2 = 0; |
|
139 | + $this->nr1 = 0; |
|
140 | + $this->nr2 = 0; |
|
141 | + |
|
142 | + $max = strlen($str); |
|
143 | + for($j = 0; $j < $max; ++$j) |
|
144 | + { |
|
145 | + $i = ord($str[$j]); |
|
146 | + $this->nr1 = $this->n1; |
|
147 | + |
|
148 | + $pos1 = ($i + $this->nr1) & self::MASK; |
|
149 | + $pos3 = ($this->t1[$pos1] + $this->nr2) & self::MASK; |
|
150 | + $pos2 = ($this->t3[$pos3] - $this->nr2) & self::MASK; |
|
151 | + $i = $this->t2[$pos2] - $this->nr1; |
|
152 | + |
|
153 | + $str[$j] = chr($i); |
|
154 | + $this->n1++; |
|
155 | + |
|
156 | + if($this->n1 == self::ROTORSZ) |
|
157 | + { |
|
158 | + $this->n1 = 0; |
|
159 | + $this->n2++; |
|
160 | + |
|
161 | + if($this->n2 == self::ROTORSZ) |
|
162 | + $this->n2 = 0; |
|
163 | + |
|
164 | + $this->nr2 = $this->n2; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + return true; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * The code for this function was translated to PHP from mcrypt's enigma.c, |
|
174 | + * I was not able to find sufficient documentation to create my own |
|
175 | + * version of this function. |
|
176 | + * Enigma requires a 13 byte key, this function will |
|
177 | + * lengthen the key to get it to 13 bytes long if it's short. It also |
|
178 | + * Sets $deck, and $t1, $t2, $t3 which I think are the Enigma rotors. |
|
179 | + * |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + private function createKey() |
|
183 | + { |
|
184 | + $this->deck = array(); |
|
185 | + $this->t1 = array(); |
|
186 | + $this->t2 = array_fill(0, self::ROTORSZ, 0); |
|
187 | + $this->t3 = $this->t2; |
|
188 | + $this->xkey = $this->key(); |
|
189 | + $klen = $this->keySize(); |
|
190 | + |
|
191 | + // get the key to exactly 13 bytes if it's less than 13 |
|
192 | + if($klen < 13) |
|
193 | + $this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT); |
|
194 | + |
|
195 | + $seed = 123; |
|
196 | + for($i = 0; $i < 13; ++$i) |
|
197 | + $seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i; |
|
198 | + |
|
199 | + // sets $t1 and $deck |
|
200 | + for($i = 0; $i < self::ROTORSZ; ++$i) |
|
201 | + { |
|
202 | + $this->t1[] = $i; |
|
203 | + $this->deck[] = $i; |
|
204 | + } |
|
205 | + |
|
206 | + // sets $t3 |
|
207 | + for($i = 0; $i < self::ROTORSZ; ++$i) |
|
208 | + { |
|
209 | + // make sure the return values are 32 bit |
|
210 | + $seed = 5 * parent::sInt32($seed) + ord($this->xkey[$i % 13]); |
|
211 | + $seed = parent::sInt32($seed); |
|
212 | + |
|
213 | + // force the returned value to be an unsigned int |
|
214 | + //$random = parent::uint32($seed % 65521); |
|
215 | + $random = parent::uInt($seed % 65521); |
|
216 | + |
|
217 | + $k = self::ROTORSZ - 1 - $i; |
|
218 | + $ic = ($random & self::MASK) % ($k + 1); |
|
219 | + |
|
220 | + // make sure the returned value is an unsigned int |
|
221 | + $random = parent::uInt($random >> 8); |
|
222 | + |
|
223 | + $temp = $this->t1[$k]; |
|
224 | + $this->t1[$k] = $this->t1[$ic]; |
|
225 | + $this->t1[$ic] = $temp; |
|
226 | + if($this->t3[$k] != 0) |
|
227 | + continue; |
|
228 | + |
|
229 | + $ic = ($random & self::MASK) % $k; |
|
230 | + while($this->t3[$ic] != 0) |
|
231 | + $ic = ($ic + 1) % $k; |
|
232 | + |
|
233 | + $this->t3[$k] = $ic; |
|
234 | + $this->t3[$ic] = $k; |
|
235 | + } |
|
236 | + |
|
237 | + // sets $t2 |
|
238 | + for($i = 0; $i < self::ROTORSZ; ++$i) |
|
239 | + { |
|
240 | + $pos = $this->t1[$i] & self::MASK; |
|
241 | + $this->t2[$pos] = $i; |
|
242 | + } |
|
243 | + |
|
244 | + // now convert $t1, $t2, $t3, $deck values to signed chars, |
|
245 | + // PHP's chr() function returns an unsigned char, so we have |
|
246 | + // to use use our own |
|
247 | + $this->t1 = array_map("parent::sChar", $this->t1); |
|
248 | + $this->t2 = array_map("parent::sChar", $this->t2); |
|
249 | + $this->t3 = array_map("parent::sChar", $this->t3); |
|
250 | + $this->deck = array_map("parent::sChar", $this->deck); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * Indicates this is a stream cipher |
|
256 | + * |
|
257 | + * @return integer Returns Cipher::STREAM |
|
258 | + */ |
|
259 | + public function type() |
|
260 | + { |
|
261 | + return parent::STREAM; |
|
262 | + } |
|
263 | 263 | } |
264 | 264 | ?> |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | $this->nr2 = 0; |
141 | 141 | |
142 | 142 | $max = strlen($str); |
143 | - for($j = 0; $j < $max; ++$j) |
|
143 | + for ($j = 0; $j < $max; ++$j) |
|
144 | 144 | { |
145 | 145 | $i = ord($str[$j]); |
146 | 146 | $this->nr1 = $this->n1; |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | $str[$j] = chr($i); |
154 | 154 | $this->n1++; |
155 | 155 | |
156 | - if($this->n1 == self::ROTORSZ) |
|
156 | + if ($this->n1 == self::ROTORSZ) |
|
157 | 157 | { |
158 | 158 | $this->n1 = 0; |
159 | 159 | $this->n2++; |
160 | 160 | |
161 | - if($this->n2 == self::ROTORSZ) |
|
161 | + if ($this->n2 == self::ROTORSZ) |
|
162 | 162 | $this->n2 = 0; |
163 | 163 | |
164 | 164 | $this->nr2 = $this->n2; |
@@ -189,22 +189,22 @@ discard block |
||
189 | 189 | $klen = $this->keySize(); |
190 | 190 | |
191 | 191 | // get the key to exactly 13 bytes if it's less than 13 |
192 | - if($klen < 13) |
|
192 | + if ($klen < 13) |
|
193 | 193 | $this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT); |
194 | 194 | |
195 | 195 | $seed = 123; |
196 | - for($i = 0; $i < 13; ++$i) |
|
196 | + for ($i = 0; $i < 13; ++$i) |
|
197 | 197 | $seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i; |
198 | 198 | |
199 | 199 | // sets $t1 and $deck |
200 | - for($i = 0; $i < self::ROTORSZ; ++$i) |
|
200 | + for ($i = 0; $i < self::ROTORSZ; ++$i) |
|
201 | 201 | { |
202 | 202 | $this->t1[] = $i; |
203 | 203 | $this->deck[] = $i; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // sets $t3 |
207 | - for($i = 0; $i < self::ROTORSZ; ++$i) |
|
207 | + for ($i = 0; $i < self::ROTORSZ; ++$i) |
|
208 | 208 | { |
209 | 209 | // make sure the return values are 32 bit |
210 | 210 | $seed = 5 * parent::sInt32($seed) + ord($this->xkey[$i % 13]); |
@@ -223,11 +223,11 @@ discard block |
||
223 | 223 | $temp = $this->t1[$k]; |
224 | 224 | $this->t1[$k] = $this->t1[$ic]; |
225 | 225 | $this->t1[$ic] = $temp; |
226 | - if($this->t3[$k] != 0) |
|
226 | + if ($this->t3[$k] != 0) |
|
227 | 227 | continue; |
228 | 228 | |
229 | 229 | $ic = ($random & self::MASK) % $k; |
230 | - while($this->t3[$ic] != 0) |
|
230 | + while ($this->t3[$ic] != 0) |
|
231 | 231 | $ic = ($ic + 1) % $k; |
232 | 232 | |
233 | 233 | $this->t3[$k] = $ic; |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | // sets $t2 |
238 | - for($i = 0; $i < self::ROTORSZ; ++$i) |
|
238 | + for ($i = 0; $i < self::ROTORSZ; ++$i) |
|
239 | 239 | { |
240 | 240 | $pos = $this->t1[$i] & self::MASK; |
241 | 241 | $this->t2[$pos] = $i; |
@@ -158,8 +158,9 @@ discard block |
||
158 | 158 | $this->n1 = 0; |
159 | 159 | $this->n2++; |
160 | 160 | |
161 | - if($this->n2 == self::ROTORSZ) |
|
162 | - $this->n2 = 0; |
|
161 | + if($this->n2 == self::ROTORSZ) { |
|
162 | + $this->n2 = 0; |
|
163 | + } |
|
163 | 164 | |
164 | 165 | $this->nr2 = $this->n2; |
165 | 166 | } |
@@ -189,12 +190,14 @@ discard block |
||
189 | 190 | $klen = $this->keySize(); |
190 | 191 | |
191 | 192 | // get the key to exactly 13 bytes if it's less than 13 |
192 | - if($klen < 13) |
|
193 | - $this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT); |
|
193 | + if($klen < 13) { |
|
194 | + $this->xkey = str_pad($this->xkey, 13, chr(0), STR_PAD_RIGHT); |
|
195 | + } |
|
194 | 196 | |
195 | 197 | $seed = 123; |
196 | - for($i = 0; $i < 13; ++$i) |
|
197 | - $seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i; |
|
198 | + for($i = 0; $i < 13; ++$i) { |
|
199 | + $seed = parent::sInt32($seed) * ord($this->xkey[$i]) + $i; |
|
200 | + } |
|
198 | 201 | |
199 | 202 | // sets $t1 and $deck |
200 | 203 | for($i = 0; $i < self::ROTORSZ; ++$i) |
@@ -223,12 +226,14 @@ discard block |
||
223 | 226 | $temp = $this->t1[$k]; |
224 | 227 | $this->t1[$k] = $this->t1[$ic]; |
225 | 228 | $this->t1[$ic] = $temp; |
226 | - if($this->t3[$k] != 0) |
|
227 | - continue; |
|
229 | + if($this->t3[$k] != 0) { |
|
230 | + continue; |
|
231 | + } |
|
228 | 232 | |
229 | 233 | $ic = ($random & self::MASK) % $k; |
230 | - while($this->t3[$ic] != 0) |
|
231 | - $ic = ($ic + 1) % $k; |
|
234 | + while($this->t3[$ic] != 0) { |
|
235 | + $ic = ($ic + 1) % $k; |
|
236 | + } |
|
232 | 237 | |
233 | 238 | $this->t3[$k] = $ic; |
234 | 239 | $this->t3[$ic] = $k; |
@@ -38,39 +38,39 @@ |
||
38 | 38 | */ |
39 | 39 | class Cipher_Rijndael_256 extends Cipher_Rijndael |
40 | 40 | { |
41 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
42 | - const BYTES_BLOCK = 32; // 256 bits |
|
41 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
42 | + const BYTES_BLOCK = 32; // 256 bits |
|
43 | 43 | |
44 | - //const BITS_KEY = 0; |
|
44 | + //const BITS_KEY = 0; |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Constructor |
|
49 | - * Sets the key used for encryption. Also sets the requied block size |
|
50 | - * |
|
51 | - * @param string $key string containing the user supplied encryption key |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function __construct($key) |
|
55 | - { |
|
56 | - // Set up the key |
|
57 | - parent::__construct(PHP_Crypt::CIPHER_RIJNDAEL_256, $key); |
|
47 | + /** |
|
48 | + * Constructor |
|
49 | + * Sets the key used for encryption. Also sets the requied block size |
|
50 | + * |
|
51 | + * @param string $key string containing the user supplied encryption key |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function __construct($key) |
|
55 | + { |
|
56 | + // Set up the key |
|
57 | + parent::__construct(PHP_Crypt::CIPHER_RIJNDAEL_256, $key); |
|
58 | 58 | |
59 | - // required block size in bits |
|
60 | - $this->blockSize(self::BYTES_BLOCK); |
|
59 | + // required block size in bits |
|
60 | + $this->blockSize(self::BYTES_BLOCK); |
|
61 | 61 | |
62 | - // expand the key now that we know the key size, and the bit size |
|
63 | - $this->expandKey(); |
|
64 | - } |
|
62 | + // expand the key now that we know the key size, and the bit size |
|
63 | + $this->expandKey(); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * Destructor |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function __destruct() |
|
73 | - { |
|
74 | - parent::__destruct(); |
|
75 | - } |
|
67 | + /** |
|
68 | + * Destructor |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function __destruct() |
|
73 | + { |
|
74 | + parent::__destruct(); |
|
75 | + } |
|
76 | 76 | } |
@@ -38,34 +38,34 @@ |
||
38 | 38 | */ |
39 | 39 | class Cipher_AES_128 extends Cipher_Rijndael_128 |
40 | 40 | { |
41 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
42 | - const BYTES_BLOCK = 16; //128 bits; |
|
41 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
42 | + const BYTES_BLOCK = 16; //128 bits; |
|
43 | 43 | |
44 | - /** @type integer BYTES_KEY The size of the key, in bytes */ |
|
45 | - const BYTES_KEY = 16; // 128 bits; |
|
44 | + /** @type integer BYTES_KEY The size of the key, in bytes */ |
|
45 | + const BYTES_KEY = 16; // 128 bits; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Constructor, Sets the key used for encryption. |
|
49 | - * |
|
50 | - * @param string $key string containing the user supplied encryption key |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function __construct($key) |
|
54 | - { |
|
55 | - // Setup AES by calling the second constructor in Rijndael_128 |
|
56 | - // The block size is set here too, since all AES implementations use 128 bit blocks |
|
57 | - parent::__construct1(PHP_Crypt::CIPHER_AES_128, $key, self::BYTES_KEY); |
|
58 | - } |
|
47 | + /** |
|
48 | + * Constructor, Sets the key used for encryption. |
|
49 | + * |
|
50 | + * @param string $key string containing the user supplied encryption key |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function __construct($key) |
|
54 | + { |
|
55 | + // Setup AES by calling the second constructor in Rijndael_128 |
|
56 | + // The block size is set here too, since all AES implementations use 128 bit blocks |
|
57 | + parent::__construct1(PHP_Crypt::CIPHER_AES_128, $key, self::BYTES_KEY); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Destructor |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function __destruct() |
|
67 | - { |
|
68 | - parent::__destruct(); |
|
69 | - } |
|
61 | + /** |
|
62 | + * Destructor |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function __destruct() |
|
67 | + { |
|
68 | + parent::__destruct(); |
|
69 | + } |
|
70 | 70 | } |
71 | 71 | ?> |
@@ -40,563 +40,563 @@ |
||
40 | 40 | */ |
41 | 41 | class Cipher_Blowfish extends Cipher |
42 | 42 | { |
43 | - /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
44 | - const BYTES_BLOCK = 8; // 64 bits; |
|
43 | + /** @type integer BYTES_BLOCK The size of the block, in bytes */ |
|
44 | + const BYTES_BLOCK = 8; // 64 bits; |
|
45 | 45 | |
46 | - // a variable length key, between 8 - 448 bits |
|
47 | - //const BYTES_KEY = 0; |
|
46 | + // a variable length key, between 8 - 448 bits |
|
47 | + //const BYTES_KEY = 0; |
|
48 | 48 | |
49 | - /** @type array $_sbox1 S-Box 1 */ |
|
50 | - private static $_sbox1 = array(); |
|
49 | + /** @type array $_sbox1 S-Box 1 */ |
|
50 | + private static $_sbox1 = array(); |
|
51 | 51 | |
52 | - /** @type string $_sbox2 S-Box 2 */ |
|
53 | - private static $_sbox2 = array(); |
|
52 | + /** @type string $_sbox2 S-Box 2 */ |
|
53 | + private static $_sbox2 = array(); |
|
54 | 54 | |
55 | - /** @type string $_sbox3 S-Box 3 */ |
|
56 | - private static $_sbox3 = array(); |
|
55 | + /** @type string $_sbox3 S-Box 3 */ |
|
56 | + private static $_sbox3 = array(); |
|
57 | 57 | |
58 | - /** @type string $_sbox4 S-Box 4 */ |
|
59 | - private static $_sbox4 = array(); |
|
58 | + /** @type string $_sbox4 S-Box 4 */ |
|
59 | + private static $_sbox4 = array(); |
|
60 | 60 | |
61 | - /** @type array $_p The P-Array, 18 elements long */ |
|
62 | - private static $_p = array(); |
|
61 | + /** @type array $_p The P-Array, 18 elements long */ |
|
62 | + private static $_p = array(); |
|
63 | 63 | |
64 | - /** @type integer $key_pos Used for keyChunk(), to determine the current |
|
64 | + /** @type integer $key_pos Used for keyChunk(), to determine the current |
|
65 | 65 | position in the key */ |
66 | - private $key_pos = 0; |
|
67 | - |
|
68 | - /** |
|
69 | - * Constructor |
|
70 | - * |
|
71 | - * @param string $key The key used for Encryption/Decryption |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public function __construct($key) |
|
75 | - { |
|
76 | - // the max length of the key is 448 bits (56 bytes) |
|
77 | - $keylen = strlen($key); |
|
78 | - if($keylen > 56) |
|
79 | - { |
|
80 | - $key = substr($key, 0, 56); |
|
81 | - $keylen = 56; |
|
82 | - } |
|
83 | - else if($keylen < 1) |
|
84 | - { |
|
85 | - $msg = "No key given. The key must be between 1 - 56 bytes."; |
|
86 | - trigger_error($msg, E_USER_WARNING); |
|
87 | - } |
|
88 | - |
|
89 | - // set the key, make sure the required length is set in bits |
|
90 | - parent::__construct(PHP_Crypt::CIPHER_BLOWFISH, $key, $keylen); |
|
91 | - |
|
92 | - // set the block size |
|
93 | - $this->blockSize(self::BYTES_BLOCK); |
|
94 | - |
|
95 | - $this->initTables(); |
|
96 | - $this->subKeys(); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Destructor |
|
102 | - * |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public function __destruct() |
|
106 | - { |
|
107 | - parent::__destruct(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Encrypt plain text data |
|
113 | - * |
|
114 | - * @param string $data A 64 bit (8 byte) plain text string |
|
115 | - * @return boolean Returns true |
|
116 | - */ |
|
117 | - public function encrypt(&$data) |
|
118 | - { |
|
119 | - $this->operation(parent::ENCRYPT); |
|
120 | - return $this->blowfish($data); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Decrypt an encrypted string |
|
126 | - * |
|
127 | - * @param string $data A 64 bit block of Blowfish encrypted data |
|
128 | - * @return boolean Returns true |
|
129 | - */ |
|
130 | - public function decrypt(&$data) |
|
131 | - { |
|
132 | - $this->operation(parent::DECRYPT); |
|
133 | - return $this->blowfish($data); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * The same alorigthm is used for both Encryption, and Decryption |
|
139 | - * |
|
140 | - * @param string $data A 64 bit block of data |
|
141 | - * @return boolean Returns true |
|
142 | - */ |
|
143 | - private function blowfish(&$data) |
|
144 | - { |
|
145 | - // divide the data into into two 32 bit halves |
|
146 | - $xl = parent::str2Dec(substr($data, 0, 4)); |
|
147 | - $xr = parent::str2Dec(substr($data, 4, 4)); |
|
148 | - |
|
149 | - for($i = 0; $i < 16; ++$i) |
|
150 | - { |
|
151 | - if($this->operation() == parent::ENCRYPT) |
|
152 | - $xl ^= self::$_p[$i]; |
|
153 | - else |
|
154 | - $xl ^= self::$_p[17-$i]; |
|
155 | - |
|
156 | - // perform F() on the left half, and XOR with the right half |
|
157 | - $xr = $this->F($xl) ^ $xr; |
|
158 | - |
|
159 | - // swap $xl and $xr |
|
160 | - $tmp = $xr; |
|
161 | - $xr = $xl; |
|
162 | - $xl = $tmp; |
|
163 | - } |
|
164 | - |
|
165 | - // swap $xl and $xr after the 16th round to undo the last swap |
|
166 | - $tmp = $xl; |
|
167 | - $xl = $xr; |
|
168 | - $xr = $tmp; |
|
169 | - |
|
170 | - // XOR the final two elements of $_p |
|
171 | - if($this->operation() == parent::ENCRYPT) |
|
172 | - { |
|
173 | - $xr ^= self::$_p[16]; |
|
174 | - $xl = $xl ^ self::$_p[17]; |
|
175 | - } |
|
176 | - else // parent::DECRYPT |
|
177 | - { |
|
178 | - $xr ^= self::$_p[1]; |
|
179 | - $xl ^= self::$_p[0]; |
|
180 | - } |
|
181 | - |
|
182 | - // recombine the two halves, force them to be 4 bytes each |
|
183 | - $data = parent::dec2Str($xl, 4).parent::dec2Str($xr, 4); |
|
184 | - |
|
185 | - return true; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Blowfish's F() function |
|
191 | - * |
|
192 | - * @param string $i A 32 bit integer |
|
193 | - */ |
|
194 | - private function F($i) |
|
195 | - { |
|
196 | - // split the 32 bits into four 8 bit parts |
|
197 | - $x[0] = $i & 0xff; // first byte |
|
198 | - $x[1] = ($i >> 8) & 0xff; // second byte |
|
199 | - $x[2] = ($i >> 16) & 0xff; // third byte |
|
200 | - $x[3] = ($i >> 24) & 0xff; // fourth byte |
|
201 | - |
|
202 | - // perform F(), make sure all values returned are |
|
203 | - // unsigned 32 bit |
|
204 | - $f = parent::uInt32(self::$_sbox1[$x[3]] + self::$_sbox2[$x[2]]); |
|
205 | - $f = parent::uInt32($f ^ self::$_sbox3[$x[1]]); |
|
206 | - $f = parent::uInt32($f + self::$_sbox4[$x[0]]); |
|
207 | - |
|
208 | - return $f; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Generates the subkeys used in Blowfish |
|
214 | - * |
|
215 | - * @return void |
|
216 | - */ |
|
217 | - private function subKeys() |
|
218 | - { |
|
219 | - // now xor each element of $_p with 32 bits from the key |
|
220 | - for($i = 0; $i < 18; ++$i) |
|
221 | - { |
|
222 | - $c = $this->keyChunk(4); |
|
223 | - self::$_p[$i] ^= parent::str2Dec($c); |
|
224 | - } |
|
225 | - |
|
226 | - // start with an 8 byte null string |
|
227 | - $zero = "\0\0\0\0\0\0\0\0"; |
|
228 | - |
|
229 | - // now we loop, each loop replacing elements of $_p, or an $_sbox with the |
|
230 | - // repeatedly encrypted zero string |
|
231 | - for($i = 0; $i < 1042; $i += 2) |
|
232 | - { |
|
233 | - // encrypt the 64 bit null string |
|
234 | - $this->encrypt($zero); |
|
235 | - |
|
236 | - // split the encrypted null string into two 32 bit parts |
|
237 | - $z0 = parent::str2Dec(substr($zero, 0, 4)); |
|
238 | - $z1 = parent::str2Dec(substr($zero, 4, 4)); |
|
239 | - |
|
240 | - // now fill the $_p, $_sbox1, $_sbox2, $_sbox3, $_sbox4 |
|
241 | - // with 4 bytes from the repeatedly encrypted 8 byte null string |
|
242 | - if($i < 18) |
|
243 | - { |
|
244 | - self::$_p[$i] = $z0; |
|
245 | - self::$_p[$i + 1] = $z1; |
|
246 | - } |
|
247 | - else if($i >= 18 && $i < 274) |
|
248 | - { |
|
249 | - self::$_sbox1[$i - 18] = $z0; |
|
250 | - self::$_sbox1[$i - 18 + 1] = $z1; |
|
251 | - } |
|
252 | - else if($i >= 274 && $i < 530) |
|
253 | - { |
|
254 | - self::$_sbox2[$i - 274] = $z0; |
|
255 | - self::$_sbox2[$i - 274 + 1] = $z1; |
|
256 | - } |
|
257 | - else if($i >= 530 && $i < 786) |
|
258 | - { |
|
259 | - self::$_sbox3[$i - 530] = $z0; |
|
260 | - self::$_sbox3[$i - 530 + 1] = $z1; |
|
261 | - } |
|
262 | - else if($i >= 786 && $i < 1042) |
|
263 | - { |
|
264 | - self::$_sbox4[$i -786] = $z0; |
|
265 | - self::$_sbox4[$i - 786 + 1] = $z1; |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Returns a substring of $this->key. The size of the substring is set in the |
|
273 | - * parameter $size. Each call to this function returns a substring starting |
|
274 | - * in the position where the last substring ended. Effectively it rotates |
|
275 | - * through the key, when it reaches the end, it starts over at the |
|
276 | - * beginning of the key and continues on. You can reset the current position |
|
277 | - * by setting the parameter $reset=true, which will start the key back at the |
|
278 | - * first byte of the $this->key string. |
|
279 | - * |
|
280 | - * @param integer $size The size of the substring to return, in bytes |
|
281 | - * @param bool $reset If set to true, sets the position back to 0, the first |
|
282 | - * byte of the key string |
|
283 | - * @return string The next substring of the key |
|
284 | - */ |
|
285 | - private function keyChunk($size = 1, $reset = false) |
|
286 | - { |
|
287 | - if($reset || $this->key_pos >= $this->keySize()) |
|
288 | - $this->key_pos = 0; |
|
289 | - |
|
290 | - $bytes = substr($this->key(), $this->key_pos, $size); |
|
291 | - $len = strlen($bytes); |
|
292 | - if($len < $size) |
|
293 | - { |
|
294 | - $bytes .= substr($this->key(), 0, $size - $len); |
|
295 | - $this->key_pos = $size - $len; |
|
296 | - } |
|
297 | - else |
|
298 | - $this->key_pos += $size; |
|
299 | - |
|
300 | - return $bytes; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Initialize the tables used in Blowfish Encryption. These |
|
306 | - * are calculated from the value of PI. We grabbed |
|
307 | - * these from the mcrypt blowfish source, which already had |
|
308 | - * these values calculated |
|
309 | - * |
|
310 | - * @return void |
|
311 | - */ |
|
312 | - private function initTables() |
|
313 | - { |
|
314 | - self::$_sbox1 = array( |
|
315 | - 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, |
|
316 | - 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, |
|
317 | - 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, |
|
318 | - 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, |
|
319 | - 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, |
|
320 | - 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, |
|
321 | - 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, |
|
322 | - 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, |
|
323 | - 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, |
|
324 | - 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, |
|
325 | - 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, |
|
326 | - 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, |
|
327 | - 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, |
|
328 | - 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, |
|
329 | - 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, |
|
330 | - 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, |
|
331 | - 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, |
|
332 | - 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, |
|
333 | - 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, |
|
334 | - 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, |
|
335 | - 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, |
|
336 | - 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, |
|
337 | - 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, |
|
338 | - 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, |
|
339 | - 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, |
|
340 | - 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, |
|
341 | - 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, |
|
342 | - 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, |
|
343 | - 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, |
|
344 | - 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, |
|
345 | - 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, |
|
346 | - 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, |
|
347 | - 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, |
|
348 | - 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, |
|
349 | - 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, |
|
350 | - 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, |
|
351 | - 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, |
|
352 | - 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, |
|
353 | - 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, |
|
354 | - 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, |
|
355 | - 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, |
|
356 | - 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, |
|
357 | - 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, |
|
358 | - 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, |
|
359 | - 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, |
|
360 | - 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, |
|
361 | - 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, |
|
362 | - 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, |
|
363 | - 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, |
|
364 | - 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, |
|
365 | - 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, |
|
366 | - 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, |
|
367 | - 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, |
|
368 | - 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, |
|
369 | - 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, |
|
370 | - 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, |
|
371 | - 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, |
|
372 | - 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, |
|
373 | - 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, |
|
374 | - 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, |
|
375 | - 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, |
|
376 | - 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, |
|
377 | - 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, |
|
378 | - 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a |
|
379 | - ); |
|
380 | - |
|
381 | - self::$_sbox2 = array( |
|
382 | - 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, |
|
383 | - 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, |
|
384 | - 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, |
|
385 | - 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, |
|
386 | - 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, |
|
387 | - 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, |
|
388 | - 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, |
|
389 | - 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, |
|
390 | - 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, |
|
391 | - 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, |
|
392 | - 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, |
|
393 | - 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, |
|
394 | - 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, |
|
395 | - 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, |
|
396 | - 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, |
|
397 | - 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, |
|
398 | - 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, |
|
399 | - 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, |
|
400 | - 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, |
|
401 | - 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, |
|
402 | - 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, |
|
403 | - 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, |
|
404 | - 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, |
|
405 | - 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, |
|
406 | - 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, |
|
407 | - 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, |
|
408 | - 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, |
|
409 | - 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, |
|
410 | - 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, |
|
411 | - 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, |
|
412 | - 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, |
|
413 | - 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, |
|
414 | - 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, |
|
415 | - 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, |
|
416 | - 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, |
|
417 | - 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, |
|
418 | - 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, |
|
419 | - 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, |
|
420 | - 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, |
|
421 | - 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, |
|
422 | - 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, |
|
423 | - 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, |
|
424 | - 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, |
|
425 | - 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, |
|
426 | - 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, |
|
427 | - 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, |
|
428 | - 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, |
|
429 | - 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, |
|
430 | - 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, |
|
431 | - 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, |
|
432 | - 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, |
|
433 | - 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, |
|
434 | - 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, |
|
435 | - 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, |
|
436 | - 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, |
|
437 | - 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, |
|
438 | - 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, |
|
439 | - 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, |
|
440 | - 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, |
|
441 | - 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, |
|
442 | - 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, |
|
443 | - 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, |
|
444 | - 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, |
|
445 | - 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 |
|
446 | - ); |
|
447 | - |
|
448 | - self::$_sbox3 = array( |
|
449 | - 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, |
|
450 | - 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, |
|
451 | - 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, |
|
452 | - 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, |
|
453 | - 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, |
|
454 | - 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, |
|
455 | - 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, |
|
456 | - 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, |
|
457 | - 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, |
|
458 | - 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, |
|
459 | - 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, |
|
460 | - 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, |
|
461 | - 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, |
|
462 | - 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, |
|
463 | - 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, |
|
464 | - 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, |
|
465 | - 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, |
|
466 | - 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, |
|
467 | - 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, |
|
468 | - 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, |
|
469 | - 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, |
|
470 | - 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, |
|
471 | - 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, |
|
472 | - 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, |
|
473 | - 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, |
|
474 | - 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, |
|
475 | - 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, |
|
476 | - 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, |
|
477 | - 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, |
|
478 | - 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, |
|
479 | - 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, |
|
480 | - 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, |
|
481 | - 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, |
|
482 | - 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, |
|
483 | - 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, |
|
484 | - 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, |
|
485 | - 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, |
|
486 | - 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, |
|
487 | - 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, |
|
488 | - 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, |
|
489 | - 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, |
|
490 | - 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, |
|
491 | - 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, |
|
492 | - 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, |
|
493 | - 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, |
|
494 | - 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, |
|
495 | - 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, |
|
496 | - 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, |
|
497 | - 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, |
|
498 | - 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, |
|
499 | - 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, |
|
500 | - 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, |
|
501 | - 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, |
|
502 | - 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, |
|
503 | - 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, |
|
504 | - 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, |
|
505 | - 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, |
|
506 | - 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, |
|
507 | - 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, |
|
508 | - 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, |
|
509 | - 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, |
|
510 | - 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, |
|
511 | - 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, |
|
512 | - 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 |
|
513 | - ); |
|
514 | - |
|
515 | - self::$_sbox4 = array( |
|
516 | - 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, |
|
517 | - 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, |
|
518 | - 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, |
|
519 | - 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, |
|
520 | - 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, |
|
521 | - 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, |
|
522 | - 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, |
|
523 | - 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, |
|
524 | - 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, |
|
525 | - 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, |
|
526 | - 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, |
|
527 | - 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, |
|
528 | - 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, |
|
529 | - 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, |
|
530 | - 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, |
|
531 | - 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, |
|
532 | - 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, |
|
533 | - 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, |
|
534 | - 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, |
|
535 | - 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, |
|
536 | - 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, |
|
537 | - 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, |
|
538 | - 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, |
|
539 | - 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, |
|
540 | - 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, |
|
541 | - 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, |
|
542 | - 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, |
|
543 | - 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, |
|
544 | - 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, |
|
545 | - 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, |
|
546 | - 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, |
|
547 | - 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, |
|
548 | - 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, |
|
549 | - 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, |
|
550 | - 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, |
|
551 | - 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, |
|
552 | - 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, |
|
553 | - 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, |
|
554 | - 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, |
|
555 | - 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, |
|
556 | - 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, |
|
557 | - 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, |
|
558 | - 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, |
|
559 | - 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, |
|
560 | - 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, |
|
561 | - 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, |
|
562 | - 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, |
|
563 | - 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, |
|
564 | - 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, |
|
565 | - 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, |
|
566 | - 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, |
|
567 | - 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, |
|
568 | - 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, |
|
569 | - 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, |
|
570 | - 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, |
|
571 | - 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, |
|
572 | - 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, |
|
573 | - 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, |
|
574 | - 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, |
|
575 | - 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, |
|
576 | - 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, |
|
577 | - 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, |
|
578 | - 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, |
|
579 | - 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 |
|
580 | - ); |
|
581 | - |
|
582 | - self::$_p = array( |
|
583 | - 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, |
|
584 | - 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, |
|
585 | - 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, |
|
586 | - 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, |
|
587 | - 0x9216d5d9, 0x8979fb1b |
|
588 | - ); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * Indicates this is a block cipher |
|
594 | - * |
|
595 | - * @return integer Returns Cipher::BLOCK |
|
596 | - */ |
|
597 | - public function type() |
|
598 | - { |
|
599 | - return parent::BLOCK; |
|
600 | - } |
|
66 | + private $key_pos = 0; |
|
67 | + |
|
68 | + /** |
|
69 | + * Constructor |
|
70 | + * |
|
71 | + * @param string $key The key used for Encryption/Decryption |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public function __construct($key) |
|
75 | + { |
|
76 | + // the max length of the key is 448 bits (56 bytes) |
|
77 | + $keylen = strlen($key); |
|
78 | + if($keylen > 56) |
|
79 | + { |
|
80 | + $key = substr($key, 0, 56); |
|
81 | + $keylen = 56; |
|
82 | + } |
|
83 | + else if($keylen < 1) |
|
84 | + { |
|
85 | + $msg = "No key given. The key must be between 1 - 56 bytes."; |
|
86 | + trigger_error($msg, E_USER_WARNING); |
|
87 | + } |
|
88 | + |
|
89 | + // set the key, make sure the required length is set in bits |
|
90 | + parent::__construct(PHP_Crypt::CIPHER_BLOWFISH, $key, $keylen); |
|
91 | + |
|
92 | + // set the block size |
|
93 | + $this->blockSize(self::BYTES_BLOCK); |
|
94 | + |
|
95 | + $this->initTables(); |
|
96 | + $this->subKeys(); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Destructor |
|
102 | + * |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public function __destruct() |
|
106 | + { |
|
107 | + parent::__destruct(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Encrypt plain text data |
|
113 | + * |
|
114 | + * @param string $data A 64 bit (8 byte) plain text string |
|
115 | + * @return boolean Returns true |
|
116 | + */ |
|
117 | + public function encrypt(&$data) |
|
118 | + { |
|
119 | + $this->operation(parent::ENCRYPT); |
|
120 | + return $this->blowfish($data); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Decrypt an encrypted string |
|
126 | + * |
|
127 | + * @param string $data A 64 bit block of Blowfish encrypted data |
|
128 | + * @return boolean Returns true |
|
129 | + */ |
|
130 | + public function decrypt(&$data) |
|
131 | + { |
|
132 | + $this->operation(parent::DECRYPT); |
|
133 | + return $this->blowfish($data); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * The same alorigthm is used for both Encryption, and Decryption |
|
139 | + * |
|
140 | + * @param string $data A 64 bit block of data |
|
141 | + * @return boolean Returns true |
|
142 | + */ |
|
143 | + private function blowfish(&$data) |
|
144 | + { |
|
145 | + // divide the data into into two 32 bit halves |
|
146 | + $xl = parent::str2Dec(substr($data, 0, 4)); |
|
147 | + $xr = parent::str2Dec(substr($data, 4, 4)); |
|
148 | + |
|
149 | + for($i = 0; $i < 16; ++$i) |
|
150 | + { |
|
151 | + if($this->operation() == parent::ENCRYPT) |
|
152 | + $xl ^= self::$_p[$i]; |
|
153 | + else |
|
154 | + $xl ^= self::$_p[17-$i]; |
|
155 | + |
|
156 | + // perform F() on the left half, and XOR with the right half |
|
157 | + $xr = $this->F($xl) ^ $xr; |
|
158 | + |
|
159 | + // swap $xl and $xr |
|
160 | + $tmp = $xr; |
|
161 | + $xr = $xl; |
|
162 | + $xl = $tmp; |
|
163 | + } |
|
164 | + |
|
165 | + // swap $xl and $xr after the 16th round to undo the last swap |
|
166 | + $tmp = $xl; |
|
167 | + $xl = $xr; |
|
168 | + $xr = $tmp; |
|
169 | + |
|
170 | + // XOR the final two elements of $_p |
|
171 | + if($this->operation() == parent::ENCRYPT) |
|
172 | + { |
|
173 | + $xr ^= self::$_p[16]; |
|
174 | + $xl = $xl ^ self::$_p[17]; |
|
175 | + } |
|
176 | + else // parent::DECRYPT |
|
177 | + { |
|
178 | + $xr ^= self::$_p[1]; |
|
179 | + $xl ^= self::$_p[0]; |
|
180 | + } |
|
181 | + |
|
182 | + // recombine the two halves, force them to be 4 bytes each |
|
183 | + $data = parent::dec2Str($xl, 4).parent::dec2Str($xr, 4); |
|
184 | + |
|
185 | + return true; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Blowfish's F() function |
|
191 | + * |
|
192 | + * @param string $i A 32 bit integer |
|
193 | + */ |
|
194 | + private function F($i) |
|
195 | + { |
|
196 | + // split the 32 bits into four 8 bit parts |
|
197 | + $x[0] = $i & 0xff; // first byte |
|
198 | + $x[1] = ($i >> 8) & 0xff; // second byte |
|
199 | + $x[2] = ($i >> 16) & 0xff; // third byte |
|
200 | + $x[3] = ($i >> 24) & 0xff; // fourth byte |
|
201 | + |
|
202 | + // perform F(), make sure all values returned are |
|
203 | + // unsigned 32 bit |
|
204 | + $f = parent::uInt32(self::$_sbox1[$x[3]] + self::$_sbox2[$x[2]]); |
|
205 | + $f = parent::uInt32($f ^ self::$_sbox3[$x[1]]); |
|
206 | + $f = parent::uInt32($f + self::$_sbox4[$x[0]]); |
|
207 | + |
|
208 | + return $f; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Generates the subkeys used in Blowfish |
|
214 | + * |
|
215 | + * @return void |
|
216 | + */ |
|
217 | + private function subKeys() |
|
218 | + { |
|
219 | + // now xor each element of $_p with 32 bits from the key |
|
220 | + for($i = 0; $i < 18; ++$i) |
|
221 | + { |
|
222 | + $c = $this->keyChunk(4); |
|
223 | + self::$_p[$i] ^= parent::str2Dec($c); |
|
224 | + } |
|
225 | + |
|
226 | + // start with an 8 byte null string |
|
227 | + $zero = "\0\0\0\0\0\0\0\0"; |
|
228 | + |
|
229 | + // now we loop, each loop replacing elements of $_p, or an $_sbox with the |
|
230 | + // repeatedly encrypted zero string |
|
231 | + for($i = 0; $i < 1042; $i += 2) |
|
232 | + { |
|
233 | + // encrypt the 64 bit null string |
|
234 | + $this->encrypt($zero); |
|
235 | + |
|
236 | + // split the encrypted null string into two 32 bit parts |
|
237 | + $z0 = parent::str2Dec(substr($zero, 0, 4)); |
|
238 | + $z1 = parent::str2Dec(substr($zero, 4, 4)); |
|
239 | + |
|
240 | + // now fill the $_p, $_sbox1, $_sbox2, $_sbox3, $_sbox4 |
|
241 | + // with 4 bytes from the repeatedly encrypted 8 byte null string |
|
242 | + if($i < 18) |
|
243 | + { |
|
244 | + self::$_p[$i] = $z0; |
|
245 | + self::$_p[$i + 1] = $z1; |
|
246 | + } |
|
247 | + else if($i >= 18 && $i < 274) |
|
248 | + { |
|
249 | + self::$_sbox1[$i - 18] = $z0; |
|
250 | + self::$_sbox1[$i - 18 + 1] = $z1; |
|
251 | + } |
|
252 | + else if($i >= 274 && $i < 530) |
|
253 | + { |
|
254 | + self::$_sbox2[$i - 274] = $z0; |
|
255 | + self::$_sbox2[$i - 274 + 1] = $z1; |
|
256 | + } |
|
257 | + else if($i >= 530 && $i < 786) |
|
258 | + { |
|
259 | + self::$_sbox3[$i - 530] = $z0; |
|
260 | + self::$_sbox3[$i - 530 + 1] = $z1; |
|
261 | + } |
|
262 | + else if($i >= 786 && $i < 1042) |
|
263 | + { |
|
264 | + self::$_sbox4[$i -786] = $z0; |
|
265 | + self::$_sbox4[$i - 786 + 1] = $z1; |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Returns a substring of $this->key. The size of the substring is set in the |
|
273 | + * parameter $size. Each call to this function returns a substring starting |
|
274 | + * in the position where the last substring ended. Effectively it rotates |
|
275 | + * through the key, when it reaches the end, it starts over at the |
|
276 | + * beginning of the key and continues on. You can reset the current position |
|
277 | + * by setting the parameter $reset=true, which will start the key back at the |
|
278 | + * first byte of the $this->key string. |
|
279 | + * |
|
280 | + * @param integer $size The size of the substring to return, in bytes |
|
281 | + * @param bool $reset If set to true, sets the position back to 0, the first |
|
282 | + * byte of the key string |
|
283 | + * @return string The next substring of the key |
|
284 | + */ |
|
285 | + private function keyChunk($size = 1, $reset = false) |
|
286 | + { |
|
287 | + if($reset || $this->key_pos >= $this->keySize()) |
|
288 | + $this->key_pos = 0; |
|
289 | + |
|
290 | + $bytes = substr($this->key(), $this->key_pos, $size); |
|
291 | + $len = strlen($bytes); |
|
292 | + if($len < $size) |
|
293 | + { |
|
294 | + $bytes .= substr($this->key(), 0, $size - $len); |
|
295 | + $this->key_pos = $size - $len; |
|
296 | + } |
|
297 | + else |
|
298 | + $this->key_pos += $size; |
|
299 | + |
|
300 | + return $bytes; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Initialize the tables used in Blowfish Encryption. These |
|
306 | + * are calculated from the value of PI. We grabbed |
|
307 | + * these from the mcrypt blowfish source, which already had |
|
308 | + * these values calculated |
|
309 | + * |
|
310 | + * @return void |
|
311 | + */ |
|
312 | + private function initTables() |
|
313 | + { |
|
314 | + self::$_sbox1 = array( |
|
315 | + 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, |
|
316 | + 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, |
|
317 | + 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, |
|
318 | + 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, |
|
319 | + 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, |
|
320 | + 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, |
|
321 | + 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, |
|
322 | + 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, |
|
323 | + 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, |
|
324 | + 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, |
|
325 | + 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, |
|
326 | + 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, |
|
327 | + 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, |
|
328 | + 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, |
|
329 | + 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, |
|
330 | + 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, |
|
331 | + 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, |
|
332 | + 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, |
|
333 | + 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, |
|
334 | + 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, |
|
335 | + 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, |
|
336 | + 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, |
|
337 | + 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, |
|
338 | + 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, |
|
339 | + 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, |
|
340 | + 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, |
|
341 | + 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, |
|
342 | + 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, |
|
343 | + 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, |
|
344 | + 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, |
|
345 | + 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, |
|
346 | + 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, |
|
347 | + 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, |
|
348 | + 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, |
|
349 | + 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, |
|
350 | + 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, |
|
351 | + 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, |
|
352 | + 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, |
|
353 | + 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, |
|
354 | + 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, |
|
355 | + 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, |
|
356 | + 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, |
|
357 | + 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, |
|
358 | + 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, |
|
359 | + 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, |
|
360 | + 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, |
|
361 | + 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, |
|
362 | + 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, |
|
363 | + 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, |
|
364 | + 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, |
|
365 | + 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, |
|
366 | + 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, |
|
367 | + 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, |
|
368 | + 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, |
|
369 | + 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, |
|
370 | + 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, |
|
371 | + 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, |
|
372 | + 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, |
|
373 | + 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, |
|
374 | + 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, |
|
375 | + 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, |
|
376 | + 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, |
|
377 | + 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, |
|
378 | + 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a |
|
379 | + ); |
|
380 | + |
|
381 | + self::$_sbox2 = array( |
|
382 | + 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, |
|
383 | + 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, |
|
384 | + 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, |
|
385 | + 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, |
|
386 | + 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, |
|
387 | + 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, |
|
388 | + 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, |
|
389 | + 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, |
|
390 | + 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, |
|
391 | + 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, |
|
392 | + 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, |
|
393 | + 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, |
|
394 | + 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, |
|
395 | + 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, |
|
396 | + 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, |
|
397 | + 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, |
|
398 | + 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, |
|
399 | + 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, |
|
400 | + 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, |
|
401 | + 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, |
|
402 | + 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, |
|
403 | + 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, |
|
404 | + 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, |
|
405 | + 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, |
|
406 | + 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, |
|
407 | + 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, |
|
408 | + 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, |
|
409 | + 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, |
|
410 | + 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, |
|
411 | + 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, |
|
412 | + 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, |
|
413 | + 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, |
|
414 | + 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, |
|
415 | + 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, |
|
416 | + 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, |
|
417 | + 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, |
|
418 | + 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, |
|
419 | + 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, |
|
420 | + 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, |
|
421 | + 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, |
|
422 | + 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, |
|
423 | + 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, |
|
424 | + 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, |
|
425 | + 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, |
|
426 | + 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, |
|
427 | + 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, |
|
428 | + 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, |
|
429 | + 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, |
|
430 | + 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, |
|
431 | + 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, |
|
432 | + 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, |
|
433 | + 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, |
|
434 | + 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, |
|
435 | + 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, |
|
436 | + 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, |
|
437 | + 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, |
|
438 | + 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, |
|
439 | + 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, |
|
440 | + 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, |
|
441 | + 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, |
|
442 | + 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, |
|
443 | + 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, |
|
444 | + 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, |
|
445 | + 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 |
|
446 | + ); |
|
447 | + |
|
448 | + self::$_sbox3 = array( |
|
449 | + 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, |
|
450 | + 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, |
|
451 | + 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, |
|
452 | + 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, |
|
453 | + 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, |
|
454 | + 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, |
|
455 | + 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, |
|
456 | + 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, |
|
457 | + 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, |
|
458 | + 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, |
|
459 | + 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, |
|
460 | + 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, |
|
461 | + 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, |
|
462 | + 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, |
|
463 | + 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, |
|
464 | + 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, |
|
465 | + 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, |
|
466 | + 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, |
|
467 | + 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, |
|
468 | + 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, |
|
469 | + 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, |
|
470 | + 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, |
|
471 | + 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, |
|
472 | + 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, |
|
473 | + 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, |
|
474 | + 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, |
|
475 | + 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, |
|
476 | + 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, |
|
477 | + 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, |
|
478 | + 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, |
|
479 | + 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, |
|
480 | + 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, |
|
481 | + 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, |
|
482 | + 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, |
|
483 | + 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, |
|
484 | + 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, |
|
485 | + 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, |
|
486 | + 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, |
|
487 | + 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, |
|
488 | + 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, |
|
489 | + 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, |
|
490 | + 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, |
|
491 | + 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, |
|
492 | + 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, |
|
493 | + 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, |
|
494 | + 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, |
|
495 | + 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, |
|
496 | + 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, |
|
497 | + 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, |
|
498 | + 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, |
|
499 | + 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, |
|
500 | + 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, |
|
501 | + 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, |
|
502 | + 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, |
|
503 | + 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, |
|
504 | + 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, |
|
505 | + 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, |
|
506 | + 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, |
|
507 | + 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, |
|
508 | + 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, |
|
509 | + 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, |
|
510 | + 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, |
|
511 | + 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, |
|
512 | + 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 |
|
513 | + ); |
|
514 | + |
|
515 | + self::$_sbox4 = array( |
|
516 | + 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, |
|
517 | + 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, |
|
518 | + 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, |
|
519 | + 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, |
|
520 | + 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, |
|
521 | + 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, |
|
522 | + 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, |
|
523 | + 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, |
|
524 | + 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, |
|
525 | + 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, |
|
526 | + 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, |
|
527 | + 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, |
|
528 | + 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, |
|
529 | + 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, |
|
530 | + 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, |
|
531 | + 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, |
|
532 | + 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, |
|
533 | + 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, |
|
534 | + 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, |
|
535 | + 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, |
|
536 | + 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, |
|
537 | + 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, |
|
538 | + 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, |
|
539 | + 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, |
|
540 | + 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, |
|
541 | + 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, |
|
542 | + 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, |
|
543 | + 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, |
|
544 | + 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, |
|
545 | + 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, |
|
546 | + 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, |
|
547 | + 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, |
|
548 | + 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, |
|
549 | + 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, |
|
550 | + 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, |
|
551 | + 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, |
|
552 | + 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, |
|
553 | + 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, |
|
554 | + 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, |
|
555 | + 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, |
|
556 | + 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, |
|
557 | + 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, |
|
558 | + 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, |
|
559 | + 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, |
|
560 | + 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, |
|
561 | + 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, |
|
562 | + 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, |
|
563 | + 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, |
|
564 | + 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, |
|
565 | + 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, |
|
566 | + 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, |
|
567 | + 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, |
|
568 | + 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, |
|
569 | + 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, |
|
570 | + 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, |
|
571 | + 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, |
|
572 | + 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, |
|
573 | + 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, |
|
574 | + 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, |
|
575 | + 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, |
|
576 | + 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, |
|
577 | + 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, |
|
578 | + 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, |
|
579 | + 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 |
|
580 | + ); |
|
581 | + |
|
582 | + self::$_p = array( |
|
583 | + 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, |
|
584 | + 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, |
|
585 | + 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, |
|
586 | + 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, |
|
587 | + 0x9216d5d9, 0x8979fb1b |
|
588 | + ); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * Indicates this is a block cipher |
|
594 | + * |
|
595 | + * @return integer Returns Cipher::BLOCK |
|
596 | + */ |
|
597 | + public function type() |
|
598 | + { |
|
599 | + return parent::BLOCK; |
|
600 | + } |
|
601 | 601 | } |
602 | 602 | ?> |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | { |
76 | 76 | // the max length of the key is 448 bits (56 bytes) |
77 | 77 | $keylen = strlen($key); |
78 | - if($keylen > 56) |
|
78 | + if ($keylen > 56) |
|
79 | 79 | { |
80 | 80 | $key = substr($key, 0, 56); |
81 | 81 | $keylen = 56; |
82 | 82 | } |
83 | - else if($keylen < 1) |
|
83 | + else if ($keylen < 1) |
|
84 | 84 | { |
85 | - $msg = "No key given. The key must be between 1 - 56 bytes."; |
|
85 | + $msg = "No key given. The key must be between 1 - 56 bytes."; |
|
86 | 86 | trigger_error($msg, E_USER_WARNING); |
87 | 87 | } |
88 | 88 | |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | $xl = parent::str2Dec(substr($data, 0, 4)); |
147 | 147 | $xr = parent::str2Dec(substr($data, 4, 4)); |
148 | 148 | |
149 | - for($i = 0; $i < 16; ++$i) |
|
149 | + for ($i = 0; $i < 16; ++$i) |
|
150 | 150 | { |
151 | - if($this->operation() == parent::ENCRYPT) |
|
151 | + if ($this->operation() == parent::ENCRYPT) |
|
152 | 152 | $xl ^= self::$_p[$i]; |
153 | 153 | else |
154 | - $xl ^= self::$_p[17-$i]; |
|
154 | + $xl ^= self::$_p[17 - $i]; |
|
155 | 155 | |
156 | 156 | // perform F() on the left half, and XOR with the right half |
157 | 157 | $xr = $this->F($xl) ^ $xr; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $xr = $tmp; |
169 | 169 | |
170 | 170 | // XOR the final two elements of $_p |
171 | - if($this->operation() == parent::ENCRYPT) |
|
171 | + if ($this->operation() == parent::ENCRYPT) |
|
172 | 172 | { |
173 | 173 | $xr ^= self::$_p[16]; |
174 | 174 | $xl = $xl ^ self::$_p[17]; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | { |
196 | 196 | // split the 32 bits into four 8 bit parts |
197 | 197 | $x[0] = $i & 0xff; // first byte |
198 | - $x[1] = ($i >> 8) & 0xff; // second byte |
|
198 | + $x[1] = ($i >> 8) & 0xff; // second byte |
|
199 | 199 | $x[2] = ($i >> 16) & 0xff; // third byte |
200 | 200 | $x[3] = ($i >> 24) & 0xff; // fourth byte |
201 | 201 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | private function subKeys() |
218 | 218 | { |
219 | 219 | // now xor each element of $_p with 32 bits from the key |
220 | - for($i = 0; $i < 18; ++$i) |
|
220 | + for ($i = 0; $i < 18; ++$i) |
|
221 | 221 | { |
222 | 222 | $c = $this->keyChunk(4); |
223 | 223 | self::$_p[$i] ^= parent::str2Dec($c); |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | |
229 | 229 | // now we loop, each loop replacing elements of $_p, or an $_sbox with the |
230 | 230 | // repeatedly encrypted zero string |
231 | - for($i = 0; $i < 1042; $i += 2) |
|
231 | + for ($i = 0; $i < 1042; $i += 2) |
|
232 | 232 | { |
233 | 233 | // encrypt the 64 bit null string |
234 | 234 | $this->encrypt($zero); |
@@ -239,29 +239,29 @@ discard block |
||
239 | 239 | |
240 | 240 | // now fill the $_p, $_sbox1, $_sbox2, $_sbox3, $_sbox4 |
241 | 241 | // with 4 bytes from the repeatedly encrypted 8 byte null string |
242 | - if($i < 18) |
|
242 | + if ($i < 18) |
|
243 | 243 | { |
244 | 244 | self::$_p[$i] = $z0; |
245 | 245 | self::$_p[$i + 1] = $z1; |
246 | 246 | } |
247 | - else if($i >= 18 && $i < 274) |
|
247 | + else if ($i >= 18 && $i < 274) |
|
248 | 248 | { |
249 | 249 | self::$_sbox1[$i - 18] = $z0; |
250 | 250 | self::$_sbox1[$i - 18 + 1] = $z1; |
251 | 251 | } |
252 | - else if($i >= 274 && $i < 530) |
|
252 | + else if ($i >= 274 && $i < 530) |
|
253 | 253 | { |
254 | 254 | self::$_sbox2[$i - 274] = $z0; |
255 | 255 | self::$_sbox2[$i - 274 + 1] = $z1; |
256 | 256 | } |
257 | - else if($i >= 530 && $i < 786) |
|
257 | + else if ($i >= 530 && $i < 786) |
|
258 | 258 | { |
259 | 259 | self::$_sbox3[$i - 530] = $z0; |
260 | 260 | self::$_sbox3[$i - 530 + 1] = $z1; |
261 | 261 | } |
262 | - else if($i >= 786 && $i < 1042) |
|
262 | + else if ($i >= 786 && $i < 1042) |
|
263 | 263 | { |
264 | - self::$_sbox4[$i -786] = $z0; |
|
264 | + self::$_sbox4[$i - 786] = $z0; |
|
265 | 265 | self::$_sbox4[$i - 786 + 1] = $z1; |
266 | 266 | } |
267 | 267 | } |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | */ |
285 | 285 | private function keyChunk($size = 1, $reset = false) |
286 | 286 | { |
287 | - if($reset || $this->key_pos >= $this->keySize()) |
|
287 | + if ($reset || $this->key_pos >= $this->keySize()) |
|
288 | 288 | $this->key_pos = 0; |
289 | 289 | |
290 | 290 | $bytes = substr($this->key(), $this->key_pos, $size); |
291 | 291 | $len = strlen($bytes); |
292 | - if($len < $size) |
|
292 | + if ($len < $size) |
|
293 | 293 | { |
294 | 294 | $bytes .= substr($this->key(), 0, $size - $len); |
295 | 295 | $this->key_pos = $size - $len; |
@@ -79,8 +79,7 @@ discard block |
||
79 | 79 | { |
80 | 80 | $key = substr($key, 0, 56); |
81 | 81 | $keylen = 56; |
82 | - } |
|
83 | - else if($keylen < 1) |
|
82 | + } else if($keylen < 1) |
|
84 | 83 | { |
85 | 84 | $msg = "No key given. The key must be between 1 - 56 bytes."; |
86 | 85 | trigger_error($msg, E_USER_WARNING); |
@@ -148,10 +147,11 @@ discard block |
||
148 | 147 | |
149 | 148 | for($i = 0; $i < 16; ++$i) |
150 | 149 | { |
151 | - if($this->operation() == parent::ENCRYPT) |
|
152 | - $xl ^= self::$_p[$i]; |
|
153 | - else |
|
154 | - $xl ^= self::$_p[17-$i]; |
|
150 | + if($this->operation() == parent::ENCRYPT) { |
|
151 | + $xl ^= self::$_p[$i]; |
|
152 | + } else { |
|
153 | + $xl ^= self::$_p[17-$i]; |
|
154 | + } |
|
155 | 155 | |
156 | 156 | // perform F() on the left half, and XOR with the right half |
157 | 157 | $xr = $this->F($xl) ^ $xr; |
@@ -172,8 +172,7 @@ discard block |
||
172 | 172 | { |
173 | 173 | $xr ^= self::$_p[16]; |
174 | 174 | $xl = $xl ^ self::$_p[17]; |
175 | - } |
|
176 | - else // parent::DECRYPT |
|
175 | + } else // parent::DECRYPT |
|
177 | 176 | { |
178 | 177 | $xr ^= self::$_p[1]; |
179 | 178 | $xl ^= self::$_p[0]; |
@@ -243,23 +242,19 @@ discard block |
||
243 | 242 | { |
244 | 243 | self::$_p[$i] = $z0; |
245 | 244 | self::$_p[$i + 1] = $z1; |
246 | - } |
|
247 | - else if($i >= 18 && $i < 274) |
|
245 | + } else if($i >= 18 && $i < 274) |
|
248 | 246 | { |
249 | 247 | self::$_sbox1[$i - 18] = $z0; |
250 | 248 | self::$_sbox1[$i - 18 + 1] = $z1; |
251 | - } |
|
252 | - else if($i >= 274 && $i < 530) |
|
249 | + } else if($i >= 274 && $i < 530) |
|
253 | 250 | { |
254 | 251 | self::$_sbox2[$i - 274] = $z0; |
255 | 252 | self::$_sbox2[$i - 274 + 1] = $z1; |
256 | - } |
|
257 | - else if($i >= 530 && $i < 786) |
|
253 | + } else if($i >= 530 && $i < 786) |
|
258 | 254 | { |
259 | 255 | self::$_sbox3[$i - 530] = $z0; |
260 | 256 | self::$_sbox3[$i - 530 + 1] = $z1; |
261 | - } |
|
262 | - else if($i >= 786 && $i < 1042) |
|
257 | + } else if($i >= 786 && $i < 1042) |
|
263 | 258 | { |
264 | 259 | self::$_sbox4[$i -786] = $z0; |
265 | 260 | self::$_sbox4[$i - 786 + 1] = $z1; |
@@ -284,8 +279,9 @@ discard block |
||
284 | 279 | */ |
285 | 280 | private function keyChunk($size = 1, $reset = false) |
286 | 281 | { |
287 | - if($reset || $this->key_pos >= $this->keySize()) |
|
288 | - $this->key_pos = 0; |
|
282 | + if($reset || $this->key_pos >= $this->keySize()) { |
|
283 | + $this->key_pos = 0; |
|
284 | + } |
|
289 | 285 | |
290 | 286 | $bytes = substr($this->key(), $this->key_pos, $size); |
291 | 287 | $len = strlen($bytes); |
@@ -293,9 +289,9 @@ discard block |
||
293 | 289 | { |
294 | 290 | $bytes .= substr($this->key(), 0, $size - $len); |
295 | 291 | $this->key_pos = $size - $len; |
292 | + } else { |
|
293 | + $this->key_pos += $size; |
|
296 | 294 | } |
297 | - else |
|
298 | - $this->key_pos += $size; |
|
299 | 295 | |
300 | 296 | return $bytes; |
301 | 297 | } |