Skip to content

Commit

Permalink
Support paragonie/ecc 2.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed May 8, 2024
1 parent 7eca487 commit 0205cbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/ECDSA/PublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/EasyECC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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
);
Expand All @@ -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
);
Expand All @@ -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;
Expand Down

0 comments on commit 0205cbc

Please sign in to comment.