Skip to content

Commit

Permalink
Merge pull request #8 from paragonie/update-phpecc-2.1
Browse files Browse the repository at this point in the history
Use paragonie/ecc v2.1.0 or older
  • Loading branch information
paragonie-security authored Apr 28, 2024
2 parents b7fcea5 + 4602825 commit 3d05396
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"php": "^7.1|^8",
"ext-gmp": "*",
"defuse/php-encryption": "^2.1",
"paragonie/ecc": "^2",
"paragonie/ecc": "^2.1",
"paragonie/sodium_compat": "^1|^2",
"paragonie/constant_time_encoding": "^2.1"
},
Expand Down
6 changes: 4 additions & 2 deletions src/Curve25519/X25519.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function createMultiPartyKey(): PublicKeyInterface
* Sets the sender's key.
*
* @param PrivateKeyInterface $key
* @return void
* @return self
* @throws \SodiumException
* @throws \TypeError
*/
Expand All @@ -109,13 +109,14 @@ public function setSenderKey(PrivateKeyInterface $key)
} else {
throw new \TypeError('Only libsodium keys are allowed');
}
return $this;
}

/**
* Sets the recipient key.
*
* @param PublicKeyInterface $key
* @return void
* @return self
* @throws \SodiumException
* @throws \TypeError
*/
Expand All @@ -128,5 +129,6 @@ public function setRecipientKey(PublicKeyInterface $key)
} else {
throw new \TypeError('Only libsodium keys are allowed');
}
return $this;
}
}
2 changes: 1 addition & 1 deletion src/ECDSA/HedgedRandomNumberGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function generate(\GMP $max): \GMP
$v = hash_hmac($this->algorithm, $v, $k, true);

$t = '';
for (;;) {
for ($tries = 0; $tries < 1024; ++$tries) {
$toff = gmp_init(0, 10);
while ($this->math->cmp($toff, $rlen) < 0) {
$v = hash_hmac($this->algorithm, $v, $k, true);
Expand Down
21 changes: 17 additions & 4 deletions src/EasyECC.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Mdanter\Ecc\EccFactory;
use Mdanter\Ecc\Math\GmpMathInterface;
use Mdanter\Ecc\Primitives\GeneratorPoint;
use Mdanter\Ecc\Random\RandomGeneratorFactory;
use Mdanter\Ecc\Serializer\PublicKey\DerPublicKeySerializer;
use Mdanter\Ecc\Serializer\Signature\DerSignatureSerializer;
use Mdanter\Ecc\Util\NumberSize;
Expand Down Expand Up @@ -76,13 +77,19 @@ public function __construct(string $curve = self::DEFAULT_CURVE)
break;
case 'P256':
$this->adapter = EccFactory::getAdapter();
$this->generator = EccFactory::getNistCurves()->generator256();
$this->generator = EccFactory::getNistCurves()->generator256(
RandomGeneratorFactory::getRandomGenerator(),
true
);
$this->hashAlgo = 'sha256';
$this->hasher = new SignHasher($this->hashAlgo, $this->adapter);
break;
case 'P384':
$this->adapter = EccFactory::getAdapter();
$this->generator = EccFactory::getNistCurves()->generator384();
$this->generator = EccFactory::getNistCurves()->generator384(
RandomGeneratorFactory::getRandomGenerator(),
true
);
$this->hashAlgo = 'sha384';
$this->hasher = new SignHasher($this->hashAlgo, $this->adapter);
break;
Expand Down Expand Up @@ -320,12 +327,18 @@ public static function getGenerator(
return CurveFactory::getGeneratorByName('secp256k1');
case 'P256':
if ($constantTime) {
return EccFactory::getNistCurves(new ConstantTimeMath())->generator256();
return EccFactory::getNistCurves(new ConstantTimeMath())->generator256(
RandomGeneratorFactory::getRandomGenerator(),
true
);
}
return EccFactory::getNistCurves()->generator256();
case 'P384':
if ($constantTime) {
return EccFactory::getNistCurves(new ConstantTimeMath())->generator384();
return EccFactory::getNistCurves(new ConstantTimeMath())->generator384(
RandomGeneratorFactory::getRandomGenerator(),
true
);
}
return EccFactory::getNistCurves()->generator384();
case 'P521':
Expand Down

0 comments on commit 3d05396

Please sign in to comment.