Module ring::arithmetic::bigint
source · Expand description
Multi-precision integers.
§Modular Arithmetic.
Modular arithmetic is done in finite commutative rings ℤ/mℤ for some modulus m. We work in finite commutative rings instead of finite fields because the RSA public modulus n is not prime, which means ℤ/nℤ contains nonzero elements that have no multiplicative inverse, so ℤ/nℤ is not a finite field.
In some calculations we need to deal with multiple rings at once. For
example, RSA private key operations operate in the rings ℤ/nℤ, ℤ/pℤ, and
ℤ/qℤ. Types and functions dealing with such rings are all parameterized
over a type M
to ensure that we don’t wrongly mix up the math, e.g. by
multiplying an element of ℤ/pℤ by an element of ℤ/qℤ modulo q. This follows
the “unit” pattern described in Static checking of units in Servo.
Elem
also uses the static unit checking pattern to statically track the
Montgomery factors that need to be canceled out in each value using it’s
E
parameter.
Modules§
- modulus 🔒
Structs§
- Elements of ℤ/mℤ for some modulus m.
Traits§
Functions§
- Calculates base**exponent (mod m).
- Does a Montgomery reduction on
limbs
assuming they are Montgomery-encoded (‘R’) and assuming they are the same size asm
, but perhaps not reduced modm
. The result will be fully reduced modm
. - Verified a == b**-1 (mod m), i.e. a**-1 == b (mod m).