Runtime Montgomery context for an odd UInt64 modulus.
The native Montgomery externs rely on proof erasure leaving p' and r2 as
runtime constructor fields 0 and 1. Any change to the data-bearing fields must
be mirrored in the C accessors and the native cross-checks.
- mkCtx :: (
The modulus is odd.
- p' : UInt64
The Montgomery inverse word, satisfying
p' · p ≡ -1 (mod R). The inverse field satisfies
p' · p ≡ R - 1 (mod R).- r2 : UInt64
The constant
R² mod p, used to convert a residue into Montgomery form. The
r2field is exactlyR² mod p.- )
Instances For
Executable Montgomery reduction (classically REDC) from a two-word product
(Thi, Tlo) encoded in base 2^64.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The carry pair (c2, addHi) represents the exact quotient u, stated over the
(mhi, mlo) pair returned by UInt64.mulFull m p rather than the split
(UInt64.mulHi m p, m * p) view.
The final subtraction logic matches the Nat-level REDC normalization step.
The executable REDC routine agrees with the Nat-level specification.
Executable REDC returns a canonical residue below the modulus.
Executable REDC represents division by the Montgomery radix modulo p.
This is the direct executable form of montgomeryReduceNat_eq_mod, avoiding an explicit
unfolding through the Nat-level REDC definition for downstream callers.