Coverage Summary for Class: BN128Fp (co.rsk.crypto.altbn128java)

Class Class, % Method, % Line, %
BN128Fp 0% (0/1) 0% (0/7) 0% (0/14)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2019 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package co.rsk.crypto.altbn128java; 21  22 import static co.rsk.crypto.altbn128java.Params.B_Fp; 23  24 /** 25  * Definition of {@link BN128} over F_p, where "p" equals {@link Params#P} <br/> 26  * 27  * Curve equation: <br/> 28  * Y^2 = X^3 + b, where "b" equals {@link Params#B_Fp} <br/> 29  * 30  * @author Mikhail Kalinin 31  * @since 21.08.2017 32  */ 33 public class BN128Fp extends BN128<Fp> { 34  35  // the point at infinity 36  static public final BN128<Fp> ZERO = new BN128Fp(Fp.ZERO, Fp.ZERO, Fp.ZERO); 37  38  protected BN128Fp(Fp x, Fp y, Fp z) { 39  super(x, y, z); 40  } 41  42  @Override 43  protected BN128<Fp> zero() { 44  return ZERO; 45  } 46  47  @Override 48  protected BN128<Fp> instance(Fp x, Fp y, Fp z) { 49  return new BN128Fp(x, y, z); 50  } 51  52  @Override 53  protected Fp b() { 54  return B_Fp; 55  } 56  57  @Override 58  protected Fp one() { 59  return Fp._1; 60  } 61  62  /** 63  * Checks whether x and y belong to Fp, 64  * then checks whether point with (x; y) coordinates lays on the curve. 65  * 66  * Returns new point if all checks have been passed, 67  * otherwise returns null 68  */ 69  public static BN128<Fp> create(byte[] xx, byte[] yy) { 70  71  Fp x = Fp.create(xx); 72  Fp y = Fp.create(yy); 73  74  // check for point at infinity 75  if (x.isZero() && y.isZero()) { 76  return ZERO; 77  } 78  79  BN128<Fp> p = new BN128Fp(x, y, Fp._1); 80  81  // check whether point is a valid one 82  if (p.isValid()) { 83  return p; 84  } else { 85  return null; 86  } 87  } 88 }