Class SM9P256V1Field
java.lang.Object
org.bouncycastle.math.ec.custom.gm.SM9P256V1Field
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 Summary
Modifier and TypeMethodDescriptionstatic voidadd(int[] x, int[] y, int[] z) static int[]static voidinv(int[] x, int[] z) static booleanisZero(int[] x) static voidmultiply(int[] x, int[] y, int[] z) static voidnegate(int[] x, int[] z) static voidsquare(int[] x, int[] z) static voidsquareN(int[] x, int n, int[] z) static voidsubtract(int[] x, int[] y, int[] z) static BigIntegertoBigInteger(int[] xMont) static voidtwice(int[] x, int[] z)
-
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
-
toBigInteger
-
inv
public static void inv(int[] x, int[] z) -
isZero
public static boolean isZero(int[] x)
-