Class Fp2Element

java.lang.Object
org.bouncycastle.crypto.bls.Fp2Element

public final class Fp2Element extends Object
Immutable element of Fp^2 = Fp[I] / (I^2 + 1), used as the base field of BLS12-381 G2.

All operations reduce modulo p eagerly. Internally the two Fp components are stored as plain BigInteger values.

  • Field Details

    • P

      public static final BigInteger P
      Field characteristic, identical to the BLS12-381 base field p.
    • ZERO

      public static final Fp2Element ZERO
      The Fp^2 zero element.
    • ONE

      public static final Fp2Element ONE
      The Fp^2 one element (1 + 0*I).
  • Method Details

    • of

      public static Fp2Element of(BigInteger c0, BigInteger c1)
    • of

      public static Fp2Element of(long c0, long c1)
    • fromFp

      public static Fp2Element fromFp(BigInteger c0)
    • c0

      public BigInteger c0()
      Returns:
      real component (the c0 in c0 + c1*I).
    • c1

      public BigInteger c1()
      Returns:
      imaginary component (the c1 in c0 + c1*I).
    • isZero

      public boolean isZero()
    • add

      public Fp2Element add(Fp2Element other)
    • sub

      public Fp2Element sub(Fp2Element other)
    • neg

      public Fp2Element neg()
    • mul

      public Fp2Element mul(Fp2Element other)
      (a + b*I)(c + d*I) = (ac - bd) + (ad + bc)*I.
    • mulFp

      public Fp2Element mulFp(BigInteger fp)
      Multiply by a Fp scalar.
    • square

      public Fp2Element square()
      (a + b*I)^2 = (a-b)(a+b) + 2ab*I.
    • frobenius

      public Fp2Element frobenius()
      Frobenius: (c0 + c1*I)^p = c0 - c1*I when p ≡ 3 (mod 4), which holds for the BLS12-381 base field.
    • inverse

      public Fp2Element inverse()
      Modular inverse: (c0 + c1*I)^-1 = (c0 - c1*I) / (c0^2 + c1^2).
    • modPow

      public Fp2Element modPow(BigInteger exponent)
      Modular exponentiation in Fp^2 by a non-negative integer exponent.
    • sgn0

      public int sgn0()
      RFC 9380 sec. 4.1 sgn0 for m = 2.
        sign_0 = c0 mod 2
        zero_0 = (c0 == 0)
        sign_1 = c1 mod 2
        return sign_0 OR (zero_0 AND sign_1)
      
    • sqrtOrNull

      public Fp2Element sqrtOrNull()
      Tries to compute a square root of this in Fp^2, using the Wahby-Boneh algorithm specialised to p ≡ 3 (mod 4) ("Fast and simple constant-time hashing to the BLS12-381 elliptic curve", Algorithm 1).
      Returns:
      a square root, or null if this is not a square.
    • isSquare

      public boolean isSquare()
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object