Fast 32-bit Montgomery Fields #
The bounded carrier, conversions, arithmetic, and field instances built on Native32 reduction.
Per-field data for a fast 32-bit Montgomery field.
- prime : Nat.Prime modulus
modulusis prime. - modulus32 : UInt32
modulusas a 32-bit word. - modulus64 : UInt64
modulusas a 64-bit word. - rModModulus : UInt32
2^32 mod modulus, the Montgomery representation of one. - r2ModModulus : UInt64
(2^32)^2 mod modulus, used to enter Montgomery form. - montgomeryNegInv : UInt32
-modulus⁻¹ mod 2^32, used by Montgomery reduction.
Instances
The fast carrier for a prime modulus: a native word below modulus,
interpreted as a Montgomery residue. At runtime this erases to UInt32.
Instances For
Implementation #
Montgomery reduction for inputs known to be below p * 2^32.
Instances For
Conversions #
Build a fast element from a canonical natural representative.
Instances For
Convert a natural number into fast Montgomery representation.
Instances For
Convert a 32-bit word into fast Montgomery representation.
Instances For
Convert from the canonical ZMod field into fast Montgomery form.
Instances For
Convert an integer into fast Montgomery representation.
Instances For
Convert a fast element to its canonical native-word representative.
Instances For
Convert a fast element to its canonical natural representative.
Instances For
Convert a fast element to the canonical ZMod field.
Instances For
Field operations #
The zero fast element.
Instances For
The one fast element.
Instances For
Fast modular addition in Montgomery form.
Instances For
Fast modular negation in Montgomery form.
Instances For
Fast modular subtraction in Montgomery form.
Instances For
Fast modular multiplication in Montgomery form.
Instances For
Fast squaring.
Instances For
Exponentiation over the fast representation using repeated squaring.
Instances For
Inversion in Montgomery form via Fermat's little theorem (x⁻¹ = x^(p-2)),
by binary exponentiation (pow).
Instances For
Division through inversion and fast multiplication.
Instances For
Correctness #
Reduction and conversions #
Converting from the canonical field to fast form and back is the identity.
Converting from fast form to the canonical field and back is the identity.
The canonical-field interpretation distinguishes fast values.
Field operations #
toField maps fast zero to canonical zero.
toField maps fast one to canonical one.
Fast negation agrees with negation in the canonical field.
Fast inversion agrees with inversion in the canonical field.
Natural casts into fast form agree with natural casts into the canonical field.
Integer casts into fast form agree with integer casts into the canonical field.
Nonnegative rational casts into fast form agree with canonical-field casts.
Rational casts into fast form agree with canonical-field casts.
Algebraic structure #
Ring equivalence between the fast Montgomery representation and the canonical field.
Instances For
Field instance transferred from the canonical field through toField.
A fast 32-bit-word field is non-binary.