D-5.1 Fast Base Conversion: FastBConv

- Reference 1: A Full RNS Variant of FV-like Somewhat Homomorphic Encryption Schemes [24]

- Reference 2: BASALISC: Programmable Hardware Accelerator for BGV FHE [25]

Suppose we have x q (where q is a big modulus). Then, we can express x by using RNS (§A-13.1) as (x1,x2,,xk), where each xi qi, i=1kqi = q, and {q1,q2,,qk} are co-prime. In RNS, we define base conversion as an operation of converting the RNS residues (x1,x2,,xk) q1 × q2 × × qk into (c1,c2,,ck) b1 × b2 × × bl, where {b1,b2,,bl} are a new base, and {q1,q2,,qk} and {b1,b2,,bl} are all co-prime. The relationship between x and c is: c = |x|b (where x q and c b). The standard way of performing base conversion is assembling (x1,x2,,xk) into x by computing x = i=1k|xizi|qi yi mod q (where yi = q qi and zi = yi1 mod qi), and then computing cj x mod bj for j [1,l]. However, this computation is slow if the modulus q is large. To compute the base conversion fast, we design the fast base conversion operation 𝖥𝖺𝗌𝗍𝖡𝖢𝗈𝗇𝗏 as follows:

Summary D-5.1 Fast Base Conversion: FastBConv

Input: (x1,x2,,xk) q1 × q2 × × qk # which represents the big value x q, where q = i=1kqi, and {q1,q2,,qk} are co-prime

𝖥𝖺𝗌𝗍𝖡𝖢𝗈𝗇𝗏(x,q,b) = 𝖥𝖺𝗌𝗍𝖡𝖢𝗈𝗇𝗏({xi}i=1k,{qi}i=1k,{bi}i=1l)

= ( i=1k|xi zi|qi yi mod bj) j[1,l]

# where yi = q qizi = yi1 mod qi, and b = i=1lbi

= (c1,c2,,cl) b1 × b2 × × bl # which represents the big value c b

The input to this FastBConv function is a list of RNS residues (x1,x2,,xk) having the prime moduli (q1,q2,,qk) as the base. This RNS vector represents the big value:

x = ( i=1kxi yi zi) mod q = ( i=1k|xi zi|qi yi) mod q # Theorem A-13.1

The output of this FastBConv function is a list of RNS residues (c1,c2,,cl) having the prime moduli (b1,b2,,bl) as the base. This RNS vector represents the big value

c = ( i=1lci yizi)mod b = ( i=1l|ci zi|bi yi)mod b # where yi = b bi and zi = yi1 mod bi

The relationship between c and x is as follows:

c = x + 𝑢𝑞 mod b (where u is an integer with the magnitude |u|k 2 + 1)

# i.e. the fast-base-converted c gets noise |𝑢𝑞|b

Proof.

We will prove why a fast base conversion of x into c gets an additional noise |u q|b (where integer |u|k 2 + 1) compared to a standard base conversion. If we did a standard (i.e., exact) base conversion of x from base moduli (q1,,qk) to (b1,,bl), then we would compute the following:

(( i=1k|x i zi|qi yi mod q) mod bj) j[1,l] = (x mod bj) j[1,l]

But 𝖥𝖺𝗌𝗍𝖡𝖢𝗈𝗇𝗏 omits the intermediate (big) reduction modulo q and directly applies (small) reduction modulo bj for the sake of fast computation, so that our conversion process does not need to handle large values whose magnitude can be as large as ±q 2. In this approach of fast base conversion, for each i [1,k], the computation result of |xi zi|qi yi is some value between [q 2, q 2], because |xi zi|qi is some integer between [qi 2 , qi 2 ] and yi = q qi. Therefore, q + 1 2 |xi zi|qi yi q 2. If we sum k such values for i [1,k], then the total sum x = i=1k|xi zi|qi yi = x + u q (Summary A-13 in §A-13) for some integer u (where u q represents the q-multiple overflows). And since we have shown that q + 1 2 |xi zi|qi yi q 2 for each i [1,k], 𝑢𝑞 has to be greater than k q + 1 2 and smaller than k q 2 (i.e., u is an integer between k 2 1 u k 2). Therefore, i=1k|xi zi|qi yi can have maximum (k 2 + 1) q underflows and k 2 q overflows. Thus, while standard (i.e., exact) base conversion computes each residue as c^j = ( i=1k|xi zi|qi yi mod q) mod bj (i.e., c^j = x mod bj), fast (i.e., approximate) base conversion computes each residue as cj = ( i=1k|xi zi|qi yi) mod bj (i.e., cj = x + 𝑢𝑞 mod bj, where integer |u|k 2 + 1). Notice that the residual difference (i.e., error) between each c^j and cj is 𝑢𝑞 mod bj, and the collective noise generated by fast base conversion from q b is 𝑢𝑞 mod b. Also, note that the RNS residue vector (c1,c2,,cl) b1 × b2 × × bl represents the big value c = x + 𝑢𝑞 mod b.

Importantly, FastBConv does not guarantee the correctness of base conversion, because the q-multiple overflow would generate a non-negligible error. Yet, FastBConv is used as an essential building block for various RNS-based operations such as ModRaiseRNS (§D-5.2) and ModSwitchRNS (§D-5.4). □