Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use paragonie/ecc v2.1.0 or older #8

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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