[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Polyfill\Php55; 13 14 /** 15 * @internal 16 */ 17 final class Php55 18 { 19 public static function boolval($val) 20 { 21 return (bool) $val; 22 } 23 24 public static function json_last_error_msg() 25 { 26 switch (json_last_error()) { 27 case JSON_ERROR_NONE: return 'No error'; 28 case JSON_ERROR_DEPTH: return 'Maximum stack depth exceeded'; 29 case JSON_ERROR_STATE_MISMATCH: return 'State mismatch (invalid or malformed JSON)'; 30 case JSON_ERROR_CTRL_CHAR: return 'Control character error, possibly incorrectly encoded'; 31 case JSON_ERROR_SYNTAX: return 'Syntax error'; 32 case JSON_ERROR_UTF8: return 'Malformed UTF-8 characters, possibly incorrectly encoded'; 33 default: return 'Unknown error'; 34 } 35 } 36 37 /** 38 * @author Sebastiaan Stok <s.stok@rollerscapes.net> 39 * @author Scott <scott@paragonie.com> 40 */ 41 public static function hash_pbkdf2($algorithm, $password, $salt, $iterations, $length = 0, $rawOutput = false) 42 { 43 // Pre-hash for optimization if password length > hash length 44 $hashLength = \strlen(hash($algorithm, '', true)); 45 switch ($algorithm) { 46 case 'sha1': 47 case 'sha224': 48 case 'sha256': 49 $blockSize = 64; 50 break; 51 case 'sha384': 52 case 'sha512': 53 $blockSize = 128; 54 break; 55 default: 56 $blockSize = $hashLength; 57 break; 58 } 59 if ($length < 1) { 60 $length = $hashLength; 61 if (!$rawOutput) { 62 $length <<= 1; 63 } 64 } 65 66 // Number of blocks needed to create the derived key 67 $blocks = ceil($length / $hashLength); 68 $digest = ''; 69 if (\strlen($password) > $blockSize) { 70 $password = hash($algorithm, $password, true); 71 } 72 73 for ($i = 1; $i <= $blocks; ++$i) { 74 $ib = $block = hash_hmac($algorithm, $salt.pack('N', $i), $password, true); 75 76 // Iterations 77 for ($j = 1; $j < $iterations; ++$j) { 78 $ib ^= ($block = hash_hmac($algorithm, $block, $password, true)); 79 } 80 81 $digest .= $ib; 82 } 83 84 if (!$rawOutput) { 85 $digest = bin2hex($digest); 86 } 87 88 return substr($digest, 0, $length); 89 } 90 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |