Debian Codegraph @

ext/ed25519_jruby/net/i2p/crypto/eddsa/math/FieldElement.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 * Note: concrete subclasses must implement hashCode() and equals()
18 */
19 public abstract class FieldElement implements Serializable {
20 private static final long serialVersionUID = 1239527465875676L;
21
22 protected final Field f;
23
24 public FieldElement(Field f) {
25 if (null == f) {
26 throw new IllegalArgumentException("field cannot be null");
27 }
28 this.f = f;
29 }
30
31 /**
32 * Encode a FieldElement in its $(b-1)$-bit encoding.
33 * @return the $(b-1)$-bit encoding of this FieldElement.
34 */
35 public byte[] toByteArray() {
36 return f.getEncoding().encode(this);
37 }
38
39 public abstract boolean isNonZero();
40
41 public boolean isNegative() {
42 return f.getEncoding().isNegative(this);
43 }
44
45 public abstract FieldElement add(FieldElement val);
46
47 public FieldElement addOne() {
48 return add(f.ONE);
49 }
50
51 public abstract FieldElement subtract(FieldElement val);
52
53 public FieldElement subtractOne() {
54 return subtract(f.ONE);
55 }
56
57 public abstract FieldElement negate();
58
59 public FieldElement divide(FieldElement val) {
60 return multiply(val.invert());
61 }
62
63 public abstract FieldElement multiply(FieldElement val);
64
65 public abstract FieldElement square();
66
67 public abstract FieldElement squareAndDouble();
68
69 public abstract FieldElement invert();
70
71 public abstract FieldElement pow22523();
72
73 public abstract FieldElement cmov(FieldElement val, final int b);
74
75 // Note: concrete subclasses must implement hashCode() and equals()
76 }