Completed
Push — development ( 6a24df...5afdf5 )
by Nils
07:52
created
includes/libraries/phpcrypt/ciphers/3Way.php 1 patch
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -140,10 +140,11 @@  discard block
 block discarded – undo
140 140
         $key = array_map("parent::str2Dec", $key);
141 141
 
142 142
         // determine which round constant to use
143
-        if($this->operation() == parent::ENCRYPT)
144
-            $rcon = self::$_rcon_enc;
145
-        else
146
-            $rcon = self::$_rcon_dec;
143
+        if($this->operation() == parent::ENCRYPT) {
144
+                    $rcon = self::$_rcon_enc;
145
+        } else {
146
+                    $rcon = self::$_rcon_dec;
147
+        }
147 148
 
148 149
         if($this->operation() == parent::DECRYPT)
149 150
         {
@@ -168,8 +169,9 @@  discard block
 block discarded – undo
168 169
 
169 170
         $this->theta($data);
170 171
 
171
-        if($this->operation() == parent::DECRYPT)
172
-            $this->invertBits($data);
172
+        if($this->operation() == parent::DECRYPT) {
173
+                    $this->invertBits($data);
174
+        }
173 175
 
174 176
         // assemble the three 32 bit parts back to a 96 bit string
175 177
         $data = parent::dec2Str($data[0], 4).parent::dec2Str($data[1], 4).
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/ARC4.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -106,8 +106,9 @@  discard block
 block discarded – undo
106 106
 		$len = strlen($text);
107 107
 		$this->prga($len);
108 108
 
109
-		for ($i = 0; $i < $len; ++$i)
110
-			$text[$i] = $text[$i] ^ $this->_key_stream[$i];
109
+		for ($i = 0; $i < $len; ++$i) {
110
+					$text[$i] = $text[$i] ^ $this->_key_stream[$i];
111
+		}
111 112
 
112 113
 		return true;
113 114
 	}
@@ -126,8 +127,9 @@  discard block
 block discarded – undo
126 127
 		$key = $this->key();
127 128
 
128 129
 		// fill $this->_s with all the values from 0-255
129
-		for ($i = 0; $i < 256; ++$i)
130
-			$this->_s[$i] = $i;
130
+		for ($i = 0; $i < 256; ++$i) {
131
+					$this->_s[$i] = $i;
132
+		}
131 133
 
132 134
 		// the changing S List
133 135
 		for ($i = 0; $i < 256; ++$i)
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/Skipjack.php 1 patch
Braces   +28 added lines, -20 removed lines patch added patch discarded remove patch
@@ -99,17 +99,21 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
@@ -289,8 +297,7 @@  discard block
 block discarded – undo
289 297
 
290 298
             $w[1] = $this->gPermutation($w[0], $key);
291 299
             $w[0] = $w[4];
