java.lang.Object
net.i2p.crypto.eddsa.math.FieldElement
net.i2p.crypto.eddsa.math.bigint.BigIntegerFieldElement
All Implemented Interfaces:
Serializable

public class BigIntegerFieldElementextends FieldElement implements Serializable
A particular element of the field \Z/(2^255-19).
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Pinned for serialized-form compatibility.
      See Also:
    • bi

      final BigInteger bi
      Variable is package private for encoding.
  • Constructor Details

    • BigIntegerFieldElement

      public BigIntegerFieldElement(Field f, BigInteger bi)
      Creates a new field element from a BigInteger value.
      Parameters:
      f - the field this element belongs to
      bi - the BigInteger value
  • Method Details

    • isNonZero

      public boolean isNonZero()
      Description copied from class: FieldElement
      Checks if this field element is non-zero.
      Specified by:
      isNonZero in class FieldElement
      Returns:
      true if this element is not equal to zero, false otherwise
    • add

      public FieldElement add(FieldElement val)
      Description copied from class: FieldElement
      Adds another field element to this one.
      Specified by:
      add in class FieldElement
      Parameters:
      val - the field element to add
      Returns:
      the sum of this element and val
    • addOne

      public FieldElement addOne()
      Description copied from class: FieldElement
      Adds one to this field element.
      Overrides:
      addOne in class FieldElement
      Returns:
      this element plus one
    • subtract

      public FieldElement subtract(FieldElement val)
      Description copied from class: FieldElement
      Subtracts another field element from this one.
      Specified by:
      subtract in class FieldElement
      Parameters:
      val - the field element to subtract
      Returns:
      the difference of this element and val
    • subtractOne

      public FieldElement subtractOne()
      Description copied from class: FieldElement
      Subtracts one from this field element.
      Overrides:
      subtractOne in class FieldElement
      Returns:
      this element minus one
    • negate

      public FieldElement negate()
      Description copied from class: FieldElement
      Negates this field element.
      Specified by:
      negate in class FieldElement
      Returns:
      the negation of this element
    • divide

      public FieldElement divide(FieldElement val)
      Description copied from class: FieldElement
      Divides this field element by another one.
      Overrides:
      divide in class FieldElement
      Parameters:
      val - the divisor; it must be non-zero, since it is inverted
      Returns:
      this element divided by val
    • divide

      public FieldElement divide(BigInteger val)
      Divide by a BigInteger.
      Parameters:
      val - the value to divide by
      Returns:
      the quotient, reduced to the range 0 to q-1
    • multiply

      public FieldElement multiply(FieldElement val)
      Description copied from class: FieldElement
      Multiplies this field element by another one.
      Specified by:
      multiply in class FieldElement
      Parameters:
      val - the field element to multiply by; implementations cast it to their own type
      Returns:
      the product of this element and val
    • square

      public FieldElement square()
      Description copied from class: FieldElement
      Squares this field element.
      Specified by:
      square in class FieldElement
      Returns:
      this element squared
    • squareAndDouble

      public FieldElement squareAndDouble()
      Description copied from class: FieldElement
      Squares this field element and doubles the result.
      Specified by:
      squareAndDouble in class FieldElement
      Returns:
      (this element squared) * 2
    • invert

      public FieldElement invert()
      Description copied from class: FieldElement
      Computes the multiplicative inverse of this field element.
      Specified by:
      invert in class FieldElement
      Returns:
      the multiplicative inverse of this element
    • mod

      public FieldElement mod(FieldElement m)
      Return this field element modulo m.
      Parameters:
      m - the modulus, in practice the field prime f.getQ()
      Returns:
      this element reduced modulo m
    • modPow

      public FieldElement modPow(FieldElement e, FieldElement m)
      Return this field element to the power e modulo m.
      Parameters:
      e - the exponent, which must not be negative
      m - the modulus, in practice the field prime f.getQ()
      Returns:
      this element raised to the power e, modulo m
    • pow

      public FieldElement pow(FieldElement e)
      Return this field element to the power e.
      Parameters:
      e - the exponent, which must not be negative
      Returns:
      this element raised to the power e, reduced modulo the field's q
    • pow22523

      public FieldElement pow22523()
      Description copied from class: FieldElement
      Raises this field element to the power of $2^{252} - 3$.
      Specified by:
      pow22523 in class FieldElement
      Returns:
      this element raised to the power of $2^{252} - 3$
    • cmov

      public FieldElement cmov(FieldElement val, int b)
      Conditional move.
      Specified by:
      cmov in class FieldElement
      Parameters:
      val - the field element to potentially assign
      b - the condition: 1 means assign val, 0 means keep this element
      Returns:
      this element, potentially modified
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object