Skip to content

Commit e828e7a

Browse files
committed
Added different decomposition level for nonce/non-nonce
1 parent 5a2b574 commit e828e7a

File tree

14 files changed

+322
-154
lines changed

14 files changed

+322
-154
lines changed

include/circuitbootstrapping.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,14 @@ void CircuitBootstrappingFFTwithInv(
230230
TRGSWFFT<typename privksP::targetP> &invtrgswfft,
231231
const TLWE<typename iksP::domainP> &tlwe, const EvalKey &ek)
232232
{
233-
constexpr array<typename privksP::targetP::T, privksP::targetP::l> h =
234-
hgen<typename privksP::targetP>();
235-
236233
alignas(64) TRGSW<typename privksP::targetP> trgsw;
237234
CircuitBootstrapping<iksP, bkP, privksP>(trgsw, tlwe, ek);
238235
for (int i = 0; i < (privksP::targetP::k + 1) * privksP::targetP::l; i++)
239236
for (int j = 0; j < privksP::targetP::k + 1; j++) {
240237
TwistIFFT<typename privksP::targetP>(trgswfft[i][j], trgsw[i][j]);
241238
for (int k = 0; k < privksP::targetP::n; k++) trgsw[i][j][k] *= -1;
242239
}
243-
for (int i = 0; i < privksP::targetP::l; i++) {
244-
trgsw[i][0][0] += h[i];
245-
trgsw[i + privksP::targetP::l][1][0] += h[i];
246-
}
240+
trgswhoneadd<typename privksP::targetP>(trgsw);
247241
for (int i = 0; i < (privksP::targetP::k + 1) * privksP::targetP::l; i++)
248242
for (int j = 0; j < privksP::targetP::k + 1; j++)
249243
TwistIFFT<typename privksP::targetP>(invtrgswfft[i][j],

include/detwfa.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@ void CMUXFFT(TRLWE<P> &res, const TRGSWFFT<P> &cs, const TRLWE<P> &c1,
1717
template <class P>
1818
TRGSWFFT<P> TRGSWFFTOneGen()
1919
{
20-
constexpr std::array<typename P::T, P::l> h = hgen<P>();
21-
2220
TRGSW<P> trgsw = {};
23-
for (int i = 0; i < P::l; i++) {
24-
for (int k = 0; k < P::k + 1; k++) {
25-
trgsw[i + k * P::l][k][0] += h[i];
26-
}
27-
}
21+
trgswhoneadd<P>(trgsw);
2822
return ApplyFFT2trgsw<P>(trgsw);
2923
}
3024

include/evalkeygens.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,13 @@ void subikskgen(SubsetKeySwitchingKey<P>& ksk, const SecretKey& sk)
273273
template <class P>
274274
relinKey<P> relinKeygen(const Key<P>& key)
275275
{
276-
constexpr std::array<typename P::T, P::l> h = hgen<P>();
277-
278276
Polynomial<P> keysquare;
279277
std::array<typename P::T, P::n> partkey;
280278
for (int i = 0; i < P::n; i++) partkey[i] = key[0 * P::n + i];
281279
PolyMulNaive<P>(keysquare, partkey, partkey);
282280
relinKey<P> relinkey;
283281
for (TRLWE<P>& ctxt : relinkey) ctxt = trlweSymEncryptZero<P>(key);
284-
for (int i = 0; i < P::l; i++)
285-
for (int j = 0; j < P::n; j++)
286-
relinkey[i][1][j] +=
287-
static_cast<typename P::T>(keysquare[j]) * h[i];
282+
halftrgswhadd<P>(relinkey, keysquare);
288283
return relinkey;
289284
}
290285

include/externs/trgsw.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
namespace TFHEpp{
55
#define INST(P) \
66
extern template void Decomposition<P>( \
7-
DecomposedPolynomial<P> & decpoly, const Polynomial<P> &poly, \
8-
typename P::T randbits)
7+
DecomposedPolynomial<P> & decpoly, const Polynomial<P> &poly)
8+
TFHEPP_EXPLICIT_INSTANTIATION_TRLWE(INST)
9+
#undef INST
10+
11+
#define INST(P) \
12+
extern template void NonceDecomposition<P>( \
13+
DecomposedNoncePolynomial<P> & decpoly, const Polynomial<P> &poly)
914
TFHEPP_EXPLICIT_INSTANTIATION_TRLWE(INST)
1015
#undef INST
1116

include/params.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,15 @@ using PolynomialRAINTT = std::array<raintt::DoubleSWord, P::n>;
8888
template <class P>
8989
using DecomposedPolynomial = std::array<Polynomial<P>, P::l>;
9090
template <class P>
91+
using DecomposedNoncePolynomial = std::array<Polynomial<P>, P::lₐ>;
92+
template <class P>
9193
using DecomposedPolynomialNTT = std::array<PolynomialNTT<P>, P::l>;
9294
template <class P>
95+
using DecomposedNoncePolynomialNTT = std::array<PolynomialNTT<P>, P::lₐ>;
96+
template <class P>
9397
using DecomposedPolynomialRAINTT = std::array<PolynomialRAINTT<P>, P::l>;
98+
template <class P>
99+
using DecomposedNoncePolynomialRAINTT = std::array<PolynomialRAINTT<P>, P::lₐ>;
94100

95101
template <class P>
96102
using TRLWE = std::array<Polynomial<P>, P::k + 1>;
@@ -104,17 +110,17 @@ template <class P>
104110
using TRLWERAINTT = std::array<PolynomialRAINTT<P>, P::k + 1>;
105111

106112
template <class P>
107-
using TRGSW = std::array<TRLWE<P>, (P::k + 1) * P::l>;
113+
using TRGSW = std::array<TRLWE<P>, P::k* P::lₐ+P::l>;
108114
template <class P>
109115
using HalfTRGSW = std::array<TRLWE<P>, P::l>;
110116
template <class P>
111-
using TRGSWFFT = aligned_array<TRLWEInFD<P>, (P::k + 1) * P::l>;
117+
using TRGSWFFT = aligned_array<TRLWEInFD<P>, P::k* P::lₐ+P::l>;
112118
template <class P>
113119
using HalfTRGSWFFT = aligned_array<TRLWEInFD<P>, P::l>;
114120
template <class P>
115-
using TRGSWNTT = std::array<TRLWENTT<P>, (P::k + 1) * P::l>;
121+
using TRGSWNTT = std::array<TRLWENTT<P>, P::k* P::lₐ+P::l>;
116122
template <class P>
117-
using TRGSWRAINTT = std::array<TRLWERAINTT<P>, (P::k + 1) * P::l>;
123+
using TRGSWRAINTT = std::array<TRLWERAINTT<P>, P::k* P::lₐ+P::l>;
118124

119125
#ifdef USE_KEY_BUNDLE
120126
template <class P>

include/params/128bit.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ struct lvl1param {
4747
// multiplication.
4848
static constexpr std::uint32_t n = 1 << nbit; // dimension
4949
static constexpr std::uint32_t k = 1;
50-
static constexpr std::uint32_t l = 3;
50+
static constexpr std::uint32_t lₐ = 3;
51+
static constexpr std::uint32_t l = 2;
5152
static constexpr std::uint32_t Bgbit = 6;
5253
static constexpr std::uint32_t Bg = 1 << Bgbit;
5354
static constexpr ErrorDistribution errordist =
@@ -68,6 +69,7 @@ struct lvl2param {
6869
// ease of polynomial multiplication.
6970
static constexpr std::uint32_t n = 1 << nbit; // dimension
7071
static constexpr std::uint32_t k = 1;
72+
static constexpr std::uint32_t lₐ = 4;
7173
static constexpr std::uint32_t l = 4;
7274
static constexpr std::uint32_t Bgbit = 9;
7375
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -88,6 +90,7 @@ struct lvl3param {
8890
// ease of polynomial multiplication.
8991
static constexpr std::uint32_t n = 1 << nbit; // dimension
9092
static constexpr std::uint32_t k = 1;
93+
static constexpr std::uint32_t lₐ = 4;
9194
static constexpr std::uint32_t l = 4;
9295
static constexpr std::uint32_t Bgbit = 9;
9396
static constexpr std::uint32_t Bg = 1 << Bgbit;

include/params/CGGI16.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct lvl1param {
4444
static constexpr std::uint32_t nbit = 10;
4545
static constexpr std::uint32_t n = 1 << nbit;
4646
static constexpr std::uint32_t k = 1;
47+
static constexpr std::uint32_t lₐ = 2;
4748
static constexpr std::uint32_t l = 2;
4849
static constexpr std::uint32_t Bgbit = 10;
4950
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -64,6 +65,7 @@ struct lvl2param {
6465
static const std::uint32_t nbit = 11;
6566
static constexpr std::uint32_t n = 1 << nbit;
6667
static constexpr std::uint32_t k = 1;
68+
static constexpr std::uint32_t lₐ = 4;
6769
static constexpr std::uint32_t l = 4;
6870
static constexpr std::uint32_t Bgbit = 9;
6971
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -84,6 +86,7 @@ struct lvl3param {
8486
// ease of polynomial multiplication.
8587
static constexpr std::uint32_t n = 1 << nbit; // dimension
8688
static constexpr std::uint32_t k = 1;
89+
static constexpr std::uint32_t lₐ = 4;
8790
static constexpr std::uint32_t l = 4;
8891
static constexpr std::uint32_t Bgbit = 9;
8992
static constexpr std::uint32_t Bg = 1 << Bgbit;

include/params/CGGI19.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct lvl1param {
4646
static constexpr std::uint32_t nbit = 10;
4747
static constexpr std::uint32_t n = 1 << nbit;
4848
static constexpr std::uint32_t k = 1;
49+
static constexpr std::uint32_t lₐ = 3;
4950
static constexpr std::uint32_t l = 3;
5051
static constexpr std::uint32_t Bgbit = 7;
5152
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -66,6 +67,7 @@ struct lvl2param {
6667
static const std::uint32_t nbit = 11;
6768
static constexpr std::uint32_t n = 1 << nbit;
6869
static constexpr std::uint32_t k = 1;
70+
static constexpr std::uint32_t lₐ = 4;
6971
static constexpr std::uint32_t l = 4;
7072
static constexpr std::uint32_t Bgbit = 9;
7173
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -86,6 +88,7 @@ struct lvl3param {
8688
// ease of polynomial multiplication.
8789
static constexpr std::uint32_t n = 1 << nbit; // dimension
8890
static constexpr std::uint32_t k = 1;
91+
static constexpr std::uint32_t lₐ = 4;
8992
static constexpr std::uint32_t l = 4;
9093
static constexpr std::uint32_t Bgbit = 9;
9194
static constexpr std::uint32_t Bg = 1 << Bgbit;

include/params/compress.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct lvl1param {
5151
// multiplication.
5252
static constexpr std::uint32_t n = 1 << nbit; // dimension
5353
static constexpr std::uint32_t k = 2;
54+
static constexpr std::uint32_t lₐ = 2;
5455
static constexpr std::uint32_t l = 2;
5556
static constexpr std::uint32_t Bgbit = 8;
5657
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -75,6 +76,7 @@ struct lvl2param {
7576
// ease of polynomial multiplication.
7677
static constexpr std::uint32_t n = 1 << nbit; // dimension
7778
static constexpr std::uint32_t k = 3;
79+
static constexpr std::uint32_t lₐ = 3;
7880
static constexpr std::uint32_t l = 3;
7981
static constexpr std::uint32_t Bgbit = 9;
8082
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -97,6 +99,7 @@ struct lvl3param {
9799
// ease of polynomial multiplication.
98100
static constexpr std::uint32_t n = 1 << nbit; // dimension
99101
static constexpr std::uint32_t k = 1;
102+
static constexpr std::uint32_t lₐ = 4;
100103
static constexpr std::uint32_t l = 4;
101104
static constexpr std::uint32_t Bgbit = 9;
102105
static constexpr std::uint32_t Bg = 1 << Bgbit;

include/params/concrete.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct lvl1param {
5353
// multiplication.
5454
static constexpr std::uint32_t n = 1 << nbit; // dimension
5555
static constexpr std::uint32_t k = 2;
56+
static constexpr std::uint32_t lₐ = 2;
5657
static constexpr std::uint32_t l = 2;
5758
static constexpr std::uint32_t Bgbit = 8;
5859
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -75,6 +76,7 @@ struct lvl2param {
7576
// ease of polynomial multiplication.
7677
static constexpr std::uint32_t n = 1 << nbit; // dimension
7778
static constexpr std::uint32_t k = 3;
79+
static constexpr std::uint32_t lₐ = 3;
7880
static constexpr std::uint32_t l = 3;
7981
static constexpr std::uint32_t Bgbit = 9;
8082
static constexpr std::uint32_t Bg = 1 << Bgbit;
@@ -94,6 +96,7 @@ struct lvl3param {
9496
// ease of polynomial multiplication.
9597
static constexpr std::uint32_t n = 1 << nbit; // dimension
9698
static constexpr std::uint32_t k = 1;
99+
static constexpr std::uint32_t lₐ = 4;
97100
static constexpr std::uint32_t l = 4;
98101
static constexpr std::uint32_t Bgbit = 9;
99102
static constexpr std::uint32_t Bg = 1 << Bgbit;

0 commit comments

Comments
 (0)