/**
  * @param PointInterface $point
  * @return string
  */
 public function serialize(PointInterface $point)
 {
     $length = CurveOidMapper::getByteSize($point->getCurve()) * 2;
     if ($this->debug) {
         error_log('Detected length: ' . $length);
         error_log('Unpadded:' . $this->adapter->decHex($point->getX()));
         error_log('Unpadded len:' . strlen($this->adapter->decHex($point->getX())));
         error_log('Padded: ' . str_pad($this->adapter->decHex($point->getX()), $length, '0', STR_PAD_LEFT));
     }
     $hexString = '04';
     $hexString .= str_pad($this->adapter->decHex($point->getX()), $length, '0', STR_PAD_LEFT);
     $hexString .= str_pad($this->adapter->decHex($point->getY()), $length, '0', STR_PAD_LEFT);
     if ($this->debug) {
         error_log('Resulting length: ' . strlen($hexString));
         error_log('Hex: ' . $hexString);
     }
     return $hexString;
 }
예제 #2
0
파일: Point.php 프로젝트: sbwdlihao/phpecc
 /**
  * {@inheritDoc}
  * @see \Mdanter\Ecc\PointInterface::cmp()
  */
 public function cmp(PointInterface $other)
 {
     if ($other->isInfinity() && $this->isInfinity()) {
         return 0;
     }
     if ($other->isInfinity() || $this->isInfinity()) {
         return 1;
     }
     $math = $this->adapter;
     $equal = $math->cmp($this->x, $other->getX()) == 0;
     $equal &= $math->cmp($this->y, $other->getY()) == 0;
     $equal &= $this->isInfinity() == $other->isInfinity();
     $equal &= $this->curve->equals($other->getCurve());
     if ($equal) {
         return 0;
     }
     return 1;
 }