RandomLib
RandomLib copied to clipboard
Fix XORMixer double XOR issue
This pull request fixes an issue where an XOR operation is done in both AbstractMixer and XORMixer, causing the source from the previous iteration to get XORed with itself, setting it to zero. This in turn causes XORMixer to always return the last source verbatim.
AbstractMixer::mix() contains the following code:
if ($j % 2 == 1) {
$stub ^= $this->mixParts1($stub, $newKey);
} else {
$stub ^= $this->mixParts2($stub, $newKey);
}
By inlining XorMixer::mixParts1() and XorMixer::mixParts2(), we get:
if ($j % 2 == 1) {
$stub = $stub ^ $stub ^ $newKey;
} else {
$stub = $stub ^ $stub ^ $newKey;
}
which is equivalent to:
if ($j % 2 == 1) {
$stub = $newKey;
} else {
$stub = $newKey;
}