Two-modulus Chinese Remainder recombination #
crtCombine D L a xL inv = a + D * ((xL - a) * inv mod L) recombines a residue a modulo D
and a residue xL modulo L, given an inverse inv of D modulo L. The difference
xL - a is taken modulo L and written as xL + (L - a mod L), so no natural-number
subtraction truncates. The output is congruent to a modulo D for all arguments and to xL
modulo L whenever inv * D ≡ 1 (mod L). Such an inverse makes D and L coprime, so
crtCombine reconstructs every x < D * L from x mod D and x mod L; Mathlib's
Nat.chineseRemainder gives the same value without an explicit formula.
Main definitions #
Cslib.crtCombine: the explicit two-modulus recombination.
Main results #
Cslib.crtCombine_modEq_left,Cslib.crtCombine_modEq_right: the output is congruent toamoduloDand, given the inverse, toxLmoduloL.Cslib.crtCombine_lt: whenevera < Dand0 < L,crtCombine D L a xL inv < D * L.Cslib.crtCombine_eq: given an inverse ofDmoduloL, recombiningx mod Dandx mod Lreturns everyx < D * L.
References #
- J. Katz, Y. Lindell, Introduction to Modern Cryptography, 3rd ed., Section 10.2.1, p. 374.
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Version 0.6, §16.4.3, p. 701 (step 3 of RSA-CRT inversion).
Chinese Remainder Theorem combination of a = x % D and xL = x % L using an inverse inv of
D modulo L; the summand L - a % L represents -a modulo L without ℕ-subtraction
underflow.
crtCombine D L a xL inv is congruent to a modulo D, for all arguments.
crtCombine D L a xL inv is congruent to xL modulo L when inv * D ≡ 1 (mod L), for
every a and xL.
Whenever a < D and 0 < L, crtCombine D L a xL inv < D * L.
Chinese Remainder Theorem reconstruction (the two-modulus case of the CRT used in
[KL20], Section 10.2.1, p. 374): for x < D * L, a = x % D, xL = x % L, and
inv * D ≡ 1 (mod L), crtCombine D L a xL inv = x. Positivity of D and L follows from
x < D * L, and their coprimality from the inverse.