Skip to content

Commit 2f77cc4

Browse files
committed
Added cb params in concrete.hpp for testing, not yet tuned enough
1 parent 8f9d82a commit 2f77cc4

File tree

4 files changed

+93
-47
lines changed

4 files changed

+93
-47
lines changed

include/cloudkey.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,28 @@ struct EvalKey {
2222
std::shared_ptr<BootstrappingKey<lvlh1param>>, // 1
2323
std::shared_ptr<BootstrappingKey<lvl02param>>, // 2
2424
std::shared_ptr<BootstrappingKey<lvlh2param>>, // 3
25+
#ifdef USE_DIFFERENT_BR_PARAM
26+
std::shared_ptr<BootstrappingKey<cblvl02param>>,
27+
std::shared_ptr<BootstrappingKey<cblvlh2param>>,
28+
#endif
2529
// BootstrappingKeyFFT
2630
std::shared_ptr<BootstrappingKeyFFT<lvl01param>>, // 4
2731
std::shared_ptr<BootstrappingKeyFFT<lvlh1param>>, // 5
2832
std::shared_ptr<BootstrappingKeyFFT<lvl02param>>, // 6
2933
std::shared_ptr<BootstrappingKeyFFT<lvlh2param>>, // 7
34+
#ifdef USE_DIFFERENT_BR_PARAM
35+
std::shared_ptr<BootstrappingKeyFFT<cblvl02param>>, // 6
36+
std::shared_ptr<BootstrappingKeyFFT<cblvlh2param>>, // 7
37+
#endif
3038
// BootstrappingKeyNTT
3139
std::shared_ptr<BootstrappingKeyNTT<lvl01param>>, // 8
3240
std::shared_ptr<BootstrappingKeyNTT<lvlh1param>>, // 9
3341
std::shared_ptr<BootstrappingKeyNTT<lvl02param>>, // 10
3442
std::shared_ptr<BootstrappingKeyNTT<lvlh2param>>, // 11
43+
#ifdef USE_DIFFERENT_BR_PARAM
44+
std::shared_ptr<BootstrappingKeyNTT<cblvl02param>>, // 10
45+
std::shared_ptr<BootstrappingKeyNTT<cblvlh2param>>, // 11
46+
#endif
3547
// KeySwitchingKey
3648
std::shared_ptr<KeySwitchingKey<lvl10param>>, // 12
3749
std::shared_ptr<KeySwitchingKey<lvl1hparam>>, // 13
@@ -51,9 +63,16 @@ struct EvalKey {
5163
// AnnihilateKey
5264
std::shared_ptr<AnnihilateKey<AHlvl1param>>, // 24
5365
std::shared_ptr<AnnihilateKey<AHlvl2param>>, // 25
66+
#ifdef USE_DIFFERENT_AH_PARAM
67+
std::shared_ptr<AnnihilateKey<cbAHlvl2param>>, // 25
68+
#endif
5469
// CBswitchingKey
5570
std::shared_ptr<CBswitchingKey<AHlvl1param>>, // 26
5671
std::shared_ptr<CBswitchingKey<AHlvl2param>> // 27
72+
#ifdef USE_DIFFERENT_AH_PARAM
73+
,
74+
std::shared_ptr<CBswitchingKey<cbAHlvl2param>> // 27
75+
#endif
5776
> keys;
5877

5978
EvalKey(SecretKey sk) { params = sk.params; }

include/params.hpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ enum class ErrorDistribution { ModularGaussian, CenteredBinomial };
3030
#include "params/128bit.hpp"
3131
#endif
3232

33+
#ifndef USE_DIFFERENT_BR_PARAM
34+
using cblvl2param = lvl2param;
35+
#endif
36+
#ifndef USE_DIFFERENT_AH_PARAM
37+
using cbAHlvl2param = AHlvl2param;
38+
#endif
39+
3340
struct lvl01param {
3441
using domainP = lvl0param;
3542
using targetP = lvl1param;
@@ -218,12 +225,29 @@ using relinKeyFFT = std::array<TRLWEInFD<P>, P::l>;
218225
#define TFHEPP_EXPLICIT_INSTANTIATION_TRLWE(fun) \
219226
fun(lvl1param); \
220227
fun(lvl2param);
228+
#ifdef USE_DIFFERENT_AH_PARAM
229+
#define TFHEPP_EXPLICIT_INSTANTIATION_ANNIHILATE(fun) \
230+
fun(AHlvl1param); \
231+
fun(AHlvl2param); \
232+
fun(cbAHlvl2param);
233+
#else
221234
#define TFHEPP_EXPLICIT_INSTANTIATION_ANNIHILATE(fun) \
222235
fun(AHlvl1param); \
223236
fun(AHlvl2param);
237+
#endif
238+
#ifdef USE_DIFFERENT_BR_PARAM
224239
#define TFHEPP_EXPLICIT_INSTANTIATION_BLIND_ROTATE(fun) \
225240
fun(lvl01param); \
226-
fun(lvl02param);
241+
fun(lvl02param); \
242+
fun(lvlh2param); \
243+
fun(cblvl02param); \
244+
fun(cblvlh2param);
245+
#else
246+
#define TFHEPP_EXPLICIT_INSTANTIATION_BLIND_ROTATE(fun) \
247+
fun(lvl01param); \
248+
fun(lvl02param); \
249+
fun(lvlh2param);
250+
#endif
227251
#define TFHEPP_EXPLICIT_INSTANTIATION_KEY_SWITCH_TO_TLWE(fun) \
228252
fun(lvl10param); \
229253
fun(lvl1hparam); \
@@ -254,7 +278,7 @@ using relinKeyFFT = std::array<TRLWEInFD<P>, P::l>;
254278
fun(lvl10param, lvl02param, lvl21param); \
255279
fun(lvl10param, lvl02param, lvl22param);
256280
#define TFHEPP_EXPLICIT_INSTANTIATION_ANNIHILATE_CIRCUIT_BOOTSTRAPPING(fun) \
257-
fun(lvl10param, lvl02param, AHlvl2param);
281+
fun(lvl10param, cblvl02param, cbAHlvl2param);
258282
#define TFHEPP_EXPLICIT_INSTANTIATION_CIRCUIT_BOOTSTRAPPING_SUBIKS(fun) \
259283
fun(lvl10param, lvl02param, lvl21param);
260284
} // namespace TFHEpp

include/params/128bit.hpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ struct lvl2param {
9292
// ease of polynomial multiplication.
9393
static constexpr std::uint32_t n = 1 << nbit; // dimension
9494
static constexpr std::uint32_t k = 1;
95-
static constexpr std::uint32_t lₐ = 4;
9695
static constexpr std::uint32_t l = 4;
96+
static constexpr std::uint32_t lₐ = l;
9797
static constexpr std::uint32_t Bgbit = 10;
98-
static constexpr std::uint32_t Bgₐbit = 10;
98+
static constexpr std::uint32_t Bgₐbit = Bgbit;
9999
static constexpr std::uint32_t Bg = 1 << Bgbit;
100100
static constexpr std::uint32_t Bgₐ = 1 << Bgₐbit;
101101
static constexpr ErrorDistribution errordist =
@@ -108,28 +108,6 @@ struct lvl2param {
108108
static_cast<double>(1ULL << (std::numeric_limits<T>::digits - 4));
109109
};
110110

111-
struct cblvl2param{
112-
using baseP = lvl2param;
113-
static constexpr int32_t key_value_max = baseP::key_value_max;
114-
static constexpr int32_t key_value_min = baseP::key_value_min;
115-
static constexpr std::uint32_t nbit = baseP::nbit;
116-
static constexpr std::uint32_t n = baseP::n; // dimension
117-
static constexpr std::uint32_t k = baseP::k;
118-
static_assert(n*k==baseP::n*baseP::k,"cblvl2param must have same key size as lvl2param");
119-
static constexpr std::uint32_t l = 4;
120-
static constexpr std::uint32_t lₐ = l;
121-
static constexpr std::uint32_t Bgbit = 10;
122-
static constexpr std::uint32_t Bgₐbit = Bgbit;
123-
static constexpr std::uint32_t Bg = 1 << Bgbit;
124-
static constexpr std::uint32_t Bgₐ = 1 << Bgₐbit;
125-
static constexpr ErrorDistribution errordist = baseP::errordist;
126-
static const inline double α = baseP::α; // fresh noise
127-
using T = typename baseP::T; // Torus representation
128-
static constexpr std::make_signed_t<T> μ = baseP::μ;
129-
static constexpr uint32_t plain_modulus = baseP::plain_modulus;
130-
static constexpr double Δ = baseP::Δ;
131-
};
132-
133111
struct AHlvl2param {
134112
using baseP = lvl2param;
135113
static constexpr int32_t key_value_max = baseP::key_value_max;
@@ -151,27 +129,6 @@ struct AHlvl2param {
151129
static constexpr double Δ = baseP::Δ;
152130
};
153131

154-
struct cbAHlvl2param {
155-
using baseP = cblvl2param;
156-
static constexpr int32_t key_value_max = baseP::key_value_max;
157-
static constexpr int32_t key_value_min = baseP::key_value_min;
158-
static constexpr std::uint32_t nbit = baseP::nbit;
159-
static constexpr std::uint32_t n = baseP::n; // dimension
160-
static constexpr std::uint32_t k = baseP::k;
161-
static constexpr std::uint32_t lₐ = 5;
162-
static constexpr std::uint32_t l = 5;
163-
static constexpr std::uint32_t Bgbit = 9;
164-
static constexpr std::uint32_t Bgₐbit = 9;
165-
static constexpr std::uint32_t Bg = 1 << Bgbit;
166-
static constexpr std::uint32_t Bgₐ = 1 << Bgₐbit;
167-
static constexpr ErrorDistribution errordist = baseP::errordist;
168-
static const inline double α = baseP::α; // fresh noise
169-
using T = typename baseP::T; // Torus representation
170-
static constexpr std::make_signed_t<T> μ = baseP::μ;
171-
static constexpr uint32_t plain_modulus = baseP::plain_modulus;
172-
static constexpr double Δ = baseP::Δ;
173-
};
174-
175132
struct lvl3param {
176133
static constexpr int32_t key_value_max = 1;
177134
static constexpr int32_t key_value_min = -1;

include/params/concrete.hpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,55 @@ struct lvl2param {
9696
static constexpr double Δ = μ;
9797
};
9898

99+
#define USE_DIFFERENT_BR_PARAM
100+
struct cblvl2param {
101+
static constexpr int32_t key_value_max = 1;
102+
static constexpr int32_t key_value_min = -1;
103+
static const std::uint32_t nbit = 10; // dimension must be a power of 2 for
104+
// ease of polynomial multiplication.
105+
static constexpr std::uint32_t n = 1 << nbit; // dimension
106+
static constexpr std::uint32_t k = 2;
107+
static constexpr std::uint32_t l = 4;
108+
static constexpr std::uint32_t lₐ = l;
109+
static constexpr std::uint32_t Bgbit = 10;
110+
static constexpr std::uint32_t Bgₐbit = Bgbit;
111+
static constexpr std::uint32_t Bg = 1 << Bgbit;
112+
static constexpr std::uint32_t Bgₐ = 1 << Bgₐbit;
113+
static constexpr ErrorDistribution errordist =
114+
ErrorDistribution::ModularGaussian;
115+
static const inline double α = std::pow(2.0, -51); // fresh noise
116+
using T = uint64_t; // Torus representation
117+
static constexpr std::make_signed_t<T> μ = 1LL << 61;
118+
static constexpr uint32_t plain_modulus = 8;
119+
static constexpr double Δ =
120+
static_cast<double>(1ULL << (std::numeric_limits<T>::digits - 4));
121+
};
122+
99123
// Dummy
100124
using AHlvl2param = lvl2param;
101125

126+
#define USE_DIFFERENT_AH_PARAM
127+
struct cbAHlvl2param {
128+
using baseP = cblvl2param;
129+
static constexpr int32_t key_value_max = baseP::key_value_max;
130+
static constexpr int32_t key_value_min = baseP::key_value_min;
131+
static constexpr std::uint32_t nbit = baseP::nbit;
132+
static constexpr std::uint32_t n = baseP::n; // dimension
133+
static constexpr std::uint32_t k = baseP::k;
134+
static constexpr std::uint32_t lₐ = 5;
135+
static constexpr std::uint32_t l = 5;
136+
static constexpr std::uint32_t Bgbit = 9;
137+
static constexpr std::uint32_t Bgₐbit = 9;
138+
static constexpr std::uint32_t Bg = 1 << Bgbit;
139+
static constexpr std::uint32_t Bgₐ = 1 << Bgₐbit;
140+
static constexpr ErrorDistribution errordist = baseP::errordist;
141+
static const inline double α = baseP::α; // fresh noise
142+
using T = typename baseP::T; // Torus representation
143+
static constexpr std::make_signed_t<T> μ = baseP::μ;
144+
static constexpr uint32_t plain_modulus = baseP::plain_modulus;
145+
static constexpr double Δ = baseP::Δ;
146+
};
147+
102148
struct lvl3param {
103149
static constexpr int32_t key_value_max = 1;
104150
static constexpr int32_t key_value_min = -1;

0 commit comments

Comments
 (0)