D-3.5 Homomorphic Ciphertext-to-Ciphertext Multiplication

CKKS’s ciphertext-to-ciphertext multiplication is partially different from that of BFV. In the case of BFV, its ciphertext modulus stays the same after each multiplication. On the other hand, CKKS reduces its ciphertext modulus size by 1 after each multiplication (which is equivalent to reducing its multiplicative level by 1). When the level reaches 0, no more multiplication can be further done (unless we bootstrap the modulus). This difference happens because the two schemes use different strategies in handling their plaintext scaling factors– BFV’s Δ = q t, whereas CKKS’s Δ can be any value such that Δ q0 where q0 is the lowest multiplicative level’s ciphertext modulus. However, both schemes use the similar relinearization technique.

To make it easy to understand, we will explain CKKS’s ciphertext-to-ciphertext multiplication based on this alternate version of RLWE (Theorem B-4.4 in §B-4.4), where the sign of the 𝐴𝑆 term is flipped in the encryption and decryption formulas.

Suppose we have the following two (CKKS) RLWE ciphertexts:

𝖱𝖫𝖶𝖤S,σ(ΔM1) = (A1,B1), where B1 = A1S + ΔM1+ E1

𝖱𝖫𝖶𝖤S,σ(ΔM2) = (A2,B2), where B2 = A2S + ΔM2+ E2

RLWE ciphertext-to-ciphertext multiplication is comprised of the following 2 steps:

1.
Find a formula for the synthetic ciphertext that is equivalent to 𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) by leveraging the following congruence relation:

𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) = 𝖱𝖫𝖶𝖤S,σ(Δ M1) 𝖱𝖫𝖶𝖤S,σ(Δ M2)

2.
Rescale 𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) to 𝖱𝖫𝖶𝖤S,σ(Δ M1M2).

We will explain each of these steps.

D-3.5.1 Synthetic Ciphertext Derivation

The 1st step of RLWE ciphertext-ciphertext multiplication is to find a way to express the following congruence relation:

𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) = 𝖱𝖫𝖶𝖤S,σ(Δ M1) 𝖱𝖫𝖶𝖤S,σ(Δ M2)

in terms of our following known values: A1, B1, A2, B2, S. First, notice that the following is true:

𝖱𝖫𝖶𝖤S,σ1( 𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) ) = 𝖱𝖫𝖶𝖤S,σ1( 𝖱𝖫𝖶𝖤S,σ(ΔM1) )𝖱𝖫𝖶𝖤S,σ1( 𝖱𝖫𝖶𝖤S,σ(ΔM2) )

, because encrypting and decrypting the multiplication of two plaintexts should give the same result as decrypting two encrypted plaintexts and then multiplying them. As the encryption and decryption functions cancel out, we get the following:

Δ2 M1M2 (Δ M1+ E1) (Δ M2+ E2)

= 𝖱𝖫𝖶𝖤S,σ1( 𝖱𝖫𝖶𝖤S,σ(Δ M1) ) 𝖱𝖫𝖶𝖤S,σ1( 𝖱𝖫𝖶𝖤S,σ(Δ M2) )

# where (Δ M1+ E1) (Δ M2+ E2) = Δ2 M1M2+ Δ M1E2+ Δ M2E1+ E1E2, where E1E2 is small enough to be eliminated upon decryption, and Δ M1E2 and Δ M2E1 will be scaled down to M1E2 and M2E1 upon modulus switch later, becoming small enough to be enough to be eliminated during decryption

Remember from §B-4.4 the following:

𝖱𝖫𝖶𝖤S,σ1( C = (A,B) ) = ΔM + E = B + A S

Thus, the above congruence relation can be rewritten as follows:

Δ2 M1M2 (Δ M1+ E1) (Δ M2+ E2)

= (B1+ A1S E1) (B2+ A2S E2)

(B1+ A1S) (B2+ A2S)

= B1B2+ (B2A1+ B1A2) S + (A1S) (A2S)

= B1B2 D0 + (B2A1+ B1A2) D1 S + (A1A2) D2 (S S)S2

= D0 + D1 S + D2 S2

