#42 fixed PHP notice in LM hash

This commit is contained in:
Roland Gruber 2017-11-14 20:42:52 +01:00
parent 7146be7ecf
commit 56fe32cad6
1 changed files with 25 additions and 25 deletions

View File

@ -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) { function doHash($in, $key, $forw) {
$ki = array(); $ki = array();
$pk1 = $this->permute($key, $this->perm1, 56); $pk1 = $this->permute($key, $this->perm1, 56);
$c = array(); $c = array();
$d = array(); $d = array();
for ($i = 0; $i < 28; $i++) { for ($i = 0; $i < 28; $i++) {
$c[$i] = $pk1[$i]; $c[$i] = $pk1[$i];
$d[$i] = $pk1[28 + $i]; $d[$i] = $pk1[28 + $i];
} }
for ($i = 0; $i < 16; $i++) { for ($i = 0; $i < 16; $i++) {
$c = $this->lshift($this->sc[$i], $c); $c = $this->lshift($this->sc[$i], $c);
$d = $this->lshift($this->sc[$i], $d); $d = $this->lshift($this->sc[$i], $d);
$cd = $c; $cd = $c;
for ($k = 0; $k < sizeof($d); $k++) $cd[] = $d[$k]; for ($k = 0; $k < sizeof($d); $k++) $cd[] = $d[$k];
$ki[$i] = $this->permute($cd, $this->perm2, 48); $ki[$i] = $this->permute($cd, $this->perm2, 48);
} }
$pd1 = $this->permute($in, $this->perm3, 64); $pd1 = $this->permute($in, $this->perm3, 64);
$l = array(); $l = array();
$r = array(); $r = array();
for ($i = 0; $i < 32; $i++) { for ($i = 0; $i < 32; $i++) {
$l[$i] = $pd1[$i]; $l[$i] = $pd1[$i];
$r[$i] = $pd1[32 + $i]; $r[$i] = $pd1[32 + $i];
} }
for ($i = 0; $i < 16; $i++) { for ($i = 0; $i < 16; $i++) {
$er = $this->permute($r, $this->perm4, 48); $er = $this->permute($r, $this->perm4, 48);
if ($forw) $erk = $this->mxor($er, $ki[$i]); if ($forw) $erk = $this->mxor($er, $ki[$i]);
else $erk = $this->mxor($er, $ki[15 - $i]); else $erk = $this->mxor($er, $ki[15 - $i]);
for ($j = 0; $j < 8; $j++) { for ($j = 0; $j < 8; $j++) {
for ($k = 0; $k < 6; $k++) { for ($k = 0; $k < 6; $k++) {
$b[$j][$k] = $erk[($j * 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(); $n = array();
$m = ($b[$j][0] << 1) | $b[$j][5]; $m = ($b[$j][0] << 1) | $b[$j][5];
$n = ($b[$j][1] << 3) | ($b[$j][2] << 2) | ($b[$j][3] << 1) | $b[$j][4]; $n = ($b[$j][1] << 3) | ($b[$j][2] << 2) | ($b[$j][3] << 1) | $b[$j][4];
for ($k = 0; $k < 4; $k++) { for ($k = 0; $k < 4; $k++) {
$b[$j][$k]=($this->sbox[$j][$m][$n] & (1 << (3-$k)))?1:0; $b[$j][$k]=($this->sbox[$j][$m][$n] & (1 << (3-$k)))?1:0;
} }
} }
for ($j = 0; $j < 8; $j++) { for ($j = 0; $j < 8; $j++) {
for ($k = 0; $k < 4; $k++) { for ($k = 0; $k < 4; $k++) {
$cb[($j * 4) + $k] = $b[$j][$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){ private function smb_hash($in, $key, $forw){
$key2 = $this->str_to_key($key); $key2 = $this->str_to_key($key);
for ($i = 0; $i < 64; $i++) { for ($i = 0; $i < 64; $i++) {
$inb[$i] = ($in[$i/8] & (1<<(7-($i%8)))) ? 1:0; $inb[$i] = ($in[$i/8] & (1<<(7-($i%8)))) ? 1:0;
$keyb[$i] = ($key2[$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++) { for ($i = 0; $i < 8; $i++) {
$out[$i] = 0; $out[$i] = 0;
} }
for ($i = 0; $i < 65; $i++) { for ($i = 0; $i < 64; $i++) {
if ( $outb[$i] ) { if ( $outb[$i] ) {
$out[$i/8] |= (1<<(7-($i%8))); $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. * PHP 4 only supports signed shifts by default.
*/ */
private function unsigned_shift_r($a, $b) { private function unsigned_shift_r($a, $b) {
$z = 0x80000000; $z = 0x80000000;
if ($z & $a) { if ($z & $a) {
$a = ($a >> 1); $a = ($a >> 1);
$a &= (~$z); $a &= (~$z);
$a |= 0x40000000; $a |= 0x40000000;
$a = ($a >> ($b - 1)); $a = ($a >> ($b - 1));
} }
else { else {
$a = ($a >> $b); $a = ($a >> $b);
} }
return $a; return $a;
} }
} }