Class FieldElement

    • Constructor Detail

      • FieldElement

        protected FieldElement​(long fieldElementPointer)
    • Method Detail

      • createFromLong

        public static FieldElement createFromLong​(long value)
        Convert an integer value to a field element
        Parameters:
        value - - A positive integer value to be converted to a field element
        Returns:
        The field element represented with the positive integer value provided as input
      • createRandom

        public static FieldElement createRandom​(long seed)
      • nativeSerializeFieldElement

        protected byte[] nativeSerializeFieldElement()
      • serializeFieldElement

        public byte[] serializeFieldElement()
      • deserialize

        public static FieldElement deserialize​(byte[] fieldElementBytes)
                                        throws IllegalArgumentException
        Deserialize a FieldElement from "fieldElementBytes"
        Parameters:
        fieldElementBytes - bytes of the FieldElement to be deserialized
        Returns:
        The deserialized FieldElement
        Throws:
        IllegalArgumentException - If fieldElementBytes.len() > FIELD_ELEMENT_LENGTH or if the bytes represent an invalid FieldElement
      • splitAt

        public List<FieldElement> splitAt​(int index)
                                   throws IndexOutOfBoundsException
        Split this FieldElement into two FieldElements. Split will happen at the specified index: one FieldElement will be read from the original bytes [0..index) and the other ones from the original bytes [index..FIELD_ELEMENT_LENGTH)
        Parameters:
        index - - a valid integer in the range (0, FIELD_ELEMENT_LENGTH)
        Returns:
        a List made up of two FieldElements, read from the original one split at index
        Throws:
        IndexOutOfBoundsException - in case of illegal index (i.e. index <= 0 OR index >= FIELD_ELEMENT_LENGTH)
      • joinAt

        public static FieldElement joinAt​(FieldElement fe1,
                                          int index1,
                                          FieldElement fe2,
                                          int index2,
                                          boolean checkZeroAfterIdx)
                                   throws IllegalArgumentException
        The inverse of the splitAt() method: join fe1.bytes[0..index1) and fe2.bytes[0..index2) in a single byte array and deserialize a FieldElement out of it.
        Parameters:
        fe1 - - the first FieldElement to join
        index1 - - the number of bytes to consider from the first FieldElement
        fe2 - - the second FieldElement to join
        index2 - - the number of bytes to consider from the second FieldElement
        checkZeroAfterIdx - - if enabled, check that fe1.bytes[index1..] and fe2.bytes[index2..] are all 0s.
        Returns:
        the FieldElement obtained from combining fe1.bytes[0..index1) with fe2.bytes[0..index2)
        Throws:
        IllegalArgumentException - if the combine operation would produce a byte array bigger than FIELD_ELEMENT_LENGTH
      • joinAt

        public static FieldElement joinAt​(FieldElement fe1,
                                          int index1,
                                          FieldElement fe2,
                                          int index2)
                                   throws IllegalArgumentException
        The inverse of the splitAt() method: join fe1.bytes[0..index1) and fe2.bytes[0..index2) in a single byte array and deserialize a FieldElement out of it.
        Parameters:
        fe1 - - the first FieldElement to join
        index1 - - the number of bytes to consider from the first FieldElement
        fe2 - - the second FieldElement to join
        index2 - - the number of bytes to consider from the second FieldElement
        Returns:
        the FieldElement obtained from combining fe1.bytes[0..index1) with fe2.bytes[0..index2)
        Throws:
        IllegalArgumentException - if the combine operation would produce a byte array bigger than FIELD_ELEMENT_LENGTH
      • nativePrintFieldElementBytes

        protected void nativePrintFieldElementBytes()
      • printFieldElementBytes

        public void printFieldElementBytes()
      • freeFieldElement

        public void freeFieldElement()