parameters = $parameters; $this->adapter = $adapter; $this->modAdapter = new ModularArithmetic($this->adapter, $this->parameters->getPrime()); } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::getModAdapter() */ public function getModAdapter() { return $this->modAdapter; } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::getInfinity() */ public function getInfinity() { return new Point($this->adapter, $this, 0, 0, 0, true); } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::getPoint() */ public function getPoint($x, $y, $order = null) { return new Point($this->adapter, $this, $x, $y, $order); } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::getGenerator() */ public function getGenerator($x, $y, $order = null, RandomNumberGeneratorInterface $randomGenerator = null) { return new GeneratorPoint($this->adapter, $this, $x, $y, $order, $randomGenerator); } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::contains() */ public function contains($x, $y) { $math = $this->adapter; $eq_zero = $math->cmp($math->mod($math->sub($math->pow($y, 2), $math->add($math->add($math->pow($x, 3), $math->mul($this->getA(), $x)), $this->getB())), $this->getPrime()), 0); return ($eq_zero == 0); } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::getA() */ public function getA() { return $this->parameters->getA(); } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::getB() */ public function getB() { return $this->parameters->getB(); } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::getPrime() */ public function getPrime() { return $this->parameters->getPrime(); } /** * @return int */ public function getSize() { return $this->parameters->getSize(); } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::cmp() */ public function cmp(CurveFpInterface $other) { $math = $this->adapter; $equal = ($math->cmp($this->getA(), $other->getA()) == 0); $equal &= ($math->cmp($this->getB(), $other->getB()) == 0); $equal &= ($math->cmp($this->getPrime(), $other->getPrime()) == 0); return ($equal) ? 0 : 1; } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::equals() */ public function equals(CurveFpInterface $other) { return $this->cmp($other) == 0; } /** * {@inheritDoc} * @see \Mdanter\Ecc\CurveFpInterface::__toString() */ public function __toString() { return 'curve(' . $this->getA() . ', ' . $this->getB() . ', ' . $this->getPrime() . ')'; } /** * @return array */ public function __debugInfo() { return [ 'a' => (string) $this->getA(), 'b' => (string) $this->getB(), 'prime' => (string) $this->getPrime() ]; } }