Barrett reduction context specialized to a Hex.ZMod64 modulus.
The stored UInt64 modulus must agree with the Nat-indexed
Hex.ZMod64 modulus;
the underlying HexArith context then provides the small-modulus fast path.
- modulus : UInt64
The executable machine-word modulus used by the underlying context.
The stored word modulus agrees with the Nat-indexed
ZMod64modulus.- toUInt64Ctx : _root_.BarrettCtx self.modulus
Instances For
Montgomery reduction context specialized to a ZMod64 modulus.
As with Hex.BarrettCtx, the executable context stores the machine-word modulus
used by the underlying HexArith Montgomery code.
- modulus : UInt64
The executable machine-word modulus used by the underlying context.
The stored word modulus agrees with the Nat-indexed
ZMod64modulus.- toUInt64Ctx : _root_.MontCtx self.modulus
Instances For
Temporary Montgomery-form residue for hot loops.
This is intentionally distinct from Hex.ZMod64: values are still reduced into
[0, p), but they represent residues in Montgomery form rather than the
canonical standard representative.
- val : UInt64
Backing word for the Montgomery-form representative.
The backing word remains reduced modulo
p.
Instances For
View a Montgomery-form residue as its backing machine word.
Instances For
View a Montgomery-form residue as its reduced Nat representative.
Instances For
Equations
Equations
The UInt64 view of a Montgomery residue is its backing word.
The Nat view of a Montgomery residue is the Nat value of its backing word.
The Nat view of a Montgomery residue is reduced modulo its indexed modulus.
Montgomery residues are equal when their backing words are equal.
Extensionality for Montgomery residues via their canonical Nat representatives.
Two Montgomery residues are equal exactly when their canonical representatives agree.
Build a Barrett hot-loop context from the indexed small modulus.
Equations
- Hex.BarrettCtx.ofModulus hp hlt = { modulus := UInt64.ofNat p, modulus_eq := ⋯, toUInt64Ctx := BarrettCtx.mk (UInt64.ofNat p) ⋯ ⋯ }
Instances For
The smart constructor stores the indexed modulus as a machine word.
The smart constructor delegates to the underlying UInt64 Barrett context.
The smart constructor's underlying Barrett context stores the reciprocal for the indexed modulus.
Multiply two standard residues using the Barrett context and repackage the
result as a Hex.ZMod64.
Equations
- ctx.mulMod a b = Hex.ZMod64.ofNat p (ctx.toUInt64Ctx.mulMod a.toUInt64 b.toUInt64).toNat
Instances For
The Hex.ZMod64 Barrett wrapper computes the ordinary modular product on reduced
representatives.
Barrett hot-loop multiplication agrees with the ordinary ZMod64
multiplication surface.
Barrett hot-loop multiplication by one on the left returns the original standard residue.
Barrett hot-loop multiplication by zero on the left returns zero.
Barrett hot-loop multiplication by one on the right returns the original standard residue.
Barrett hot-loop multiplication by zero on the right returns zero.
Barrett hot-loop multiplication is commutative on standard residues.
Barrett hot-loop multiplication is associative on standard residues.
Build a Montgomery hot-loop context from the indexed modulus and the
word-level odd-modulus side condition required by the underlying HexArith
context.
Equations
- Hex.MontCtx.ofOddModulus hp hodd = { modulus := Hex.ZMod64.modulusWord p hp, modulus_eq := ⋯, toUInt64Ctx := MontCtx.mk (Hex.ZMod64.modulusWord p hp) hodd }
Instances For
The smart constructor stores the canonical machine-word modulus.
The smart constructor's stored word modulus agrees with the indexed modulus.
The smart constructor delegates to the underlying UInt64 Montgomery context.
Convert a standard residue into Montgomery form.
Instances For
Multiply two Montgomery-form residues, staying inside the Montgomery domain.
Instances For
Convert a Montgomery-form loop temporary back to the standard Hex.ZMod64
representation.
Equations
- ctx.fromMont a = Hex.ZMod64.ofNat p (ctx.toUInt64Ctx.fromMont a.toUInt64).toNat
Instances For
toMont delegates to the underlying UInt64 Montgomery conversion.
mulMont delegates to the underlying UInt64 Montgomery multiplication.
fromMont exposes the reduced Nat value computed by the underlying context.
The Nat value of toMont is multiplication by the Montgomery radix.
fromMont removes one Montgomery radix factor from a Montgomery-form loop
temporary.
Converting a standard residue into Montgomery form and back is the identity.
Multiplying two standard residues by entering Montgomery form, multiplying, and leaving Montgomery form computes the ordinary modular product.
Montgomery multiplication preserves the represented standard-residue product when converted back out of Montgomery form.
Multiplying two standard residues by entering Montgomery form, multiplying, and
leaving Montgomery form agrees with ordinary Hex.ZMod64 multiplication.
The Montgomery round trip for a wrapped product returns the original residue when the left standard input is one.
The Montgomery round trip for a wrapped product returns the original residue when the right standard input is one.
The Montgomery round trip for a wrapped product is commutative on standard residue inputs.
The Montgomery round trip for wrapped products is associative on standard residue inputs.