#42 fixed PHP notice in LM hash
This commit is contained in:
parent
7146be7ecf
commit
56fe32cad6
|
@ -188,39 +188,39 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12
|
|||
*/
|
||||
function doHash($in, $key, $forw) {
|
||||
$ki = array();
|
||||
|
||||
|
||||
$pk1 = $this->permute($key, $this->perm1, 56);
|
||||
|
||||
|
||||
$c = array();
|
||||
$d = array();
|
||||
for ($i = 0; $i < 28; $i++) {
|
||||
$c[$i] = $pk1[$i];
|
||||
$d[$i] = $pk1[28 + $i];
|
||||
}
|
||||
|
||||
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$c = $this->lshift($this->sc[$i], $c);
|
||||
$d = $this->lshift($this->sc[$i], $d);
|
||||
|
||||
|
||||
$cd = $c;
|
||||
for ($k = 0; $k < sizeof($d); $k++) $cd[] = $d[$k];
|
||||
$ki[$i] = $this->permute($cd, $this->perm2, 48);
|
||||
}
|
||||
|
||||
|
||||
$pd1 = $this->permute($in, $this->perm3, 64);
|
||||
|
||||
|
||||
$l = array();
|
||||
$r = array();
|
||||
for ($i = 0; $i < 32; $i++) {
|
||||
$l[$i] = $pd1[$i];
|
||||
$r[$i] = $pd1[32 + $i];
|
||||
}
|
||||
|
||||
|
||||
for ($i = 0; $i < 16; $i++) {
|
||||
$er = $this->permute($r, $this->perm4, 48);
|
||||
if ($forw) $erk = $this->mxor($er, $ki[$i]);
|
||||
else $erk = $this->mxor($er, $ki[15 - $i]);
|
||||
|
||||
|
||||
for ($j = 0; $j < 8; $j++) {
|
||||
for ($k = 0; $k < 6; $k++) {
|
||||
$b[$j][$k] = $erk[($j * 6) + $k];
|
||||
|
@ -231,12 +231,12 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12
|
|||
$n = array();
|
||||
$m = ($b[$j][0] << 1) | $b[$j][5];
|
||||
$n = ($b[$j][1] << 3) | ($b[$j][2] << 2) | ($b[$j][3] << 1) | $b[$j][4];
|
||||
|
||||
|
||||
for ($k = 0; $k < 4; $k++) {
|
||||
$b[$j][$k]=($this->sbox[$j][$m][$n] & (1 << (3-$k)))?1:0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for ($j = 0; $j < 8; $j++) {
|
||||
for ($k = 0; $k < 4; $k++) {
|
||||
$cb[($j * 4) + $k] = $b[$j][$k];
|
||||
|
@ -283,7 +283,7 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12
|
|||
*/
|
||||
private function smb_hash($in, $key, $forw){
|
||||
$key2 = $this->str_to_key($key);
|
||||
|
||||
|
||||
for ($i = 0; $i < 64; $i++) {
|
||||
$inb[$i] = ($in[$i/8] & (1<<(7-($i%8)))) ? 1:0;
|
||||
$keyb[$i] = ($key2[$i/8] & (1<<(7-($i%8)))) ? 1:0;
|
||||
|
@ -293,7 +293,7 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12
|
|||
for ($i = 0; $i < 8; $i++) {
|
||||
$out[$i] = 0;
|
||||
}
|
||||
for ($i = 0; $i < 65; $i++) {
|
||||
for ($i = 0; $i < 64; $i++) {
|
||||
if ( $outb[$i] ) {
|
||||
$out[$i/8] |= (1<<(7-($i%8)));
|
||||
}
|
||||
|
@ -357,19 +357,19 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12
|
|||
*
|
||||
* PHP 4 only supports signed shifts by default.
|
||||
*/
|
||||
private function unsigned_shift_r($a, $b) {
|
||||
$z = 0x80000000;
|
||||
if ($z & $a) {
|
||||
$a = ($a >> 1);
|
||||
$a &= (~$z);
|
||||
$a |= 0x40000000;
|
||||
$a = ($a >> ($b - 1));
|
||||
}
|
||||
else {
|
||||
$a = ($a >> $b);
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
private function unsigned_shift_r($a, $b) {
|
||||
$z = 0x80000000;
|
||||
if ($z & $a) {
|
||||
$a = ($a >> 1);
|
||||
$a &= (~$z);
|
||||
$a |= 0x40000000;
|
||||
$a = ($a >> ($b - 1));
|
||||
}
|
||||
else {
|
||||
$a = ($a >> $b);
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue