Interface SecpFieldElement

All Known Implementing Classes:
SecpFieldElementImpl

public interface SecpFieldElement
A number that is a valid element of the P256K1 field. We use this instead of BigInteger so we can use a fixed-length, unsigned representation for simplicity and performance.
  • Method Details

    • toBigInteger

      BigInteger toBigInteger()
      Get the field element as a BigInteger
      Returns:
      field element value
    • serialize

      byte[] serialize()
      Get serialized field element (32 bytes unsigned)
      Returns:
      serialized field element
    • isOdd

      boolean isOdd()
      Get the parity of the field value
      Returns:
      true if odd, false if even
    • of

      Construct a SecpFieldElement from a BigInteger
      Parameters:
      i - integer
      Returns:
      valid element
    • of

      static SecpFieldElement of(byte[] bytes)
      Construct a field element from a byte-array of 32 bytes
      Parameters:
      bytes - array containing a valid field element
      Returns:
      field element
    • isInRange

      static boolean isInRange(BigInteger e)
      Check if an integer is in the inclusive range 0 to P - 1, where P is the prime of the SECG P256K1 prime finite field.
      Parameters:
      e - A possible field element to validate
      Returns:
      true if valid
    • checkInRange

      static BigInteger checkInRange(BigInteger e)
      Throw IllegalArgumentException if an integer is not in the inclusive range 0 to P - 1, where P is the prime of the SECP256K1 prime finite field.
      Parameters:
      e - unvalidated integer
      Returns:
      a validated integer
    • checkInRange

      static byte[] checkInRange(byte[] e)
      Throw IllegalArgumentException if the byte array is not the length.

      NOTE: We are not currently validating for value less than P

      Parameters:
      e - unvalidated integer
      Returns:
      a validated integer
    • integerTo32Bytes

      static byte[] integerTo32Bytes(BigInteger i)
      Convert a BigInteger to a fixed-length byte array
      Parameters:
      i - an unsigned BigInteger containing a valid Secp256k1 field value
      Returns:
      a 32-byte, big-endian unsigned integer value