Debian Codegraph @

ext/ed25519_jruby/net/i2p/crypto/eddsa/math/Curve.java

raw symbols SCIP
1 /**
2 * EdDSA-Java by str4d
3 *
4 * To the extent possible under law, the person who associated CC0 with
5 * EdDSA-Java has waived all copyright and related or neighboring rights
6 * to EdDSA-Java.
7 *
8 * You should have received a copy of the CC0 legalcode along with this
9 * work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
10 *
11 */
12 package net.i2p.crypto.eddsa.math;
13
14 import java.io.Serializable;
15
16 /**
17 * A twisted Edwards curve.
18 * Points on the curve satisfy $-x^2 + y^2 = 1 + d x^2y^2$
19 * @author str4d
20 *
21 */
22 public class Curve implements Serializable {
23 private static final long serialVersionUID = 4578920872509827L;
24 private final Field f;
25 private final FieldElement d;
26 private final FieldElement d2;
27 private final FieldElement I;
28
29 private final GroupElement zeroP2;
30 private final GroupElement zeroP3;
31 private final GroupElement zeroPrecomp;
32
33 public Curve(Field f, byte[] d, FieldElement I) {
34 this.f = f;
35 this.d = f.fromByteArray(d);
36 this.d2 = this.d.add(this.d);
37 this.I = I;
38
39 FieldElement zero = f.ZERO;
40 FieldElement one = f.ONE;
41 zeroP2 = GroupElement.p2(this, zero, one, one);
42 zeroP3 = GroupElement.p3(this, zero, one, one, zero);
43 zeroPrecomp = GroupElement.precomp(this, one, one, zero);
44 }
45
46 public Field getField() {
47 return f;
48 }
49
50 public FieldElement getD() {
51 return d;
52 }
53
54 public FieldElement get2D() {
55 return d2;
56 }
57
58 public FieldElement getI() {
59 return I;
60 }
61
62 public GroupElement getZero(GroupElement.Representation repr) {
63 switch (repr) {
64 case P2:
65 return zeroP2;
66 case P3:
67 return zeroP3;
68 case PRECOMP:
69 return zeroPrecomp;
70 default:
71 return null;
72 }
73 }
74
75 public GroupElement createPoint(byte[] P, boolean precompute) {
76 GroupElement ge = new GroupElement(this, P);
77 if (precompute)
78 ge.precompute(true);
79 return ge;
80 }
81
82 @Override
83 public int hashCode() {
84 return f.hashCode() ^
85 d.hashCode() ^
86 I.hashCode();
87 }
88
89 @Override
90 public boolean equals(Object o) {
91 if (o == this)
92 return true;
93 if (!(o instanceof Curve))
94 return false;
95 Curve c = (Curve) o;
96 return f.equals(c.getField()) &&
97 d.equals(c.getD()) &&
98 I.equals(c.getI());
99 }
100 }