@@ -43,73 +43,73 @@ |
||
43 | 43 | * created gif files by almost 50%. |
44 | 44 | */ |
45 | 45 | |
46 | - // path to data files |
|
47 | - $path = './images_gif'; |
|
46 | + // path to data files |
|
47 | + $path = './images_gif'; |
|
48 | 48 | |
49 | - // get code from GET request, use dummy pattern if code not defined |
|
50 | - $code = isset($_GET['code']) ? $_GET['code'] : '20100804020102040810'; |
|
49 | + // get code from GET request, use dummy pattern if code not defined |
|
50 | + $code = isset($_GET['code']) ? $_GET['code'] : '20100804020102040810'; |
|
51 | 51 | |
52 | - // get frame delay from GET request, default to "safe speed" if delay not |
|
53 | - // defined or invalid. delay is specified in ms in the request and needs |
|
54 | - // to be converted to 1/100s for use in GIF files |
|
55 | - $delay = isset($_GET['delay']) ? ($_GET['delay']+0)/10 : 8; |
|
56 | - $delay = ($delay > 0) ? $delay : 8; |
|
52 | + // get frame delay from GET request, default to "safe speed" if delay not |
|
53 | + // defined or invalid. delay is specified in ms in the request and needs |
|
54 | + // to be converted to 1/100s for use in GIF files |
|
55 | + $delay = isset($_GET['delay']) ? ($_GET['delay']+0)/10 : 8; |
|
56 | + $delay = ($delay > 0) ? $delay : 8; |
|
57 | 57 | |
58 | - // code string must only contain hex characters, code length is limited to |
|
59 | - // 1024 characters (512 frames) |
|
60 | - $codelen = strlen($code); |
|
61 | - if ( ctype_xdigit($code) && $codelen < 1024 ) { |
|
58 | + // code string must only contain hex characters, code length is limited to |
|
59 | + // 1024 characters (512 frames) |
|
60 | + $codelen = strlen($code); |
|
61 | + if ( ctype_xdigit($code) && $codelen < 1024 ) { |
|
62 | 62 | |
63 | - // get prepared gif file header |
|
64 | - $gif = file_get_contents($path.'/head.bin'); |
|
63 | + // get prepared gif file header |
|
64 | + $gif = file_get_contents($path.'/head.bin'); |
|
65 | 65 | |
66 | - // build graphic control extension block |
|
67 | - // disposal method = 0 |
|
68 | - // transparent color = 255 |
|
69 | - $ext = "\x21\xf9\x04\x01".chr($delay&0xff).chr(($delay>>8)&0xff)."\xff\x00"; |
|
66 | + // build graphic control extension block |
|
67 | + // disposal method = 0 |
|
68 | + // transparent color = 255 |
|
69 | + $ext = "\x21\xf9\x04\x01".chr($delay&0xff).chr(($delay>>8)&0xff)."\xff\x00"; |
|
70 | 70 | |
71 | - // output image header |
|
72 | - header('Content-type:image/gif'); |
|
73 | - print($gif); |
|
71 | + // output image header |
|
72 | + header('Content-type:image/gif'); |
|
73 | + print($gif); |
|
74 | 74 | |
75 | - // append image data blocks as necessary |
|
76 | - $size = filesize($path.'/data.bin'); |
|
77 | - $data = fopen($path.'/data.bin','r'); |
|
78 | - if ($data) { |
|
75 | + // append image data blocks as necessary |
|
76 | + $size = filesize($path.'/data.bin'); |
|
77 | + $data = fopen($path.'/data.bin','r'); |
|
78 | + if ($data) { |
|
79 | 79 | |
80 | - // load the index from the data file and unpack it into a PHP array. |
|
81 | - // the index array contains the file offsets of the 4096 delta and |
|
82 | - // base images inside the data file. |
|
83 | - $index = unpack("V*", fread($data, 64*64*4)); |
|
80 | + // load the index from the data file and unpack it into a PHP array. |
|
81 | + // the index array contains the file offsets of the 4096 delta and |
|
82 | + // base images inside the data file. |
|
83 | + $index = unpack("V*", fread($data, 64*64*4)); |
|
84 | 84 | |
85 | - // when a code is repeated (prev and curr have the same value) a |
|
86 | - // base image is inserted instead of a delta image. the first frame |
|
87 | - // in the animation must be a base image, so we peek at the flicker |
|
88 | - // code and set $prev to the first value in the string |
|
89 | - $prev = hexdec(substr($code, 0, 2)); |
|
90 | - for ($i = 0; $i < $codelen; $i+=2) { |
|
85 | + // when a code is repeated (prev and curr have the same value) a |
|
86 | + // base image is inserted instead of a delta image. the first frame |
|
87 | + // in the animation must be a base image, so we peek at the flicker |
|
88 | + // code and set $prev to the first value in the string |
|
89 | + $prev = hexdec(substr($code, 0, 2)); |
|
90 | + for ($i = 0; $i < $codelen; $i+=2) { |
|
91 | 91 | |
92 | - // get current code |
|
93 | - $curr = hexdec(substr($code, $i, 2)); |
|
92 | + // get current code |
|
93 | + $curr = hexdec(substr($code, $i, 2)); |
|
94 | 94 | |
95 | - // locate image block in data file |
|
96 | - $blockIdx = $prev*64+$curr+1; // array starts at 1 |
|
97 | - $blockPos = $index[$blockIdx]; |
|
98 | - $blockLen = ($blockIdx < 4096 ? $index[$blockIdx+1] : $size) - $blockPos; |
|
95 | + // locate image block in data file |
|
96 | + $blockIdx = $prev*64+$curr+1; // array starts at 1 |
|
97 | + $blockPos = $index[$blockIdx]; |
|
98 | + $blockLen = ($blockIdx < 4096 ? $index[$blockIdx+1] : $size) - $blockPos; |
|
99 | 99 | |
100 | - // output extension header |
|
101 | - print($ext); |
|
100 | + // output extension header |
|
101 | + print($ext); |
|
102 | 102 | |
103 | - // output image block |
|
104 | - fseek($data, $blockPos); |
|
105 | - print(fread($data, $blockLen)); |
|
103 | + // output image block |
|
104 | + fseek($data, $blockPos); |
|
105 | + print(fread($data, $blockLen)); |
|
106 | 106 | |
107 | - $prev = $curr; |
|
108 | - } |
|
107 | + $prev = $curr; |
|
108 | + } |
|
109 | 109 | |
110 | - // file terminator |
|
111 | - print(";"); |
|
112 | - } |
|
113 | - } |
|
110 | + // file terminator |
|
111 | + print(";"); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | /******/ |
115 | 115 | ?> |
116 | 116 | \ No newline at end of file |
@@ -52,21 +52,21 @@ discard block |
||
52 | 52 | // get frame delay from GET request, default to "safe speed" if delay not |
53 | 53 | // defined or invalid. delay is specified in ms in the request and needs |
54 | 54 | // to be converted to 1/100s for use in GIF files |
55 | - $delay = isset($_GET['delay']) ? ($_GET['delay']+0)/10 : 8; |
|
55 | + $delay = isset($_GET['delay']) ? ($_GET['delay'] + 0) / 10 : 8; |
|
56 | 56 | $delay = ($delay > 0) ? $delay : 8; |
57 | 57 | |
58 | 58 | // code string must only contain hex characters, code length is limited to |
59 | 59 | // 1024 characters (512 frames) |
60 | 60 | $codelen = strlen($code); |
61 | - if ( ctype_xdigit($code) && $codelen < 1024 ) { |
|
61 | + if (ctype_xdigit($code) && $codelen < 1024) { |
|
62 | 62 | |
63 | 63 | // get prepared gif file header |
64 | - $gif = file_get_contents($path.'/head.bin'); |
|
64 | + $gif = file_get_contents($path.'/head.bin'); |
|
65 | 65 | |
66 | 66 | // build graphic control extension block |
67 | 67 | // disposal method = 0 |
68 | 68 | // transparent color = 255 |
69 | - $ext = "\x21\xf9\x04\x01".chr($delay&0xff).chr(($delay>>8)&0xff)."\xff\x00"; |
|
69 | + $ext = "\x21\xf9\x04\x01".chr($delay & 0xff).chr(($delay >> 8) & 0xff)."\xff\x00"; |
|
70 | 70 | |
71 | 71 | // output image header |
72 | 72 | header('Content-type:image/gif'); |
@@ -74,28 +74,28 @@ discard block |
||
74 | 74 | |
75 | 75 | // append image data blocks as necessary |
76 | 76 | $size = filesize($path.'/data.bin'); |
77 | - $data = fopen($path.'/data.bin','r'); |
|
77 | + $data = fopen($path.'/data.bin', 'r'); |
|
78 | 78 | if ($data) { |
79 | 79 | |
80 | 80 | // load the index from the data file and unpack it into a PHP array. |
81 | 81 | // the index array contains the file offsets of the 4096 delta and |
82 | 82 | // base images inside the data file. |
83 | - $index = unpack("V*", fread($data, 64*64*4)); |
|
83 | + $index = unpack("V*", fread($data, 64 * 64 * 4)); |
|
84 | 84 | |
85 | 85 | // when a code is repeated (prev and curr have the same value) a |
86 | 86 | // base image is inserted instead of a delta image. the first frame |
87 | 87 | // in the animation must be a base image, so we peek at the flicker |
88 | 88 | // code and set $prev to the first value in the string |
89 | 89 | $prev = hexdec(substr($code, 0, 2)); |
90 | - for ($i = 0; $i < $codelen; $i+=2) { |
|
90 | + for ($i = 0; $i < $codelen; $i += 2) { |
|
91 | 91 | |
92 | 92 | // get current code |
93 | 93 | $curr = hexdec(substr($code, $i, 2)); |
94 | 94 | |
95 | 95 | // locate image block in data file |
96 | - $blockIdx = $prev*64+$curr+1; // array starts at 1 |
|
96 | + $blockIdx = $prev * 64 + $curr + 1; // array starts at 1 |
|
97 | 97 | $blockPos = $index[$blockIdx]; |
98 | - $blockLen = ($blockIdx < 4096 ? $index[$blockIdx+1] : $size) - $blockPos; |
|
98 | + $blockLen = ($blockIdx < 4096 ? $index[$blockIdx + 1] : $size) - $blockPos; |
|
99 | 99 | |
100 | 100 | // output extension header |
101 | 101 | print($ext); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | if ($engine == self::ENGINE_OPENSSL) { |
192 | 192 | $this->cipher_name_openssl_ecb = 'des-ede3'; |
193 | 193 | $mode = $this->_openssl_translate_mode(); |
194 | - $this->cipher_name_openssl = $mode == 'ecb' ? 'des-ede3' : 'des-ede3-' . $mode; |
|
194 | + $this->cipher_name_openssl = $mode == 'ecb' ? 'des-ede3' : 'des-ede3-'.$mode; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | return parent::isValidEngine($engine); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | case 192: |
236 | 236 | break; |
237 | 237 | default: |
238 | - throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys of sizes 128 or 192 bits are supported'); |
|
238 | + throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys of sizes 128 or 192 bits are supported'); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | parent::setKeyLength($length); |
@@ -257,16 +257,16 @@ discard block |
||
257 | 257 | function setKey($key) |
258 | 258 | { |
259 | 259 | if ($this->explicit_key_length !== false && strlen($key) != $this->explicit_key_length) { |
260 | - throw new \LengthException('Key length has already been set to ' . $this->explicit_key_length . ' bytes and this key is ' . strlen($key) . ' bytes'); |
|
260 | + throw new \LengthException('Key length has already been set to '.$this->explicit_key_length.' bytes and this key is '.strlen($key).' bytes'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | switch (strlen($key)) { |
264 | 264 | case 16: |
265 | - $key.= substr($key, 0, 8); |
|
265 | + $key .= substr($key, 0, 8); |
|
266 | 266 | case 24: |
267 | 267 | break; |
268 | 268 | default: |
269 | - throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16 or 24 are supported'); |
|
269 | + throw new \LengthException('Key of size '.strlen($key).' not supported by this algorithm. Only keys of sizes 16 or 24 are supported'); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | // copied from self::setKey() |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | $this->_setEngine(); |
277 | 277 | |
278 | 278 | if ($this->mode_3cbc) { |
279 | - $this->des[0]->setKey(substr($key, 0, 8)); |
|
280 | - $this->des[1]->setKey(substr($key, 8, 8)); |
|
279 | + $this->des[0]->setKey(substr($key, 0, 8)); |
|
280 | + $this->des[1]->setKey(substr($key, 8, 8)); |
|
281 | 281 | $this->des[2]->setKey(substr($key, 16, 8)); |
282 | 282 | } |
283 | 283 | } |
@@ -464,13 +464,13 @@ discard block |
||
464 | 464 | list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]); |
465 | 465 | for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { |
466 | 466 | $A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^ |
467 | - $m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^ |
|
468 | - $m2[$q1[$q0[$i] ^ $key[11]] ^ $key[3]] ^ |
|
469 | - $m3[$q1[$q1[$i] ^ $key[12]] ^ $key[4]]; |
|
467 | + $m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^ |
|
468 | + $m2[$q1[$q0[$i] ^ $key[11]] ^ $key[3]] ^ |
|
469 | + $m3[$q1[$q1[$i] ^ $key[12]] ^ $key[4]]; |
|
470 | 470 | $B = $m0[$q0[$q0[$j] ^ $key[13]] ^ $key[5]] ^ |
471 | - $m1[$q0[$q1[$j] ^ $key[14]] ^ $key[6]] ^ |
|
472 | - $m2[$q1[$q0[$j] ^ $key[15]] ^ $key[7]] ^ |
|
473 | - $m3[$q1[$q1[$j] ^ $key[16]] ^ $key[8]]; |
|
471 | + $m1[$q0[$q1[$j] ^ $key[14]] ^ $key[6]] ^ |
|
472 | + $m2[$q1[$q0[$j] ^ $key[15]] ^ $key[7]] ^ |
|
473 | + $m3[$q1[$q1[$j] ^ $key[16]] ^ $key[8]]; |
|
474 | 474 | $B = ($B << 8) | ($B >> 24 & 0xff); |
475 | 475 | $K[] = $A+= $B; |
476 | 476 | $K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); |
@@ -488,13 +488,13 @@ discard block |
||
488 | 488 | list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]); |
489 | 489 | for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { |
490 | 490 | $A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ |
491 | - $m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ |
|
492 | - $m2[$q1[$q0[$q0[$i] ^ $key[19]] ^ $key[11]] ^ $key[3]] ^ |
|
493 | - $m3[$q1[$q1[$q0[$i] ^ $key[20]] ^ $key[12]] ^ $key[4]]; |
|
491 | + $m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ |
|
492 | + $m2[$q1[$q0[$q0[$i] ^ $key[19]] ^ $key[11]] ^ $key[3]] ^ |
|
493 | + $m3[$q1[$q1[$q0[$i] ^ $key[20]] ^ $key[12]] ^ $key[4]]; |
|
494 | 494 | $B = $m0[$q0[$q0[$q1[$j] ^ $key[21]] ^ $key[13]] ^ $key[5]] ^ |
495 | - $m1[$q0[$q1[$q1[$j] ^ $key[22]] ^ $key[14]] ^ $key[6]] ^ |
|
496 | - $m2[$q1[$q0[$q0[$j] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^ |
|
497 | - $m3[$q1[$q1[$q0[$j] ^ $key[24]] ^ $key[16]] ^ $key[8]]; |
|
495 | + $m1[$q0[$q1[$q1[$j] ^ $key[22]] ^ $key[14]] ^ $key[6]] ^ |
|
496 | + $m2[$q1[$q0[$q0[$j] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^ |
|
497 | + $m3[$q1[$q1[$q0[$j] ^ $key[24]] ^ $key[16]] ^ $key[8]]; |
|
498 | 498 | $B = ($B << 8) | ($B >> 24 & 0xff); |
499 | 499 | $K[] = $A+= $B; |
500 | 500 | $K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); |
@@ -513,13 +513,13 @@ discard block |
||
513 | 513 | list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]); |
514 | 514 | for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { |
515 | 515 | $A = $m0[$q0[$q0[$q1[$q1[$i] ^ $key[25]] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ |
516 | - $m1[$q0[$q1[$q1[$q0[$i] ^ $key[26]] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ |
|
517 | - $m2[$q1[$q0[$q0[$q0[$i] ^ $key[27]] ^ $key[19]] ^ $key[11]] ^ $key[3]] ^ |
|
518 | - $m3[$q1[$q1[$q0[$q1[$i] ^ $key[28]] ^ $key[20]] ^ $key[12]] ^ $key[4]]; |
|
516 | + $m1[$q0[$q1[$q1[$q0[$i] ^ $key[26]] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ |
|
517 | + $m2[$q1[$q0[$q0[$q0[$i] ^ $key[27]] ^ $key[19]] ^ $key[11]] ^ $key[3]] ^ |
|
518 | + $m3[$q1[$q1[$q0[$q1[$i] ^ $key[28]] ^ $key[20]] ^ $key[12]] ^ $key[4]]; |
|
519 | 519 | $B = $m0[$q0[$q0[$q1[$q1[$j] ^ $key[29]] ^ $key[21]] ^ $key[13]] ^ $key[5]] ^ |
520 | - $m1[$q0[$q1[$q1[$q0[$j] ^ $key[30]] ^ $key[22]] ^ $key[14]] ^ $key[6]] ^ |
|
521 | - $m2[$q1[$q0[$q0[$q0[$j] ^ $key[31]] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^ |
|
522 | - $m3[$q1[$q1[$q0[$q1[$j] ^ $key[32]] ^ $key[24]] ^ $key[16]] ^ $key[8]]; |
|
520 | + $m1[$q0[$q1[$q1[$q0[$j] ^ $key[30]] ^ $key[22]] ^ $key[14]] ^ $key[6]] ^ |
|
521 | + $m2[$q1[$q0[$q0[$q0[$j] ^ $key[31]] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^ |
|
522 | + $m3[$q1[$q1[$q0[$q1[$j] ^ $key[32]] ^ $key[24]] ^ $key[16]] ^ $key[8]]; |
|
523 | 523 | $B = ($B << 8) | ($B >> 24 & 0xff); |
524 | 524 | $K[] = $A+= $B; |
525 | 525 | $K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); |
@@ -611,25 +611,25 @@ discard block |
||
611 | 611 | $ki = 7; |
612 | 612 | while ($ki < 39) { |
613 | 613 | $t0 = $S0[ $R0 & 0xff] ^ |
614 | - $S1[($R0 >> 8) & 0xff] ^ |
|
615 | - $S2[($R0 >> 16) & 0xff] ^ |
|
616 | - $S3[($R0 >> 24) & 0xff]; |
|
614 | + $S1[($R0 >> 8) & 0xff] ^ |
|
615 | + $S2[($R0 >> 16) & 0xff] ^ |
|
616 | + $S3[($R0 >> 24) & 0xff]; |
|
617 | 617 | $t1 = $S0[($R1 >> 24) & 0xff] ^ |
618 | - $S1[ $R1 & 0xff] ^ |
|
619 | - $S2[($R1 >> 8) & 0xff] ^ |
|
620 | - $S3[($R1 >> 16) & 0xff]; |
|
618 | + $S1[ $R1 & 0xff] ^ |
|
619 | + $S2[($R1 >> 8) & 0xff] ^ |
|
620 | + $S3[($R1 >> 16) & 0xff]; |
|
621 | 621 | $R2^= $t0 + $t1 + $K[++$ki]; |
622 | 622 | $R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31); |
623 | 623 | $R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ($t0 + ($t1 << 1) + $K[++$ki]); |
624 | 624 | |
625 | 625 | $t0 = $S0[ $R2 & 0xff] ^ |
626 | - $S1[($R2 >> 8) & 0xff] ^ |
|
627 | - $S2[($R2 >> 16) & 0xff] ^ |
|
628 | - $S3[($R2 >> 24) & 0xff]; |
|
626 | + $S1[($R2 >> 8) & 0xff] ^ |
|
627 | + $S2[($R2 >> 16) & 0xff] ^ |
|
628 | + $S3[($R2 >> 24) & 0xff]; |
|
629 | 629 | $t1 = $S0[($R3 >> 24) & 0xff] ^ |
630 | - $S1[ $R3 & 0xff] ^ |
|
631 | - $S2[($R3 >> 8) & 0xff] ^ |
|
632 | - $S3[($R3 >> 16) & 0xff]; |
|
630 | + $S1[ $R3 & 0xff] ^ |
|
631 | + $S2[($R3 >> 8) & 0xff] ^ |
|
632 | + $S3[($R3 >> 16) & 0xff]; |
|
633 | 633 | $R0^= ($t0 + $t1 + $K[++$ki]); |
634 | 634 | $R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31); |
635 | 635 | $R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + $K[++$ki]); |
@@ -637,9 +637,9 @@ discard block |
||
637 | 637 | |
638 | 638 | // @codingStandardsIgnoreStart |
639 | 639 | return pack("V4", $K[4] ^ $R2, |
640 | - $K[5] ^ $R3, |
|
641 | - $K[6] ^ $R0, |
|
642 | - $K[7] ^ $R1); |
|
640 | + $K[5] ^ $R3, |
|
641 | + $K[6] ^ $R0, |
|
642 | + $K[7] ^ $R1); |
|
643 | 643 | // @codingStandardsIgnoreEnd |
644 | 644 | } |
645 | 645 | |
@@ -667,25 +667,25 @@ discard block |
||
667 | 667 | $ki = 40; |
668 | 668 | while ($ki > 8) { |
669 | 669 | $t0 = $S0[$R0 & 0xff] ^ |
670 | - $S1[$R0 >> 8 & 0xff] ^ |
|
671 | - $S2[$R0 >> 16 & 0xff] ^ |
|
672 | - $S3[$R0 >> 24 & 0xff]; |
|
670 | + $S1[$R0 >> 8 & 0xff] ^ |
|
671 | + $S2[$R0 >> 16 & 0xff] ^ |
|
672 | + $S3[$R0 >> 24 & 0xff]; |
|
673 | 673 | $t1 = $S0[$R1 >> 24 & 0xff] ^ |
674 | - $S1[$R1 & 0xff] ^ |
|
675 | - $S2[$R1 >> 8 & 0xff] ^ |
|
676 | - $S3[$R1 >> 16 & 0xff]; |
|
674 | + $S1[$R1 & 0xff] ^ |
|
675 | + $S2[$R1 >> 8 & 0xff] ^ |
|
676 | + $S3[$R1 >> 16 & 0xff]; |
|
677 | 677 | $R3^= $t0 + ($t1 << 1) + $K[--$ki]; |
678 | 678 | $R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31; |
679 | 679 | $R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ($t0 + $t1 + $K[--$ki]); |
680 | 680 | |
681 | 681 | $t0 = $S0[$R2 & 0xff] ^ |
682 | - $S1[$R2 >> 8 & 0xff] ^ |
|
683 | - $S2[$R2 >> 16 & 0xff] ^ |
|
684 | - $S3[$R2 >> 24 & 0xff]; |
|
682 | + $S1[$R2 >> 8 & 0xff] ^ |
|
683 | + $S2[$R2 >> 16 & 0xff] ^ |
|
684 | + $S3[$R2 >> 24 & 0xff]; |
|
685 | 685 | $t1 = $S0[$R3 >> 24 & 0xff] ^ |
686 | - $S1[$R3 & 0xff] ^ |
|
687 | - $S2[$R3 >> 8 & 0xff] ^ |
|
688 | - $S3[$R3 >> 16 & 0xff]; |
|
686 | + $S1[$R3 & 0xff] ^ |
|
687 | + $S2[$R3 >> 8 & 0xff] ^ |
|
688 | + $S3[$R3 >> 16 & 0xff]; |
|
689 | 689 | $R1^= $t0 + ($t1 << 1) + $K[--$ki]; |
690 | 690 | $R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31; |
691 | 691 | $R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + $K[--$ki]); |
@@ -693,9 +693,9 @@ discard block |
||
693 | 693 | |
694 | 694 | // @codingStandardsIgnoreStart |
695 | 695 | return pack("V4", $K[0] ^ $R2, |
696 | - $K[1] ^ $R3, |
|
697 | - $K[2] ^ $R0, |
|
698 | - $K[3] ^ $R1); |
|
696 | + $K[1] ^ $R3, |
|
697 | + $K[2] ^ $R0, |
|
698 | + $K[3] ^ $R1); |
|
699 | 699 | // @codingStandardsIgnoreEnd |
700 | 700 | } |
701 | 701 | |
@@ -835,11 +835,11 @@ discard block |
||
835 | 835 | |
836 | 836 | $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( |
837 | 837 | array( |
838 | - 'init_crypt' => $init_crypt, |
|
839 | - 'init_encrypt' => '', |
|
840 | - 'init_decrypt' => '', |
|
841 | - 'encrypt_block' => $encrypt_block, |
|
842 | - 'decrypt_block' => $decrypt_block |
|
838 | + 'init_crypt' => $init_crypt, |
|
839 | + 'init_encrypt' => '', |
|
840 | + 'init_decrypt' => '', |
|
841 | + 'encrypt_block' => $encrypt_block, |
|
842 | + 'decrypt_block' => $decrypt_block |
|
843 | 843 | ) |
844 | 844 | ); |
845 | 845 | } |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | case 256: |
403 | 403 | break; |
404 | 404 | default: |
405 | - throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported'); |
|
405 | + throw new \LengthException('Key of size '.strlen($key).' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported'); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | parent::setKeyLength($length); |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | case 32: |
427 | 427 | break; |
428 | 428 | default: |
429 | - throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported'); |
|
429 | + throw new \LengthException('Key of size '.strlen($key).' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported'); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | parent::setKey($key); |
@@ -462,8 +462,8 @@ discard block |
||
462 | 462 | case 16: |
463 | 463 | list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[1], $le_longs[2]); |
464 | 464 | list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[3], $le_longs[4]); |
465 | - for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { |
|
466 | - $A = $m0[$q0[$q0[$i] ^ $key[ 9]] ^ $key[1]] ^ |
|
465 | + for ($i = 0, $j = 1; $i < 40; $i += 2, $j += 2) { |
|
466 | + $A = $m0[$q0[$q0[$i] ^ $key[9]] ^ $key[1]] ^ |
|
467 | 467 | $m1[$q0[$q1[$i] ^ $key[10]] ^ $key[2]] ^ |
468 | 468 | $m2[$q1[$q0[$i] ^ $key[11]] ^ $key[3]] ^ |
469 | 469 | $m3[$q1[$q1[$i] ^ $key[12]] ^ $key[4]]; |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | $m2[$q1[$q0[$j] ^ $key[15]] ^ $key[7]] ^ |
473 | 473 | $m3[$q1[$q1[$j] ^ $key[16]] ^ $key[8]]; |
474 | 474 | $B = ($B << 8) | ($B >> 24 & 0xff); |
475 | - $K[] = $A+= $B; |
|
476 | - $K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); |
|
475 | + $K[] = $A += $B; |
|
476 | + $K[] = (($A += $B) << 9 | $A >> 23 & 0x1ff); |
|
477 | 477 | } |
478 | 478 | for ($i = 0; $i < 256; ++$i) { |
479 | 479 | $S0[$i] = $m0[$q0[$q0[$i] ^ $s4] ^ $s0]; |
@@ -486,8 +486,8 @@ discard block |
||
486 | 486 | list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[1], $le_longs[2]); |
487 | 487 | list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[3], $le_longs[4]); |
488 | 488 | list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[5], $le_longs[6]); |
489 | - for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { |
|
490 | - $A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ |
|
489 | + for ($i = 0, $j = 1; $i < 40; $i += 2, $j += 2) { |
|
490 | + $A = $m0[$q0[$q0[$q1[$i] ^ $key[17]] ^ $key[9]] ^ $key[1]] ^ |
|
491 | 491 | $m1[$q0[$q1[$q1[$i] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ |
492 | 492 | $m2[$q1[$q0[$q0[$i] ^ $key[19]] ^ $key[11]] ^ $key[3]] ^ |
493 | 493 | $m3[$q1[$q1[$q0[$i] ^ $key[20]] ^ $key[12]] ^ $key[4]]; |
@@ -496,8 +496,8 @@ discard block |
||
496 | 496 | $m2[$q1[$q0[$q0[$j] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^ |
497 | 497 | $m3[$q1[$q1[$q0[$j] ^ $key[24]] ^ $key[16]] ^ $key[8]]; |
498 | 498 | $B = ($B << 8) | ($B >> 24 & 0xff); |
499 | - $K[] = $A+= $B; |
|
500 | - $K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); |
|
499 | + $K[] = $A += $B; |
|
500 | + $K[] = (($A += $B) << 9 | $A >> 23 & 0x1ff); |
|
501 | 501 | } |
502 | 502 | for ($i = 0; $i < 256; ++$i) { |
503 | 503 | $S0[$i] = $m0[$q0[$q0[$q1[$i] ^ $s8] ^ $s4] ^ $s0]; |
@@ -511,8 +511,8 @@ discard block |
||
511 | 511 | list($sb, $sa, $s9, $s8) = $this->_mdsrem($le_longs[3], $le_longs[4]); |
512 | 512 | list($s7, $s6, $s5, $s4) = $this->_mdsrem($le_longs[5], $le_longs[6]); |
513 | 513 | list($s3, $s2, $s1, $s0) = $this->_mdsrem($le_longs[7], $le_longs[8]); |
514 | - for ($i = 0, $j = 1; $i < 40; $i+= 2, $j+= 2) { |
|
515 | - $A = $m0[$q0[$q0[$q1[$q1[$i] ^ $key[25]] ^ $key[17]] ^ $key[ 9]] ^ $key[1]] ^ |
|
514 | + for ($i = 0, $j = 1; $i < 40; $i += 2, $j += 2) { |
|
515 | + $A = $m0[$q0[$q0[$q1[$q1[$i] ^ $key[25]] ^ $key[17]] ^ $key[9]] ^ $key[1]] ^ |
|
516 | 516 | $m1[$q0[$q1[$q1[$q0[$i] ^ $key[26]] ^ $key[18]] ^ $key[10]] ^ $key[2]] ^ |
517 | 517 | $m2[$q1[$q0[$q0[$q0[$i] ^ $key[27]] ^ $key[19]] ^ $key[11]] ^ $key[3]] ^ |
518 | 518 | $m3[$q1[$q1[$q0[$q1[$i] ^ $key[28]] ^ $key[20]] ^ $key[12]] ^ $key[4]]; |
@@ -521,8 +521,8 @@ discard block |
||
521 | 521 | $m2[$q1[$q0[$q0[$q0[$j] ^ $key[31]] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^ |
522 | 522 | $m3[$q1[$q1[$q0[$q1[$j] ^ $key[32]] ^ $key[24]] ^ $key[16]] ^ $key[8]]; |
523 | 523 | $B = ($B << 8) | ($B >> 24 & 0xff); |
524 | - $K[] = $A+= $B; |
|
525 | - $K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); |
|
524 | + $K[] = $A += $B; |
|
525 | + $K[] = (($A += $B) << 9 | $A >> 23 & 0x1ff); |
|
526 | 526 | } |
527 | 527 | for ($i = 0; $i < 256; ++$i) { |
528 | 528 | $S0[$i] = $m0[$q0[$q0[$q1[$q1[$i] ^ $sc] ^ $s8] ^ $s4] ^ $s0]; |
@@ -556,34 +556,34 @@ discard block |
||
556 | 556 | |
557 | 557 | // Shift the others up. |
558 | 558 | $B = ($B << 8) | (0xff & ($A >> 24)); |
559 | - $A<<= 8; |
|
559 | + $A <<= 8; |
|
560 | 560 | |
561 | 561 | $u = $t << 1; |
562 | 562 | |
563 | 563 | // Subtract the modular polynomial on overflow. |
564 | 564 | if ($t & 0x80) { |
565 | - $u^= 0x14d; |
|
565 | + $u ^= 0x14d; |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | // Remove t * (a * x^2 + 1). |
569 | 569 | $B ^= $t ^ ($u << 16); |
570 | 570 | |
571 | 571 | // Form u = a*t + t/a = t*(a + 1/a). |
572 | - $u^= 0x7fffffff & ($t >> 1); |
|
572 | + $u ^= 0x7fffffff & ($t >> 1); |
|
573 | 573 | |
574 | 574 | // Add the modular polynomial on underflow. |
575 | 575 | if ($t & 0x01) { |
576 | - $u^= 0xa6 ; |
|
576 | + $u ^= 0xa6; |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | // Remove t * (a + 1/a) * (x^3 + x). |
580 | - $B^= ($u << 24) | ($u << 8); |
|
580 | + $B ^= ($u << 24) | ($u << 8); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | return array( |
584 | 584 | 0xff & $B >> 24, |
585 | 585 | 0xff & $B >> 16, |
586 | - 0xff & $B >> 8, |
|
586 | + 0xff & $B >> 8, |
|
587 | 587 | 0xff & $B); |
588 | 588 | } |
589 | 589 | |
@@ -610,27 +610,27 @@ discard block |
||
610 | 610 | |
611 | 611 | $ki = 7; |
612 | 612 | while ($ki < 39) { |
613 | - $t0 = $S0[ $R0 & 0xff] ^ |
|
614 | - $S1[($R0 >> 8) & 0xff] ^ |
|
613 | + $t0 = $S0[$R0 & 0xff] ^ |
|
614 | + $S1[($R0 >> 8) & 0xff] ^ |
|
615 | 615 | $S2[($R0 >> 16) & 0xff] ^ |
616 | 616 | $S3[($R0 >> 24) & 0xff]; |
617 | 617 | $t1 = $S0[($R1 >> 24) & 0xff] ^ |
618 | - $S1[ $R1 & 0xff] ^ |
|
619 | - $S2[($R1 >> 8) & 0xff] ^ |
|
618 | + $S1[$R1 & 0xff] ^ |
|
619 | + $S2[($R1 >> 8) & 0xff] ^ |
|
620 | 620 | $S3[($R1 >> 16) & 0xff]; |
621 | - $R2^= $t0 + $t1 + $K[++$ki]; |
|
621 | + $R2 ^= $t0 + $t1 + $K[++$ki]; |
|
622 | 622 | $R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31); |
623 | 623 | $R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ($t0 + ($t1 << 1) + $K[++$ki]); |
624 | 624 | |
625 | - $t0 = $S0[ $R2 & 0xff] ^ |
|
626 | - $S1[($R2 >> 8) & 0xff] ^ |
|
625 | + $t0 = $S0[$R2 & 0xff] ^ |
|
626 | + $S1[($R2 >> 8) & 0xff] ^ |
|
627 | 627 | $S2[($R2 >> 16) & 0xff] ^ |
628 | 628 | $S3[($R2 >> 24) & 0xff]; |
629 | 629 | $t1 = $S0[($R3 >> 24) & 0xff] ^ |
630 | - $S1[ $R3 & 0xff] ^ |
|
631 | - $S2[($R3 >> 8) & 0xff] ^ |
|
630 | + $S1[$R3 & 0xff] ^ |
|
631 | + $S2[($R3 >> 8) & 0xff] ^ |
|
632 | 632 | $S3[($R3 >> 16) & 0xff]; |
633 | - $R0^= ($t0 + $t1 + $K[++$ki]); |
|
633 | + $R0 ^= ($t0 + $t1 + $K[++$ki]); |
|
634 | 634 | $R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31); |
635 | 635 | $R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + $K[++$ki]); |
636 | 636 | } |
@@ -666,27 +666,27 @@ discard block |
||
666 | 666 | |
667 | 667 | $ki = 40; |
668 | 668 | while ($ki > 8) { |
669 | - $t0 = $S0[$R0 & 0xff] ^ |
|
670 | - $S1[$R0 >> 8 & 0xff] ^ |
|
669 | + $t0 = $S0[$R0 & 0xff] ^ |
|
670 | + $S1[$R0 >> 8 & 0xff] ^ |
|
671 | 671 | $S2[$R0 >> 16 & 0xff] ^ |
672 | 672 | $S3[$R0 >> 24 & 0xff]; |
673 | 673 | $t1 = $S0[$R1 >> 24 & 0xff] ^ |
674 | - $S1[$R1 & 0xff] ^ |
|
675 | - $S2[$R1 >> 8 & 0xff] ^ |
|
674 | + $S1[$R1 & 0xff] ^ |
|
675 | + $S2[$R1 >> 8 & 0xff] ^ |
|
676 | 676 | $S3[$R1 >> 16 & 0xff]; |
677 | - $R3^= $t0 + ($t1 << 1) + $K[--$ki]; |
|
677 | + $R3 ^= $t0 + ($t1 << 1) + $K[--$ki]; |
|
678 | 678 | $R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31; |
679 | 679 | $R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ($t0 + $t1 + $K[--$ki]); |
680 | 680 | |
681 | - $t0 = $S0[$R2 & 0xff] ^ |
|
682 | - $S1[$R2 >> 8 & 0xff] ^ |
|
681 | + $t0 = $S0[$R2 & 0xff] ^ |
|
682 | + $S1[$R2 >> 8 & 0xff] ^ |
|
683 | 683 | $S2[$R2 >> 16 & 0xff] ^ |
684 | 684 | $S3[$R2 >> 24 & 0xff]; |
685 | 685 | $t1 = $S0[$R3 >> 24 & 0xff] ^ |
686 | - $S1[$R3 & 0xff] ^ |
|
687 | - $S2[$R3 >> 8 & 0xff] ^ |
|
686 | + $S1[$R3 & 0xff] ^ |
|
687 | + $S2[$R3 >> 8 & 0xff] ^ |
|
688 | 688 | $S3[$R3 >> 16 & 0xff]; |
689 | - $R1^= $t0 + ($t1 << 1) + $K[--$ki]; |
|
689 | + $R1 ^= $t0 + ($t1 << 1) + $K[--$ki]; |
|
690 | 690 | $R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31; |
691 | 691 | $R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + $K[--$ki]); |
692 | 692 | } |
@@ -707,16 +707,16 @@ discard block |
||
707 | 707 | */ |
708 | 708 | function _setupInlineCrypt() |
709 | 709 | { |
710 | - $lambda_functions =& self::_getLambdaFunctions(); |
|
710 | + $lambda_functions = & self::_getLambdaFunctions(); |
|
711 | 711 | |
712 | 712 | // Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one. |
713 | 713 | // (Currently, for Crypt_Twofish, one generated $lambda_function cost on php5.5@32bit ~140kb unfreeable mem and ~240kb on php5.5@64bit) |
714 | - $gen_hi_opt_code = (bool)(count($lambda_functions) < 10); |
|
714 | + $gen_hi_opt_code = (bool) (count($lambda_functions) < 10); |
|
715 | 715 | |
716 | 716 | // Generation of a unique hash for our generated code |
717 | 717 | $code_hash = "Crypt_Twofish, {$this->mode}"; |
718 | 718 | if ($gen_hi_opt_code) { |
719 | - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); |
|
719 | + $code_hash = str_pad($code_hash, 32).$this->_hashInlineCryptFunction($this->key); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | if (!isset($lambda_functions[$code_hash])) { |
@@ -736,16 +736,16 @@ discard block |
||
736 | 736 | '; |
737 | 737 | break; |
738 | 738 | default: |
739 | - $K = array(); |
|
739 | + $K = array(); |
|
740 | 740 | for ($i = 0; $i < 40; ++$i) { |
741 | - $K[] = '$K_' . $i; |
|
741 | + $K[] = '$K_'.$i; |
|
742 | 742 | } |
743 | 743 | $init_crypt = ' |
744 | 744 | $S0 = $self->S0; |
745 | 745 | $S1 = $self->S1; |
746 | 746 | $S2 = $self->S2; |
747 | 747 | $S3 = $self->S3; |
748 | - list(' . implode(',', $K) . ') = $self->K; |
|
748 | + list(' . implode(',', $K).') = $self->K; |
|
749 | 749 | '; |
750 | 750 | } |
751 | 751 | |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | $R3 = '.$K[3].' ^ $in[4]; |
759 | 759 | '; |
760 | 760 | for ($ki = 7, $i = 0; $i < 8; ++$i) { |
761 | - $encrypt_block.= ' |
|
761 | + $encrypt_block .= ' |
|
762 | 762 | $t0 = $S0[ $R0 & 0xff] ^ |
763 | 763 | $S1[($R0 >> 8) & 0xff] ^ |
764 | 764 | $S2[($R0 >> 16) & 0xff] ^ |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | $R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].'); |
785 | 785 | '; |
786 | 786 | } |
787 | - $encrypt_block.= ' |
|
787 | + $encrypt_block .= ' |
|
788 | 788 | $in = pack("V4", '.$K[4].' ^ $R2, |
789 | 789 | '.$K[5].' ^ $R3, |
790 | 790 | '.$K[6].' ^ $R0, |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | $R3 = '.$K[7].' ^ $in[4]; |
801 | 801 | '; |
802 | 802 | for ($ki = 40, $i = 0; $i < 8; ++$i) { |
803 | - $decrypt_block.= ' |
|
803 | + $decrypt_block .= ' |
|
804 | 804 | $t0 = $S0[$R0 & 0xff] ^ |
805 | 805 | $S1[$R0 >> 8 & 0xff] ^ |
806 | 806 | $S2[$R0 >> 16 & 0xff] ^ |
@@ -826,7 +826,7 @@ discard block |
||
826 | 826 | $R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + '.$K[--$ki].'); |
827 | 827 | '; |
828 | 828 | } |
829 | - $decrypt_block.= ' |
|
829 | + $decrypt_block .= ' |
|
830 | 830 | $in = pack("V4", '.$K[0].' ^ $R2, |
831 | 831 | '.$K[1].' ^ $R3, |
832 | 832 | '.$K[2].' ^ $R0, |
@@ -423,13 +423,13 @@ discard block |
||
423 | 423 | $l^= $p[$i]; |
424 | 424 | $r^= ($sb_0[$l >> 24 & 0xff] + |
425 | 425 | $sb_1[$l >> 16 & 0xff] ^ |
426 | - $sb_2[$l >> 8 & 0xff]) + |
|
426 | + $sb_2[$l >> 8 & 0xff]) + |
|
427 | 427 | $sb_3[$l & 0xff]; |
428 | 428 | |
429 | 429 | $r^= $p[$i + 1]; |
430 | 430 | $l^= ($sb_0[$r >> 24 & 0xff] + |
431 | 431 | $sb_1[$r >> 16 & 0xff] ^ |
432 | - $sb_2[$r >> 8 & 0xff]) + |
|
432 | + $sb_2[$r >> 8 & 0xff]) + |
|
433 | 433 | $sb_3[$r & 0xff]; |
434 | 434 | } |
435 | 435 | return pack("N*", $r ^ $p[17], $l ^ $p[16]); |
@@ -458,13 +458,13 @@ discard block |
||
458 | 458 | $l^= $p[$i]; |
459 | 459 | $r^= ($sb_0[$l >> 24 & 0xff] + |
460 | 460 | $sb_1[$l >> 16 & 0xff] ^ |
461 | - $sb_2[$l >> 8 & 0xff]) + |
|
461 | + $sb_2[$l >> 8 & 0xff]) + |
|
462 | 462 | $sb_3[$l & 0xff]; |
463 | 463 | |
464 | 464 | $r^= $p[$i - 1]; |
465 | 465 | $l^= ($sb_0[$r >> 24 & 0xff] + |
466 | 466 | $sb_1[$r >> 16 & 0xff] ^ |
467 | - $sb_2[$r >> 8 & 0xff]) + |
|
467 | + $sb_2[$r >> 8 & 0xff]) + |
|
468 | 468 | $sb_3[$r & 0xff]; |
469 | 469 | } |
470 | 470 | return pack("N*", $r ^ $p[0], $l ^ $p[1]); |
@@ -577,11 +577,11 @@ discard block |
||
577 | 577 | |
578 | 578 | $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( |
579 | 579 | array( |
580 | - 'init_crypt' => $init_crypt, |
|
581 | - 'init_encrypt' => '', |
|
582 | - 'init_decrypt' => '', |
|
583 | - 'encrypt_block' => $encrypt_block, |
|
584 | - 'decrypt_block' => $decrypt_block |
|
580 | + 'init_crypt' => $init_crypt, |
|
581 | + 'init_encrypt' => '', |
|
582 | + 'init_decrypt' => '', |
|
583 | + 'encrypt_block' => $encrypt_block, |
|
584 | + 'decrypt_block' => $decrypt_block |
|
585 | 585 | ) |
586 | 586 | ); |
587 | 587 | } |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | function setKeyLength($length) |
313 | 313 | { |
314 | 314 | if ($length < 32 || $length > 448) { |
315 | - throw new \LengthException('Key size of ' . $length . ' bits is not supported by this algorithm. Only keys of sizes between 32 and 448 bits are supported'); |
|
315 | + throw new \LengthException('Key size of '.$length.' bits is not supported by this algorithm. Only keys of sizes between 32 and 448 bits are supported'); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | $this->key_length = $length >> 3; |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | $this->cipher_name_openssl_ecb = 'bf-ecb'; |
340 | - $this->cipher_name_openssl = 'bf-' . $this->_openssl_translate_mode(); |
|
340 | + $this->cipher_name_openssl = 'bf-'.$this->_openssl_translate_mode(); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | return parent::isValidEngine($engine); |
@@ -387,13 +387,13 @@ discard block |
||
387 | 387 | $data = "\0\0\0\0\0\0\0\0"; |
388 | 388 | for ($i = 0; $i < 18; $i += 2) { |
389 | 389 | list($l, $r) = array_values(unpack('N*', $data = $this->_encryptBlock($data))); |
390 | - $this->bctx['p'][$i ] = $l; |
|
390 | + $this->bctx['p'][$i] = $l; |
|
391 | 391 | $this->bctx['p'][$i + 1] = $r; |
392 | 392 | } |
393 | 393 | for ($i = 0; $i < 4; ++$i) { |
394 | 394 | for ($j = 0; $j < 256; $j += 2) { |
395 | 395 | list($l, $r) = array_values(unpack('N*', $data = $this->_encryptBlock($data))); |
396 | - $this->bctx['sb'][$i][$j ] = $l; |
|
396 | + $this->bctx['sb'][$i][$j] = $l; |
|
397 | 397 | $this->bctx['sb'][$i][$j + 1] = $r; |
398 | 398 | } |
399 | 399 | } |
@@ -419,18 +419,18 @@ discard block |
||
419 | 419 | $l = $in[1]; |
420 | 420 | $r = $in[2]; |
421 | 421 | |
422 | - for ($i = 0; $i < 16; $i+= 2) { |
|
423 | - $l^= $p[$i]; |
|
424 | - $r^= ($sb_0[$l >> 24 & 0xff] + |
|
425 | - $sb_1[$l >> 16 & 0xff] ^ |
|
426 | - $sb_2[$l >> 8 & 0xff]) + |
|
427 | - $sb_3[$l & 0xff]; |
|
428 | - |
|
429 | - $r^= $p[$i + 1]; |
|
430 | - $l^= ($sb_0[$r >> 24 & 0xff] + |
|
431 | - $sb_1[$r >> 16 & 0xff] ^ |
|
432 | - $sb_2[$r >> 8 & 0xff]) + |
|
433 | - $sb_3[$r & 0xff]; |
|
422 | + for ($i = 0; $i < 16; $i += 2) { |
|
423 | + $l ^= $p[$i]; |
|
424 | + $r ^= ($sb_0[$l >> 24 & 0xff] + |
|
425 | + $sb_1[$l >> 16 & 0xff] ^ |
|
426 | + $sb_2[$l >> 8 & 0xff]) + |
|
427 | + $sb_3[$l & 0xff]; |
|
428 | + |
|
429 | + $r ^= $p[$i + 1]; |
|
430 | + $l ^= ($sb_0[$r >> 24 & 0xff] + |
|
431 | + $sb_1[$r >> 16 & 0xff] ^ |
|
432 | + $sb_2[$r >> 8 & 0xff]) + |
|
433 | + $sb_3[$r & 0xff]; |
|
434 | 434 | } |
435 | 435 | return pack("N*", $r ^ $p[17], $l ^ $p[16]); |
436 | 436 | } |
@@ -454,18 +454,18 @@ discard block |
||
454 | 454 | $l = $in[1]; |
455 | 455 | $r = $in[2]; |
456 | 456 | |
457 | - for ($i = 17; $i > 2; $i-= 2) { |
|
458 | - $l^= $p[$i]; |
|
459 | - $r^= ($sb_0[$l >> 24 & 0xff] + |
|
460 | - $sb_1[$l >> 16 & 0xff] ^ |
|
461 | - $sb_2[$l >> 8 & 0xff]) + |
|
462 | - $sb_3[$l & 0xff]; |
|
463 | - |
|
464 | - $r^= $p[$i - 1]; |
|
465 | - $l^= ($sb_0[$r >> 24 & 0xff] + |
|
466 | - $sb_1[$r >> 16 & 0xff] ^ |
|
467 | - $sb_2[$r >> 8 & 0xff]) + |
|
468 | - $sb_3[$r & 0xff]; |
|
457 | + for ($i = 17; $i > 2; $i -= 2) { |
|
458 | + $l ^= $p[$i]; |
|
459 | + $r ^= ($sb_0[$l >> 24 & 0xff] + |
|
460 | + $sb_1[$l >> 16 & 0xff] ^ |
|
461 | + $sb_2[$l >> 8 & 0xff]) + |
|
462 | + $sb_3[$l & 0xff]; |
|
463 | + |
|
464 | + $r ^= $p[$i - 1]; |
|
465 | + $l ^= ($sb_0[$r >> 24 & 0xff] + |
|
466 | + $sb_1[$r >> 16 & 0xff] ^ |
|
467 | + $sb_2[$r >> 8 & 0xff]) + |
|
468 | + $sb_3[$r & 0xff]; |
|
469 | 469 | } |
470 | 470 | return pack("N*", $r ^ $p[0], $l ^ $p[1]); |
471 | 471 | } |
@@ -478,17 +478,17 @@ discard block |
||
478 | 478 | */ |
479 | 479 | function _setupInlineCrypt() |
480 | 480 | { |
481 | - $lambda_functions =& self::_getLambdaFunctions(); |
|
481 | + $lambda_functions = & self::_getLambdaFunctions(); |
|
482 | 482 | |
483 | 483 | // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. |
484 | 484 | // (Currently, for Blowfish, one generated $lambda_function cost on php5.5@32bit ~100kb unfreeable mem and ~180kb on php5.5@64bit) |
485 | 485 | // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one. |
486 | - $gen_hi_opt_code = (bool)(count($lambda_functions) < 10); |
|
486 | + $gen_hi_opt_code = (bool) (count($lambda_functions) < 10); |
|
487 | 487 | |
488 | 488 | // Generation of a unique hash for our generated code |
489 | 489 | $code_hash = "Crypt_Blowfish, {$this->mode}"; |
490 | 490 | if ($gen_hi_opt_code) { |
491 | - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); |
|
491 | + $code_hash = str_pad($code_hash, 32).$this->_hashInlineCryptFunction($this->key); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | if (!isset($lambda_functions[$code_hash])) { |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | '; |
507 | 507 | break; |
508 | 508 | default: |
509 | - $p = array(); |
|
509 | + $p = array(); |
|
510 | 510 | for ($i = 0; $i < 18; ++$i) { |
511 | - $p[] = '$p_' . $i; |
|
511 | + $p[] = '$p_'.$i; |
|
512 | 512 | } |
513 | 513 | $init_crypt = ' |
514 | 514 | list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"]; |
515 | - list(' . implode(',', $p) . ') = $self->bctx["p"]; |
|
515 | + list(' . implode(',', $p).') = $self->bctx["p"]; |
|
516 | 516 | |
517 | 517 | '; |
518 | 518 | } |
@@ -523,25 +523,25 @@ discard block |
||
523 | 523 | $l = $in[1]; |
524 | 524 | $r = $in[2]; |
525 | 525 | '; |
526 | - for ($i = 0; $i < 16; $i+= 2) { |
|
527 | - $encrypt_block.= ' |
|
528 | - $l^= ' . $p[$i] . '; |
|
526 | + for ($i = 0; $i < 16; $i += 2) { |
|
527 | + $encrypt_block .= ' |
|
528 | + $l^= ' . $p[$i].'; |
|
529 | 529 | $r^= ($sb_0[$l >> 24 & 0xff] + |
530 | 530 | $sb_1[$l >> 16 & 0xff] ^ |
531 | 531 | $sb_2[$l >> 8 & 0xff]) + |
532 | 532 | $sb_3[$l & 0xff]; |
533 | 533 | |
534 | - $r^= ' . $p[$i + 1] . '; |
|
534 | + $r^= ' . $p[$i + 1].'; |
|
535 | 535 | $l^= ($sb_0[$r >> 24 & 0xff] + |
536 | 536 | $sb_1[$r >> 16 & 0xff] ^ |
537 | 537 | $sb_2[$r >> 8 & 0xff]) + |
538 | 538 | $sb_3[$r & 0xff]; |
539 | 539 | '; |
540 | 540 | } |
541 | - $encrypt_block.= ' |
|
541 | + $encrypt_block .= ' |
|
542 | 542 | $in = pack("N*", |
543 | - $r ^ ' . $p[17] . ', |
|
544 | - $l ^ ' . $p[16] . ' |
|
543 | + $r ^ ' . $p[17].', |
|
544 | + $l ^ ' . $p[16].' |
|
545 | 545 | ); |
546 | 546 | '; |
547 | 547 | |
@@ -552,15 +552,15 @@ discard block |
||
552 | 552 | $r = $in[2]; |
553 | 553 | '; |
554 | 554 | |
555 | - for ($i = 17; $i > 2; $i-= 2) { |
|
556 | - $decrypt_block.= ' |
|
557 | - $l^= ' . $p[$i] . '; |
|
555 | + for ($i = 17; $i > 2; $i -= 2) { |
|
556 | + $decrypt_block .= ' |
|
557 | + $l^= ' . $p[$i].'; |
|
558 | 558 | $r^= ($sb_0[$l >> 24 & 0xff] + |
559 | 559 | $sb_1[$l >> 16 & 0xff] ^ |
560 | 560 | $sb_2[$l >> 8 & 0xff]) + |
561 | 561 | $sb_3[$l & 0xff]; |
562 | 562 | |
563 | - $r^= ' . $p[$i - 1] . '; |
|
563 | + $r^= ' . $p[$i - 1].'; |
|
564 | 564 | $l^= ($sb_0[$r >> 24 & 0xff] + |
565 | 565 | $sb_1[$r >> 16 & 0xff] ^ |
566 | 566 | $sb_2[$r >> 8 & 0xff]) + |
@@ -568,10 +568,10 @@ discard block |
||
568 | 568 | '; |
569 | 569 | } |
570 | 570 | |
571 | - $decrypt_block.= ' |
|
571 | + $decrypt_block .= ' |
|
572 | 572 | $in = pack("N*", |
573 | - $r ^ ' . $p[0] . ', |
|
574 | - $l ^ ' . $p[1] . ' |
|
573 | + $r ^ ' . $p[0].', |
|
574 | + $l ^ ' . $p[1].' |
|
575 | 575 | ); |
576 | 576 | '; |
577 | 577 |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | case 256: |
92 | 92 | break; |
93 | 93 | default: |
94 | - throw new \LengthException('Key of size ' . $length . ' not supported by this algorithm. Only keys of sizes 128, 192 or 256 supported'); |
|
94 | + throw new \LengthException('Key of size '.$length.' not supported by this algorithm. Only keys of sizes 128, 192 or 256 supported'); |
|
95 | 95 | } |
96 | 96 | parent::setKeyLength($length); |
97 | 97 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | case 32: |
116 | 116 | break; |
117 | 117 | default: |
118 | - throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported'); |
|
118 | + throw new \LengthException('Key of size '.strlen($key).' not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported'); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | parent::setKey($key); |
@@ -709,13 +709,13 @@ discard block |
||
709 | 709 | $t = unpack('Nl/Nr', $block); |
710 | 710 | list($l, $r) = array($t['l'], $t['r']); |
711 | 711 | $block = ($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") | |
712 | - ($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | |
|
713 | - ($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | |
|
714 | - ($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") | |
|
715 | - ($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | |
|
716 | - ($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | |
|
717 | - ($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") | |
|
718 | - ($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01"); |
|
712 | + ($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | |
|
713 | + ($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | |
|
714 | + ($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") | |
|
715 | + ($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | |
|
716 | + ($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | |
|
717 | + ($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") | |
|
718 | + ($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01"); |
|
719 | 719 | |
720 | 720 | // Extract L0 and R0. |
721 | 721 | $t = unpack('Nl/Nr', $block); |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | |
733 | 733 | // S-box indexing. |
734 | 734 | $t = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^ |
735 | - $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^ |
|
736 | - $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^ |
|
737 | - $sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ $l; |
|
735 | + $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^ |
|
736 | + $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^ |
|
737 | + $sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ $l; |
|
738 | 738 | // end of "the Feistel (F) function" |
739 | 739 | |
740 | 740 | $l = $r; |
@@ -749,13 +749,13 @@ discard block |
||
749 | 749 | |
750 | 750 | // Perform the inverse IP permutation. |
751 | 751 | return ($shuffleinvip[($r >> 24) & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") | |
752 | - ($shuffleinvip[($l >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | |
|
753 | - ($shuffleinvip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | |
|
754 | - ($shuffleinvip[($l >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") | |
|
755 | - ($shuffleinvip[($r >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | |
|
756 | - ($shuffleinvip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | |
|
757 | - ($shuffleinvip[ $r & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") | |
|
758 | - ($shuffleinvip[ $l & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01"); |
|
752 | + ($shuffleinvip[($l >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | |
|
753 | + ($shuffleinvip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | |
|
754 | + ($shuffleinvip[($l >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") | |
|
755 | + ($shuffleinvip[($r >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | |
|
756 | + ($shuffleinvip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | |
|
757 | + ($shuffleinvip[ $r & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") | |
|
758 | + ($shuffleinvip[ $l & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01"); |
|
759 | 759 | } |
760 | 760 | |
761 | 761 | /** |
@@ -1230,13 +1230,13 @@ discard block |
||
1230 | 1230 | $t = unpack('Nl/Nr', $key); |
1231 | 1231 | list($l, $r) = array($t['l'], $t['r']); |
1232 | 1232 | $key = ($this->shuffle[$pc1map[ $r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x00") | |
1233 | - ($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") | |
|
1234 | - ($this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x00") | |
|
1235 | - ($this->shuffle[$pc1map[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x00") | |
|
1236 | - ($this->shuffle[$pc1map[ $l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x00") | |
|
1237 | - ($this->shuffle[$pc1map[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x00") | |
|
1238 | - ($this->shuffle[$pc1map[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x00") | |
|
1239 | - ($this->shuffle[$pc1map[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x00"); |
|
1233 | + ($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") | |
|
1234 | + ($this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x00") | |
|
1235 | + ($this->shuffle[$pc1map[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x00") | |
|
1236 | + ($this->shuffle[$pc1map[ $l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x00") | |
|
1237 | + ($this->shuffle[$pc1map[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x00") | |
|
1238 | + ($this->shuffle[$pc1map[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x00") | |
|
1239 | + ($this->shuffle[$pc1map[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x00"); |
|
1240 | 1240 | $key = unpack('Nc/Nd', $key); |
1241 | 1241 | $c = ( $key['c'] >> 4) & 0x0FFFFFFF; |
1242 | 1242 | $d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F); |
@@ -1253,9 +1253,9 @@ discard block |
||
1253 | 1253 | |
1254 | 1254 | // Perform the PC-2 transformation. |
1255 | 1255 | $cp = $pc2mapc1[ $c >> 24 ] | $pc2mapc2[($c >> 16) & 0xFF] | |
1256 | - $pc2mapc3[($c >> 8) & 0xFF] | $pc2mapc4[ $c & 0xFF]; |
|
1256 | + $pc2mapc3[($c >> 8) & 0xFF] | $pc2mapc4[ $c & 0xFF]; |
|
1257 | 1257 | $dp = $pc2mapd1[ $d >> 24 ] | $pc2mapd2[($d >> 16) & 0xFF] | |
1258 | - $pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[ $d & 0xFF]; |
|
1258 | + $pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[ $d & 0xFF]; |
|
1259 | 1259 | |
1260 | 1260 | // Reorder: odd bytes/even bytes. Push the result in key schedule. |
1261 | 1261 | $val1 = ( $cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) | |
@@ -1440,11 +1440,11 @@ discard block |
||
1440 | 1440 | // Creates the inline-crypt function |
1441 | 1441 | $lambda_functions[$code_hash] = $this->_createInlineCryptFunction( |
1442 | 1442 | array( |
1443 | - 'init_crypt' => $init_crypt, |
|
1444 | - 'init_encrypt' => $init_encrypt, |
|
1445 | - 'init_decrypt' => $init_decrypt, |
|
1446 | - 'encrypt_block' => $crypt_block[self::ENCRYPT], |
|
1447 | - 'decrypt_block' => $crypt_block[self::DECRYPT] |
|
1443 | + 'init_crypt' => $init_crypt, |
|
1444 | + 'init_encrypt' => $init_encrypt, |
|
1445 | + 'init_decrypt' => $init_decrypt, |
|
1446 | + 'encrypt_block' => $crypt_block[self::ENCRYPT], |
|
1447 | + 'decrypt_block' => $crypt_block[self::DECRYPT] |
|
1448 | 1448 | ) |
1449 | 1449 | ); |
1450 | 1450 | } |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | if ($this->key_length_max == 8) { |
612 | 612 | if ($engine == self::ENGINE_OPENSSL) { |
613 | 613 | $this->cipher_name_openssl_ecb = 'des-ecb'; |
614 | - $this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode(); |
|
614 | + $this->cipher_name_openssl = 'des-'.$this->_openssl_translate_mode(); |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | function setKey($key) |
633 | 633 | { |
634 | 634 | if (!($this instanceof TripleDES) && strlen($key) != 8) { |
635 | - throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of size 8 are supported'); |
|
635 | + throw new \LengthException('Key of size '.strlen($key).' not supported by this algorithm. Only keys of size 8 are supported'); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | // Sets the key |
@@ -697,8 +697,8 @@ discard block |
||
697 | 697 | $sbox8 = array_map("intval", $this->sbox8); |
698 | 698 | /* Merge $shuffle with $[inv]ipmap */ |
699 | 699 | for ($i = 0; $i < 256; ++$i) { |
700 | - $shuffleip[] = $this->shuffle[$this->ipmap[$i]]; |
|
701 | - $shuffleinvip[] = $this->shuffle[$this->invipmap[$i]]; |
|
700 | + $shuffleip[] = $this->shuffle[$this->ipmap[$i]]; |
|
701 | + $shuffleinvip[] = $this->shuffle[$this->invipmap[$i]]; |
|
702 | 702 | } |
703 | 703 | } |
704 | 704 | |
@@ -708,12 +708,12 @@ discard block |
||
708 | 708 | // Do the initial IP permutation. |
709 | 709 | $t = unpack('Nl/Nr', $block); |
710 | 710 | list($l, $r) = array($t['l'], $t['r']); |
711 | - $block = ($shuffleip[ $r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") | |
|
712 | - ($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | |
|
711 | + $block = ($shuffleip[$r & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") | |
|
712 | + ($shuffleip[($r >> 8) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | |
|
713 | 713 | ($shuffleip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | |
714 | 714 | ($shuffleip[($r >> 24) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") | |
715 | - ($shuffleip[ $l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | |
|
716 | - ($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | |
|
715 | + ($shuffleip[$l & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | |
|
716 | + ($shuffleip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | |
|
717 | 717 | ($shuffleip[($l >> 16) & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") | |
718 | 718 | ($shuffleip[($l >> 24) & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01"); |
719 | 719 | |
@@ -727,14 +727,14 @@ discard block |
||
727 | 727 | // start of "the Feistel (F) function" - see the following URL: |
728 | 728 | // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png |
729 | 729 | // Merge key schedule. |
730 | - $b1 = (($r >> 3) & 0x1FFFFFFF) ^ ($r << 29) ^ $keys[++$ki]; |
|
731 | - $b2 = (($r >> 31) & 0x00000001) ^ ($r << 1) ^ $keys[++$ki]; |
|
730 | + $b1 = (($r >> 3) & 0x1FFFFFFF) ^ ($r << 29) ^ $keys[++$ki]; |
|
731 | + $b2 = (($r >> 31) & 0x00000001) ^ ($r << 1) ^ $keys[++$ki]; |
|
732 | 732 | |
733 | 733 | // S-box indexing. |
734 | 734 | $t = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^ |
735 | 735 | $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^ |
736 | - $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^ |
|
737 | - $sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ $l; |
|
736 | + $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^ |
|
737 | + $sbox7[$b1 & 0x3F] ^ $sbox8[$b2 & 0x3F] ^ $l; |
|
738 | 738 | // end of "the Feistel (F) function" |
739 | 739 | |
740 | 740 | $l = $r; |
@@ -752,10 +752,10 @@ discard block |
||
752 | 752 | ($shuffleinvip[($l >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | |
753 | 753 | ($shuffleinvip[($r >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | |
754 | 754 | ($shuffleinvip[($l >> 16) & 0xFF] & "\x10\x10\x10\x10\x10\x10\x10\x10") | |
755 | - ($shuffleinvip[($r >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | |
|
756 | - ($shuffleinvip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | |
|
757 | - ($shuffleinvip[ $r & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") | |
|
758 | - ($shuffleinvip[ $l & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01"); |
|
755 | + ($shuffleinvip[($r >> 8) & 0xFF] & "\x08\x08\x08\x08\x08\x08\x08\x08") | |
|
756 | + ($shuffleinvip[($l >> 8) & 0xFF] & "\x04\x04\x04\x04\x04\x04\x04\x04") | |
|
757 | + ($shuffleinvip[$r & 0xFF] & "\x02\x02\x02\x02\x02\x02\x02\x02") | |
|
758 | + ($shuffleinvip[$l & 0xFF] & "\x01\x01\x01\x01\x01\x01\x01\x01"); |
|
759 | 759 | } |
760 | 760 | |
761 | 761 | /** |
@@ -1229,43 +1229,43 @@ discard block |
||
1229 | 1229 | // Perform the PC/1 transformation and compute C and D. |
1230 | 1230 | $t = unpack('Nl/Nr', $key); |
1231 | 1231 | list($l, $r) = array($t['l'], $t['r']); |
1232 | - $key = ($this->shuffle[$pc1map[ $r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x00") | |
|
1233 | - ($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") | |
|
1232 | + $key = ($this->shuffle[$pc1map[$r & 0xFF]] & "\x80\x80\x80\x80\x80\x80\x80\x00") | |
|
1233 | + ($this->shuffle[$pc1map[($r >> 8) & 0xFF]] & "\x40\x40\x40\x40\x40\x40\x40\x00") | |
|
1234 | 1234 | ($this->shuffle[$pc1map[($r >> 16) & 0xFF]] & "\x20\x20\x20\x20\x20\x20\x20\x00") | |
1235 | 1235 | ($this->shuffle[$pc1map[($r >> 24) & 0xFF]] & "\x10\x10\x10\x10\x10\x10\x10\x00") | |
1236 | - ($this->shuffle[$pc1map[ $l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x00") | |
|
1237 | - ($this->shuffle[$pc1map[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x00") | |
|
1236 | + ($this->shuffle[$pc1map[$l & 0xFF]] & "\x08\x08\x08\x08\x08\x08\x08\x00") | |
|
1237 | + ($this->shuffle[$pc1map[($l >> 8) & 0xFF]] & "\x04\x04\x04\x04\x04\x04\x04\x00") | |
|
1238 | 1238 | ($this->shuffle[$pc1map[($l >> 16) & 0xFF]] & "\x02\x02\x02\x02\x02\x02\x02\x00") | |
1239 | 1239 | ($this->shuffle[$pc1map[($l >> 24) & 0xFF]] & "\x01\x01\x01\x01\x01\x01\x01\x00"); |
1240 | 1240 | $key = unpack('Nc/Nd', $key); |
1241 | - $c = ( $key['c'] >> 4) & 0x0FFFFFFF; |
|
1241 | + $c = ($key['c'] >> 4) & 0x0FFFFFFF; |
|
1242 | 1242 | $d = (($key['d'] >> 4) & 0x0FFFFFF0) | ($key['c'] & 0x0F); |
1243 | 1243 | |
1244 | 1244 | $keys[$des_round] = array( |
1245 | 1245 | self::ENCRYPT => array(), |
1246 | 1246 | self::DECRYPT => array_fill(0, 32, 0) |
1247 | 1247 | ); |
1248 | - for ($i = 0, $ki = 31; $i < 16; ++$i, $ki-= 2) { |
|
1248 | + for ($i = 0, $ki = 31; $i < 16; ++$i, $ki -= 2) { |
|
1249 | 1249 | $c <<= $shifts[$i]; |
1250 | 1250 | $c = ($c | ($c >> 28)) & 0x0FFFFFFF; |
1251 | 1251 | $d <<= $shifts[$i]; |
1252 | 1252 | $d = ($d | ($d >> 28)) & 0x0FFFFFFF; |
1253 | 1253 | |
1254 | 1254 | // Perform the PC-2 transformation. |
1255 | - $cp = $pc2mapc1[ $c >> 24 ] | $pc2mapc2[($c >> 16) & 0xFF] | |
|
1256 | - $pc2mapc3[($c >> 8) & 0xFF] | $pc2mapc4[ $c & 0xFF]; |
|
1257 | - $dp = $pc2mapd1[ $d >> 24 ] | $pc2mapd2[($d >> 16) & 0xFF] | |
|
1258 | - $pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[ $d & 0xFF]; |
|
1255 | + $cp = $pc2mapc1[$c >> 24] | $pc2mapc2[($c >> 16) & 0xFF] | |
|
1256 | + $pc2mapc3[($c >> 8) & 0xFF] | $pc2mapc4[$c & 0xFF]; |
|
1257 | + $dp = $pc2mapd1[$d >> 24] | $pc2mapd2[($d >> 16) & 0xFF] | |
|
1258 | + $pc2mapd3[($d >> 8) & 0xFF] | $pc2mapd4[$d & 0xFF]; |
|
1259 | 1259 | |
1260 | 1260 | // Reorder: odd bytes/even bytes. Push the result in key schedule. |
1261 | - $val1 = ( $cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) | |
|
1262 | - (($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF); |
|
1263 | - $val2 = (($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) | |
|
1264 | - (($dp >> 8) & 0x0000FF00) | ( $dp & 0x000000FF); |
|
1265 | - $keys[$des_round][self::ENCRYPT][ ] = $val1; |
|
1261 | + $val1 = ($cp & 0xFF000000) | (($cp << 8) & 0x00FF0000) | |
|
1262 | + (($dp >> 16) & 0x0000FF00) | (($dp >> 8) & 0x000000FF); |
|
1263 | + $val2 = (($cp << 8) & 0xFF000000) | (($cp << 16) & 0x00FF0000) | |
|
1264 | + (($dp >> 8) & 0x0000FF00) | ($dp & 0x000000FF); |
|
1265 | + $keys[$des_round][self::ENCRYPT][] = $val1; |
|
1266 | 1266 | $keys[$des_round][self::DECRYPT][$ki - 1] = $val1; |
1267 | - $keys[$des_round][self::ENCRYPT][ ] = $val2; |
|
1268 | - $keys[$des_round][self::DECRYPT][$ki ] = $val2; |
|
1267 | + $keys[$des_round][self::ENCRYPT][] = $val2; |
|
1268 | + $keys[$des_round][self::DECRYPT][$ki] = $val2; |
|
1269 | 1269 | } |
1270 | 1270 | } |
1271 | 1271 | |
@@ -1301,7 +1301,7 @@ discard block |
||
1301 | 1301 | */ |
1302 | 1302 | function _setupInlineCrypt() |
1303 | 1303 | { |
1304 | - $lambda_functions =& self::_getLambdaFunctions(); |
|
1304 | + $lambda_functions = & self::_getLambdaFunctions(); |
|
1305 | 1305 | |
1306 | 1306 | // Engine configuration for: |
1307 | 1307 | // - DES ($des_rounds == 1) or |
@@ -1312,7 +1312,7 @@ discard block |
||
1312 | 1312 | // (Currently, for DES, one generated $lambda_function cost on php5.5@32bit ~135kb unfreeable mem and ~230kb on php5.5@64bit) |
1313 | 1313 | // (Currently, for TripleDES, one generated $lambda_function cost on php5.5@32bit ~240kb unfreeable mem and ~340kb on php5.5@64bit) |
1314 | 1314 | // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one |
1315 | - $gen_hi_opt_code = (bool)( count($lambda_functions) < 10 ); |
|
1315 | + $gen_hi_opt_code = (bool) (count($lambda_functions) < 10); |
|
1316 | 1316 | |
1317 | 1317 | // Generation of a unique hash for our generated code |
1318 | 1318 | $code_hash = "Crypt_DES, $des_rounds, {$this->mode}"; |
@@ -1322,7 +1322,7 @@ discard block |
||
1322 | 1322 | // After max 10 hi-optimized functions, we create generic |
1323 | 1323 | // (still very fast.. but not ultra) functions for each $mode/$des_rounds |
1324 | 1324 | // Currently 2 * 5 generic functions will be then max. possible. |
1325 | - $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key); |
|
1325 | + $code_hash = str_pad($code_hash, 32).$this->_hashInlineCryptFunction($this->key); |
|
1326 | 1326 | } |
1327 | 1327 | |
1328 | 1328 | // Is there a re-usable $lambda_functions in there? If not, we have to create it. |
@@ -1338,7 +1338,7 @@ discard block |
||
1338 | 1338 | $sbox6 = array_map("intval", $self->sbox6); |
1339 | 1339 | $sbox7 = array_map("intval", $self->sbox7); |
1340 | 1340 | $sbox8 = array_map("intval", $self->sbox8);' |
1341 | - /* Merge $shuffle with $[inv]ipmap */ . ' |
|
1341 | + /* Merge $shuffle with $[inv]ipmap */.' |
|
1342 | 1342 | for ($i = 0; $i < 256; ++$i) { |
1343 | 1343 | $shuffleip[] = $self->shuffle[$self->ipmap[$i]]; |
1344 | 1344 | $shuffleinvip[] = $self->shuffle[$self->invipmap[$i]]; |
@@ -1366,8 +1366,8 @@ discard block |
||
1366 | 1366 | self::DECRYPT => array() |
1367 | 1367 | ); |
1368 | 1368 | for ($i = 0, $c = count($this->keys[self::ENCRYPT]); $i < $c; ++$i) { |
1369 | - $k[self::ENCRYPT][$i] = '$ke[' . $i . ']'; |
|
1370 | - $k[self::DECRYPT][$i] = '$kd[' . $i . ']'; |
|
1369 | + $k[self::ENCRYPT][$i] = '$ke['.$i.']'; |
|
1370 | + $k[self::DECRYPT][$i] = '$kd['.$i.']'; |
|
1371 | 1371 | } |
1372 | 1372 | $init_encrypt = '$ke = $self->keys[self::ENCRYPT];'; |
1373 | 1373 | $init_decrypt = '$kd = $self->keys[self::DECRYPT];'; |
@@ -1407,14 +1407,14 @@ discard block |
||
1407 | 1407 | // start of "the Feistel (F) function" - see the following URL: |
1408 | 1408 | // http://en.wikipedia.org/wiki/Image:Data_Encryption_Standard_InfoBox_Diagram.png |
1409 | 1409 | // Merge key schedule. |
1410 | - $crypt_block[$c].= ' |
|
1411 | - $b1 = ((' . $r . ' >> 3) & 0x1FFFFFFF) ^ (' . $r . ' << 29) ^ ' . $k[$c][++$ki] . '; |
|
1412 | - $b2 = ((' . $r . ' >> 31) & 0x00000001) ^ (' . $r . ' << 1) ^ ' . $k[$c][++$ki] . ';' . |
|
1410 | + $crypt_block[$c] .= ' |
|
1411 | + $b1 = ((' . $r.' >> 3) & 0x1FFFFFFF) ^ ('.$r.' << 29) ^ '.$k[$c][++$ki].'; |
|
1412 | + $b2 = ((' . $r.' >> 31) & 0x00000001) ^ ('.$r.' << 1) ^ '.$k[$c][++$ki].';'. |
|
1413 | 1413 | /* S-box indexing. */ |
1414 | - $l . ' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^ |
|
1414 | + $l.' = $sbox1[($b1 >> 24) & 0x3F] ^ $sbox2[($b2 >> 24) & 0x3F] ^ |
|
1415 | 1415 | $sbox3[($b1 >> 16) & 0x3F] ^ $sbox4[($b2 >> 16) & 0x3F] ^ |
1416 | 1416 | $sbox5[($b1 >> 8) & 0x3F] ^ $sbox6[($b2 >> 8) & 0x3F] ^ |
1417 | - $sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ ' . $l . '; |
|
1417 | + $sbox7[ $b1 & 0x3F] ^ $sbox8[ $b2 & 0x3F] ^ ' . $l.'; |
|
1418 | 1418 | '; |
1419 | 1419 | // end of "the Feistel (F) function" |
1420 | 1420 | |
@@ -1425,7 +1425,7 @@ discard block |
||
1425 | 1425 | } |
1426 | 1426 | |
1427 | 1427 | // Perform the inverse IP permutation. |
1428 | - $crypt_block[$c].= '$in = |
|
1428 | + $crypt_block[$c] .= '$in = |
|
1429 | 1429 | ($shuffleinvip[($l >> 24) & 0xFF] & "\x80\x80\x80\x80\x80\x80\x80\x80") | |
1430 | 1430 | ($shuffleinvip[($r >> 24) & 0xFF] & "\x40\x40\x40\x40\x40\x40\x40\x40") | |
1431 | 1431 | ($shuffleinvip[($l >> 16) & 0xFF] & "\x20\x20\x20\x20\x20\x20\x20\x20") | |
@@ -176,14 +176,14 @@ discard block |
||
176 | 176 | $n = strrev($n->toBytes()); |
177 | 177 | $e = str_pad(strrev($e->toBytes()), 4, "\0"); |
178 | 178 | $key = pack('aavV', chr(self::PRIVATEKEYBLOB), chr(2), 0, self::CALG_RSA_KEYX); |
179 | - $key.= pack('VVa*', self::RSA2, 8 * strlen($n), $e); |
|
180 | - $key.= $n; |
|
181 | - $key.= strrev($primes[1]->toBytes()); |
|
182 | - $key.= strrev($primes[2]->toBytes()); |
|
183 | - $key.= strrev($exponents[1]->toBytes()); |
|
184 | - $key.= strrev($exponents[2]->toBytes()); |
|
185 | - $key.= strrev($coefficients[1]->toBytes()); |
|
186 | - $key.= strrev($d->toBytes()); |
|
179 | + $key .= pack('VVa*', self::RSA2, 8 * strlen($n), $e); |
|
180 | + $key .= $n; |
|
181 | + $key .= strrev($primes[1]->toBytes()); |
|
182 | + $key .= strrev($primes[2]->toBytes()); |
|
183 | + $key .= strrev($exponents[1]->toBytes()); |
|
184 | + $key .= strrev($exponents[2]->toBytes()); |
|
185 | + $key .= strrev($coefficients[1]->toBytes()); |
|
186 | + $key .= strrev($d->toBytes()); |
|
187 | 187 | |
188 | 188 | return Base64::encode($key); |
189 | 189 | } |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | $n = strrev($n->toBytes()); |
202 | 202 | $e = str_pad(strrev($e->toBytes()), 4, "\0"); |
203 | 203 | $key = pack('aavV', chr(self::PUBLICKEYBLOB), chr(2), 0, self::CALG_RSA_KEYX); |
204 | - $key.= pack('VVa*', self::RSA1, 8 * strlen($n), $e); |
|
205 | - $key.= $n; |
|
204 | + $key .= pack('VVa*', self::RSA1, 8 * strlen($n), $e); |
|
205 | + $key .= $n; |
|
206 | 206 | |
207 | 207 | return Base64::encode($key); |
208 | 208 | } |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | return "<RSAKeyValue>\r\n" . |
122 | - ' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" . |
|
123 | - ' <Exponent>' . Base64::encode($e->toBytes()) . "</Exponent>\r\n" . |
|
124 | - ' <P>' . Base64::encode($primes[1]->toBytes()) . "</P>\r\n" . |
|
125 | - ' <Q>' . Base64::encode($primes[2]->toBytes()) . "</Q>\r\n" . |
|
126 | - ' <DP>' . Base64::encode($exponents[1]->toBytes()) . "</DP>\r\n" . |
|
127 | - ' <DQ>' . Base64::encode($exponents[2]->toBytes()) . "</DQ>\r\n" . |
|
128 | - ' <InverseQ>' . Base64::encode($coefficients[2]->toBytes()) . "</InverseQ>\r\n" . |
|
129 | - ' <D>' . Base64::encode($d->toBytes()) . "</D>\r\n" . |
|
130 | - '</RSAKeyValue>'; |
|
122 | + ' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" . |
|
123 | + ' <Exponent>' . Base64::encode($e->toBytes()) . "</Exponent>\r\n" . |
|
124 | + ' <P>' . Base64::encode($primes[1]->toBytes()) . "</P>\r\n" . |
|
125 | + ' <Q>' . Base64::encode($primes[2]->toBytes()) . "</Q>\r\n" . |
|
126 | + ' <DP>' . Base64::encode($exponents[1]->toBytes()) . "</DP>\r\n" . |
|
127 | + ' <DQ>' . Base64::encode($exponents[2]->toBytes()) . "</DQ>\r\n" . |
|
128 | + ' <InverseQ>' . Base64::encode($coefficients[2]->toBytes()) . "</InverseQ>\r\n" . |
|
129 | + ' <D>' . Base64::encode($d->toBytes()) . "</D>\r\n" . |
|
130 | + '</RSAKeyValue>'; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -141,8 +141,8 @@ discard block |
||
141 | 141 | static function savePublicKey(BigInteger $n, BigInteger $e) |
142 | 142 | { |
143 | 143 | return "<RSAKeyValue>\r\n" . |
144 | - ' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" . |
|
145 | - ' <Exponent>' . Base64::encode($e->toBytes()) . "</Exponent>\r\n" . |
|
146 | - '</RSAKeyValue>'; |
|
144 | + ' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" . |
|
145 | + ' <Exponent>' . Base64::encode($e->toBytes()) . "</Exponent>\r\n" . |
|
146 | + '</RSAKeyValue>'; |
|
147 | 147 | } |
148 | 148 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $use_errors = libxml_use_internal_errors(true); |
57 | 57 | |
58 | 58 | $dom = new \DOMDocument(); |
59 | - if (!$dom->loadXML('<xml>' . $key . '</xml>')) { |
|
59 | + if (!$dom->loadXML('<xml>'.$key.'</xml>')) { |
|
60 | 60 | return false; |
61 | 61 | } |
62 | 62 | $xpath = new \DOMXPath($dom); |
@@ -118,15 +118,15 @@ discard block |
||
118 | 118 | if (count($primes) != 2) { |
119 | 119 | return false; |
120 | 120 | } |
121 | - return "<RSAKeyValue>\r\n" . |
|
122 | - ' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" . |
|
123 | - ' <Exponent>' . Base64::encode($e->toBytes()) . "</Exponent>\r\n" . |
|
124 | - ' <P>' . Base64::encode($primes[1]->toBytes()) . "</P>\r\n" . |
|
125 | - ' <Q>' . Base64::encode($primes[2]->toBytes()) . "</Q>\r\n" . |
|
126 | - ' <DP>' . Base64::encode($exponents[1]->toBytes()) . "</DP>\r\n" . |
|
127 | - ' <DQ>' . Base64::encode($exponents[2]->toBytes()) . "</DQ>\r\n" . |
|
128 | - ' <InverseQ>' . Base64::encode($coefficients[2]->toBytes()) . "</InverseQ>\r\n" . |
|
129 | - ' <D>' . Base64::encode($d->toBytes()) . "</D>\r\n" . |
|
121 | + return "<RSAKeyValue>\r\n". |
|
122 | + ' <Modulus>'.Base64::encode($n->toBytes())."</Modulus>\r\n". |
|
123 | + ' <Exponent>'.Base64::encode($e->toBytes())."</Exponent>\r\n". |
|
124 | + ' <P>'.Base64::encode($primes[1]->toBytes())."</P>\r\n". |
|
125 | + ' <Q>'.Base64::encode($primes[2]->toBytes())."</Q>\r\n". |
|
126 | + ' <DP>'.Base64::encode($exponents[1]->toBytes())."</DP>\r\n". |
|
127 | + ' <DQ>'.Base64::encode($exponents[2]->toBytes())."</DQ>\r\n". |
|
128 | + ' <InverseQ>'.Base64::encode($coefficients[2]->toBytes())."</InverseQ>\r\n". |
|
129 | + ' <D>'.Base64::encode($d->toBytes())."</D>\r\n". |
|
130 | 130 | '</RSAKeyValue>'; |
131 | 131 | } |
132 | 132 | |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | */ |
141 | 141 | static function savePublicKey(BigInteger $n, BigInteger $e) |
142 | 142 | { |
143 | - return "<RSAKeyValue>\r\n" . |
|
144 | - ' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" . |
|
145 | - ' <Exponent>' . Base64::encode($e->toBytes()) . "</Exponent>\r\n" . |
|
143 | + return "<RSAKeyValue>\r\n". |
|
144 | + ' <Modulus>'.Base64::encode($n->toBytes())."</Modulus>\r\n". |
|
145 | + ' <Exponent>'.Base64::encode($e->toBytes())."</Exponent>\r\n". |
|
146 | 146 | '</RSAKeyValue>'; |
147 | 147 | } |
148 | 148 | } |
@@ -150,12 +150,12 @@ |
||
150 | 150 | $RSAPrivateKey = pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey); |
151 | 151 | |
152 | 152 | $RSAPrivateKey = "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" . |
153 | - chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
154 | - '-----END ENCRYPTED PRIVATE KEY-----'; |
|
153 | + chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
154 | + '-----END ENCRYPTED PRIVATE KEY-----'; |
|
155 | 155 | } else { |
156 | 156 | $RSAPrivateKey = "-----BEGIN PRIVATE KEY-----\r\n" . |
157 | - chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
158 | - '-----END PRIVATE KEY-----'; |
|
157 | + chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
158 | + '-----END PRIVATE KEY-----'; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $RSAPrivateKey; |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | // coefficient INTEGER -- ti |
89 | 89 | // } |
90 | 90 | $OtherPrimeInfo = pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($primes[$i]->toBytes(true))), $primes[$i]->toBytes(true)); |
91 | - $OtherPrimeInfo.= pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true)); |
|
92 | - $OtherPrimeInfo.= pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true)); |
|
93 | - $OtherPrimeInfos.= pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo); |
|
91 | + $OtherPrimeInfo .= pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($exponents[$i]->toBytes(true))), $exponents[$i]->toBytes(true)); |
|
92 | + $OtherPrimeInfo .= pack('Ca*a*', self::ASN1_INTEGER, ASN1::encodeLength(strlen($coefficients[$i]->toBytes(true))), $coefficients[$i]->toBytes(true)); |
|
93 | + $OtherPrimeInfos .= pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($OtherPrimeInfo)), $OtherPrimeInfo); |
|
94 | 94 | } |
95 | - $RSAPrivateKey.= pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos); |
|
95 | + $RSAPrivateKey .= pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($OtherPrimeInfos)), $OtherPrimeInfos); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | $RSAPrivateKey = pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey); |
@@ -149,12 +149,12 @@ discard block |
||
149 | 149 | |
150 | 150 | $RSAPrivateKey = pack('Ca*a*', self::ASN1_SEQUENCE, ASN1::encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey); |
151 | 151 | |
152 | - $RSAPrivateKey = "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" . |
|
153 | - chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
152 | + $RSAPrivateKey = "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n". |
|
153 | + chunk_split(Base64::encode($RSAPrivateKey), 64). |
|
154 | 154 | '-----END ENCRYPTED PRIVATE KEY-----'; |
155 | 155 | } else { |
156 | - $RSAPrivateKey = "-----BEGIN PRIVATE KEY-----\r\n" . |
|
157 | - chunk_split(Base64::encode($RSAPrivateKey), 64) . |
|
156 | + $RSAPrivateKey = "-----BEGIN PRIVATE KEY-----\r\n". |
|
157 | + chunk_split(Base64::encode($RSAPrivateKey), 64). |
|
158 | 158 | '-----END PRIVATE KEY-----'; |
159 | 159 | } |
160 | 160 | |
@@ -194,18 +194,18 @@ discard block |
||
194 | 194 | |
195 | 195 | // sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption. |
196 | 196 | $rsaOID = "\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00"; // hex version of MA0GCSqGSIb3DQEBAQUA |
197 | - $RSAPublicKey = chr(0) . $RSAPublicKey; |
|
198 | - $RSAPublicKey = chr(3) . ASN1::encodeLength(strlen($RSAPublicKey)) . $RSAPublicKey; |
|
197 | + $RSAPublicKey = chr(0).$RSAPublicKey; |
|
198 | + $RSAPublicKey = chr(3).ASN1::encodeLength(strlen($RSAPublicKey)).$RSAPublicKey; |
|
199 | 199 | |
200 | 200 | $RSAPublicKey = pack( |
201 | 201 | 'Ca*a*', |
202 | 202 | self::ASN1_SEQUENCE, |
203 | - ASN1::encodeLength(strlen($rsaOID . $RSAPublicKey)), |
|
204 | - $rsaOID . $RSAPublicKey |
|
203 | + ASN1::encodeLength(strlen($rsaOID.$RSAPublicKey)), |
|
204 | + $rsaOID.$RSAPublicKey |
|
205 | 205 | ); |
206 | 206 | |
207 | - $RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" . |
|
208 | - chunk_split(Base64::encode($RSAPublicKey), 64) . |
|
207 | + $RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n". |
|
208 | + chunk_split(Base64::encode($RSAPublicKey), 64). |
|
209 | 209 | '-----END PUBLIC KEY-----'; |
210 | 210 | |
211 | 211 | return $RSAPublicKey; |