Exemplo n.º 1
0
 function compute(&$hashData)
 {
     static $vars = 'abcdefgh';
     static $K = null;
     if ($K === null) {
         $K = array((int) 0x428a2f98, (int) 0x71374491, (int) 3049323471.0, (int) 0.0, (int) 0x3956c25b, (int) 0x59f111f1, (int) 2453635748.0, (int) 0.0, (int) 3624381080.0, (int) 0x12835b01, (int) 0x243185be, (int) 0x550c7dc3, (int) 0x72be5d74, (int) 0.0, (int) 2614888103.0, (int) 3248222580.0, (int) 0.0, (int) 0.0, (int) 0xfc19dc6, (int) 0x240ca1cc, (int) 0x2de92c6f, (int) 0x4a7484aa, (int) 0x5cb0a9dc, (int) 0x76f988da, (int) 0.0, (int) 2821834349.0, (int) 2952996808.0, (int) 3210313671.0, (int) 0.0, (int) 3584528711.0, (int) 0x6ca6351, (int) 0x14292967, (int) 0x27b70a85, (int) 0x2e1b2138, (int) 0x4d2c6dfc, (int) 0x53380d13, (int) 0x650a7354, (int) 0x766a0abb, (int) 0.0, (int) 2456956037.0, (int) 0.0, (int) 2820302411.0, (int) 3259730800.0, (int) 3345764771.0, (int) 0.0, (int) 3600352804.0, (int) 0.0, (int) 0x106aa070, (int) 0x19a4c116, (int) 0x1e376c08, (int) 0x2748774c, (int) 0x34b0bcb5, (int) 0x391c0cb3, (int) 0x4ed8aa4a, (int) 0x5b9cca4f, (int) 0x682e6ff3, (int) 0x748f82ee, (int) 0x78a5636f, (int) 2227730452.0, (int) 2361852424.0, (int) 0.0, (int) 0.0, (int) 0.0, (int) 3329325298.0);
     }
     $W = array();
     for ($i = 0, $numChunks = sizeof($hashData->chunks); $i < $numChunks; $i++) {
         //  initialize the registers
         for ($j = 0; $j < 8; $j++) {
             ${$vars[$j]} = $hashData->hash[$j];
         }
         //  the SHA-256 compression function
         for ($j = 0; $j < 64; $j++) {
             if ($j < 16) {
                 $T1 = ord($hashData->chunks[$i][$j * 4]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 1]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 2]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 3]) & 0xff;
                 $W[$j] = $T1;
             } else {
                 $W[$j] = SHA256::sum(($W[$j - 2] >> 17 & 0x7fff | $W[$j - 2] << 15) ^ ($W[$j - 2] >> 19 & 0x1fff | $W[$j - 2] << 13) ^ $W[$j - 2] >> 10 & 0x3fffff, $W[$j - 7], ($W[$j - 15] >> 7 & 0x1ffffff | $W[$j - 15] << 25) ^ ($W[$j - 15] >> 18 & 0x3fff | $W[$j - 15] << 14) ^ $W[$j - 15] >> 3 & 0x1fffffff, $W[$j - 16]);
             }
             $T1 = SHA256::sum($h, ($e >> 6 & 0x3ffffff | $e << 26) ^ ($e >> 11 & 0x1fffff | $e << 21) ^ ($e >> 25 & 0x7f | $e << 7), $e & $f ^ ~$e & $g, $K[$j], $W[$j]);
             $T2 = SHA256::sum(($a >> 2 & 0x3fffffff | $a << 30) ^ ($a >> 13 & 0x7ffff | $a << 19) ^ ($a >> 22 & 0x3ff | $a << 10), $a & $b ^ $a & $c ^ $b & $c);
             $h = $g;
             $g = $f;
             $f = $e;
             $e = SHA256::sum($d, $T1);
             $d = $c;
             $c = $b;
             $b = $a;
             $a = SHA256::sum($T1, $T2);
         }
         //  compute the next hash set
         for ($j = 0; $j < 8; $j++) {
             $hashData->hash[$j] = SHA256::sum(${$vars[$j]}, $hashData->hash[$j]);
         }
     }
 }
