java.lang.Object
net.i2p.crypto.eddsa.math.FieldElement
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
BigIntegerFieldElement, Ed25519FieldElement
Represents an element in a finite field of order $2^{b}-3$. Note: concrete subclasses must implement hashCode() and equals().
- See Also:
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final FieldThe field this element belongs to.private static final longPinned for serialized-form compatibility.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionabstract FieldElementadd(FieldElement val) Adds another field element to this one.addOne()Adds one to this field element.abstract FieldElementcmov(FieldElement val, int b) Conditional move - sets this element to val if b is 1, otherwise leaves it unchanged.divide(FieldElement val) Divides this field element by another one.abstract FieldElementinvert()Computes the multiplicative inverse of this field element.booleanChecks if this field element is negative.abstract booleanChecks if this field element is non-zero.abstract FieldElementmultiply(FieldElement val) Multiplies this field element by another one.abstract FieldElementnegate()Negates this field element.abstract FieldElementpow22523()Raises this field element to the power of $2^{252} - 3$.abstract FieldElementsquare()Squares this field element.abstract FieldElementSquares this field element and doubles the result.abstract FieldElementsubtract(FieldElement val) Subtracts another field element from this one.Subtracts one from this field element.byte[]Encode a FieldElement in its $(b-1)$-bit encoding.
Field Details
serialVersionUID
private static final long serialVersionUIDPinned for serialized-form compatibility.- See Also:
f
The field this element belongs to.
Constructor Details
FieldElement
Creates a new field element in the specified field.- Parameters:
f- the field this element belongs to- Throws:
IllegalArgumentException- if f is null
Method Details
toByteArray
public byte[] toByteArray()Encode a FieldElement in its $(b-1)$-bit encoding.- Returns:
- the $(b-1)$-bit encoding of this FieldElement
isNonZero
public abstract boolean isNonZero()Checks if this field element is non-zero.- Returns:
- true if this element is not equal to zero, false otherwise
isNegative
public boolean isNegative()Checks if this field element is negative. Negative is defined as the least significant bit being 1.- Returns:
- true if this element is negative, false otherwise
add
Adds another field element to this one.- Parameters:
val- the field element to add- Returns:
- the sum of this element and val
addOne
subtract
Subtracts another field element from this one.- Parameters:
val- the field element to subtract- Returns:
- the difference of this element and val
subtractOne
Subtracts one from this field element.- Returns:
- this element minus one
negate
Negates this field element.- Returns:
- the negation of this element
divide
Divides this field element by another one.- Parameters:
val- the divisor; it must be non-zero, since it is inverted- Returns:
- this element divided by val
multiply
Multiplies this field element by another one.- Parameters:
val- the field element to multiply by; implementations cast it to their own type- Returns:
- the product of this element and val
square
squareAndDouble
Squares this field element and doubles the result.- Returns:
- (this element squared) * 2
invert
Computes the multiplicative inverse of this field element.- Returns:
- the multiplicative inverse of this element
- Throws:
ArithmeticException- if this element is zero
pow22523
Raises this field element to the power of $2^{252} - 3$.- Returns:
- this element raised to the power of $2^{252} - 3$
cmov
Conditional move - sets this element to val if b is 1, otherwise leaves it unchanged.- Parameters:
val- the field element to potentially assignb- the condition: 1 means assign val, 0 means keep this element- Returns:
- this element, potentially modified