芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/kwesioben.com/paymoney/vendor/mdanter/ecc/src/Primitives/CurveFp.php
parameters = $parameters; $this->adapter = $adapter; $this->modAdapter = new ModularArithmetic($this->adapter, $this->parameters->getPrime()); } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::getModAdapter() */ public function getModAdapter(): ModularArithmetic { return $this->modAdapter; } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::getPoint() */ public function getPoint(\GMP $x, \GMP $y, \GMP $order = null): PointInterface { return new Point($this->adapter, $this, $x, $y, $order); } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::getInfinity() */ public function getInfinity(): PointInterface { return new Point($this->adapter, $this, gmp_init(0, 10), gmp_init(0, 10), null, true); } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::getGenerator() */ public function getGenerator(\GMP $x, \GMP $y, \GMP $order, RandomNumberGeneratorInterface $randomGenerator = null): GeneratorPoint { return new GeneratorPoint($this->adapter, $this, $x, $y, $order, $randomGenerator); } /** * @param bool $wasOdd * @param \GMP $xCoord * @return \GMP */ public function recoverYfromX(bool $wasOdd, \GMP $xCoord): \GMP { $math = $this->adapter; $prime = $this->getPrime(); try { $root = $this->adapter->getNumberTheory()->squareRootModP( $math->add( $math->add( $this->modAdapter->pow($xCoord, gmp_init(3, 10)), $math->mul($this->getA(), $xCoord) ), $this->getB() ), $prime ); } catch (SquareRootException $e) { throw new PointRecoveryException("Failed to recover y coordinate for point", 0, $e); } if ($math->equals($math->mod($root, gmp_init(2, 10)), gmp_init(1)) === $wasOdd) { return $root; } else { return $math->sub($prime, $root); } } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::contains() */ public function contains(\GMP $x, \GMP $y): bool { $math = $this->adapter; $eq_zero = $math->equals( $this->modAdapter->sub( $math->pow($y, 2), $math->add( $math->add( $math->pow($x, 3), $math->mul($this->getA(), $x) ), $this->getB() ) ), gmp_init(0, 10) ); return $eq_zero; } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::getA() */ public function getA(): \GMP { return $this->parameters->getA(); } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::getB() */ public function getB(): \GMP { return $this->parameters->getB(); } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::getPrime() */ public function getPrime(): \GMP { return $this->parameters->getPrime(); } /** * @return int */ public function getSize(): int { return $this->parameters->getSize(); } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::cmp() */ public function cmp(CurveFpInterface $other): int { $math = $this->adapter; $equal = $math->equals($this->getA(), $other->getA()); $equal &= $math->equals($this->getB(), $other->getB()); $equal &= $math->equals($this->getPrime(), $other->getPrime()); return ($equal) ? 0 : 1; } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::equals() */ public function equals(CurveFpInterface $other): bool { return $this->cmp($other) == 0; } /** * {@inheritDoc} * @see \Mdanter\Ecc\Primitives\CurveFpInterface::__toString() */ public function __toString(): string { return 'curve(' . $this->adapter->toString($this->getA()) . ', ' . $this->adapter->toString($this->getB()) . ', ' . $this->adapter->toString($this->getPrime()) . ')'; } /** * @return array */ public function __debugInfo() { return [ 'a' => $this->adapter->toString($this->getA()), 'b' => $this->adapter->toString($this->getB()), 'prime' => $this->adapter->toString($this->getPrime()) ]; } }