@@ -163,19 +163,19 @@ |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * Get MD5 as binary string |
|
| 167 | - * @param string $string |
|
| 168 | - */ |
|
| 166 | + * Get MD5 as binary string |
|
| 167 | + * @param string $string |
|
| 168 | + */ |
|
| 169 | 169 | function _md5_16($string) |
| 170 | 170 | { |
| 171 | 171 | return pack('H*', md5($string)); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | - * Compute O value |
|
| 176 | - * @param string $user_pass |
|
| 177 | - * @param string $owner_pass |
|
| 178 | - */ |
|
| 175 | + * Compute O value |
|
| 176 | + * @param string $user_pass |
|
| 177 | + * @param string $owner_pass |
|
| 178 | + */ |
|
| 179 | 179 | function _Ovalue($user_pass, $owner_pass) |
| 180 | 180 | { |
| 181 | 181 | $tmp = $this->_md5_16($owner_pass); |
@@ -224,15 +224,17 @@ discard block |
||
| 224 | 224 | function SetDisplayMode($zoom, $layout = 'default') |
| 225 | 225 | { |
| 226 | 226 | // Set display mode in viewer |
| 227 | - if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' || $zoom == 'default' || !is_string($zoom)) |
|
| 228 | - $this->ZoomMode = $zoom; |
|
| 229 | - else |
|
| 230 | - $this->Error('Incorrect zoom display mode: '.$zoom); |
|
| 231 | - if ($layout == 'single' || $layout == 'continuous' || $layout == 'two' || $layout == 'default') |
|
| 232 | - $this->LayoutMode = $layout; |
|
| 233 | - else |
|
| 234 | - $this->Error('Incorrect layout display mode: '.$layout); |
|
| 235 | -} |
|
| 227 | + if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' || $zoom == 'default' || !is_string($zoom)) { |
|
| 228 | + $this->ZoomMode = $zoom; |
|
| 229 | + } else { |
|
| 230 | + $this->Error('Incorrect zoom display mode: '.$zoom); |
|
| 231 | + } |
|
| 232 | + if ($layout == 'single' || $layout == 'continuous' || $layout == 'two' || $layout == 'default') { |
|
| 233 | + $this->LayoutMode = $layout; |
|
| 234 | + } else { |
|
| 235 | + $this->Error('Incorrect layout display mode: '.$layout); |
|
| 236 | + } |
|
| 237 | + } |
|
| 236 | 238 | |
| 237 | 239 | /** |
| 238 | 240 | * @param boolean $compress |
@@ -513,23 +515,23 @@ discard block |
||
| 513 | 515 | // Add a TrueType, OpenType or Type1 font |
| 514 | 516 | $family = strtolower($family); |
| 515 | 517 | $style = strtoupper($style); |
| 516 | - if ($style == 'IB') |
|
| 517 | - $style = 'BI'; |
|
| 518 | + if ($style == 'IB') { |
|
| 519 | + $style = 'BI'; |
|
| 520 | + } |
|
| 518 | 521 | if ($file == '') { |
| 519 | 522 | if ($uni) { |
| 520 | 523 | $file = str_replace(' ', '', $family).strtolower($style).'.ttf'; |
| 521 | - } |
|
| 522 | - else { |
|
| 524 | + } else { |
|
| 523 | 525 | $file = str_replace(' ', '', $family).strtolower($style).'.php'; |
| 524 | 526 | } |
| 525 | 527 | } |
| 526 | 528 | $fontkey = $family.$style; |
| 527 | - if (isset($this->fonts[$fontkey])) |
|
| 528 | - return; |
|
| 529 | + if (isset($this->fonts[$fontkey])) { |
|
| 530 | + return; |
|
| 531 | + } |
|
| 529 | 532 | |
| 530 | 533 | if ($uni) { |
| 531 | - if (defined("_SYSTEM_TTFONTS") && file_exists(_SYSTEM_TTFONTS.$file)) { $ttffilename = _SYSTEM_TTFONTS.$file; } |
|
| 532 | - else { $ttffilename = $this->_getfontpath().'unifont/'.$file; } |
|
| 534 | + if (defined("_SYSTEM_TTFONTS") && file_exists(_SYSTEM_TTFONTS.$file)) { $ttffilename = _SYSTEM_TTFONTS.$file; } else { $ttffilename = $this->_getfontpath().'unifont/'.$file; } |
|
| 533 | 535 | $unifilename = $this->_getfontpath().'unifont/'.strtolower(substr($file, 0, (strpos($file, '.')))); |
| 534 | 536 | $name = ''; |
| 535 | 537 | $originalsize = 0; |
@@ -2410,18 +2412,19 @@ discard block |
||
| 2410 | 2412 | for ($i = 0; $i < $len; $i++) { |
| 2411 | 2413 | $uni = -1; |
| 2412 | 2414 | $h = ord($str[$i]); |
| 2413 | - if ($h <= 0x7F) |
|
| 2414 | - $uni = $h; |
|
| 2415 | - elseif ($h >= 0xC2) { |
|
| 2416 | - if (($h <= 0xDF) && ($i < $len - 1)) |
|
| 2417 | - $uni = ($h & 0x1F) << 6 | (ord($str[++$i]) & 0x3F); |
|
| 2418 | - elseif (($h <= 0xEF) && ($i < $len - 2)) |
|
| 2419 | - $uni = ($h & 0x0F) << 12 | (ord($str[++$i]) & 0x3F) << 6 |
|
| 2415 | + if ($h <= 0x7F) { |
|
| 2416 | + $uni = $h; |
|
| 2417 | + } elseif ($h >= 0xC2) { |
|
| 2418 | + if (($h <= 0xDF) && ($i < $len - 1)) { |
|
| 2419 | + $uni = ($h & 0x1F) << 6 | (ord($str[++$i]) & 0x3F); |
|
| 2420 | + } elseif (($h <= 0xEF) && ($i < $len - 2)) { |
|
| 2421 | + $uni = ($h & 0x0F) << 12 | (ord($str[++$i]) & 0x3F) << 6 |
|
| 2420 | 2422 | | (ord($str[++$i]) & 0x3F); |
| 2421 | - elseif (($h <= 0xF4) && ($i < $len - 3)) |
|
| 2422 | - $uni = ($h & 0x0F) << 18 | (ord($str[++$i]) & 0x3F) << 12 |
|
| 2423 | + } elseif (($h <= 0xF4) && ($i < $len - 3)) { |
|
| 2424 | + $uni = ($h & 0x0F) << 18 | (ord($str[++$i]) & 0x3F) << 12 |
|
| 2423 | 2425 | | (ord($str[++$i]) & 0x3F) << 6 |
| 2424 | 2426 | | (ord($str[++$i]) & 0x3F); |
| 2427 | + } |
|
| 2425 | 2428 | } |
| 2426 | 2429 | if ($uni >= 0) { |
| 2427 | 2430 | $out[] = $uni; |
@@ -67,8 +67,9 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | // if we do not have an even number of hex characters |
| 69 | 69 | // append a 0 to the beginning to make it even |
| 70 | - if (strlen($hex) % 2) |
|
| 71 | - $hex = "0$hex"; |
|
| 70 | + if (strlen($hex) % 2) { |
|
| 71 | + $hex = "0$hex"; |
|
| 72 | + } |
|
| 72 | 73 | |
| 73 | 74 | $parts = str_split($hex, 2); |
| 74 | 75 | $parts = array_map(function($v) { |
@@ -90,8 +91,9 @@ discard block |
||
| 90 | 91 | { |
| 91 | 92 | // php version >= 5.4 have a hex2bin function, use it |
| 92 | 93 | // if it exists |
| 93 | - if (function_exists("hex2bin")) |
|
| 94 | - return hex2bin($hex); |
|
| 94 | + if (function_exists("hex2bin")) { |
|
| 95 | + return hex2bin($hex); |
|
| 96 | + } |
|
| 95 | 97 | |
| 96 | 98 | $parts = str_split($hex, 2); |
| 97 | 99 | $parts = array_map(function($v) { |
@@ -235,14 +237,16 @@ discard block |
||
| 235 | 237 | |
| 236 | 238 | // if we do not have an even number of hex characters |
| 237 | 239 | // append a 0 to the beginning. dechex() drops leading 0's |
| 238 | - if (strlen($hex) % 2) |
|
| 239 | - $hex = "0$hex"; |
|
| 240 | + if (strlen($hex) % 2) { |
|
| 241 | + $hex = "0$hex"; |
|
| 242 | + } |
|
| 240 | 243 | |
| 241 | 244 | // if the number of bytes in the hex is less than |
| 242 | 245 | // what we need it to be, add null bytes to the |
| 243 | 246 | // front of the hex to padd it to the required size |
| 244 | - if (($req_bytes * 2) > strlen($hex)) |
|
| 245 | - $hex = str_pad($hex, ($req_bytes * 2), "0", STR_PAD_LEFT); |
|
| 247 | + if (($req_bytes * 2) > strlen($hex)) { |
|
| 248 | + $hex = str_pad($hex, ($req_bytes * 2), "0", STR_PAD_LEFT); |
|
| 249 | + } |
|
| 246 | 250 | |
| 247 | 251 | return $hex; |
| 248 | 252 | } |
@@ -306,8 +310,7 @@ discard block |
||
| 306 | 310 | { |
| 307 | 311 | $width = $len_a; |
| 308 | 312 | $b = str_pad($b, $width, "0", STR_PAD_LEFT); |
| 309 | - } |
|
| 310 | - else if ($len_a < $len_b) |
|
| 313 | + } else if ($len_a < $len_b) |
|
| 311 | 314 | { |
| 312 | 315 | $width = $len_b; |
| 313 | 316 | $a = str_pad($a, $width, "0", STR_PAD_LEFT); |
@@ -334,13 +337,15 @@ discard block |
||
| 334 | 337 | $count = func_num_args(); |
| 335 | 338 | |
| 336 | 339 | // we need a minimum of 2 values |
| 337 | - if ($count < 2) |
|
| 338 | - return false; |
|
| 340 | + if ($count < 2) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 339 | 343 | |
| 340 | 344 | // first get all hex values to an even number |
| 341 | 345 | array_walk($hex, function(&$val, $i) { |
| 342 | - if (strlen($val) % 2) |
|
| 343 | - $val = "0".$val; |
|
| 346 | + if (strlen($val) % 2) { |
|
| 347 | + $val = "0".$val; |
|
| 348 | + } |
|
| 344 | 349 | }); |
| 345 | 350 | |
| 346 | 351 | $res = 0; |
@@ -348,9 +353,9 @@ discard block |
||
| 348 | 353 | { |
| 349 | 354 | // if this is the first loop, set the 'result' to the first |
| 350 | 355 | // hex value |
| 351 | - if ($i == 0) |
|
| 352 | - $res = $hex[0]; |
|
| 353 | - else |
|
| 356 | + if ($i == 0) { |
|
| 357 | + $res = $hex[0]; |
|
| 358 | + } else |
|
| 354 | 359 | { |
| 355 | 360 | // to make the code easier to follow |
| 356 | 361 | $h1 = $res; |
@@ -362,10 +367,11 @@ discard block |
||
| 362 | 367 | |
| 363 | 368 | // now check that both hex values are the same length, |
| 364 | 369 | // if not pad them with 0's until they are |
| 365 | - if ($len1 > $len2) |
|
| 366 | - $h2 = str_pad($h2, $len1, "0", STR_PAD_LEFT); |
|
| 367 | - else if ($len1 < $len2) |
|
| 368 | - $h1 = str_pad($h1, $len2, "0", STR_PAD_LEFT); |
|
| 370 | + if ($len1 > $len2) { |
|
| 371 | + $h2 = str_pad($h2, $len1, "0", STR_PAD_LEFT); |
|
| 372 | + } else if ($len1 < $len2) { |
|
| 373 | + $h1 = str_pad($h1, $len2, "0", STR_PAD_LEFT); |
|
| 374 | + } |
|
| 369 | 375 | |
| 370 | 376 | // PHP knows how to XOR each byte in a string, so convert the |
| 371 | 377 | // hex to a string, XOR, and convert back |
@@ -407,8 +413,10 @@ discard block |
||
| 407 | 413 | // the same negative number given to it, the work around is |
| 408 | 414 | // to use sprintf(). |
| 409 | 415 | // Tested with php 5.3.x on Windows XP & Linux 32bit |
| 410 | - if ($ret < 0) |
|
| 411 | - $ret = sprintf("%u", $ret) + 0; // convert from string to int |
|
| 416 | + if ($ret < 0) { |
|
| 417 | + $ret = sprintf("%u", $ret) + 0; |
|
| 418 | + } |
|
| 419 | + // convert from string to int |
|
| 412 | 420 | |
| 413 | 421 | return $ret; |
| 414 | 422 | } |
@@ -422,9 +430,10 @@ discard block |
||
| 422 | 430 | */ |
| 423 | 431 | public static function sInt32($int) |
| 424 | 432 | { |
| 425 | - if (PHP_INT_SIZE === 4) // 32 bit |
|
| 433 | + if (PHP_INT_SIZE === 4) { |
|
| 434 | + // 32 bit |
|
| 426 | 435 | return self::sInt($int); |
| 427 | - else // PHP_INT_SIZE === 8 // 64 bit |
|
| 436 | + } else // PHP_INT_SIZE === 8 // 64 bit |
|
| 428 | 437 | { |
| 429 | 438 | $arr = unpack("l", pack("l", $int)); |
| 430 | 439 | return $arr[1]; |
@@ -440,9 +449,10 @@ discard block |
||
| 440 | 449 | */ |
| 441 | 450 | public static function uInt32($int) |
| 442 | 451 | { |
| 443 | - if (PHP_INT_SIZE === 4) // 32 bit |
|
| 452 | + if (PHP_INT_SIZE === 4) { |
|
| 453 | + // 32 bit |
|
| 444 | 454 | return self::uInt($int); |
| 445 | - else // PHP_INT_SIZE === 8 // 64 bit |
|
| 455 | + } else // PHP_INT_SIZE === 8 // 64 bit |
|
| 446 | 456 | { |
| 447 | 457 | $arr = unpack("L", pack("L", $int)); |
| 448 | 458 | return $arr[1]; |
@@ -484,8 +494,9 @@ discard block |
||
| 484 | 494 | */ |
| 485 | 495 | public static function rotBitsLeft32($i, $shifts) |
| 486 | 496 | { |
| 487 | - if ($shifts <= 0) |
|
| 488 | - return $i; |
|
| 497 | + if ($shifts <= 0) { |
|
| 498 | + return $i; |
|
| 499 | + } |
|
| 489 | 500 | |
| 490 | 501 | $shifts &= 0x1f; /* higher rotates would not bring anything */ |
| 491 | 502 | |
@@ -509,8 +520,9 @@ discard block |
||
| 509 | 520 | */ |
| 510 | 521 | public static function rotBitsRight32($i, $shifts) |
| 511 | 522 | { |
| 512 | - if ($shifts <= 0) |
|
| 513 | - return $i; |
|
| 523 | + if ($shifts <= 0) { |
|
| 524 | + return $i; |
|
| 525 | + } |
|
| 514 | 526 | |
| 515 | 527 | $shifts &= 0x1f; /* higher rotates would not bring anything */ |
| 516 | 528 | |
@@ -547,19 +559,19 @@ discard block |
||
| 547 | 559 | |
| 548 | 560 | if ($src == PHP_Crypt::RAND_DEV_RAND) |
| 549 | 561 | { |
| 550 | - if (file_exists(PHP_Crypt::RAND_DEV_RAND)) |
|
| 551 | - $bytes = file_get_contents(PHP_CRYPT::RAND_DEV_RAND, false, null, 0, $byte_len); |
|
| 552 | - else |
|
| 553 | - $err_msg = PHP_Crypt::RAND_DEV_RAND." not found"; |
|
| 554 | - } |
|
| 555 | - else if ($src == PHP_Crypt::RAND_DEV_URAND) |
|
| 562 | + if (file_exists(PHP_Crypt::RAND_DEV_RAND)) { |
|
| 563 | + $bytes = file_get_contents(PHP_CRYPT::RAND_DEV_RAND, false, null, 0, $byte_len); |
|
| 564 | + } else { |
|
| 565 | + $err_msg = PHP_Crypt::RAND_DEV_RAND." not found"; |
|
| 566 | + } |
|
| 567 | + } else if ($src == PHP_Crypt::RAND_DEV_URAND) |
|
| 556 | 568 | { |
| 557 | - if (file_exists(PHP_Crypt::RAND_DEV_URAND)) |
|
| 558 | - $bytes = file_get_contents(PHP_CRYPT::RAND_DEV_URAND, false, null, 0, $byte_len); |
|
| 559 | - else |
|
| 560 | - $err_msg = PHP_Crypt::RAND_DEV_URAND." not found"; |
|
| 561 | - } |
|
| 562 | - else if ($src == PHP_Crypt::RAND_WIN_COM) |
|
| 569 | + if (file_exists(PHP_Crypt::RAND_DEV_URAND)) { |
|
| 570 | + $bytes = file_get_contents(PHP_CRYPT::RAND_DEV_URAND, false, null, 0, $byte_len); |
|
| 571 | + } else { |
|
| 572 | + $err_msg = PHP_Crypt::RAND_DEV_URAND." not found"; |
|
| 573 | + } |
|
| 574 | + } else if ($src == PHP_Crypt::RAND_WIN_COM) |
|
| 563 | 575 | { |
| 564 | 576 | if (extension_loaded('com_dotnet')) |
| 565 | 577 | { |
@@ -571,22 +583,23 @@ discard block |
||
| 571 | 583 | // binary data on Windows |
| 572 | 584 | $com = @new \COM("CAPICOM.Utilities.1"); |
| 573 | 585 | $bytes = $com->GetRandom($byte_len, 0); |
| 574 | - } |
|
| 575 | - catch (Exception $e) |
|
| 586 | + } catch (Exception $e) |
|
| 576 | 587 | { |
| 577 | 588 | $err_msg = "Windows COM exception: ".$e->getMessage(); |
| 578 | 589 | } |
| 579 | 590 | |
| 580 | - if (!$bytes) |
|
| 581 | - $err_msg = "Windows COM failed to create random string of bytes"; |
|
| 591 | + if (!$bytes) { |
|
| 592 | + $err_msg = "Windows COM failed to create random string of bytes"; |
|
| 593 | + } |
|
| 594 | + } else { |
|
| 595 | + $err_msg = "The COM_DOTNET extension is not loaded"; |
|
| 582 | 596 | } |
| 583 | - else |
|
| 584 | - $err_msg = "The COM_DOTNET extension is not loaded"; |
|
| 585 | 597 | } |
| 586 | 598 | |
| 587 | 599 | // trigger a warning if something went wrong |
| 588 | - if ($err_msg != "") |
|
| 589 | - trigger_error("$err_msg. Defaulting to PHP_Crypt::RAND", E_USER_WARNING); |
|
| 600 | + if ($err_msg != "") { |
|
| 601 | + trigger_error("$err_msg. Defaulting to PHP_Crypt::RAND", E_USER_WARNING); |
|
| 602 | + } |
|
| 590 | 603 | |
| 591 | 604 | // if the random bytes where not created properly or PHP_Crypt::RAND was |
| 592 | 605 | // passed as the $src param, create the bytes using mt_rand(). It's not |
@@ -597,8 +610,9 @@ discard block |
||
| 597 | 610 | |
| 598 | 611 | // md5() hash a random number to get a 16 byte string, keep looping |
| 599 | 612 | // until we have a string as long or longer than the ciphers block size |
| 600 | - for ($i = 0; ($i * self::HASH_LEN) < $byte_len; ++$i) |
|
| 601 | - $bytes .= md5(mt_rand(), true); |
|
| 613 | + for ($i = 0; ($i * self::HASH_LEN) < $byte_len; ++$i) { |
|
| 614 | + $bytes .= md5(mt_rand(), true); |
|
| 615 | + } |
|
| 602 | 616 | } |
| 603 | 617 | |
| 604 | 618 | // because $bytes may have come from mt_rand() or /dev/urandom which are not |
@@ -611,8 +625,9 @@ discard block |
||
| 611 | 625 | // some ciphers which have a block size larger than 16 bytes |
| 612 | 626 | $tmp = ""; |
| 613 | 627 | $loop = ceil(strlen($bytes) / self::HASH_LEN); |
| 614 | - for ($i = 0; $i < $loop; ++$i) |
|
| 615 | - $tmp .= md5(substr($bytes, ($i * self::HASH_LEN), self::HASH_LEN), true); |
|
| 628 | + for ($i = 0; $i < $loop; ++$i) { |
|
| 629 | + $tmp .= md5(substr($bytes, ($i * self::HASH_LEN), self::HASH_LEN), true); |
|
| 630 | + } |
|
| 616 | 631 | |
| 617 | 632 | // grab the number of bytes equal to the requested $byte_len |
| 618 | 633 | return substr($tmp, 0, $byte_len); |
@@ -67,8 +67,9 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | // if the size of padding is not greater than 1 |
| 69 | 69 | // just return true, no padding will be done |
| 70 | - if (!($bytes > 0)) |
|
| 71 | - return true; |
|
| 70 | + if (!($bytes > 0)) { |
|
| 71 | + return true; |
|
| 72 | + } |
|
| 72 | 73 | |
| 73 | 74 | switch ($type) |
| 74 | 75 | { |
@@ -196,11 +197,11 @@ discard block |
||
| 196 | 197 | $pos = strlen($text) - 1; |
| 197 | 198 | $c = ord($text[$pos]); |
| 198 | 199 | |
| 199 | - if ($c == 0) |
|
| 200 | - return true; |
|
| 201 | - else if ($c == 1) |
|
| 202 | - $text = substr($text, 0, -1); |
|
| 203 | - else |
|
| 200 | + if ($c == 0) { |
|
| 201 | + return true; |
|
| 202 | + } else if ($c == 1) { |
|
| 203 | + $text = substr($text, 0, -1); |
|
| 204 | + } else |
|
| 204 | 205 | { |
| 205 | 206 | // the total null bytes are 1 less than the value of the final byte |
| 206 | 207 | $nc = $c - 1; |
@@ -226,8 +227,9 @@ discard block |
||
| 226 | 227 | // create the random pad bytes, we do one less than |
| 227 | 228 | // needed because the last byte is reserved for the |
| 228 | 229 | // number of padded bytes |
| 229 | - for ($i = 0; $i < ($bytes - 1); ++$i) |
|
| 230 | - $text .= chr(mt_rand(0, 255)); |
|
| 230 | + for ($i = 0; $i < ($bytes - 1); ++$i) { |
|
| 231 | + $text .= chr(mt_rand(0, 255)); |
|
| 232 | + } |
|
| 231 | 233 | |
| 232 | 234 | // add the byte to indicate the padding length |
| 233 | 235 | $text .= chr($bytes); |
@@ -248,8 +250,9 @@ discard block |
||
| 248 | 250 | |
| 249 | 251 | // if we got a null byte at the end of the string, |
| 250 | 252 | // just return |
| 251 | - if ($c == 0) |
|
| 252 | - return true; |
|
| 253 | + if ($c == 0) { |
|
| 254 | + return true; |
|
| 255 | + } |
|
| 253 | 256 | |
| 254 | 257 | $text = substr($text, 0, $c); |
| 255 | 258 | return true; |
@@ -285,8 +288,9 @@ discard block |
||
| 285 | 288 | $pos = strlen($text) - 1; |
| 286 | 289 | $c = ord($text[$pos]); |
| 287 | 290 | |
| 288 | - if ($c == 0) |
|
| 289 | - return true; |
|
| 291 | + if ($c == 0) { |
|
| 292 | + return true; |
|
| 293 | + } |
|
| 290 | 294 | |
| 291 | 295 | $text = preg_replace('/'.preg_quote(chr($c)).'{'.$c.'}$/', "", $text); |
| 292 | 296 | return true; |
@@ -309,8 +313,9 @@ discard block |
||
| 309 | 313 | |
| 310 | 314 | // if we are only padding one byte, then 0x80 is all we need |
| 311 | 315 | // else we follow up with null bytes |
| 312 | - if ($bytes > 1) |
|
| 313 | - $text = str_pad($text, ($len - 1), chr(0), STR_PAD_RIGHT); |
|
| 316 | + if ($bytes > 1) { |
|
| 317 | + $text = str_pad($text, ($len - 1), chr(0), STR_PAD_RIGHT); |
|
| 318 | + } |
|
| 314 | 319 | |
| 315 | 320 | return true; |
| 316 | 321 | } |
@@ -99,17 +99,21 @@ discard block |
||
| 99 | 99 | $pos = (4 * $i) - 4; |
| 100 | 100 | $subkey = substr($this->expanded_key, $pos, 4); |
| 101 | 101 | |
| 102 | - if ($i >= 1 && $i <= 8) |
|
| 103 | - $this->ruleA($text, $subkey, $i); |
|
| 102 | + if ($i >= 1 && $i <= 8) { |
|
| 103 | + $this->ruleA($text, $subkey, $i); |
|
| 104 | + } |
|
| 104 | 105 | |
| 105 | - if ($i >= 9 && $i <= 16) |
|
| 106 | - $this->ruleB($text, $subkey, $i); |
|
| 106 | + if ($i >= 9 && $i <= 16) { |
|
| 107 | + $this->ruleB($text, $subkey, $i); |
|
| 108 | + } |
|
| 107 | 109 | |
| 108 | - if ($i >= 17 && $i <= 24) |
|
| 109 | - $this->ruleA($text, $subkey, $i); |
|
| 110 | + if ($i >= 17 && $i <= 24) { |
|
| 111 | + $this->ruleA($text, $subkey, $i); |
|
| 112 | + } |
|
| 110 | 113 | |
| 111 | - if ($i >= 25 && $i <= 32) |
|
| 112 | - $this->ruleB($text, $subkey, $i); |
|
| 114 | + if ($i >= 25 && $i <= 32) { |
|
| 115 | + $this->ruleB($text, $subkey, $i); |
|
| 116 | + } |
|
| 113 | 117 | } |
| 114 | 118 | |
| 115 | 119 | return true; |
@@ -130,17 +134,21 @@ discard block |
||
| 130 | 134 | $pos = ($i - 1) * 4; |
| 131 | 135 | $subkey = substr($this->expanded_key, $pos, 4); |
| 132 | 136 | |
| 133 | - if ($i <= 32 && $i >= 25) |
|
| 134 | - $this->ruleB($text, $subkey, $i); |
|
| 137 | + if ($i <= 32 && $i >= 25) { |
|
| 138 | + $this->ruleB($text, $subkey, $i); |
|
| 139 | + } |
|
| 135 | 140 | |
| 136 | - if ($i <= 24 && $i >= 17) |
|
| 137 | - $this->ruleA($text, $subkey, $i); |
|
| 141 | + if ($i <= 24 && $i >= 17) { |
|
| 142 | + $this->ruleA($text, $subkey, $i); |
|
| 143 | + } |
|
| 138 | 144 | |
| 139 | - if ($i <= 16 && $i >= 9) |
|
| 140 | - $this->ruleB($text, $subkey, $i); |
|
| 145 | + if ($i <= 16 && $i >= 9) { |
|
| 146 | + $this->ruleB($text, $subkey, $i); |
|
| 147 | + } |
|
| 141 | 148 | |
| 142 | - if ($i <= 8 && $i >= 1) |
|
| 143 | - $this->ruleA($text, $subkey, $i); |
|
| 149 | + if ($i <= 8 && $i >= 1) { |
|
| 150 | + $this->ruleA($text, $subkey, $i); |
|
| 151 | + } |
|
| 144 | 152 | } |
| 145 | 153 | |
| 146 | 154 | return true; |
@@ -334,8 +342,9 @@ discard block |
||
| 334 | 342 | |
| 335 | 343 | for ($i = 0; $i < 128; ++$i) |
| 336 | 344 | { |
| 337 | - if ($pos == $key_bytes) |
|
| 338 | - $pos = 0; |
|
| 345 | + if ($pos == $key_bytes) { |
|
| 346 | + $pos = 0; |
|
| 347 | + } |
|
| 339 | 348 | |
| 340 | 349 | $this->expanded_key .= $key[$pos]; |
| 341 | 350 | ++$pos; |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $key_len = strlen($key); |
| 63 | 63 | |
| 64 | - if ($key_len == 8 || $key_len == 16) |
|
| 65 | - $key = self::expandKey($key, $key_len); |
|
| 66 | - else if ($key_len < self::BYTES_KEY) |
|
| 64 | + if ($key_len == 8 || $key_len == 16) { |
|
| 65 | + $key = self::expandKey($key, $key_len); |
|
| 66 | + } else if ($key_len < self::BYTES_KEY) |
|
| 67 | 67 | { |
| 68 | 68 | $msg = PHP_Crypt::CIPHER_3DES." requires an 8, 16, or 24 byte key. "; |
| 69 | 69 | $msg .= "$key_len bytes received."; |
@@ -109,10 +109,13 @@ discard block |
||
| 109 | 109 | $key = substr($this->key(), ($i * 8), $blocksz); |
| 110 | 110 | $this->keyPermutation($key); |
| 111 | 111 | |
| 112 | - if ($i % 2) // round 1 |
|
| 112 | + if ($i % 2) { |
|
| 113 | + // round 1 |
|
| 113 | 114 | $this->operation(parent::DECRYPT); |
| 114 | - else // rounds 0 and 2 |
|
| 115 | + } else { |
|
| 116 | + // rounds 0 and 2 |
|
| 115 | 117 | $this->operation(parent::ENCRYPT); |
| 118 | + } |
|
| 116 | 119 | |
| 117 | 120 | $this->des($text); |
| 118 | 121 | } |
@@ -138,10 +141,13 @@ discard block |
||
| 138 | 141 | $key = substr($this->key(), ($i * 8), $blocksz); |
| 139 | 142 | $this->keyPermutation($key); |
| 140 | 143 | |
| 141 | - if ($i % 2) // round 1 |
|
| 144 | + if ($i % 2) { |
|
| 145 | + // round 1 |
|
| 142 | 146 | $this->operation(parent::ENCRYPT); |
| 143 | - else // round 0 and 2 |
|
| 147 | + } else { |
|
| 148 | + // round 0 and 2 |
|
| 144 | 149 | $this->operation(parent::DECRYPT); |
| 150 | + } |
|
| 145 | 151 | |
| 146 | 152 | $this->des($text); |
| 147 | 153 | } |
@@ -210,8 +216,9 @@ discard block |
||
| 210 | 216 | // of these. |
| 211 | 217 | $CnDn = array_merge($c[$i], $d[$i]); |
| 212 | 218 | $this->sub_keys[$i - 1] = ""; |
| 213 | - for ($j = 0; $j < 48; ++$j) |
|
| 214 | - $this->sub_keys[$i - 1] .= $CnDn[parent::$_pc2[$j] - 1]; |
|
| 219 | + for ($j = 0; $j < 48; ++$j) { |
|
| 220 | + $this->sub_keys[$i - 1] .= $CnDn[parent::$_pc2[$j] - 1]; |
|
| 221 | + } |
|
| 215 | 222 | } |
| 216 | 223 | |
| 217 | 224 | // the sub_keys are created, we are done with the key permutation |
@@ -235,13 +242,15 @@ discard block |
||
| 235 | 242 | { |
| 236 | 243 | // if we were given an 8 byte key, repeat it |
| 237 | 244 | // 3 times to produce a 24 byte key |
| 238 | - if ($len == 8) |
|
| 239 | - $key = str_repeat($key, 3); |
|
| 245 | + if ($len == 8) { |
|
| 246 | + $key = str_repeat($key, 3); |
|
| 247 | + } |
|
| 240 | 248 | |
| 241 | 249 | // if we were given a 16 byte key, add the first |
| 242 | 250 | // 8 bytes to the end of the key to produce 24 bytes |
| 243 | - if ($len == 16) |
|
| 244 | - $key .= substr($key, 0, 8); |
|
| 251 | + if ($len == 16) { |
|
| 252 | + $key .= substr($key, 0, 8); |
|
| 253 | + } |
|
| 245 | 254 | |
| 246 | 255 | // return the key |
| 247 | 256 | return $key; |
@@ -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; |
@@ -242,23 +242,19 @@ discard block |
||
| 242 | 242 | { |
| 243 | 243 | self::$_p[$i] = $z0; |
| 244 | 244 | self::$_p[$i + 1] = $z1; |
| 245 | - } |
|
| 246 | - else if ($i >= 18 && $i < 274) |
|
| 245 | + } else if ($i >= 18 && $i < 274) |
|
| 247 | 246 | { |
| 248 | 247 | self::$_sbox1[$i - 18] = $z0; |
| 249 | 248 | self::$_sbox1[$i - 18 + 1] = $z1; |
| 250 | - } |
|
| 251 | - else if ($i >= 274 && $i < 530) |
|
| 249 | + } else if ($i >= 274 && $i < 530) |
|
| 252 | 250 | { |
| 253 | 251 | self::$_sbox2[$i - 274] = $z0; |
| 254 | 252 | self::$_sbox2[$i - 274 + 1] = $z1; |
| 255 | - } |
|
| 256 | - else if ($i >= 530 && $i < 786) |
|
| 253 | + } else if ($i >= 530 && $i < 786) |
|
| 257 | 254 | { |
| 258 | 255 | self::$_sbox3[$i - 530] = $z0; |
| 259 | 256 | self::$_sbox3[$i - 530 + 1] = $z1; |
| 260 | - } |
|
| 261 | - else if ($i >= 786 && $i < 1042) |
|
| 257 | + } else if ($i >= 786 && $i < 1042) |
|
| 262 | 258 | { |
| 263 | 259 | self::$_sbox4[$i - 786] = $z0; |
| 264 | 260 | self::$_sbox4[$i - 786 + 1] = $z1; |
@@ -283,8 +279,9 @@ discard block |
||
| 283 | 279 | */ |
| 284 | 280 | private function keyChunk($size = 1, $reset = false) |
| 285 | 281 | { |
| 286 | - if ($reset || $this->key_pos >= $this->keySize()) |
|
| 287 | - $this->key_pos = 0; |
|
| 282 | + if ($reset || $this->key_pos >= $this->keySize()) { |
|
| 283 | + $this->key_pos = 0; |
|
| 284 | + } |
|
| 288 | 285 | |
| 289 | 286 | $bytes = substr($this->key(), $this->key_pos, $size); |
| 290 | 287 | $len = strlen($bytes); |
@@ -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; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | for ($i = 0; $i < $max; ++$i) |
| 164 | 164 | { |
| 165 | 165 | $pos = $i * 2; |
| 166 | - $text[$pos] = chr($w[$i]); |
|
| 166 | + $text[$pos] = chr($w[$i]); |
|
| 167 | 167 | $text[$pos + 1] = chr($w[$i] >> 8); |
| 168 | 168 | } |
| 169 | 169 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | for ($i = 0; $i < $max; ++$i) |
| 238 | 238 | { |
| 239 | 239 | $pos = $i * 2; |
| 240 | - $text[$pos] = chr($w[$i]); |
|
| 240 | + $text[$pos] = chr($w[$i]); |
|
| 241 | 241 | $text[$pos + 1] = chr($w[$i] >> 8); |
| 242 | 242 | } |
| 243 | 243 | |
@@ -276,8 +276,9 @@ discard block |
||
| 276 | 276 | $len = $this->keySize(); |
| 277 | 277 | |
| 278 | 278 | // the max length of the key is 128 bytes |
| 279 | - if ($len > 128) |
|
| 280 | - $this->xkey = substr($this->xkey, 0, 128); |
|
| 279 | + if ($len > 128) { |
|
| 280 | + $this->xkey = substr($this->xkey, 0, 128); |
|
| 281 | + } |
|
| 281 | 282 | |
| 282 | 283 | // now expanded the rest of the key to 128 bytes, using the sbox |
| 283 | 284 | for ($i = $len; $i < 128; ++$i) |
@@ -288,8 +289,9 @@ discard block |
||
| 288 | 289 | |
| 289 | 290 | // the sbox is only 255 bytes, so if we extend past that |
| 290 | 291 | // we need to modulo 256 so we have a valid position |
| 291 | - if ($pos > 255) |
|
| 292 | - $pos -= 256; |
|
| 292 | + if ($pos > 255) { |
|
| 293 | + $pos -= 256; |
|
| 294 | + } |
|
| 293 | 295 | |
| 294 | 296 | $this->xkey .= chr(self::$_sbox[$pos]); |
| 295 | 297 | } |