From c6296ae5457ae6e61a9466a1497c6b0130460343 Mon Sep 17 00:00:00 2001 From: "hilder.vitor" Date: Tue, 5 Apr 2022 22:55:00 +0200 Subject: [PATCH] function enc_ngs: Now FFT(msg) is computed before the loop instead of inside it --- include/keygen.h | 4 ++-- src/keygen.cpp | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/keygen.h b/include/keygen.h index 1427357..473031c 100644 --- a/include/keygen.h +++ b/include/keygen.h @@ -128,7 +128,7 @@ class KeyGen * @param[in] m polynomial to encrypt * @param[in] l dimension of the vector ciphertext * @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); @@ -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] l dimension of the vector ciphertext * @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); diff --git a/src/keygen.cpp b/src/keygen.cpp index 31b6d36..924df44 100644 --- a/src/keygen.cpp +++ b/src/keygen.cpp @@ -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); } -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++) 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); FFTPoly g_fft(Param::N2p1); 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); vector tmp_ct_long(Param::N); vector tmp_ct_int(Param::N); - int powerB = 1; - for (int i = 0; i < l; i++) { // 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) tmp_ct = g_fft * sk_boot_inv_fft; // compute g * sk_boot^(-1) + B^i * m - fftN.to_fft(msg_fft, msg); // msg = m * B^i - tmp_ct += msg_fft; + tmp_ct += msg_powB; // inverse FFT of the above result fftN.from_fft(tmp_ct_long, tmp_ct); // 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; - mult_poly_by_int(msg, B); + mult_fft_poly_by_int(msg_powB, B); // msg_powB = msg * B^i } }