@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * (64 characters for example) for keeping high entropy. |
86 | 86 | * The pass-phrase is converted internaly into |
87 | 87 | * a binary key that is to be used for encryption. |
88 | - * @return mixed base64 encrypted string, FALSE on failure. |
|
88 | + * @return string|false base64 encrypted string, FALSE on failure. |
|
89 | 89 | */ |
90 | 90 | public static function enc($string, $pass) { |
91 | 91 | |
@@ -283,6 +283,10 @@ discard block |
||
283 | 283 | return self::mbstring_func_overload() ? mb_strlen($str, '8bit') : strlen($str); |
284 | 284 | } |
285 | 285 | |
286 | + /** |
|
287 | + * @param integer $start |
|
288 | + * @param integer $length |
|
289 | + */ |
|
286 | 290 | protected static function substr($str, $start, $length = null) { |
287 | 291 | |
288 | 292 | if (self::mbstring_func_overload()) { |
@@ -296,6 +300,9 @@ discard block |
||
296 | 300 | return isset($length) ? substr($str, $start, $length) : substr($str, $start); |
297 | 301 | } |
298 | 302 | |
303 | + /** |
|
304 | + * @param integer $length |
|
305 | + */ |
|
299 | 306 | protected static function random_bytes($length) { |
300 | 307 | |
301 | 308 | $length = (int) $length; |
@@ -440,6 +447,11 @@ discard block |
||
440 | 447 | */ |
441 | 448 | } |
442 | 449 | |
450 | + /** |
|
451 | + * @param string $string |
|
452 | + * @param string $key |
|
453 | + * @param string $iv |
|
454 | + */ |
|
443 | 455 | protected static function aes_cbc_encrypt($string, $key, $iv) { |
444 | 456 | |
445 | 457 | $key_size = self::$key_size; |
@@ -472,6 +484,11 @@ discard block |
||
472 | 484 | return false; |
473 | 485 | } |
474 | 486 | |
487 | + /** |
|
488 | + * @param string $crypted |
|
489 | + * @param string $key |
|
490 | + * @param string $iv |
|
491 | + */ |
|
475 | 492 | protected static function aes_cbc_decrypt($crypted, $key, $iv) { |
476 | 493 | |
477 | 494 | $key_size = self::$key_size; |
@@ -512,6 +529,9 @@ discard block |
||
512 | 529 | return $string.str_repeat(chr($pad), $pad); |
513 | 530 | } |
514 | 531 | |
532 | + /** |
|
533 | + * @param string $string |
|
534 | + */ |
|
515 | 535 | protected static function remove_pkcs7_pad($string) { |
516 | 536 | |
517 | 537 | // 128 bits: $block_length = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | $bytes = ($total > $hash_len) ? $hash_len : $total; |
380 | 380 | $total -= $bytes; |
381 | 381 | //collect any entropy available from the PHP system and filesystem |
382 | - $entropy = rand() . uniqid(mt_rand(), true) . $SSLstr; |
|
382 | + $entropy = rand().uniqid(mt_rand(), true).$SSLstr; |
|
383 | 383 | $entropy .= implode('', @fstat(@fopen(__FILE__, 'r'))); |
384 | - $entropy .= memory_get_usage() . getmypid(); |
|
385 | - $entropy .= serialize($_ENV) . serialize($_SERVER); |
|
384 | + $entropy .= memory_get_usage().getmypid(); |
|
385 | + $entropy .= serialize($_ENV).serialize($_SERVER); |
|
386 | 386 | if (function_exists('posix_times')) { |
387 | 387 | $entropy .= serialize(posix_times()); |
388 | 388 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | $var = sha1($var); |
401 | 401 | } |
402 | 402 | $c2 = microtime(true); |
403 | - $entropy .= $c1 . $c2; |
|
403 | + $entropy .= $c1.$c2; |
|
404 | 404 | } |
405 | 405 | // Based on the above measurement determine the total rounds |
406 | 406 | // in order to bound the total running time. |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | $var = sha1($var); |
416 | 416 | } |
417 | 417 | $c2 = microtime(); |
418 | - $entropy .= $c1 . $c2; |
|
418 | + $entropy .= $c1.$c2; |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | // We assume sha1 is a deterministic extractor for the $entropy variable. |
@@ -216,8 +216,7 @@ discard block |
||
216 | 216 | { |
217 | 217 | $test = random_bytes(1); |
218 | 218 | self::$random_bytes_exists = true; |
219 | - } |
|
220 | - catch (Exception $e) { |
|
219 | + } catch (Exception $e) { |
|
221 | 220 | // Do nothing. |
222 | 221 | } |
223 | 222 | } |
@@ -305,8 +304,7 @@ discard block |
||
305 | 304 | try |
306 | 305 | { |
307 | 306 | return random_bytes($length); |
308 | - } |
|
309 | - catch (Exception $e) { |
|
307 | + } catch (Exception $e) { |
|
310 | 308 | // Do nothing, continue. |
311 | 309 | } |
312 | 310 | } |