Coverage Summary for Class: BN128Fp2 (co.rsk.crypto.altbn128java)
Class |
Class, %
|
Method, %
|
Line, %
|
BN128Fp2 |
0%
(0/1)
|
0%
(0/8)
|
0%
(0/15)
|
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 java.math.BigInteger;
23
24 import static co.rsk.crypto.altbn128java.Params.B_Fp2;
25
26 /**
27 * Definition of {@link BN128} over F_p2, where "p" equals {@link Params#P} <br/>
28 *
29 * Curve equation: <br/>
30 * Y^2 = X^3 + b, where "b" equals {@link Params#B_Fp2} <br/>
31 *
32 * @author Mikhail Kalinin
33 * @since 31.08.2017
34 */
35 public class BN128Fp2 extends BN128<Fp2> {
36
37 // the point at infinity
38 static public final BN128<Fp2> ZERO = new BN128Fp2(Fp2.ZERO, Fp2.ZERO, Fp2.ZERO);
39
40 protected BN128Fp2(Fp2 x, Fp2 y, Fp2 z) {
41 super(x, y, z);
42 }
43
44 @Override
45 protected BN128<Fp2> zero() {
46 return ZERO;
47 }
48
49 @Override
50 protected BN128<Fp2> instance(Fp2 x, Fp2 y, Fp2 z) {
51 return new BN128Fp2(x, y, z);
52 }
53
54 @Override
55 protected Fp2 b() {
56 return B_Fp2;
57 }
58
59 @Override
60 protected Fp2 one() {
61 return Fp2._1;
62 }
63
64 protected BN128Fp2(BigInteger a, BigInteger b, BigInteger c, BigInteger d) {
65 super(Fp2.create(a, b), Fp2.create(c, d), Fp2._1);
66 }
67
68 /**
69 * Checks whether provided data are coordinates of a point on the curve,
70 * then checks if this point is a member of subgroup of order "r"
71 * and if checks have been passed it returns a point, otherwise returns null
72 */
73 public static BN128<Fp2> create(byte[] aa, byte[] bb, byte[] cc, byte[] dd) {
74
75 Fp2 x = Fp2.create(aa, bb);
76 Fp2 y = Fp2.create(cc, dd);
77
78 // check for point at infinity
79 if (x.isZero() && y.isZero()) {
80 return ZERO;
81 }
82
83 BN128<Fp2> p = new BN128Fp2(x, y, Fp2._1);
84
85 // check whether point is a valid one
86 if (p.isValid()) {
87 return p;
88 } else {
89 return null;
90 }
91 }
92 }