= 𝖱𝖫𝖶𝖤S,σ1( Cα = (D1,D0) ) + D2 S2 # since D0 + D1 S = 𝖱𝖫𝖶𝖤S,σ1( Cα = (D1,D0) )

In the final step above, we converted D0 + D1 S into 𝖱𝖫𝖶𝖤S,σ1( Cα = (D1,D0) ), where Cα is the synthetic RLWE ciphertext (D1,D0) encrypted by S. Similarly, our next task is to derive a synthetic RLWE ciphertext Cβ such that D2 S2 = 𝖱𝖫𝖶𝖤S,σ1(Cβ). The reason why we want this synthetic ciphertext is that we do not want the square of S (i.e., S2), because if we continue to keep S2, then over more consequent ciphertext-to-ciphertext multiplications, this term will aggregate exponentially growing bigger exponents such as S4,S8,..., which would exponentially increase the computational overhead of decryption. In the next subsection, we will explain how to derive the synthetic RLWE ciphertext Cβ such that D2 S2 = 𝖱𝖫𝖶𝖤S,σ1(Cβ).

D-3.5.2 Relinearization Method 1 – Ciphertext Decomposition

As explained in BFV’s ciphertext-to-ciphertext multiplication (§D-2.7.3), relinearization is a process of converting the polynomial triplet (D0,D1,D2) Rn,q3, which can be decrypted into ΔM using S and S2 as keys, into the polynomial pairs (Cα,Cβ) Rn,q2, which can be decrypted into the same ΔM by using S as key. In the previous subsection, we explained that we can convert D0 and D1 into Cα simply by viewing D0 and D1 as Cα = (D1,D0). The process of converting D2 into Cβ is exactly the same as the technique explained in §D-2.7.3, which applies the gadget decomposition (§A-6.4) on D2 and computes an inner product with the RLev encryption (§B-5) of S2. Specifically, we compute the following:

𝖱𝖫𝖶𝖤S,σ1(Cβ = 𝖣𝖾𝖼𝗈𝗆𝗉β,l(D2), 𝖱𝖫𝖾𝗏S,σβ,l(S2)) # the scaling factors of 𝖱𝖫𝖾𝗏S,σβ,l(S2) are all 1

= D2,1(E1+ S2 q β) + D2,2(E2+ S2 q β2) + + D2,l(El+ S2 q βl)

= i=1l(EiD2,i) + S2 (D2,1 q β + D2,2 q β2 + + D2,l q βl)

= i=1l𝜖i + D2 S2 # where 𝜖i = EiD2,i

D2 S2 # because i=1l𝜖i D2 E (where E is the noise embedded in 𝖱𝖫𝖶𝖤S,σ(S2)

Finally, we get the following relation:

𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) Cα + Cβ , where Cα = (D1,D0), Cβ = 𝖣𝖾𝖼𝗈𝗆𝗉β,l(D2), 𝖱𝖫𝖾𝗏S,σβ,l(S2)

In the next subsection, we introduce another (older) relinearization technique.

D-3.5.3 Relinearization Method 2 – Ciphertext Modulus Switch

At the setup stage of the RLWE scheme, we craft a special pair of polynomials modulo q as follows:

A $Rn,qk

E σRn,q

𝑒𝑣𝑘 = (A,  AS + E+ S2) Rn,q2

𝑒𝑣𝑘 is called an evaluation key, which is essentially a RLWE ciphertext of S2 encrypted by the secret key S without any scaling factor Δ. Remember that our goal is to find a synthetic RLWE ciphertext Cβ such that decrypting it gives us D2 S2, that is: 𝖱𝖫𝖶𝖤S,σ1(Cβ) = D2 S2. Let’s suppose that Cβ = D2 𝑒𝑣𝑘. Then, decrypting Cβ gives us the following:

𝖱𝖫𝖶𝖤S,σ1(Cβ = (D2 𝑒𝑣𝑘)) = 𝖱𝖫𝖶𝖤S,σ1( C = (D2A,  D2AS + D2E+ D2 S2) )

= D2AS D2AS + D2E+ D2 S2

= D2E+ D2 S2

