public function __construct(Point $generator, Point $point)
 {
     $this->curve = $generator->getCurve();
     $this->generator = $generator;
     $this->point = $point;
     $n = $generator->getOrder();
     if ($n == null) {
         throw new ErrorExcpetion("Generator Must have order.");
     }
     if (Point::cmp(Point::mul($n, $point), Point::$infinity) != 0) {
         throw new ErrorException("Generator Point order is bad.");
     }
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         if (gmp_cmp($point->getX(), 0) < 0 || gmp_cmp($n, $point->getX()) <= 0 || gmp_cmp($point->getY(), 0) < 0 || gmp_cmp($n, $point->getY()) <= 0) {
             throw new ErrorException("Generator Point has x and y out of range.");
         }
     } else {
         if (extension_loaded('bcmath') && USE_EXT == 'BCMATH') {
             if (bccomp($point->getX(), 0) == -1 || bccomp($n, $point->getX()) != 1 || bccomp($point->getY(), 0) == -1 || bccomp($n, $point->getY()) != 1) {
                 throw new ErrorException("Generator Point has x and y out of range.");
             }
         } else {
             throw new ErrorException("Please install BCMATH or GMP");
         }
     }
 }
Beispiel #2
0
 public static function point_is_valid(Point $generator, $x, $y)
 {
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         $n = $generator->getOrder();
         $curve = $generator->getCurve();
         if (gmp_cmp($x, 0) < 0 || gmp_cmp($n, $x) <= 0 || gmp_cmp($y, 0) < 0 || gmp_cmp($n, $y) <= 0) {
             return false;
         }
         $containment = $curve->contains($x, $y);
         if (!$containment) {
             return false;
         }
         $point = new Point($curve, $x, $y);
         $op = Point::mul($n, $point);
         if (!(Point::cmp($op, Point::$infinity) == 0)) {
             return false;
         }
         return true;
     } else {
         if (extension_loaded('bcmath') && USE_EXT == 'BCMATH') {
             $n = $generator->getOrder();
             $curve = $generator->getCurve();
             if (bccomp($x, 0) == -1 || bccomp($n, $x) != 1 || bccomp($y, 0) == -1 || bccomp($n, $y) != 1) {
                 return false;
             }
             $containment = $curve->contains($x, $y);
             if (!$containment) {
                 return false;
             }
             $point = new Point($curve, $x, $y);
             $op = Point::mul($n, $point);
             if (!(Point::cmp($op, Point::$infinity) == 0)) {
                 return false;
             }
             return true;
         } else {
             throw new ErrorException("Please install BCMATH or GMP");
         }
     }
 }