Explicit Chinese Remainder Theorem

Let pip_i coprime positive integers for i=1,...,Ki=1,...,K. Let aia_i be an integer satisfying 0ai<pi0 \leq a_i < p_i for each ii.

The Chinese Remainder Theorem (CRT) provides a way to determine an integer aa such that:

a=a1modp1a = a_1 \; mod \; p_1

......

a=aKmodpKa = a_K \; mod \; p_K

To determine aa, we proceed as follows. Define:

P=p1pKP = p_1 \cdots p_K

Pi=PpiP_i = \frac{P}{p_i}

ti=Pi1modpit_i = P_i^{-1} \; mod \; p_i

The value aa can be constructed as:

a=i=1KtiPiaia = \sum_{i=1}^K t_i P_i a_i

It’s clear that a=aimodpia = a_i \; mod \; p_i because

tiPiai=1ai=aimodpit_i P_i a_i = 1 a_i = a_i \; mod \; p_i

and

tiPiai=0modpjforijt_i P_i a_i = 0 \; mod \; p_j \; \; \text{for} \; i \neq j

The value aa is unique up to modulo PP, but we do not know the integer rr for which:

rPa<(r+1)Pr P \leq a < (r+1)P

For example, in lattice-based cryptography, the integer aa is sometimes represented as (a1,...,aK)(a_1, ..., a_K) for performance reasons. However, at some point, one needs to reconstruct aa from (a1,...,aK).(a_1, ..., a_K). In these cases, a<P|a| < P (in fact, a<P2|a| < \frac{P}{2} because the values are centered around 00). So, how can we reconstruct aa?

This is where the explicit CRT (opens new window) comes into play. Let’s express aa a bit differently:

a=Pi=1Ktipiaia = P \sum_{i=1}^K \frac{t_i}{p_i} a_i

We define (which is generally not an integer):

z=i=1Ktipiaiz = \sum_{i=1}^K \frac{t_i}{p_i} a_i

Let’s define uu to be congruent to aa, satisfying

u=amodP,0u<Pu = a \; mod \; P, \;\;\; 0 \leq u < P

It holds:

Pz=u+rPPz = u + rP

P(zr)=uP(z - r) = u

If it holds u<P2|u| < \frac{P}{2}, then zr<12z-r < \frac{1}{2}. That means:

r=round(z)r = round(z)

So we can compute uu as:

u=PzPround(z)u = P \cdot z - P \cdot round(z)