@@ -455,6 +455,52 @@ void TLWE2TablePacking(TRLWE<P> &res, std::array<TLWE<P>, num_tlwe> &tlwe,
455455 }
456456}
457457
458+ template <class P , uint num_tlwe, uint num_func>
459+ void TLWE2TablePackingManyLUT (TRLWE<P> &res, std::array<std::array<TLWE<P>, num_tlwe>,num_func> &tlwe,
460+ const AnnihilateKey<P> &ahk)
461+ {
462+ static_assert (std::has_single_bit (num_tlwe),
463+ " Currently, num_tlwe must be power of 2" );
464+ constexpr uint l = std::countr_zero (num_tlwe);
465+ static_assert (num_func == 2 ,
466+ " Currently, num_func must be 2" );
467+ constexpr uint f = std::countr_zero (num_func);
468+ std::array<TRLWE<P>, num_func> temptrlwe;
469+ for (int index = 0 ; index < num_func; index++){
470+ PackLWEs<P>(temptrlwe[index], tlwe[index], ahk, l, 0 , 1 );
471+ for (int i = l; i < P::nbit-f; i++) {
472+ TRLWE<P> tempmul;
473+ for (int j = 0 ; j < P::k + 1 ; j++)
474+ PolynomialMulByXai<P>(tempmul[j], temptrlwe[index][j], P::n >> (i + 1 ));
475+ TRLWE<P> tempsub;
476+ for (int j = 0 ; j < (P::k + 1 ) * P::n; j++) {
477+ temptrlwe[index][0 ][j] /= 2 ;
478+ tempmul[0 ][j] /= 2 ;
479+ tempsub[0 ][j] = temptrlwe[index][0 ][j] - tempmul[0 ][j];
480+ temptrlwe[index][0 ][j] += tempmul[0 ][j];
481+ }
482+ // reuse tempmul
483+ EvalAuto<P>(tempmul, tempsub, (1 << (i + 1 )) + 1 , ahk[i]);
484+ for (int j = 0 ; j < (P::k + 1 ) * P::n; j++) temptrlwe[index][0 ][j] += tempmul[0 ][j];
485+ }
486+ }
487+ {
488+ TRLWE<P> tempoddmul;
489+ for (int i = 0 ; i < P::k + 1 ; i++) {
490+ PolynomialMulByXai<P>(tempoddmul[i], temptrlwe[1 ][i],1 );
491+ for (int j = 0 ; j < P::n; j++) {
492+ temptrlwe[0 ][i][j] /= 2 ;
493+ tempoddmul[i][j] /= 2 ;
494+ temptrlwe[1 ][i][j] = temptrlwe[0 ][i][j] - tempoddmul[i][j];
495+ }
496+ }
497+ EvalAuto<P>(res, temptrlwe[1 ], (1 << P::nbit) + 1 , ahk[P::nbit - 1 ]);
498+ for (int i = 0 ; i < P::k + 1 ; i++)
499+ for (int j = 0 ; j < P::n; j++)
500+ res[i][j] += temptrlwe[0 ][i][j] + tempoddmul[i][j];
501+ }
502+ }
503+
458504template <class P >
459505void PackLWEsLSB (TRLWE<P> &res, const std::vector<TLWE<P>> &tlwe,
460506 const AnnihilateKey<P> &ahk, const uint l, const uint offset,
0 commit comments