From 0205cbc07c5f232bc809a489e92a11d9cf2e1498 Mon Sep 17 00:00:00 2001 From: Paragon Initiative Enterprises Date: Wed, 8 May 2024 12:43:23 -0400 Subject: [PATCH] Support paragonie/ecc 2.3+ --- src/ECDSA/PublicKey.php | 14 +++++++------- src/EasyECC.php | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ECDSA/PublicKey.php b/src/ECDSA/PublicKey.php index 049f905..9931c7f 100644 --- a/src/ECDSA/PublicKey.php +++ b/src/ECDSA/PublicKey.php @@ -90,29 +90,29 @@ public static function fromString( $adapter = EccFactory::getAdapter(); switch ($curve) { case 'K256': - $generator = CurveFactory::getGeneratorByName('secp256k1'); + $generator = EccFactory::getSecgCurves()->generator256k1(null, true); $namedCurve = $generator->getCurve(); if (Binary::safeStrlen($hexString) !== 66) { throw new InvalidPublicKeyException('Public key is the wrong size for ' . $curve); } break; case 'P256': - $generator = EccFactory::getNistCurves()->generator256(); - $namedCurve = EccFactory::getNistCurves()->curve256(); + $generator = EccFactory::getNistCurves()->generator256(null, true); + $namedCurve = $generator->getCurve(); if (Binary::safeStrlen($hexString) !== 66) { throw new InvalidPublicKeyException('Public key is the wrong size for ' . $curve); } break; case 'P384': - $generator = EccFactory::getNistCurves()->generator384(); - $namedCurve = EccFactory::getNistCurves()->curve384(); + $generator = EccFactory::getNistCurves()->generator384(null, true); + $namedCurve = $generator->getCurve(); if (Binary::safeStrlen($hexString) !== 98) { throw new InvalidPublicKeyException('Public key is the wrong size for ' . $curve); } break; case 'P521': - $generator = EccFactory::getNistCurves()->generator521(); - $namedCurve = EccFactory::getNistCurves()->curve521(); + $generator = EccFactory::getNistCurves()->generator521(null, true); + $namedCurve = $generator->getCurve(); if (Binary::safeStrlen($hexString) !== 134) { throw new InvalidPublicKeyException('Public key is the wrong size for ' . $curve); } diff --git a/src/EasyECC.php b/src/EasyECC.php index 78f9c3d..3bc909b 100644 --- a/src/EasyECC.php +++ b/src/EasyECC.php @@ -8,6 +8,7 @@ use Mdanter\Ecc\Crypto\Signature\Signer; use Mdanter\Ecc\Crypto\Signature\SignHasher; use Mdanter\Ecc\Curves\CurveFactory; +use Mdanter\Ecc\Curves\SecureCurveFactory; use Mdanter\Ecc\EccFactory; use Mdanter\Ecc\Math\GmpMathInterface; use Mdanter\Ecc\Primitives\GeneratorPoint; @@ -23,7 +24,6 @@ use ParagonIE\EasyECC\ECDSA\SecretKey; use ParagonIE\EasyECC\ECDSA\Signature; use ParagonIE\EasyECC\Exception\ConfigException; -use ParagonIE\EasyECC\Exception\EasyEccException; use ParagonIE\EasyECC\Exception\NotImplementedException; /** @@ -71,13 +71,13 @@ public function __construct(string $curve = self::DEFAULT_CURVE) switch ($curve) { case 'K256': $this->adapter = EccFactory::getAdapter(); - $this->generator = CurveFactory::getGeneratorByName('secp256k1'); + $this->generator = SecureCurveFactory::getGeneratorByName('secp256k1'); $this->hashAlgo = 'sha256'; $this->hasher = new SignHasher($this->hashAlgo, $this->adapter); break; case 'P256': $this->adapter = EccFactory::getAdapter(); - $this->generator = EccFactory::getNistCurves()->generator256( + $this->generator = EccFactory::getNistCurves($this->adapter)->generator256( RandomGeneratorFactory::getRandomGenerator(), true ); @@ -86,7 +86,7 @@ public function __construct(string $curve = self::DEFAULT_CURVE) break; case 'P384': $this->adapter = EccFactory::getAdapter(); - $this->generator = EccFactory::getNistCurves()->generator384( + $this->generator = EccFactory::getNistCurves($this->adapter)->generator384( RandomGeneratorFactory::getRandomGenerator(), true ); @@ -95,7 +95,7 @@ public function __construct(string $curve = self::DEFAULT_CURVE) break; case 'P521': $this->adapter = EccFactory::getAdapter(); - $this->generator = EccFactory::getNistCurves()->generator521(); + $this->generator = EccFactory::getNistCurves($this->adapter)->generator521(); $this->hashAlgo = 'sha512'; $this->hasher = new SignHasher($this->hashAlgo, $this->adapter); break;