D-5.4 RNS-based Modulus Switch: ModSwitchRNS

Modulus switch is an operation of reducing a ciphertext’s modulus from q to q (where q < q) and updating the target value from x to x q q . Modulus switch is used for lowering the multiplicative level of a ciphertext upon each ciphertext-to-ciphertext multiplication (in the case of BFV, CKKS, or BGV) or even upon each ciphertext-to-plaintext multiplication (in the case of CKKS). Upon each modulus switch from q q of a ciphertext, the scaling factor of the underlying plaintext in the ciphertext also gets reduced by the same proportion: q q .

The modulus switch operation of an RNS-based ciphertext is denoted as ModSwitchRNS, which requires that the output base moduli are a subset of the input base moduli. In other words, like the case of ModDropRNS, it only supports a modulus switch from 𝑞𝑏 q, where q and b are co-prime.

Suppose we have (χ1,χ2,,χk+l) q1 × q2 × × qk × b1 × b2 × × bl, which represents the value χ = ( i=1k |χi (𝑞𝑏 qi ) 1| qi 𝑞𝑏 qi ) + ( j=k+1k+l |χj (𝑞𝑏 bj) 1| bj 𝑞𝑏 bj) mod 𝑞𝑏.

Given χ 𝑞𝑏, ModSwitchRNS from 𝑞𝑏 q is an operation of updating χ 𝑞𝑏 to some y q where y χ b . Unlike in regular modulus switch where we can directly arithmetically divide χ by b and round it, an RNS vector is incompatible with direct arithmetic division on the residues. Therefore, our alternative strategy is to find some small value χ^ such that χ χ^ mod b. Once we find such χ^, then χ χ^ mod 𝑞𝑏 becomes divisible by b (since their difference is some multiple of b), and thus we can compute χ χ^ b χ b . Note that in this computation, the additionally introduced error of modulus switch caused by replacing χ with χ χ^ is equivalent to: | χ b χ χ^ b | χ^ b . After the (exact) division of χ χ^ b , we directly replace the modulus 𝑞𝑏 with q. This direct replacement of modulus is arithmetically allowed because the computation result of χ χ^ b is guaranteed to be within q 2 and q 2 1 (since 𝑞𝑏 2 χ 𝑞𝑏 2 1). Therefore, we can derive the following formula:

χ χ^ b mod q = |b1|q (χ χ^) mod q

In the above relation, we can arithmetically replace b with |b1|q, because χ χ^ is divisible by b and b is guaranteed to have an inverse modulo q (since b and q are co-prime). Next, we can compute |b1|q (χ χ^) mod q based on their RNS residues as follows:

|b1|q (χ χ^) mod q

= (|b1|q1 (χ1 χ^1), |b1|q2 (χ2 χ^2), , |b1|qk (χk χ^k)) q1 × q2 × × qk

= (y1,y2,,yk) # where each yi = |b1|qi (χi χ^i) mod qi

Now, our task is to derive an expression for some small χ^ such that χ χ^ is divisible by b. We propose that χ^ = |χ|b + 𝑢𝑏 for some small integer |u|l 2 + 1. Then, notice that χ χ^ is divisible by b as follows:

|χ χ^|b = ||χ|b (|χ|b + 𝑢𝑏)|b = |𝑢𝑏|b = 0

Now, we will derive the RNS vector of χ^ mod q = |χ|b + 𝑢𝑏 mod q, which is to be plugged into |b1|q (χ χ^) mod q. First, we derive the RNS vector of |χ|b as follows:

(|χ|b1,|χ|b2,,|χ|bl) = (χk+1,χk+2,,χk+l) b1 × b2 × × bl

Next, we can compute its fast base conversion from b q as follows:

𝖥𝖺𝗌𝗍𝖡𝖢𝗈𝗇𝗏({χk+i}i=1l,b,q)

= (χ^1,χ^2,,χ^k) q1 × q2 × × qk

Now, notice that the above RNS residue vector (χ^1,χ^2,,χ^k) represents the value χ^ = |χ|b + u b mod q (where integer |u|l 2 + 1), which is our desired formula for χ^. Therefore, χ^ = 𝖥𝖺𝗌𝗍𝖡𝖢𝗈𝗇𝗏({χk+i}i=1l,b,q).

Note that χ^ q 2 1 and q 2 χ^, because ||χ|b + u b| < ( l 2 + 1) b + b 2 q 2 (here we assume that b q, as we assume the modulus switch operation is used to remove only a single prime factor from the large base q). Therefore, the magnitude of the error generated by computing b1 (χ χ^) is approximately χ^ b < ( l 2 + 1) b + b 2 b = 𝑙𝑏 + 3b 2b = l + 3 2 < l 2 + 2.

We summarize the ModSwitchRNS operation as follows:

Summary D-5.4 ModSwitchRNS

Input: (χ1,χ2,,χk+l) q1 × q2 × × qk × b1 × b2 × × bl

# which represents χ = ( i=1k |χi (𝑞𝑏 qi ) 1| qi 𝑞𝑏 qi ) + ( j=k+1k+l |χj (𝑞𝑏 bj) 1| bj 𝑞𝑏 bj) mod 𝑞𝑏

Notations

Main Steps

𝖬𝗈𝖽𝖲𝗐𝗂𝗍𝖼𝗁𝖱𝖭𝖲({χi}i=1k+l,𝑞𝑏,q)

= {|b1|qi (χi χ^i) mod qi}i=1k q1 × q2 × × qk

, whose RNS residue vector represents the value |b1|q (χ χ^) mod q. The magnitude of noise generated by ModSwitchRNS is roughly χ^ b < l 2 + 2.

D-5.4.1 Comparing ModSwitchRNS, ModRaiseRNS, and ModDropRNS

Given a big value x q in an RNS vector, ModSwitchRNS reduces its modulus from q q as well as explicitly decreases the modulo value x by the proportion of q q (i.e., updates x to x q q ). On the other hand, ModDropRNS from q q updates the modulo value from x |x|q (where q divides q), which is different from decreasing x by the proportion of q q like modulus switch. ModRaiseRNS from q 𝑞𝑏 (where q divides 𝑞𝑏) increases the modulus without explicitly modifying the modulo value x, but generates some q-overflow noise. ModSwitchRNS and ModRaiseRNS generate some noise, whereas ModDropRNS does not generate any noise.