Skip to content

Commit

Permalink
Final tweaks as we get ready for v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Feb 15, 2018
1 parent ffca8de commit 1f6e568
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Core32/Int64.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,24 @@ public function mulInt($int = 0, $size = 0)
* @return array<int, ParagonIE_Sodium_Core32_Int64>
* @throws SodiumException
* @throws TypeError
* @psalm-suppress MixedInferredReturnType
*/
public static function ctSelect(
ParagonIE_Sodium_Core32_Int64 $A,
ParagonIE_Sodium_Core32_Int64 $B
) {
$a = clone $A;
$b = clone $B;
/** @var int $aNeg */
$aNeg = ($a->limbs[0] >> 15) & 1;
/** @var int $bNeg */
$bNeg = ($b->limbs[0] >> 15) & 1;
/** @var int $m */
$m = (-($aNeg & $bNeg)) | 1;
/** @var int $swap */
$swap = $bNeg & ~$aNeg;
/** @var int $d */
$d = -$swap;

/*
if ($bNeg && !$aNeg) {
Expand All @@ -230,13 +238,11 @@ public static function ctSelect(
$b = $int->mulInt(-1);
}
*/
$swap = $bNeg & ~$aNeg;
$d = -$swap;
$x = $a->xorInt64($b)->mask64($d, $d);
$a = $a->xorInt64($x)->mulInt($m);
$b = $b->xorInt64($x)->mulInt($m);

return array($a, $b);
return array(
$a->xorInt64($x)->mulInt($m),
$b->xorInt64($x)->mulInt($m)
);
}

/**
Expand Down

0 comments on commit 1f6e568

Please sign in to comment.