Skip to content

Commit

Permalink
Reduce noise from Scrutinizer
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Apr 28, 2024
1 parent 87d860f commit e361a69
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Crypto/EcDH/EcDHInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ public function createMultiPartyKey(): PublicKeyInterface;
* Sets the sender's key.
*
* @param PrivateKeyInterface $key
* @return self
*/
public function setSenderKey(PrivateKeyInterface $key);

/**
* Sets the recipient key.
*
* @param PublicKeyInterface $key
* @return void
* @return self
* @psalm-suppress PossiblyUnusedReturnValue
*/
public function setRecipientKey(PublicKeyInterface $key);
}
1 change: 0 additions & 1 deletion src/Curves/CurveFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Mdanter\Ecc\Curves;

use Mdanter\Ecc\Exception\UnknownCurveException;
use Mdanter\Ecc\Exception\UnsupportedCurveException;
use Mdanter\Ecc\Math\GmpMathInterface;
use Mdanter\Ecc\Math\MathAdapterFactory;
Expand Down
3 changes: 3 additions & 0 deletions src/Curves/OptimizedCurveFp.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public function setOptimizedCurveOps(OptimizedCurveOpsInterface $ops): Optimized

public function getOptimizedCurveOps(): OptimizedCurveOpsInterface
{
if (is_null($this->optimizedOps)) {
throw new \TypeError('Optimized ops was not set');
}
return $this->optimizedOps;
}
}
6 changes: 6 additions & 0 deletions src/Exception/UnsupportedCurveException.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ public function hasOid(): bool

public function getCurveName(): string
{
if (is_null($this->curveName)) {
return '';
}
return $this->curveName;
}

public function getOid(): string
{
if (is_null($this->oid)) {
return '';
}
return $this->oid;
}
}
4 changes: 2 additions & 2 deletions src/Optimized/Common/BarretReductionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ protected function barrettReduce(GMP $product): GMP
$ctMath = new ConstantTimeMath();

$b = ((gmp_sign($r) >> 1)) & 1;
$rPrime = $r + $this->p;
$rPrime = gmp_add($r, $this->p);
$r = $ctMath->select($b, $rPrime, $r);

// Guaranteed to be reduced after 2 cycles
for ($i = 0; $i < 2; ++$i) {
$rPrime = $r - $this->p;
$rPrime = gmp_sub($r, $this->p);
// $b = 1 if $rPrime > 0, which means subtracting is necessary
$b = (~(gmp_sign($rPrime) >> 1)) & 1;
$r = $ctMath->select($b, $rPrime, $r);
Expand Down

0 comments on commit e361a69

Please sign in to comment.