## 5 The Proposed Solution
### Computation  
1. \(CSP_{1}\) re-encrypts the matrix ciphertext: - For each element \(ct_{i}\) in the matrix ciphertext \(\mathbf{ct}\), \(0<i\leq m\times d\), \(CSP_{1}\) runs \(PRE.ReEnc(rk_{f\to f^{\prime}},c_{i})\to ct_{i}^{\prime}\) to re-encrypt \(ct_{i}\) into \(ct_{i}^{\prime}\), where \(ct_{i}=(A,B)=(g^{a\tau_{i}},g^{\tau_{i}}(1+f_{i}N))\), \(rk_{f\to f^{\prime}}=\frac{a^{\prime}}{a}\). Then, \(ct_{i}^{\prime}=(A^{rk_{f\to f^{\prime}}},B)=(g^{a^{\prime}\tau_{i}}g^{ \tau_{i}}(1+f_{i}N)\ )mod\ N^{2}\).  
2. \(CSP_{1}\) sends the re-encryption ciphertext with a mask to \(CSP_{2}\): - For each element \(ct^{\prime}_{i}\) in \(ct^{\prime}=(ct^{\prime}_{1},\dots,ct^{\prime}_{m\cdot d})^{\top}\), \(0<i\leq m\cdot d\), \(CSP_{1}\) samples \(r^{\prime}_{i}\stackrel{{\$}}{{\leftarrow}}\mathbb{Z}_{N^{2}}\) as the mask. - For each mask \(r^{\prime}_{i}\), run \(HE.Enc(r^{\prime}_{i},pk^{\prime}_{f})\to rct^{\prime}_{i}\) with the temporary key \(pk^{\prime}_{f}\) to generate \(rct^{\prime}_{i}=(g^{a^{\prime}r_{i}},\ g^{\prime}_{i}(1+r^{\prime}_{i}N))\ mod {N^{2}}\), where \(\hat{r}_{i}\stackrel{{\$}}{{\leftarrow}}\mathbb{Z}_{N^{2}}\). - For \(i\in[m\cdot d]\), run \(HE.Eval(ct^{\prime}_{i},rct^{\prime}_{i})\to ct^{\prime}_{i}\oplus rct^{ \prime}_{i}\) to generate the masked ciphertext \(mct^{\prime}_{i}=rct^{\prime}_{i}\oplus ct^{\prime}_{i}\to Enc(f_{i}+r_{i})\). - \(CSP_{1}\) sends the masked ciphertext \(mct^{\prime}=\{mct^{\prime}_{i}\}_{i=1}^{m\times d}\) and the user's input ciphertext \(\mathbf{c}=\{c_{i}\}_{i=1}^{d}\) to \(CSP_{2}\). 3. \(CSP_{1}\) computes the final result's first part \(\mathbf{res^{1}}\): - Parse \(\mathbf{r^{\prime}}\) as a \(m\times d\)-size matrix and write \(r^{\prime}_{i,j}\) to index the \((i,j)\)-th element. - For \(i\in[m]\), run \(HE.Eval((r^{\prime}_{i,1},\dots,r^{\prime}_{i,d}),(c_{1},\dots,c_{d}))\to res ^{1}_{i}\) to generate \(res^{1}_{i}=\sum_{j=1}^{d}r^{\prime}_{i,j}c_{j}\). The first part of the final result is \(\mathbf{res^{1}}=[res^{1}_{1},...,res^{1}_{m}]^{\top}\). 4. \(CSP_{2}\) performs the decryption for the masked ciphertext: - After receiving the masked ciphertext \(\{mct^{\prime}_{i}\}_{i=1}^{m\times d}\), for \(i\in[m\cdot d]\), \(CSP_{2}\) runs \(HE.Dec(mct^{\prime}_{i},sk^{\prime}_{f})\to f^{\prime}_{i}\) to generate the masked matrix parameters \(\{f^{\prime}_{i}=f_{i}+r^{\prime}_{i}\}_{i=1}^{m\times d}\). - Parse \(\mathbf{f^{\prime}}=(f^{\prime}_{1},...,f^{\prime}_{m\cdot d})\) as an \(m\times d\)-size matrix and write \(f^{\prime}_{i,j}\) to index the \((i,j)\)-th element. It holds that \(f^{\prime}_{i,j}\)=\(f_{i,j}+r^{\prime}_{i,j}\). 5. \(CSP_{2}\) computes the second part of the final result \(\mathbf{res^{2}}\): - For \(i\in[m]\), run \(HE.Eval((f^{\prime}_{i,1},\dots,f^{\prime}_{i,d}),(c_{1},\dots,c_{d}))\to res ^{2}_{i}\) to generate \(res^{2}_{i}=\sum_{j=1}^{d}f_{i,j}c_{j}\). Then, send the second part of the final result \(\mathbf{res^{2}}=[res^{2}_{1},...,res^{2}_{m}]^{\top}\) to \(CSP_{1}\). 6. \(CSP_{1}\) computes the final result \(\mathbf{res}\) and returns it to the user: - For \(i\in[m],CSP_{1}\) computes \(res_{i}=res^{2}_{i}-res^{1}_{i}=\sum_{j=1}^{d}f^{\prime}_{i,j}c_{j}-\sum_{j=1}^{ d}r^{\prime}_{i,j}c_{j}=\sum_{j=1}^{d}f_{i,j}c_{j}\). Then, the final result \(\mathbf{res}\)=\([res_{1},\dots,res_{m}]^{\top}\) is returned to the user.