But unfortunately, D2E+ D2 S2D2 S2, because D2E0 (as D2 is not necessarily a small number).This is because D2 = A1A2, D2E can be any arbitrary value between [0,q).

To solve the above problem, we modify the evaluation key as a set of polynomials in big modulo g as follows:

A $Rn,qk

E σRn,q

g $qL2 # where g is some large integer power of 2, qL is the largest modulo before any relinearization

𝑒𝑣𝑘𝑔 = (A,AS + E+ gS2) Rn,𝑔𝑞2

𝑒𝑣𝑘𝑔 is essentially an RLWE ciphertext of gS2 encrypted by S. We can derive the following:

𝑒𝑣𝑘𝑔 = (A,AS + E+ gS2) Rn,𝑔𝑞2

= (A mod 𝑔𝑞,  AS + E+ gS2 mod 𝑔𝑞)

= (A+ k2𝑔𝑞,  AS + E+ gS2 + k1𝑔𝑞) (for some integers k1,k2)

Note that D2 = A1A2 Rn,q

= D2 mod q

= D2 + k3q (for some integer k3)

Now, let’s multiply D2 to each component of 𝑒𝑣𝑘𝑔 as follows:

(A+ k2𝑔𝑞,  AS + E+ gS2 + k1𝑔𝑞) (D2 + k3q)

= ( D2A+ D2k2𝑔𝑞 + k3qA+ k3qk2𝑔𝑞,

D2AS + D2E+ gD2 S2 + D2k1𝑔𝑞 k3qAS + k3qE+ k3𝑞𝑔S2 + k3qk1𝑔𝑞)

Now, we switch the modulus of this RLWE ciphertext from 𝑔𝑞 q based on the technique in §C-4.5:

(D2A g +D2k2𝑔𝑞 g +k3qA g +k3qk2𝑔𝑞 g ,  D2AS g +D2E g +gD2 S2 g +D2k1𝑔𝑞 g k3qAS g +k3qE g +k3𝑞𝑔S2 g +k3qk1𝑔𝑞 g )

= (D2A g + D2k2q + k3qA g + k3qk2q,

  D2AS g + D2E g + D2 S2 + D2k1q k3qAS g + k3qE g + k3qS2 + k3qk1q)

= (D2A g + k3qA g  mod q,  D2AS g + D2E g + D2 S2 k3qAS g + k3qE g  mod q)

= Cβ Rn,q2

Now, we finally got Cβ which is in the form of RLWE ciphertext modulo q. Remember that our goal is to express D2 S2 as a decryption of RLWE ciphertext. If we treat Cβ as a synthetic RLWE ciphertext and decrypt it, we get the following:

𝖱𝖫𝖶𝖤S,σ1(Cβ) # where Cβ is treated as a synthetic RLWE ciphertext

= 𝖱𝖫𝖶𝖤S,σ1(( D2AS g + D2E g + D2 S2 k3qAS g + k3qE g , D2A g + k3qA g ))

= D2AS g + D2E g + D2 S2 k3qAS g + k3qE g + D2A g S + k3qA g S

D2E g + D2 S2 + k3qE g # D2AS g + D2A g S = k3qAS g + k3qA g S 0

D2 S2 # D2E g 0, k3qE g 0

As shown in the above, decrypting Cβ gives us D2 S2. Therefore, we reach the following conclusion:

Δ2 M1M2 𝖱𝖫𝖶𝖤S,σ1(Cα) + 𝖱𝖫𝖶𝖤S,σ1(Cβ) , where Cα = (D1,D0), Cβ = D2 𝑒𝑣𝑘𝑔 g

Therefore, we finally get the following congruence relation:

𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) Cα + Cβ , where Cα = (D1,D0), Cβ = D2 𝑒𝑣𝑘𝑔 g

Our last step of ciphertext-to-ciphertext multiplication is to convert 𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) into 𝖱𝖫𝖶𝖤S,σ(Δ M1M2), because if the result of ciphertext-to-ciphertext multiplication is M1M2 = M3, then for consistency purposes, the resulting RLWE ciphertext is supposed to be:

