Example #1
0
 /**
  * @param CurveFpInterface $curve
  * @return mixed
  */
 public static function getByteSize(CurveFpInterface $curve)
 {
     if ($curve instanceof NamedCurveFp && array_key_exists($curve->getName(), self::$sizeMap)) {
         return self::$sizeMap[$curve->getName()];
     }
     throw new \RuntimeException('Unsupported curve type.');
 }
 /**
  * @param CurveFpInterface $curve
  * @param string           $data
  * @return PointInterface
  */
 public function unserialize(CurveFpInterface $curve, $data)
 {
     if (substr($data, 0, 2) != '04') {
         throw new \InvalidArgumentException('Invalid data: only uncompressed keys are supported.');
     }
     $data = substr($data, 2);
     $dataLength = strlen($data);
     $x = $this->adapter->hexDec(substr($data, 0, $dataLength / 2));
     $y = $this->adapter->hexDec(substr($data, $dataLength / 2));
     return $curve->getPoint($x, $y);
 }
Example #3
0
 /**
  * {@inheritDoc}
  * @see \Mdanter\Ecc\PointInterface::getDouble()
  */
 public function getDouble()
 {
     if ($this->isInfinity()) {
         return $this->curve->getInfinity();
     }
     $math = $this->adapter;
     $modMath = $this->modAdapter;
     $a = $this->curve->getA();
     $threeX2 = $math->mul(3, $math->pow($this->x, 2));
     $tangent = $modMath->div($math->add($threeX2, $a), $math->mul(2, $this->y));
     $x3 = $modMath->sub($math->pow($tangent, 2), $math->mul(2, $this->x));
     $y3 = $modMath->sub($math->mul($tangent, $math->sub($this->x, $x3)), $this->y);
     return new self($this->adapter, $this->curve, $x3, $y3, $this->order);
 }
Example #4
0
 /**
  * {@inheritDoc}
  * @see \Mdanter\Ecc\CurveFpInterface::cmp()
  */
 public function cmp(CurveFpInterface $other)
 {
     $math = $this->adapter;
     $equal = $math->cmp($this->a, $other->getA()) == 0;
     $equal &= $math->cmp($this->b, $other->getB()) == 0;
     $equal &= $math->cmp($this->prime, $other->getPrime()) == 0;
     return $equal ? 0 : 1;
 }
Example #5
0
 /**
  * {@inheritDoc}
  * @see \Mdanter\Ecc\MathAdapterInterface::getPrimeFieldArithmetic()
  */
 public function getPrimeFieldArithmetic(CurveFpInterface $curve)
 {
     return $this->getModularArithmetic($curve->getPrime());
 }
Example #6
-1
 private function add(MathAdapterInterface $math, CurveFpInterface $c, $x1, $y1, $x2, $y2, $x3, $y3)
 {
     $p1 = $c->getPoint($x1, $y1);
     $p2 = $c->getPoint($x2, $y2);
     $p3 = $p1->add($p2);
     $this->assertEquals($math->mod($p3->getX(), 23), $x3);
     $this->assertEquals($math->mod($p3->getY(), 23), $y3);
 }