Fast eight-limb Montgomery fields #
The bounded carrier, conversions, arithmetic, and field instances built on the raw eight-limb
Montgomery operations of Montgomery/Native64x8. This is the multi-limb analogue of
Montgomery/Native32Field, for prime moduli below 2 ^ 255.
A carrier element stores the Montgomery residue x * 2 ^ 256 mod q as eight 32-bit limbs;
toField divides that residue by 2 ^ 256 again and lands in ZMod modulus. All arithmetic
is transported along toField, which is a ring isomorphism onto ZMod modulus.
Main results #
FastField— the carrier,{ x : Limbs8 // x.Bounded ∧ x.toNat < modulus }toField_add,toField_mul, … —@[simp]equivalences with the canonical fieldMont64x8Field— the per-field constants classringEquiv,instField— the ring isomorphism and the transferredFieldinstance
Per-field constants #
Per-field data for a fast eight-limb Montgomery field with radix R = 2 ^ 256. All
side conditions are concrete numeral facts, discharged by decide at instantiation.
- prime : Nat.Prime modulus
modulusis prime. - modulusLimbs : Limbs8
The modulus in eight 32-bit limbs.
- rModModulus : Limbs8
2 ^ 256 mod modulus, the Montgomery representation of one. - r2ModModulus : Limbs8
(2 ^ 256) ^ 2 mod modulus, used to enter Montgomery form. - montgomeryNegInv : UInt64
-modulus⁻¹ mod 2 ^ 32, used by Montgomery reduction. - modulusLimbs_bounded : (modulusLimbs modulus).Bounded
- rModModulus_bounded : (rModModulus modulus).Bounded
- r2ModModulus_bounded : (r2ModModulus modulus).Bounded
Instances
Modulus facts #
The carrier #
The fast carrier for a prime modulus: eight 32-bit limbs holding a value below modulus,
interpreted as a Montgomery residue. At runtime this erases to Limbs8.
Instances For
Arithmetic #
The zero element.
Instances For
The one element, the Montgomery residue 2 ^ 256 mod modulus.
Instances For
Fast modular addition in Montgomery form.
Instances For
Fast modular subtraction in Montgomery form.
Instances For
Fast modular negation in Montgomery form.
Instances For
Fast Montgomery multiplication.
Instances For
Fast squaring.
Instances For
Exponentiation by repeated squaring.
Instances For
Inversion by Fermat's little theorem, x⁻¹ = x ^ (modulus - 2).
Instances For
Division through inversion.
Instances For
Conversions #
The canonical limb representative of a fast element: one Montgomery reduction.
Instances For
The canonical natural representative of a fast element.
Instances For
The canonical ZMod value of a fast element.
Instances For
Build a fast element from a canonical natural representative.
Instances For
Convert a natural number into fast Montgomery form.
Instances For
Convert from the canonical field into fast Montgomery form.
Instances For
Convert an integer into fast Montgomery form.
Instances For
Correctness #
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 #
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 eight-limb field is non-binary.