𝖱𝖫𝖶𝖤S,σ(Δ M1M2) = 𝖱𝖫𝖶𝖤S,σ(Δ M3)

We will explain this process in the next subsection.

D-3.5.4 Rescaling

To convert 𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) into 𝖱𝖫𝖶𝖤S,σ(Δ M1M2), we cannot simply divide the ciphertext 𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) by Δ, because as explained in §A-1.2.2, modulo arithmetic does not support direct division. Multiplying the RLWE ciphertext by Δ1 (i.e., an inverse of Δ) does not work either, because the only useful property we can use for inverse multiplication is: a a1 1. If an inverse is multiplied to any other values other than its counterpart, the result is an arbitrary value. For example, if Δ1 is multiplied to a noise (i.e., Δ1E), then the result can be a very huge value. Thus, multiplying the RLWE ciphertext by Δ1 does not help due to the unpredictable result of the noise term.

The safest way to convert 𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) into 𝖱𝖫𝖶𝖤S,σ(Δ M1M2) is modulus switch (§C-4.5), which is essentially modulo rescaling (§A-12). For this to work, the RLWE setup stage should design the ciphertext domain q as q0 ΔL, where L is denoted as the level of multiplication, and q0 Δ (which is important for the accuracy of homomorphic modulo reduction during bootstrapping in §D-3.13). Upon each ciphertext-to-ciphertext multiplication, we switch the modulus of the RLWE ciphertext from q0 Δi q0 Δi1, which effectively converts the plaintext’s squared scaling factor Δ2 (in 𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2)) into Δ (in 𝖱𝖫𝖶𝖤S,σ(Δ M1M2)). Once the RLWE ciphertext’s level reaches 0 (i.e., ciphertext modulus q0), we cannot do any more ciphertext-to-ciphertext multiplication, in which case we need a special process called bootstrapping to re-initialize the modulus level to L.

However, one problem with this setup is that ΔL will be a huge number. Performing homomorphic addition or multiplication over modulo ΔL is computationally expensive. To reduce the overhead of ciphertext size, we use the Chinese remainder theorem (§A-13): given an integer x mod W where W is a multiplication of L + 1 co-primes such that W = w0w1w2w3wL, the following congruence relationships hold:

x d0 mod w0

x d1 mod w1

x d2 mod w2

x dL mod wL

, where x = m=0Ldmymzm mod W,  ym = W wm,  zm = ym1 mod wm, and w0 = q0

In other words, x mod W can be isomorphically mapped to a vector of smaller numbers (d0,d1,,dl) each in modulo w0,w1,,wl, addition/multiplication with big elements in modulo W can be done by using their encoded smaller-magnitude CRT vectors element-wise, and later decode the intended big-number result. By leveraging this property, we design the CKKS scheme’s maximal ciphertext modulus as W = m=0Lwm, where L is the maximum multiplicative level, w0 = q0 Δ, and all other wi Δ. Then, whenever reaching from the l-th to the next lower l 1-th multiplicative level, we switch its modulus from q = m=0lwm to q^ = m=0l1wm as follows:

( C = (A,B) ) Rn,q 𝖱𝖫𝖶𝖤S,σ( C^ = (A^,B^) ) Rn,q^

q = m=0lwm, # where all wm are prime numbers, w0 = q0 Δ p to ensure the scaled plaintext ΔM during homomorphic operations never overflows the ciphertext modulus even at the lowest multiplicative level, and all other wi Δ

q^ = q wl

Ai^ = q^ q Ai = a^i,0 + a^i,1X + a^i,2X2 + + a^i,n1Xn1, where each a^i,j = ai,jq^ q = ai,j wl q^

B^ = q^ q B = b^0 + b^1X + b^2X2 + + b^n1Xn1, where each b^j = bjq^ q = bj wl q^

𝖱𝖫𝖶𝖤S,σ(ΔM) = (A^,B^) Rn,q^

The above update of ({Ai}i=0k1,B) to ({A^i}i=0k1,B^) effectively changes Δ,E to Δ^,E^ as follows:

E^ = e^0 + e^1X + e^2X2 + + e^n1Xn1, where each e^j = ejq^ q = ej wl q^

