
 Miroslav Ćurčić - 2007-11-10 18:53:15 - 
In reply to message 20 from matthew bagleyJust SOLVED !
Problem was in arithmetics in functions "zeroFill" and "mix" when running on 64 bits system.
Changes:
	function zeroFill($a, $b) {
		$z = hexdec('80000000');
		if ($z & $a) {
			$a = ($a>>1);
			$a &=  0x7FFFFFFF;
			$a |= 0x40000000;
			$a = $this->shr32($a,($b-1));
		} else {
			$a = $this->shr32($a,$b);
		}
		return $a;
	}
	function shr32 ($a, $b) {
	    if ($b==0) return $a;
	    if ($b==32) return 0;
	    $res= ($a & 0x7FFFFFFF) >> $b;
	    if (0x80000000 & $a) $res |= (1<<(31-$b));   
	    return $res;
	}
	function xor32($a, $b) {
    	    return ($a ^ $b) & 0xFFFFFFFF;
	}
	
	function mix($a,$b,$c) {
		$a -= $b; $a -= $c; $a= $this->xor32($a, ($this->zeroFill($c,13)));
		$b -= $c; $b -= $a; $b= $this->xor32($b, $a<<8);
		$c -= $a; $c -= $b; $c= $this->xor32($c, ($this->zeroFill($b,13)));
		$a -= $b; $a -= $c; $a= $this->xor32($a, ($this->zeroFill($c,12)));
		$b -= $c; $b -= $a; $b= $this->xor32($b, ($a<<16));
		$c -= $a; $c -= $b; $c= $this->xor32($c, ($this->zeroFill($b,5)));
		$a -= $b; $a -= $c; $a= $this->xor32($a, ($this->zeroFill($c,3)));
		$b -= $c; $b -= $a; $b= $this->xor32($b, ($a<<10));
		$c -= $a; $c -= $b; $c= $this->xor32($c, ($this->zeroFill($b,15)));
		return array($a,$b,$c);
	}