292
-        }
293
-        else // parent::DECRYPT
300
+        } else // parent::DECRYPT
294 301
         {
295 302
             /*
296 303
 			 * Set W4 as the old W0
@@ -335,8 +342,9 @@  discard block
 block discarded – undo
335 342
 
336 343
         for($i = 0; $i < 128; ++$i)
337 344
         {
338
-            if($pos == $key_bytes)
339
-                $pos = 0;
345
+            if($pos == $key_bytes) {
346
+                            $pos = 0;
347
+            }
340 348
 
341 349
             $this->expanded_key .= $key[$pos];
342 350
             ++$pos;
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/Vigenere.php 1 patch
Braces   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
 		// The key must be prepared so that it is the same length as the
176 176
 		// message. If it is longer or shorter we need to modify it
177 177
 		// to make it the correct length
178
-		if ($keylen > $len)
179
-			$this->expanded_key = substr($this->expanded_key, 0, $len);
180
-		else if ($len > $keylen)
178
+		if ($keylen > $len) {
179
+					$this->expanded_key = substr($this->expanded_key, 0, $len);
180
+		} else if ($len > $keylen)
181 181
 		{
182 182
 			// if the key is shorter than the message, then we need pad the key
183 183
 			// by repeating it until it is the correct length
@@ -186,8 +186,9 @@  discard block
 block discarded – undo
186 186
 
187 187
 			for ($i = 0; $i < $diff; ++$i)
188 188
 			{
189
-				if ($pos >= $keylen)
190
-					$pos = 0;
189
+				if ($pos >= $keylen) {
190
+									$pos = 0;
191
+				}
191 192
 
192 193
 				$this->expanded_key .= $this->expanded_key[$pos];
193 194
 				++$pos;
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/3DES.php 1 patch
Braces   +22 added lines, -13 removed lines patch added patch discarded remove patch
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/Rijndael.php 1 patch
Braces   +103 added lines, -77 removed lines patch added patch discarded remove patch
@@ -188,12 +188,13 @@  discard block
 block discarded – undo
188 188
 		// if the key and block size is 16, do 10 rounds
189 189
 		// if the key or block size is 24, and neither is longer than 24, do 12 rounds
190 190
 		// if either key or block size is 32, do 14 rounds
191
-		if ($key_sz == 16 && $blk_sz == 16)
192
-			$loops = 10;
193
-		else if (($key_sz == 24 || $blk_sz == 24) && $key_sz <= 24 && $blk_sz <= 24)
194
-			$loops = 12;
195
-		else if ($key_sz == 32 || $blk_sz == 32)
196
-			$loops = 14;
191
+		if ($key_sz == 16 && $blk_sz == 16) {
192
+					$loops = 10;
193
+		} else if (($key_sz == 24 || $blk_sz == 24) && $key_sz <= 24 && $blk_sz <= 24) {
194
+					$loops = 12;
195
+		} else if ($key_sz == 32 || $blk_sz == 32) {
196
+					$loops = 14;
197
+		}
197 198
 
198 199
 		// now begin the encryption
199 200
 		$this->addRoundKey($text, 0);
@@ -204,8 +205,9 @@  discard block
 block discarded – undo
204 205
 			$this->shiftRow($text);
205 206
 
206 207
 			// the last iteration does not use mixColumn
207
-			if ($i < $loops)
208
-				$this->mixColumn($text);
208
+			if ($i < $loops) {
209
+							$this->mixColumn($text);
210
+			}
209 211
 
210 212
 			$this->addRoundKey($text, $i);
211 213
 		}
@@ -232,12 +234,13 @@  discard block
 block discarded – undo
232 234
 		// if the key and block size is 16, do 10 rounds
233 235
 		// if the key or block size is 24, and neither is longer than 24, do 12 rounds
234 236
 		// if either key or block size is 32, do 14 rounds
235
-		if ($key_sz == 16 && $blk_sz == 16)
236
-			$loops = 10;
237
-		else if (($key_sz == 24 || $blk_sz == 24) && $key_sz <= 24 && $blk_sz <= 24)
238
-			$loops = 12;
239
-		else if ($key_sz == 32 || $blk_sz == 32)
240
-			$loops = 14;
237
+		if ($key_sz == 16 && $blk_sz == 16) {
238
+					$loops = 10;
239
+		} else if (($key_sz == 24 || $blk_sz == 24) && $key_sz <= 24 && $blk_sz <= 24) {
240
+					$loops = 12;
241
+		} else if ($key_sz == 32 || $blk_sz == 32) {
242
+					$loops = 14;
243
+		}
241 244
 
242 245
 		// now begin the decryption
243 246
 		$this->addRoundKey($text, 0);
@@ -249,8 +252,9 @@  discard block
 block discarded – undo
249 252
 			$this->addRoundKey($text, $i);
250 253
 
251 254
 			// the last iteration does not use mixColumn
252
-			if ($i < $loops)
253
-				$this->mixColumn($text);
255
+			if ($i < $loops) {
256
+							$this->mixColumn($text);
257
+			}
254 258
 		}
255 259
 
256 260
 		return true;
@@ -280,8 +284,9 @@  discard block
 block discarded – undo
280 284
 	protected function mixColumnMultiply($m, $byte)
281 285
 	{
282 286
 		// if multiplying by 1, then we just return the same number
283
-		if ($m == 0x01)
284
-			return $byte;
287
+		if ($m == 0x01) {
288
+					return $byte;
289
+		}
285 290
 
286 291
 		$hex = parent::dec2Hex($byte);
287 292
 		$row = parent::hex2Dec($hex[0]);
@@ -289,28 +294,34 @@  discard block
 block discarded – undo
289 294
 		$pos = ($row * 16) + $col;
290 295
 
291 296
 		// multiply by 2 (comes from self::$_matrix_mult during encryption)
292
-		if ($m == 0x02)
293
-			return self::$_gm2[$pos];
297
+		if ($m == 0x02) {
298
+					return self::$_gm2[$pos];
299
+		}
294 300
 
295 301
 		// multiply by 3 (comes from self::$_matrix_mult during encryption)
296
-		if ($m == 0x03)
297
-			return self::$_gm3[$pos];
302
+		if ($m == 0x03) {
303
+					return self::$_gm3[$pos];
304
+		}
298 305
 
299 306
 		// multiply by 9 (comes from self::$_matrix_mult_inv during decryption)
300
-		if ($m == 0x09)
301
-			return self::$_gm9[$pos];
307
+		if ($m == 0x09) {
308
+					return self::$_gm9[$pos];
309
+		}
302 310
 
303 311
 		// multiply by 11 (comes from self::$_matrix_mult_inv during decryption)
304
-		if ($m == 0x0b)
305
-			return self::$_gm11[$pos];
312
+		if ($m == 0x0b) {
313
+					return self::$_gm11[$pos];
314
+		}
306 315
 
307 316
 		// multiply by 13 (comes from self::$_matrix_mult_inv during decryption)
308
-		if ($m == 0x0d)
309
-			return self::$_gm13[$pos];
317
+		if ($m == 0x0d) {
318
+					return self::$_gm13[$pos];
319
+		}
310 320
 
311 321
 		// multiply by 14 (comes from self::$_matrix_mult_inv during decryption)
312
-		if ($m == 0x0e)
313
-			return self::$_gm14[$pos];
322
+		if ($m == 0x0e) {
323
+					return self::$_gm14[$pos];
324
+		}
314 325
 	}
315 326
 
316 327
 
@@ -331,13 +342,15 @@  discard block
 block discarded – undo
331 342
 		$ek_len = strlen($this->xkey);
332 343
 		$len = $this->blockSize();
333 344
 
334
-		if ($this->operation() == parent::ENCRYPT)
335
-			$offset = $round * $len;
336
-		else
337
-			$offset = ($ek_len - ($round * $len)) - $len;
345
+		if ($this->operation() == parent::ENCRYPT) {
346
+					$offset = $round * $len;
347
+		} else {
348
+					$offset = ($ek_len - ($round * $len)) - $len;
349
+		}
338 350
 
339
-		for ($i = 0; $i < $len; ++$i)
340
-			$text[$i] = $text[$i] ^ $this->xkey[$offset + $i];
351
+		for ($i = 0; $i < $len; ++$i) {
352
+					$text[$i] = $text[$i] ^ $this->xkey[$offset + $i];
353
+		}
341 354
 	}
342 355
 
343 356
 
@@ -361,10 +374,12 @@  discard block
 block discarded – undo
361 374
 			$pos = ($row * 16) + $col;
362 375
 
363 376
 			// return the corresponding value from the sbox
364
-			if ($this->operation() == parent::ENCRYPT)
365
-				$text[$i] = chr(self::$_s[$pos]);
366
-			else // parent::DECRYPT uses the inverse sbox
377
+			if ($this->operation() == parent::ENCRYPT) {
378
+							$text[$i] = chr(self::$_s[$pos]);
379
+			} else {
380
+			    // parent::DECRYPT uses the inverse sbox
367 381
 				$text[$i] = chr(self::$_s_inv[$pos]);
382
+			}
368 383
 		}
369 384
 	}
370 385
 
@@ -381,10 +396,12 @@  discard block
 block discarded – undo
381 396
 		$tmp = $t;
382 397
 
383 398
 		// the matrix we use depends on if we are encrypting or decrypting
384
-		if ($this->operation() == parent::ENCRYPT)
385
-			$m = self::$_matrix_mult;
386
-		else // parent::DECRYPT
399
+		if ($this->operation() == parent::ENCRYPT) {
400
+					$m = self::$_matrix_mult;
401
+		} else {
402
+		    // parent::DECRYPT
387 403
 			$m = self::$_matrix_mult_inv;
404
+		}
388 405
 
389 406
 		// the number of rounds we make depends on the block size of the text
390 407
 		// used during encryption/decryption
@@ -619,12 +636,13 @@  discard block
 block discarded – undo
619 636
 	 */
620 637
 	protected function expandKey()
621 638
 	{
622
-		if ($this->keySize() == 16)
623
-			return $this->expandKey128();
624
-		else if ($this->keySize() == 24)
625
-			return $this->expandKey192();
626
-		else if ($this->keySize() == 32)
627
-			return $this->expandKey256();
639
+		if ($this->keySize() == 16) {
640
+					return $this->expandKey128();
641
+		} else if ($this->keySize() == 24) {
642
+					return $this->expandKey192();
643
+		} else if ($this->keySize() == 32) {
644
+					return $this->expandKey256();
645
+		}
628 646
 	}
629 647
 
630 648
 
@@ -642,19 +660,22 @@  discard block
 block discarded – undo
642 660
 
643 661
 		// the number of rounds we make depends on the block size of the text
644 662
 		// used during encryption/decryption
645
-		if ($this->blockSize() == 16)
646
-			$max = 44;
647
-		if ($this->blockSize() == 24)
648
-			$max = 78;
649
-		if ($this->blockSize() == 32)
650
-			$max = 120;
663
+		if ($this->blockSize() == 16) {
664
+					$max = 44;
665
+		}
666
+		if ($this->blockSize() == 24) {
667
+					$max = 78;
668
+		}
669
+		if ($this->blockSize() == 32) {
670
+					$max = 120;
671
+		}
651 672
 
652 673
 		// 16 byte key expands to 176 bytes
653 674
 		for ($i = 0; $i < $max; ++$i)
654 675
 		{
655
-			if ($i >= 0 && $i <= 3)
656
-				$this->xkey .= $this->k($i * 4);
657
-			else if (($i % 4) == 0)
676
+			if ($i >= 0 && $i <= 3) {
677
+							$this->xkey .= $this->k($i * 4);
678
+			} else if (($i % 4) == 0)
658 679
 			{
659 680
 				// rotate the 4 bytes
660 681
 				$subword = $this->rotWord($this->ek(($i - 1) * 4));
@@ -701,19 +722,22 @@  discard block
 block discarded – undo
701 722
 
702 723
 		// the number of rounds we make depends on the block size of the text
703 724
 		// used during encryption/decryption
704
-		if ($this->blockSize() == 16)
705
-			$max = 52;
706
-		if ($this->blockSize() == 24)
707
-			$max = 78;
708
-		if ($this->blockSize() == 32)
709
-			$max = 120;
725
+		if ($this->blockSize() == 16) {
726
+					$max = 52;
727
+		}
728
+		if ($this->blockSize() == 24) {
729
+					$max = 78;
730
+		}
731
+		if ($this->blockSize() == 32) {
732
+					$max = 120;
733
+		}
710 734
 
711 735
 		// 24 byte key expands to 208 bytes
712 736
 		for ($i = 0; $i < $max; ++$i)
713 737
 		{
714
-			if ($i >= 0 && $i <= 5)
715
-				$this->xkey .= $this->k($i * 4);
716
-			else if (($i % 6) == 0)
738
+			if ($i >= 0 && $i <= 5) {
739
+							$this->xkey .= $this->k($i * 4);
740
+			} else if (($i % 6) == 0)
717 741
 			{
718 742
 				// rotate the 4 bytes
719 743
 				$subword = $this->rotWord($this->ek(($i - 1) * 4));
@@ -760,19 +784,22 @@  discard block
 block discarded – undo
760 784
 
761 785
 		// the number of rounds we make depends on the block size of the text
762 786
 		// used during encryption/decryption
763
-		if ($this->blockSize() == 16)
764
-			$max = 60;
765
-		if ($this->blockSize() == 24)
766
-			$max = 90;
767
-		if ($this->blockSize() == 32)
768
-			$max = 120;
787
+		if ($this->blockSize() == 16) {
788
+					$max = 60;
789
+		}
790
+		if ($this->blockSize() == 24) {
791
+					$max = 90;
792
+		}
793
+		if ($this->blockSize() == 32) {
794
+					$max = 120;
795
+		}
769 796
 
770 797
 		// 32 byte key expands to 240 bytes
771 798
 		for ($i = 0; $i < $max; ++$i)
772 799
 		{
773
-			if ($i >= 0 && $i <= 7)
774
-				$this->xkey .= $this->k($i * 4);
775
-			else if ($i % 8 == 0)
800
+			if ($i >= 0 && $i <= 7) {
801
+							$this->xkey .= $this->k($i * 4);
802
+			} else if ($i % 8 == 0)
776 803
 			{
777 804
 				// rotate the 4 bytes
778 805
 				$subword = $this->rotWord($this->ek(($i - 1) * 4));
@@ -791,8 +818,7 @@  discard block
 block discarded – undo
791 818
 				$h3 = parent::str2Hex($ek);
792 819
 				$res = parent::xorHex($h1, $h2, $h3);
793 820
 				$this->xkey .= parent::hex2Str($res);
794
-			}
795
-			else if ($i % 4 == 0)
821
+			} else if ($i % 4 == 0)
796 822
 			{
797 823
 				// get the subsitution from the s-box
798 824
 				$subword = $this->ek(($i - 1) * 4);
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/ciphers/CAST128.php 1 patch
Braces   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -92,8 +92,7 @@  discard block
 block discarded – undo
92 92
 		{
93 93
 			$key = substr($key, 0, self::BYTES_KEY_MAX);
94 94
 			$keylen = self::BYTES_KEY_MAX;
95
-		}
96
-		else if ($keylen < self::BYTES_KEY_MIN)
95
+		} else if ($keylen < self::BYTES_KEY_MIN)
97 96
 		{
98 97
 			$msg  = PHP_Crypt::CIPHER_CAST_128." requires a key size between ";
99 98
 			$msg .= "5 - 16 bytes.";
@@ -341,8 +340,9 @@  discard block
 block discarded – undo
341 340
 
342 341
 		// the max length of the key is 16 bytes, however if it is
343 342
 		// less, pad it with null to get ito to 16 bytes
344
-		if ($this->keySize() < self::BYTES_KEY_MAX)
345
-			$x = str_pad($x, self::BYTES_KEY_MAX, "\0", STR_PAD_RIGHT);
343
+		if ($this->keySize() < self::BYTES_KEY_MAX) {
344
+					$x = str_pad($x, self::BYTES_KEY_MAX, "\0", STR_PAD_RIGHT);
345
+		}
346 346
 
347 347
 		/*
348 348
 		 * NOW FOR THE UGLY PART, THIS IS TAKEN FROM PAGE 3-4 OF
@@ -639,8 +639,9 @@  discard block
 block discarded – undo
639 639
 
640 640
 		// there is 4kb in the s5 - s8 sboxes, which are not needed after we
641 641
 		// create the subkeys, so free up the memory. unset() doesn't work here
642
-		for ($i = 5; $i <= 8; ++$i)
643
-			self::${"_s$i"} = null;
642
+		for ($i = 5; $i <= 8; ++$i) {
643
+					self::${"_s$i"} = null;
644
+		}
644 645
 	}
645 646
 
646 647
 
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/Core.php 1 patch
Braces   +70 added lines, -55 removed lines patch added patch discarded remove patch
@@ -67,8 +67,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
includes/libraries/phpcrypt/Cipher.php 1 patch
Braces   +18 added lines, -14 removed lines patch added patch discarded remove patch
@@ -150,8 +150,9 @@  discard block
 block discarded – undo
150 150
      */
151 151
     public function operation($op = 0)
152 152
     {
153
-        if($op == self::ENCRYPT || $op == self::DECRYPT)
154
-            $this->operation = $op;
153
+        if($op == self::ENCRYPT || $op == self::DECRYPT) {
154
+                    $this->operation = $op;
155
+        }
155 156
 
156 157
         return $this->operation;
157 158
     }
@@ -164,8 +165,9 @@  discard block
 block discarded – undo
164 165
      */
165 166
     public function name($name = "")
166 167
     {
167
-        if($name != "")
168
-            $this->cipher_name = $name;
168
+        if($name != "") {
169
+                    $this->cipher_name = $name;
170
+        }
169 171
 
170 172
         return $this->cipher_name;
171 173
     }
@@ -179,13 +181,15 @@  discard block
 block discarded – undo
179 181
      */
180 182
     public function blockSize($bytes = 0)
181 183
     {
182
-        if($bytes > 0)
183
-            $this->block_size = $bytes;
184
+        if($bytes > 0) {
185
+                    $this->block_size = $bytes;
186
+        }
184 187
 
185 188
         // in some cases a blockSize is not set, such as stream ciphers.
186 189
         // so just return 0 for the block size
187
-        if(!isset($this->block_size))
188
-            return 0;
190
+        if(!isset($this->block_size)) {
191
+                    return 0;
192
+        }
189 193
 
190 194
         return $this->block_size;
191 195
     }
@@ -224,10 +228,11 @@  discard block
 block discarded – undo
224 228
             // given, we need to make sure the new key meets the size
225 229
             // requirements. This can be determined from the $this->key_len
226 230
             // member set from the previous key
227
-            if($this->key_len > 0 && $req_sz == 0)
228
-                $req_sz = $this->key_len;
229
-            else
230
-                $this->key_len = strlen($key);
231
+            if($this->key_len > 0 && $req_sz == 0) {
232
+                            $req_sz = $this->key_len;
233
+            } else {
234
+                            $this->key_len = strlen($key);
235
+            }
231 236
 
232 237
             if($req_sz > 0)
233 238
             {
@@ -236,8 +241,7 @@  discard block
 block discarded – undo
236 241
                     // shorten the key length
237 242
                     $key = substr($key, 0, $req_sz);
238 243
                     $this->key_len = $req_sz;
239
-                }
240
-                else if($this->key_len < $req_sz)
244
+                } else if($this->key_len < $req_sz)
241 245
                 {
242 246
                     // send a notice that the key was too small
243 247
                     // NEVER PAD THE KEY, THIS WOULD BE INSECURE!!!!!
Please login to merge, or discard this patch.