Δ^ = Δ2q^ q = Δ2 wl Δ # If we treat Δ^ as Δ, the rounding error slightly increases the noise E^ to E^ + EΔ, while the decryption of (A^,B^) outputs the same M

Note that after the rescaling, the plaintext scaling factor of (A^,B^) is also updated to Δ^. Meanwhile, M and S stay the same as before.

After we switch the modulus of the ciphertext C from q q^ by multiplying q^ q to A and B, the encrypted original plaintext term Δ2M1M2 will become Δ2M1M2q^ q = Δ2M1M2 wl = (Δ + 𝜖Δ) M1M2, where 𝜖Δ 0, because as explained before, we chose {wi}i=1L such that wi Δ. Therefore, (Δ + 𝜖Δ) M1M2 = ΔM1M2+ 𝜖ΔM1M2, where 𝜖ΔM1M2 0, which becomes part of the noise term of the modulus-switched (i.e., rescaled) new ciphertext C^.

The benefit of this design of the CRT (Chinese remainder problem)-based ciphertext modulus and rescaling is that we can isomorphically decompose the huge coefficients (bigger than 64 bits) of polynomials in ciphertexts into l-dimensional Chinese remainder vectors (Theorem A-13.2 in §A-13) and perform element-wise addition or multiplication for computing coefficients over the small vector elements. This promotes computational efficiency for homomorphic addition and multiplication over a large ciphertext modulus (although the number of addition/multiplication operations increases). This technique is called Residue Number System (RNS). When CRT is used in ciphertexts, the security regarding the ciphertext modulus depends on the smallest and the largest CRT elements.

Initial Scaling Factor Δ Upon Encryption: To support multi-level multiplicative levels (using CRT), we need to modify the generic scaling factor setup presented in Summary B-4.2 (§B-4.2) from Δ = q t to Δ = wL.

Noise Growth: Upon each step of rescaling during ciphertext-ciphertext multiplication, the noise also gets scaled down by 1 Δ (or by 1 wl at multiplicative level l in the case of using CRT). Therefore, if the accumulated noise is smaller than Δ (wl in the case of using CRT), running a single ciphertext-ciphertext multiplication operation effectively reduces the noise against growing. However, during each ciphertext-to-ciphertext multiplication, the encrypted (noisy) plaintext is (ΔM1 + E1) (ΔM2 + E2) = Δ2M1M2 + Δ (M1E2 + M2E1) + E1E2, and rescaling roughly has the effect of dividing this by Δ, which approximately gives us ΔM1M2 + M1E2 + M2E1 + E1E2 Δ . Because of the (M1E2 + M2E1) term, the noise actually grows compared to before ciphertext-to-ciphertext multiplication. Therefore, ciphertext-to-ciphertext multiplication inevitably increases the noise.

D-3.5.5 Comparing BFV and CKKS Bootstrapping

CKKS bootstrapping shares several common aspects with BFV bootstrapping. CKKS’s ModRaise and Homomorphic Decryption steps are equivalent to BFV’s Homomorphic Decryption (without modulo-q reduction) step. BFV homomorphically multiplies polynomial A and B whose coefficients are in pe with the encrypted secret key whose ciphertext modulus is q, which generates the modulo wrap-around coefficient values peK. Similarly, CKKS coefficients are in q0 with the encrypted secret key whose ciphertext modulus is qL, which generates the modulo wrap-around coefficient values q0K. However, they use different strategies to handle their modulo wrap-around values. CKKS uses evaluation of the sine function having a period of q0 to approximately eliminate q0K (i.e., EvalExp). On the other hand, BFV uses digit extraction to scale down peK by pe1 and then treats the remaining small 𝑝𝐾 as part of the modulo wrap-around value of the plaintext. The requirement of the digit extraction algorithm is that the plaintext inputs should be represented as base-p values, and because of this, BFV bootstrapping includes the initial step of modulus switch from q pe, where pe is used as the plaintext modulus after homomorphic decryption.

Both BFV and CKKS use the same strategy for their CoeffToSlot, SlotToCoeff, and Scaling Factor Re-interpretation steps.

