Class SM9P256V1Field

java.lang.Object
org.bouncycastle.math.ec.custom.gm.SM9P256V1Field

public class SM9P256V1Field extends Object
Prime-field arithmetic for the SM9 256-bit Barreto-Naehrig base field F_q (GM/T 0044.5-2016), used by the G1 curve SM9P256V1Curve.

Unlike SM2P256V1Field (whose sparse prime admits a fast Solinas reduction and stores elements in the ordinary residue representation), the SM9 BN prime is a general 256-bit prime, so this field keeps elements in Montgomery form (a·R mod q, R = 2^256) and multiplies with a Montgomery (SOS) reduction. Fixed-limb Nat256 arithmetic makes the field operations constant time (no data-dependent branches beyond the standard conditional subtractions), unlike the variable-length BigInteger the generic ECCurve.Fp would use.

The constants n0 = -q^-1 mod 2^32 and R^2 mod q are derived from q at class load (a micro-optimisation would inline them as int[] literals as SM2 does).

  • Method Details

    • add

      public static void add(int[] x, int[] y, int[] z)
    • subtract

      public static void subtract(int[] x, int[] y, int[] z)
    • negate

      public static void negate(int[] x, int[] z)
    • twice

      public static void twice(int[] x, int[] z)
    • multiply

      public static void multiply(int[] x, int[] y, int[] z)
    • square

      public static void square(int[] x, int[] z)
    • squareN

      public static void squareN(int[] x, int n, int[] z)
    • fromBigInteger

      public static int[] fromBigInteger(BigInteger x)
    • toBigInteger

      public static BigInteger toBigInteger(int[] xMont)
    • inv

      public static void inv(int[] x, int[] z)
    • isZero

      public static boolean isZero(int[] x)