function enc_ngs: Now FFT(msg) is computed before the loop instead of inside it

This commit is contained in:
hilder.vitor
2022-04-05 22:55:00 +02:00
committed by iliailia
parent 834d9f2ab9
commit c6296ae545
2 changed files with 7 additions and 9 deletions

View File

@ -128,7 +128,7 @@ class KeyGen
* @param[in] m polynomial to encrypt * @param[in] m polynomial to encrypt
* @param[in] l dimension of the vector ciphertext * @param[in] l dimension of the vector ciphertext
* @param[in] B base used in the gadget vector * @param[in] B base used in the gadget vector
* @param[in] sk_boot contains f and f^-1 * @param[in] sk_boot contains bootstrapping secret key and its inverse
**/ **/
void enc_ngs(NGSFFTctxt& ct, const ModQPoly& m, int l, int B, const SKey_boot& sk_boot); void enc_ngs(NGSFFTctxt& ct, const ModQPoly& m, int l, int B, const SKey_boot& sk_boot);
@ -138,7 +138,7 @@ void enc_ngs(NGSFFTctxt& ct, const ModQPoly& m, int l, int B, const SKey_boot& s
* @param[in] m integer to encrypt (it is treated as a degree-0 polynomial) * @param[in] m integer to encrypt (it is treated as a degree-0 polynomial)
* @param[in] l dimension of the vector ciphertext * @param[in] l dimension of the vector ciphertext
* @param[in] B base used in the gadget vector * @param[in] B base used in the gadget vector
* @param[in] sk_boot contains f and f^-1 * @param[in] sk_boot contains bootstrapping secret key and its inverse
**/ **/
void enc_ngs(NGSFFTctxt& ct, int m, int l, int B, const SKey_boot& sk_boot); void enc_ngs(NGSFFTctxt& ct, int m, int l, int B, const SKey_boot& sk_boot);

View File

@ -288,7 +288,7 @@ void enc_ngs(NGSFFTctxt& ct, int m, int l, int B, const SKey_boot& sk_boot)
enc_ngs(ct, msg, l, B, sk_boot); enc_ngs(ct, msg, l, B, sk_boot);
} }
void mult_poly_by_int(ModQPoly& a, const int b){ void mult_fft_poly_by_int(FFTPoly& a, const int b){
for(int i = 0; i < a.size(); i++) for(int i = 0; i < a.size(); i++)
a[i] *= b; a[i] *= b;
} }
@ -302,13 +302,12 @@ void enc_ngs(NGSFFTctxt& ct, const ModQPoly& m, int l, int B, const SKey_boot& s
fftN.to_fft(sk_boot_inv_fft, sk_boot.sk_inv); fftN.to_fft(sk_boot_inv_fft, sk_boot.sk_inv);
FFTPoly g_fft(Param::N2p1); FFTPoly g_fft(Param::N2p1);
ModQPoly msg(m); // at each iteration i, msg will be equal to m * B^i ModQPoly msg(m); // at each iteration i, msg will be equal to m * B^i
FFTPoly msg_fft(Param::N2p1); FFTPoly msg_powB(Param::N2p1);
fftN.to_fft(msg_powB, msg); // FFT of m * B^i
FFTPoly tmp_ct(Param::N2p1); FFTPoly tmp_ct(Param::N2p1);
vector<long> tmp_ct_long(Param::N); vector<long> tmp_ct_long(Param::N);
vector<int> tmp_ct_int(Param::N); vector<int> tmp_ct_int(Param::N);
int powerB = 1;
for (int i = 0; i < l; i++) for (int i = 0; i < l; i++)
{ {
// sample random ternary vector // sample random ternary vector
@ -319,8 +318,7 @@ void enc_ngs(NGSFFTctxt& ct, const ModQPoly& m, int l, int B, const SKey_boot& s
// compute g * sk_boot^(-1) // compute g * sk_boot^(-1)
tmp_ct = g_fft * sk_boot_inv_fft; tmp_ct = g_fft * sk_boot_inv_fft;
// compute g * sk_boot^(-1) + B^i * m // compute g * sk_boot^(-1) + B^i * m
fftN.to_fft(msg_fft, msg); // msg = m * B^i tmp_ct += msg_powB;
tmp_ct += msg_fft;
// inverse FFT of the above result // inverse FFT of the above result
fftN.from_fft(tmp_ct_long, tmp_ct); fftN.from_fft(tmp_ct_long, tmp_ct);
// reduction modulo q_boot // reduction modulo q_boot
@ -330,7 +328,7 @@ void enc_ngs(NGSFFTctxt& ct, const ModQPoly& m, int l, int B, const SKey_boot& s
ct[i] = tmp_ct; ct[i] = tmp_ct;
mult_poly_by_int(msg, B); mult_fft_poly_by_int(msg_powB, B); // msg_powB = msg * B^i
} }
} }