Multiplicative Level: A critical difference between BFV and CKKS is that in BFV, the ciphertext modulus q stays the same after ciphertext-ciphertext multiplication, and there is no restriction on the number of ciphertext-ciphertext multiplications. On the other hand, in CKKS, the ciphertext modulus changes from ql ql1 after each multiplication, and when it reaches q0, no more multiplication can be done, unless we reset the ciphertext modulus to qL by using the modulus bootstrapping technique (§D-3.13).

Limitation of Noise Handling: Although CKKS’s rescaling during ciphertext-to-ciphertext multiplication reduces the magnitude of noise E by Δ, it also reduces the ciphertext modulus by the same amount, and thus the relative noise-to-ciphertext-modulus ratio does not get decreased by rescaling. In order to reduce (or reset) the noise-to-modulus ratio, we need to do bootstrapping (§D-3.13), which will be explained at the end of this section.

D-3.5.6 Summary

To put all things together, CKKS’s ciphertext-to-ciphertext multiplication is summarized as follows:

Summary D-3.5.6 CKKS’s Ciphertext-to-Ciphertext Multiplication

Suppose we have the following two RLWE ciphertexts:

𝖱𝖫𝖶𝖤S,σ(ΔM1) = (A1,B1), where B1 = A1S + ΔM1+ E1

𝖱𝖫𝖶𝖤S,σ(ΔM2) = (A2,B2), where B2 = A2S + ΔM2+ E2

Multiplication between these two ciphertexts is performed as follows:

1.
Basic Multiplication

Compute the following:

D0 = B1B2

D1 = B2A1+ B1A2

D2 = A1A2

, where Δ2M1M2 B1B2 D0 + (B2A1+ B1A2) D1 S + (A1A2) D2 S S S2

= D0 + D1 S + D2 S2

2.
Relinearization

𝖱𝖫𝖶𝖤S,σ(Δ2 M1M2) 𝖱𝖫𝖶𝖤S,σ( (D0 + D1 S + D2 S2) ) Cα + Cβ

, where  Cα = (D1,D0),

Cβ = 𝖣𝖾𝖼𝗈𝗆𝗉β,l(D2), 𝖱𝖫𝖾𝗏S,σβ,l(S2) or D2 𝑒𝑣𝑘𝑔 g ,

𝑒𝑣𝑘𝑔 = (AS + E+ gS2,A) Rn,𝑔𝑞2,  g = qL2, L :  the maximum level

3.
Rescaling

Switch the relinearlized ciphertext’s modulus from q q^ by updating (A,B) to (A^,B^) as follows:

( C = (A,B) ) Rn,q ( C^ = (A^,B^) ) Rn,q^

q = m=0lwm, # where all wm are prime numbers, w0 = q0 Δ p to ensure the plaintext ΔM during homomorphic operations never overflows the ciphertext modulus even at the lowest multiplicative level, and all other wi Δ

q^ = q wl

A^ = q^ q A = a^0 + a^1X + a^2X2 + + a^n1Xn1, where each a^i = aiq^ q = ai wl q^

B^ = q^ q B = b^0 + b^1X + b^2X2 + + b^n1Xn1, where each b^i = biq^ q = bi wl q^

The above update of (A,B) to (A^,B^) effectively changes Δ,E to Δ^,E^ as follows:

E^ = e^0 + e^1X + e^2X2 + + e^n1Xn1, where each e^i = eiq^ q = ei wl q^

Δ^ = Δ2q^ q = Δ2 wl Δ # This rounding error slightly increases the noise E^ to E^ + EΔ, while the decryption of (A^,B^) outputs the same plaintext M

Note that after the rescaling, the ciphertext modulus changes from q q^, and the plaintext scaling factor of (A^,B^) is also updated to Δ^. Meanwhile, the plaintext M and the secret key S stay the same as before.

Swapping the Order of Relinearization and Rescaling: The order of relinearization and rescaling is interchangeable. Running rescaling before relinearization reduces the size of the ciphertext modulus, and therefore the subsequent relinearization can be executed faster.