Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/PHPSecLi.../Crypt
File: Hash.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
[3] Fix | Delete
*
[4] Fix | Delete
* Uses hash() or mhash() if available and an internal implementation, otherwise. Currently supports the following:
[5] Fix | Delete
*
[6] Fix | Delete
* md2, md5, md5-96, sha1, sha1-96, sha256, sha384, and sha512
[7] Fix | Delete
*
[8] Fix | Delete
* If {@link Crypt_Hash::setKey() setKey()} is called, {@link Crypt_Hash::hash() hash()} will return the HMAC as opposed to
[9] Fix | Delete
* the hash. If no valid algorithm is provided, sha1 will be used.
[10] Fix | Delete
*
[11] Fix | Delete
* PHP versions 4 and 5
[12] Fix | Delete
*
[13] Fix | Delete
* {@internal The variable names are the same as those in
[14] Fix | Delete
* {@link http://tools.ietf.org/html/rfc2104#section-2 RFC2104}.}}
[15] Fix | Delete
*
[16] Fix | Delete
* Here's a short example of how to use this library:
[17] Fix | Delete
* <code>
[18] Fix | Delete
* <?php
[19] Fix | Delete
* include 'Crypt/Hash.php';
[20] Fix | Delete
*
[21] Fix | Delete
* $hash = new Crypt_Hash('sha1');
[22] Fix | Delete
*
[23] Fix | Delete
* $hash->setKey('abcdefg');
[24] Fix | Delete
*
[25] Fix | Delete
* echo base64_encode($hash->hash('abcdefg'));
[26] Fix | Delete
* ?>
[27] Fix | Delete
* </code>
[28] Fix | Delete
*
[29] Fix | Delete
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
[30] Fix | Delete
* of this software and associated documentation files (the "Software"), to deal
[31] Fix | Delete
* in the Software without restriction, including without limitation the rights
[32] Fix | Delete
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
[33] Fix | Delete
* copies of the Software, and to permit persons to whom the Software is
[34] Fix | Delete
* furnished to do so, subject to the following conditions:
[35] Fix | Delete
*
[36] Fix | Delete
* The above copyright notice and this permission notice shall be included in
[37] Fix | Delete
* all copies or substantial portions of the Software.
[38] Fix | Delete
*
[39] Fix | Delete
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
[40] Fix | Delete
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
[41] Fix | Delete
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
[42] Fix | Delete
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
[43] Fix | Delete
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
[44] Fix | Delete
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
[45] Fix | Delete
* THE SOFTWARE.
[46] Fix | Delete
*
[47] Fix | Delete
* @category Crypt
[48] Fix | Delete
* @package Crypt_Hash
[49] Fix | Delete
* @author Jim Wigginton <terrafrost@php.net>
[50] Fix | Delete
* @copyright MMVII Jim Wigginton
[51] Fix | Delete
* @license http://www.opensource.org/licenses/mit-license.html MIT License
[52] Fix | Delete
* @link http://phpseclib.sourceforge.net
[53] Fix | Delete
*/
[54] Fix | Delete
[55] Fix | Delete
/**#@+
[56] Fix | Delete
* @access private
[57] Fix | Delete
* @see Crypt_Hash::Crypt_Hash()
[58] Fix | Delete
*/
[59] Fix | Delete
/**
[60] Fix | Delete
* Toggles the internal implementation
[61] Fix | Delete
*/
[62] Fix | Delete
define('CRYPT_HASH_MODE_INTERNAL', 1);
[63] Fix | Delete
/**
[64] Fix | Delete
* Toggles the mhash() implementation, which has been deprecated on PHP 5.3.0+.
[65] Fix | Delete
*/
[66] Fix | Delete
define('CRYPT_HASH_MODE_MHASH', 2);
[67] Fix | Delete
/**
[68] Fix | Delete
* Toggles the hash() implementation, which works on PHP 5.1.2+.
[69] Fix | Delete
*/
[70] Fix | Delete
define('CRYPT_HASH_MODE_HASH', 3);
[71] Fix | Delete
/**#@-*/
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
[75] Fix | Delete
*
[76] Fix | Delete
* @package Crypt_Hash
[77] Fix | Delete
* @author Jim Wigginton <terrafrost@php.net>
[78] Fix | Delete
* @access public
[79] Fix | Delete
*/
[80] Fix | Delete
class Crypt_Hash
[81] Fix | Delete
{
[82] Fix | Delete
/**
[83] Fix | Delete
* Hash Parameter
[84] Fix | Delete
*
[85] Fix | Delete
* @see Crypt_Hash::setHash()
[86] Fix | Delete
* @var Integer
[87] Fix | Delete
* @access private
[88] Fix | Delete
*/
[89] Fix | Delete
public $hashParam;
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Byte-length of compression blocks / key (Internal HMAC)
[93] Fix | Delete
*
[94] Fix | Delete
* @see Crypt_Hash::setAlgorithm()
[95] Fix | Delete
* @var Integer
[96] Fix | Delete
* @access private
[97] Fix | Delete
*/
[98] Fix | Delete
public $b;
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Byte-length of hash output (Internal HMAC)
[102] Fix | Delete
*
[103] Fix | Delete
* @see Crypt_Hash::setHash()
[104] Fix | Delete
* @var Integer
[105] Fix | Delete
* @access private
[106] Fix | Delete
*/
[107] Fix | Delete
public $l = false;
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Hash Algorithm
[111] Fix | Delete
*
[112] Fix | Delete
* @see Crypt_Hash::setHash()
[113] Fix | Delete
* @var String
[114] Fix | Delete
* @access private
[115] Fix | Delete
*/
[116] Fix | Delete
public $hash;
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Key
[120] Fix | Delete
*
[121] Fix | Delete
* @see Crypt_Hash::setKey()
[122] Fix | Delete
* @var String
[123] Fix | Delete
* @access private
[124] Fix | Delete
*/
[125] Fix | Delete
public $key = false;
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Outer XOR (Internal HMAC)
[129] Fix | Delete
*
[130] Fix | Delete
* @see Crypt_Hash::setKey()
[131] Fix | Delete
* @var String
[132] Fix | Delete
* @access private
[133] Fix | Delete
*/
[134] Fix | Delete
public $opad;
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Inner XOR (Internal HMAC)
[138] Fix | Delete
*
[139] Fix | Delete
* @see Crypt_Hash::setKey()
[140] Fix | Delete
* @var String
[141] Fix | Delete
* @access private
[142] Fix | Delete
*/
[143] Fix | Delete
public $ipad;
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Default Constructor.
[147] Fix | Delete
*
[148] Fix | Delete
* @param optional String $hash
[149] Fix | Delete
*
[150] Fix | Delete
* @return Crypt_Hash
[151] Fix | Delete
* @access public
[152] Fix | Delete
*/
[153] Fix | Delete
public function __construct($hash = 'sha1')
[154] Fix | Delete
{
[155] Fix | Delete
if (!defined('CRYPT_HASH_MODE')) {
[156] Fix | Delete
switch (true) {
[157] Fix | Delete
case extension_loaded('hash'):
[158] Fix | Delete
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_HASH);
[159] Fix | Delete
break;
[160] Fix | Delete
case extension_loaded('mhash'):
[161] Fix | Delete
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_MHASH);
[162] Fix | Delete
break;
[163] Fix | Delete
default:
[164] Fix | Delete
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL);
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
$this->setHash($hash);
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Sets the key for HMACs
[173] Fix | Delete
*
[174] Fix | Delete
* Keys can be of any length.
[175] Fix | Delete
*
[176] Fix | Delete
* @access public
[177] Fix | Delete
*
[178] Fix | Delete
* @param optional String $key
[179] Fix | Delete
*/
[180] Fix | Delete
public function setKey($key = false)
[181] Fix | Delete
{
[182] Fix | Delete
$this->key = $key;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Gets the hash function.
[187] Fix | Delete
*
[188] Fix | Delete
* As set by the constructor or by the setHash() method.
[189] Fix | Delete
*
[190] Fix | Delete
* @access public
[191] Fix | Delete
* @return String
[192] Fix | Delete
*/
[193] Fix | Delete
public function getHash()
[194] Fix | Delete
{
[195] Fix | Delete
return $this->hashParam;
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Sets the hash function.
[200] Fix | Delete
*
[201] Fix | Delete
* @access public
[202] Fix | Delete
*
[203] Fix | Delete
* @param String $hash
[204] Fix | Delete
*/
[205] Fix | Delete
public function setHash($hash)
[206] Fix | Delete
{
[207] Fix | Delete
$this->hashParam = $hash = strtolower($hash);
[208] Fix | Delete
switch ($hash) {
[209] Fix | Delete
case 'md5-96':
[210] Fix | Delete
case 'sha1-96':
[211] Fix | Delete
$this->l = 12; // 96 / 8 = 12
[212] Fix | Delete
break;
[213] Fix | Delete
case 'md2':
[214] Fix | Delete
case 'md5':
[215] Fix | Delete
$this->l = 16;
[216] Fix | Delete
break;
[217] Fix | Delete
case 'sha1':
[218] Fix | Delete
$this->l = 20;
[219] Fix | Delete
break;
[220] Fix | Delete
case 'sha256':
[221] Fix | Delete
$this->l = 32;
[222] Fix | Delete
break;
[223] Fix | Delete
case 'sha384':
[224] Fix | Delete
$this->l = 48;
[225] Fix | Delete
break;
[226] Fix | Delete
case 'sha512':
[227] Fix | Delete
$this->l = 64;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
switch ($hash) {
[231] Fix | Delete
case 'md2':
[232] Fix | Delete
$mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_HASH && in_array('md2', hash_algos()) ?
[233] Fix | Delete
CRYPT_HASH_MODE_HASH : CRYPT_HASH_MODE_INTERNAL;
[234] Fix | Delete
break;
[235] Fix | Delete
case 'sha384':
[236] Fix | Delete
case 'sha512':
[237] Fix | Delete
$mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_MHASH ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
[238] Fix | Delete
break;
[239] Fix | Delete
default:
[240] Fix | Delete
$mode = CRYPT_HASH_MODE;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
switch ($mode) {
[244] Fix | Delete
case CRYPT_HASH_MODE_MHASH:
[245] Fix | Delete
switch ($hash) {
[246] Fix | Delete
case 'md5':
[247] Fix | Delete
case 'md5-96':
[248] Fix | Delete
$this->hash = MHASH_MD5;
[249] Fix | Delete
break;
[250] Fix | Delete
case 'sha256':
[251] Fix | Delete
$this->hash = MHASH_SHA256;
[252] Fix | Delete
break;
[253] Fix | Delete
case 'sha1':
[254] Fix | Delete
case 'sha1-96':
[255] Fix | Delete
default:
[256] Fix | Delete
$this->hash = MHASH_SHA1;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
return;
[260] Fix | Delete
case CRYPT_HASH_MODE_HASH:
[261] Fix | Delete
switch ($hash) {
[262] Fix | Delete
case 'md5':
[263] Fix | Delete
case 'md5-96':
[264] Fix | Delete
$this->hash = 'md5';
[265] Fix | Delete
[266] Fix | Delete
return;
[267] Fix | Delete
case 'md2':
[268] Fix | Delete
case 'sha256':
[269] Fix | Delete
case 'sha384':
[270] Fix | Delete
case 'sha512':
[271] Fix | Delete
$this->hash = $hash;
[272] Fix | Delete
[273] Fix | Delete
return;
[274] Fix | Delete
case 'sha1':
[275] Fix | Delete
case 'sha1-96':
[276] Fix | Delete
default:
[277] Fix | Delete
$this->hash = 'sha1';
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
return;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
switch ($hash) {
[284] Fix | Delete
case 'md2':
[285] Fix | Delete
$this->b = 16;
[286] Fix | Delete
$this->hash = array($this, '_md2');
[287] Fix | Delete
break;
[288] Fix | Delete
case 'md5':
[289] Fix | Delete
case 'md5-96':
[290] Fix | Delete
$this->b = 64;
[291] Fix | Delete
$this->hash = array($this, '_md5');
[292] Fix | Delete
break;
[293] Fix | Delete
case 'sha256':
[294] Fix | Delete
$this->b = 64;
[295] Fix | Delete
$this->hash = array($this, '_sha256');
[296] Fix | Delete
break;
[297] Fix | Delete
case 'sha384':
[298] Fix | Delete
case 'sha512':
[299] Fix | Delete
$this->b = 128;
[300] Fix | Delete
$this->hash = array($this, '_sha512');
[301] Fix | Delete
break;
[302] Fix | Delete
case 'sha1':
[303] Fix | Delete
case 'sha1-96':
[304] Fix | Delete
default:
[305] Fix | Delete
$this->b = 64;
[306] Fix | Delete
$this->hash = array($this, '_sha1');
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
$this->ipad = str_repeat(chr(0x36), $this->b);
[310] Fix | Delete
$this->opad = str_repeat(chr(0x5C), $this->b);
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
/**
[314] Fix | Delete
* Compute the HMAC.
[315] Fix | Delete
*
[316] Fix | Delete
* @access public
[317] Fix | Delete
*
[318] Fix | Delete
* @param String $text
[319] Fix | Delete
*
[320] Fix | Delete
* @return String
[321] Fix | Delete
*/
[322] Fix | Delete
public function hash($text)
[323] Fix | Delete
{
[324] Fix | Delete
$mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
[325] Fix | Delete
[326] Fix | Delete
if (!empty($this->key) || is_string($this->key)) {
[327] Fix | Delete
switch ($mode) {
[328] Fix | Delete
case CRYPT_HASH_MODE_MHASH:
[329] Fix | Delete
$output = mhash($this->hash, $text, $this->key);
[330] Fix | Delete
break;
[331] Fix | Delete
case CRYPT_HASH_MODE_HASH:
[332] Fix | Delete
$output = hash_hmac($this->hash, $text, $this->key, true);
[333] Fix | Delete
break;
[334] Fix | Delete
case CRYPT_HASH_MODE_INTERNAL:
[335] Fix | Delete
/* "Applications that use keys longer than B bytes will first hash the key using H and then use the
[336] Fix | Delete
resultant L byte string as the actual key to HMAC."
[337] Fix | Delete
[338] Fix | Delete
-- http://tools.ietf.org/html/rfc2104#section-2 */
[339] Fix | Delete
$key = strlen($this->key) > $this->b ? call_user_func($this->hash, $this->key) : $this->key;
[340] Fix | Delete
[341] Fix | Delete
$key = str_pad($key, $this->b, chr(0)); // step 1
[342] Fix | Delete
$temp = $this->ipad ^ $key; // step 2
[343] Fix | Delete
$temp .= $text; // step 3
[344] Fix | Delete
$temp = call_user_func($this->hash, $temp); // step 4
[345] Fix | Delete
$output = $this->opad ^ $key; // step 5
[346] Fix | Delete
$output .= $temp; // step 6
[347] Fix | Delete
$output = call_user_func($this->hash, $output); // step 7
[348] Fix | Delete
}
[349] Fix | Delete
} else {
[350] Fix | Delete
switch ($mode) {
[351] Fix | Delete
case CRYPT_HASH_MODE_MHASH:
[352] Fix | Delete
$output = mhash($this->hash, $text);
[353] Fix | Delete
break;
[354] Fix | Delete
case CRYPT_HASH_MODE_HASH:
[355] Fix | Delete
$output = hash($this->hash, $text, true);
[356] Fix | Delete
break;
[357] Fix | Delete
case CRYPT_HASH_MODE_INTERNAL:
[358] Fix | Delete
$output = call_user_func($this->hash, $text);
[359] Fix | Delete
}
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
return substr($output, 0, $this->l);
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* Returns the hash length (in bytes)
[367] Fix | Delete
*
[368] Fix | Delete
* @access public
[369] Fix | Delete
* @return Integer
[370] Fix | Delete
*/
[371] Fix | Delete
public function getLength()
[372] Fix | Delete
{
[373] Fix | Delete
return $this->l;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Wrapper for MD5
[378] Fix | Delete
*
[379] Fix | Delete
* @access private
[380] Fix | Delete
*
[381] Fix | Delete
* @param String $m
[382] Fix | Delete
*/
[383] Fix | Delete
public function _md5($m)
[384] Fix | Delete
{
[385] Fix | Delete
return pack('H*', md5($m));
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
/**
[389] Fix | Delete
* Wrapper for SHA1
[390] Fix | Delete
*
[391] Fix | Delete
* @access private
[392] Fix | Delete
*
[393] Fix | Delete
* @param String $m
[394] Fix | Delete
*/
[395] Fix | Delete
public function _sha1($m)
[396] Fix | Delete
{
[397] Fix | Delete
return pack('H*', sha1($m));
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* Pure-PHP implementation of MD2
[402] Fix | Delete
*
[403] Fix | Delete
* See {@link http://tools.ietf.org/html/rfc1319 RFC1319}.
[404] Fix | Delete
*
[405] Fix | Delete
* @access private
[406] Fix | Delete
*
[407] Fix | Delete
* @param String $m
[408] Fix | Delete
*/
[409] Fix | Delete
public function _md2($m)
[410] Fix | Delete
{
[411] Fix | Delete
static $s = array(
[412] Fix | Delete
41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6,
[413] Fix | Delete
19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188,
[414] Fix | Delete
76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24,
[415] Fix | Delete
138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251,
[416] Fix | Delete
245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63,
[417] Fix | Delete
148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50,
[418] Fix | Delete
39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165,
[419] Fix | Delete
181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210,
[420] Fix | Delete
150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157,
[421] Fix | Delete
112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27,
[422] Fix | Delete
96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15,
[423] Fix | Delete
85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197,
[424] Fix | Delete
234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65,
[425] Fix | Delete
129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123,
[426] Fix | Delete
8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233,
[427] Fix | Delete
203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228,
[428] Fix | Delete
166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237,
[429] Fix | Delete
31, 26, 219, 153, 141, 51, 159, 17, 131, 20,
[430] Fix | Delete
);
[431] Fix | Delete
[432] Fix | Delete
// Step 1. Append Padding Bytes
[433] Fix | Delete
$pad = 16 - (strlen($m) & 0xF);
[434] Fix | Delete
$m .= str_repeat(chr($pad), $pad);
[435] Fix | Delete
[436] Fix | Delete
$length = strlen($m);
[437] Fix | Delete
[438] Fix | Delete
// Step 2. Append Checksum
[439] Fix | Delete
$c = str_repeat(chr(0), 16);
[440] Fix | Delete
$l = chr(0);
[441] Fix | Delete
for ($i = 0; $i < $length; $i += 16) {
[442] Fix | Delete
for ($j = 0; $j < 16; $j++) {
[443] Fix | Delete
// RFC1319 incorrectly states that C[j] should be set to S[c xor L]
[444] Fix | Delete
//$c[$j] = chr($s[ord($m[$i + $j] ^ $l)]);
[445] Fix | Delete
// per <http://www.rfc-editor.org/errata_search.php?rfc=1319>, however, C[j] should be set to S[c xor L] xor C[j]
[446] Fix | Delete
$c[$j] = chr($s[ord($m[$i + $j] ^ $l)] ^ ord($c[$j]));
[447] Fix | Delete
$l = $c[$j];
[448] Fix | Delete
}
[449] Fix | Delete
}
[450] Fix | Delete
$m .= $c;
[451] Fix | Delete
[452] Fix | Delete
$length += 16;
[453] Fix | Delete
[454] Fix | Delete
// Step 3. Initialize MD Buffer
[455] Fix | Delete
$x = str_repeat(chr(0), 48);
[456] Fix | Delete
[457] Fix | Delete
// Step 4. Process Message in 16-Byte Blocks
[458] Fix | Delete
for ($i = 0; $i < $length; $i += 16) {
[459] Fix | Delete
for ($j = 0; $j < 16; $j++) {
[460] Fix | Delete
$x[$j + 16] = $m[$i + $j];
[461] Fix | Delete
$x[$j + 32] = $x[$j + 16] ^ $x[$j];
[462] Fix | Delete
}
[463] Fix | Delete
$t = chr(0);
[464] Fix | Delete
for ($j = 0; $j < 18; $j++) {
[465] Fix | Delete
for ($k = 0; $k < 48; $k++) {
[466] Fix | Delete
$x[$k] = $t = $x[$k] ^ chr($s[ord($t)]);
[467] Fix | Delete
//$t = $x[$k] = $x[$k] ^ chr($s[ord($t)]);
[468] Fix | Delete
}
[469] Fix | Delete
$t = chr(ord($t) + $j);
[470] Fix | Delete
}
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
// Step 5. Output
[474] Fix | Delete
return substr($x, 0, 16);
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
/**
[478] Fix | Delete
* Pure-PHP implementation of SHA256
[479] Fix | Delete
*
[480] Fix | Delete
* See {@link http://en.wikipedia.org/wiki/SHA_hash_functions#SHA-256_.28a_SHA-2_variant.29_pseudocode SHA-256 (a SHA-2 variant) pseudocode - Wikipedia}.
[481] Fix | Delete
*
[482] Fix | Delete
* @access private
[483] Fix | Delete
*
[484] Fix | Delete
* @param String $m
[485] Fix | Delete
*/
[486] Fix | Delete
public function _sha256($m)
[487] Fix | Delete
{
[488] Fix | Delete
if (extension_loaded('suhosin')) {
[489] Fix | Delete
return pack('H*', sha256($m));
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
// Initialize variables
[493] Fix | Delete
$hash = array(
[494] Fix | Delete
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
[495] Fix | Delete
);
[496] Fix | Delete
// Initialize table of round constants
[497] Fix | Delete
// (first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
[498] Fix | Delete
static $k = array(
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function