Exemplo n.º 2
0
 function compute(&$hashData)
 {
     static $vars = 'abcdefgh';
     static $K = null;
     if ($K === null) {
         /*
                  $K = array(
         	(int)0x428A2F98, (int)0x71374491, (int)0xB5C0FBCF, (int)0xE9B5DBA5,
         	(int)0x3956C25B, (int)0x59F111F1, (int)0x923F82A4, (int)0xAB1C5ED5,
         	(int)0xD807AA98, (int)0x12835B01, (int)0x243185BE, (int)0x550C7DC3,
         	(int)0x72BE5D74, (int)0x80DEB1FE, (int)0x9BDC06A7, (int)0xC19BF174,
         	(int)0xE49B69C1, (int)0xEFBE4786, (int)0x0FC19DC6, (int)0x240CA1CC,
         	(int)0x2DE92C6F, (int)0x4A7484AA, (int)0x5CB0A9DC, (int)0x76F988DA,
         	(int)0x983E5152, (int)0xA831C66D, (int)0xB00327C8, (int)0xBF597FC7,
         	(int)0xC6E00BF3, (int)0xD5A79147, (int)0x06CA6351, (int)0x14292967,
         	(int)0x27B70A85, (int)0x2E1B2138, (int)0x4D2C6DFC, (int)0x53380D13,
         	(int)0x650A7354, (int)0x766A0ABB, (int)0x81C2C92E, (int)0x92722C85,
         	(int)0xA2BFE8A1, (int)0xA81A664B, (int)0xC24B8B70, (int)0xC76C51A3,
         	(int)0xD192E819, (int)0xD6990624, (int)0xF40E3585, (int)0x106AA070,
         	(int)0x19A4C116, (int)0x1E376C08, (int)0x2748774C, (int)0x34B0BCB5,
         	(int)0x391C0CB3, (int)0x4ED8AA4A, (int)0x5B9CCA4F, (int)0x682E6FF3,
         	(int)0x748F82EE, (int)0x78A5636F, (int)0x84C87814, (int)0x8CC70208,
         	(int)0x90BEFFFA, (int)0xA4506CEB, (int)0xBEF9A3F7, (int)0xC67178F2
                 );
         */
         $K = array(1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987, 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998);
     }
     $W = array();
     for ($i = 0, $numChunks = sizeof($hashData->chunks); $i < $numChunks; $i++) {
         // initialize the registers
         for ($j = 0; $j < 8; $j++) {
             ${$vars[$j]} = $hashData->hash[$j];
         }
         // the SHA-256 compression function
         for ($j = 0; $j < 64; $j++) {
             if ($j < 16) {
                 $T1 = ord($hashData->chunks[$i][$j * 4]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 1]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 2]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 3]) & 0xff;
                 $W[$j] = $T1;
             } else {
                 $W[$j] = SHA256::sum(($W[$j - 2] >> 17 & 0x7fff | $W[$j - 2] << 15) ^ ($W[$j - 2] >> 19 & 0x1fff | $W[$j - 2] << 13) ^ $W[$j - 2] >> 10 & 0x3fffff, $W[$j - 7], ($W[$j - 15] >> 7 & 0x1ffffff | $W[$j - 15] << 25) ^ ($W[$j - 15] >> 18 & 0x3fff | $W[$j - 15] << 14) ^ $W[$j - 15] >> 3 & 0x1fffffff, $W[$j - 16]);
             }
             $T1 = SHA256::sum($h, ($e >> 6 & 0x3ffffff | $e << 26) ^ ($e >> 11 & 0x1fffff | $e << 21) ^ ($e >> 25 & 0x7f | $e << 7), $e & $f ^ ~$e & $g, $K[$j], $W[$j]);
             $T2 = SHA256::sum(($a >> 2 & 0x3fffffff | $a << 30) ^ ($a >> 13 & 0x7ffff | $a << 19) ^ ($a >> 22 & 0x3ff | $a << 10), $a & $b ^ $a & $c ^ $b & $c);
             $h = $g;
             $g = $f;
             $f = $e;
             $e = SHA256::sum($d, $T1);
             $d = $c;
             $c = $b;
             $b = $a;
             $a = SHA256::sum($T1, $T2);
         }
         //    compute the next hash set
         for ($j = 0; $j < 8; $j++) {
             $hashData->hash[$j] = SHA256::sum(${$vars[$j]}, $hashData->hash[$j]);
         }
     }
 }
Exemplo n.º 3
0
 function compute(&$hashData)
 {
     static $vars = 'abcdefgh';
     static $K = null;
     if ($K === null) {
         $K = array(1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987, 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998);
     }
     $W = array();
     for ($i = 0, $numChunks = sizeof($hashData->chunks); $i < $numChunks; $i++) {
         for ($j = 0; $j < 8; $j++) {
             ${$vars[$j]} = $hashData->hash[$j];
         }
         for ($j = 0; $j < 64; $j++) {
             if ($j < 16) {
                 $T1 = ord($hashData->chunks[$i][$j * 4]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 1]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 2]) & 0xff;
                 $T1 <<= 8;
                 $T1 |= ord($hashData->chunks[$i][$j * 4 + 3]) & 0xff;
                 $W[$j] = $T1;
             } else {
                 $W[$j] = SHA256::sum(($W[$j - 2] >> 17 & 0x7fff | $W[$j - 2] << 15) ^ ($W[$j - 2] >> 19 & 0x1fff | $W[$j - 2] << 13) ^ $W[$j - 2] >> 10 & 0x3fffff, $W[$j - 7], ($W[$j - 15] >> 7 & 0x1ffffff | $W[$j - 15] << 25) ^ ($W[$j - 15] >> 18 & 0x3fff | $W[$j - 15] << 14) ^ $W[$j - 15] >> 3 & 0x1fffffff, $W[$j - 16]);
             }
             $T1 = SHA256::sum($h, ($e >> 6 & 0x3ffffff | $e << 26) ^ ($e >> 11 & 0x1fffff | $e << 21) ^ ($e >> 25 & 0x7f | $e << 7), $e & $f ^ ~$e & $g, $K[$j], $W[$j]);
             $T2 = SHA256::sum(($a >> 2 & 0x3fffffff | $a << 30) ^ ($a >> 13 & 0x7ffff | $a << 19) ^ ($a >> 22 & 0x3ff | $a << 10), $a & $b ^ $a & $c ^ $b & $c);
             $h = $g;
             $g = $f;
             $f = $e;
             $e = SHA256::sum($d, $T1);
             $d = $c;
             $c = $b;
             $b = $a;
             $a = SHA256::sum($T1, $T2);
         }
         for ($j = 0; $j < 8; $j++) {
             $hashData->hash[$j] = SHA256::sum(${$vars[$j]}, $hashData->hash[$j]);
         }
     }
 }