diff --git a/CMakeLists.txt b/CMakeLists.txt index aac11c2..0d30d8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,9 +97,7 @@ if(NOT USE_TERNARY) endif() endif() - -# if(USE_AVX512) - # string(APPEND CMAKE_CXX_FLAGS " -mprefer-vector-width=512") +# if(USE_AVX512) string(APPEND CMAKE_CXX_FLAGS " -mprefer-vector-width=512") # endif() if(USE_FFTW3) diff --git a/include/circuitbootstrapping.hpp b/include/circuitbootstrapping.hpp index a764529..8406a78 100644 --- a/include/circuitbootstrapping.hpp +++ b/include/circuitbootstrapping.hpp @@ -26,7 +26,8 @@ void CircuitBootstrapping(TRGSW &trgsw, const TLWE &tlwe, const EvalKey &ek) { - alignas(64) std::array, privksP::targetP::l> temp; + alignas(64) std::array, privksP::targetP::l> + temp; GateBootstrappingManyLUT( temp, tlwe, ek.getbkfft(), CBtestvector()); for (int i = 0; i < privksP::targetP::l; i++) { @@ -81,7 +82,8 @@ void CircuitBootstrappingSub(TRGSW &trgsw, { alignas(64) TLWE tlwelvl0; IdentityKeySwitch(tlwelvl0, tlwe, ek.getiksk()); - alignas(64) std::array, privksP::targetP::l> temp; + alignas(64) std::array, privksP::targetP::l> + temp; GateBootstrappingManyLUT( temp, tlwelvl0, ek.getbkfft(), CBtestvector()); for (int i = 0; i < privksP::targetP::l; i++) { diff --git a/include/cloudkey.hpp b/include/cloudkey.hpp index c0e613b..ac4a15d 100644 --- a/include/cloudkey.hpp +++ b/include/cloudkey.hpp @@ -416,19 +416,23 @@ struct EvalKey { void emplacebkfft(const SecretKey& sk) { if constexpr (std::is_same_v) { - bkfftlvl01 = std::unique_ptr>(new (std::align_val_t(64)) BootstrappingKeyFFT()); + bkfftlvl01 = std::unique_ptr>( + new (std::align_val_t(64)) BootstrappingKeyFFT()); bkfftgen(*bkfftlvl01, sk); } else if constexpr (std::is_same_v) { - bkfftlvlh1 = std::unique_ptr>(new (std::align_val_t(64)) BootstrappingKeyFFT()); + bkfftlvlh1 = std::unique_ptr>( + new (std::align_val_t(64)) BootstrappingKeyFFT()); bkfftgen(*bkfftlvlh1, sk); } else if constexpr (std::is_same_v) { - bkfftlvl02 = std::unique_ptr>(new (std::align_val_t(64)) BootstrappingKeyFFT()); + bkfftlvl02 = std::unique_ptr>( + new (std::align_val_t(64)) BootstrappingKeyFFT()); bkfftgen(*bkfftlvl02, sk); } else if constexpr (std::is_same_v) { - bkfftlvlh2 = std::unique_ptr>(new (std::align_val_t(64)) BootstrappingKeyFFT()); + bkfftlvlh2 = std::unique_ptr>( + new (std::align_val_t(64)) BootstrappingKeyFFT()); bkfftgen(*bkfftlvlh2, sk); } else @@ -528,15 +532,18 @@ struct EvalKey { void emplaceiksk(const SecretKey& sk) { if constexpr (std::is_same_v) { - iksklvl10 = std::unique_ptr>(new (std::align_val_t(64)) KeySwitchingKey()); + iksklvl10 = std::unique_ptr>( + new (std::align_val_t(64)) KeySwitchingKey()); ikskgen(*iksklvl10, sk); } else if constexpr (std::is_same_v) { - iksklvl1h = std::unique_ptr>(new (std::align_val_t(64)) KeySwitchingKey()); + iksklvl1h = std::unique_ptr>( + new (std::align_val_t(64)) KeySwitchingKey()); ikskgen(*iksklvl1h, sk); } else if constexpr (std::is_same_v) { - iksklvl20 = std::unique_ptr>(new (std::align_val_t(64)) KeySwitchingKey()); + iksklvl20 = std::unique_ptr>( + new (std::align_val_t(64)) KeySwitchingKey()); ikskgen(*iksklvl20, sk); } // else if constexpr (std::is_same_v) { @@ -545,15 +552,18 @@ struct EvalKey { // ikskgen(*iksklvlh2, sk); // } else if constexpr (std::is_same_v) { - iksklvl21 = std::unique_ptr>(new (std::align_val_t(64)) KeySwitchingKey()); + iksklvl21 = std::unique_ptr>( + new (std::align_val_t(64)) KeySwitchingKey()); ikskgen(*iksklvl21, sk); } else if constexpr (std::is_same_v) { - iksklvl22 = std::unique_ptr>(new (std::align_val_t(64)) KeySwitchingKey()); + iksklvl22 = std::unique_ptr>( + new (std::align_val_t(64)) KeySwitchingKey()); ikskgen(*iksklvl22, sk); } else if constexpr (std::is_same_v) { - iksklvl31 = std::unique_ptr>(new (std::align_val_t(64)) KeySwitchingKey()); + iksklvl31 = std::unique_ptr>( + new (std::align_val_t(64)) KeySwitchingKey()); ikskgen(*iksklvl31, sk); } else @@ -576,15 +586,21 @@ struct EvalKey { const SecretKey& sk) { if constexpr (std::is_same_v) { - privksklvl11[key] = std::unique_ptr>(new (std::align_val_t(64)) PrivateKeySwitchingKey()); + privksklvl11[key] = + std::unique_ptr>(new ( + std::align_val_t(64)) PrivateKeySwitchingKey()); privkskgen(*privksklvl11[key], func, sk); } else if constexpr (std::is_same_v) { - privksklvl21[key] = std::unique_ptr>(new (std::align_val_t(64)) PrivateKeySwitchingKey()); + privksklvl21[key] = + std::unique_ptr>(new ( + std::align_val_t(64)) PrivateKeySwitchingKey()); privkskgen(*privksklvl21[key], func, sk); } else if constexpr (std::is_same_v) { - privksklvl22[key] = std::unique_ptr>(new (std::align_val_t(64)) PrivateKeySwitchingKey()); + privksklvl22[key] = + std::unique_ptr>(new ( + std::align_val_t(64)) PrivateKeySwitchingKey()); privkskgen(*privksklvl22[key], func, sk); } else diff --git a/include/mulfft.hpp b/include/mulfft.hpp index f570e54..db49ca9 100644 --- a/include/mulfft.hpp +++ b/include/mulfft.hpp @@ -95,10 +95,10 @@ inline void TwistFFT(Polynomial

&res, const PolynomialInFD

&a) template inline void TwistFFTrescale(Polynomial

&res, const PolynomialInFD

&a) { - if constexpr (std::is_same_v){ - if constexpr(std::is_same_v) + if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) fftplvl1.execute_direct_torus32_rescale(res.data(), a.data(), P::Δ); - else if constexpr(std::is_same_v) + else if constexpr (std::is_same_v) fftplvl1.execute_direct_torus64_rescale(res.data(), a.data(), P::Δ); } else if constexpr (std::is_same_v) @@ -147,33 +147,35 @@ inline void TwistIFFT(PolynomialInFD

&res, const Polynomial

&a) template inline void MulInFD(std::array &res, const std::array &b) { - #ifdef USE_INTERLEAVED_FORMAT - for(int i = 0; i < N / 2; i++){ - const std::complex tmp = std::complex(res[2*i], res[2*i+1]) * std::complex(b[2*i], b[2*i+1]); - res[2*i] = tmp.real(); - res[2*i+1] = tmp.imag(); +#ifdef USE_INTERLEAVED_FORMAT + for (int i = 0; i < N / 2; i++) { + const std::complex tmp = std::complex(res[2 * i], res[2 * i + 1]) * + std::complex(b[2 * i], b[2 * i + 1]); + res[2 * i] = tmp.real(); + res[2 * i + 1] = tmp.imag(); } - #else +#else for (int i = 0; i < N / 2; i++) { double aimbim = res[i + N / 2] * b[i + N / 2]; double arebim = res[i] * b[i + N / 2]; res[i] = std::fma(res[i], b[i], -aimbim); res[i + N / 2] = std::fma(res[i + N / 2], b[i], arebim); } - #endif +#endif } template inline void MulInFD(std::array &res, const std::array &a, const std::array &b) { - #ifdef USE_INTERLEAVED_FORMAT - for(int i = 0; i < N / 2; i++){ - const std::complex tmp = std::complex(a[2*i], a[2*i+1]) * std::complex(b[2*i], b[2*i+1]); - res[2*i] = tmp.real(); - res[2*i+1] = tmp.imag(); +#ifdef USE_INTERLEAVED_FORMAT + for (int i = 0; i < N / 2; i++) { + const std::complex tmp = std::complex(a[2 * i], a[2 * i + 1]) * + std::complex(b[2 * i], b[2 * i + 1]); + res[2 * i] = tmp.real(); + res[2 * i + 1] = tmp.imag(); } - #else +#else // for (int i = 0; i < N / 2; i++) { // double aimbim = a[i + N / 2] * b[i + N / 2]; // double arebim = a[i] * b[i + N / 2]; @@ -205,7 +207,7 @@ inline void MulInFD(std::array &res, const std::array &a, res[i + N / 2] += a[i] * b[i + N / 2]; res[i] -= a[i + N / 2] * b[i + N / 2]; } - #endif +#endif } // Be careful about memory accesss (We assume b has relatively high memory @@ -214,13 +216,14 @@ template inline void FMAInFD(std::array &res, const std::array &a, const std::array &b) { - #ifdef USE_INTERLEAVED_FORMAT - for(int i = 0; i < N / 2; i++){ - std::complex tmp = std::complex(a[2*i], a[2*i+1]) * std::complex(b[2*i], b[2*i+1]); - res[2*i] += tmp.real(); - res[2*i+1] += tmp.imag(); +#ifdef USE_INTERLEAVED_FORMAT + for (int i = 0; i < N / 2; i++) { + std::complex tmp = std::complex(a[2 * i], a[2 * i + 1]) * + std::complex(b[2 * i], b[2 * i + 1]); + res[2 * i] += tmp.real(); + res[2 * i + 1] += tmp.imag(); } - #else +#else for (int i = 0; i < N / 2; i++) { res[i] = std::fma(a[i], b[i], res[i]); res[i + N / 2] = std::fma(a[i + N / 2], b[i], res[i + N / 2]); @@ -229,13 +232,13 @@ inline void FMAInFD(std::array &res, const std::array &a, res[i + N / 2] = std::fma(a[i], b[i + N / 2], res[i + N / 2]); res[i] -= a[i + N / 2] * b[i + N / 2]; } - // for (int i = 0; i < N / 2; i++) { - // res[i] = std::fma(a[i + N / 2], b[i + N / 2], -res[i]); - // res[i] = std::fma(a[i], b[i], -res[i]); - // res[i + N / 2] = std::fma(a[i], b[i + N / 2], res[i + N / 2]); - // res[i + N / 2] = std::fma(a[i + N / 2], b[i], res[i + N / 2]); - // } - #endif +// for (int i = 0; i < N / 2; i++) { +// res[i] = std::fma(a[i + N / 2], b[i + N / 2], -res[i]); +// res[i] = std::fma(a[i], b[i], -res[i]); +// res[i + N / 2] = std::fma(a[i], b[i + N / 2], res[i + N / 2]); +// res[i + N / 2] = std::fma(a[i + N / 2], b[i], res[i + N / 2]); +// } +#endif } template @@ -302,11 +305,11 @@ inline void PolyMulRescaleUnsigned(Polynomial

&res, const UnsignedPolynomial

&b) { // if constexpr (std::is_same_v) { - PolynomialInFD

ffta, fftb; - TwistIFFT

(ffta, a); - TwistIFFT

(fftb, b); - MulInFD(ffta, ffta, fftb); - TwistFFTrescale

(res, ffta); + PolynomialInFD

ffta, fftb; + TwistIFFT

(ffta, a); + TwistIFFT

(fftb, b); + MulInFD(ffta, ffta, fftb); + TwistFFTrescale

(res, ffta); // } // else // static_assert(false_v, "Undefined PolyMul!"); @@ -333,7 +336,7 @@ inline void PolyMulNaive(Polynomial

&res, const Polynomial

&a, template std::unique_ptr, 2 * P::n>> XaittGen() { - std::unique_ptr, 2 *P::n>> xaitt = + std::unique_ptr, 2 * P::n>> xaitt = std::make_unique, 2 * P::n>>(); for (int i = 0; i < 2 * P::n; i++) { std::array xai = {}; @@ -350,7 +353,7 @@ std::unique_ptr, 2 * P::n>> XaittGen() template std::unique_ptr, 2 * P::n>> XaittGenNTT() { - std::unique_ptr, 2 *P::n>> xaitt = + std::unique_ptr, 2 * P::n>> xaitt = std::make_unique, 2 * P::n>>(); for (int i = 0; i < 2 * P::n; i++) { std::array xai = {}; @@ -366,10 +369,10 @@ std::unique_ptr, 2 * P::n>> XaittGenNTT() #if defined(USE_TERNARY) || defined(USE_KEY_BUNDLE) alignas(64) static const std::unique_ptr< - const std::array, 2 *lvl1param::n>> xaittlvl1 = + const std::array, 2 * lvl1param::n>> xaittlvl1 = XaittGen(); alignas(64) static const std::unique_ptr< - const std::array, 2 *lvl2param::n>> xaittlvl2 = + const std::array, 2 * lvl2param::n>> xaittlvl2 = XaittGen(); #endif #ifdef USE_TERNARY diff --git a/include/params.hpp b/include/params.hpp index 006b86e..81c954a 100644 --- a/include/params.hpp +++ b/include/params.hpp @@ -8,7 +8,8 @@ namespace TFHEpp { -template struct alignas( 64 ) aligned_array : public std::array { }; +template +struct alignas(64) aligned_array : public std::array {}; enum class ErrorDistribution { ModularGaussian, CenteredBinomial }; diff --git a/include/params/tfhe-rs.hpp b/include/params/tfhe-rs.hpp index 000af1f..111d3ff 100644 --- a/include/params/tfhe-rs.hpp +++ b/include/params/tfhe-rs.hpp @@ -18,8 +18,9 @@ struct lvl0param { ErrorDistribution::ModularGaussian; static constexpr double α = 3.2192861177056265e-06; // fresh noise, 2^{-17.6} - using T = uint32_t; // Torus representation - static constexpr std::make_signed_t μ = 1U << (std::numeric_limits::digits - 3); + using T = uint32_t; // Torus representation + static constexpr std::make_signed_t μ = + 1U << (std::numeric_limits::digits - 3); static constexpr uint32_t plain_modulus = 2; static constexpr double Δ = static_cast(1ULL << std::numeric_limits::digits) / @@ -37,7 +38,8 @@ struct lvlhalfparam { ErrorDistribution::ModularGaussian; static const inline double α = std::pow(2.0, -17); // fresh noise using T = uint32_t; // Torus representation - static constexpr std::make_signed_t μ = 1U << (std::numeric_limits::digits - 3); + static constexpr std::make_signed_t μ = + 1U << (std::numeric_limits::digits - 3); static constexpr uint32_t plain_modulus = 8; static constexpr double Δ = static_cast(1ULL << std::numeric_limits::digits) / @@ -59,7 +61,7 @@ struct lvl1param { ErrorDistribution::ModularGaussian; static const inline double α = 3.966608917163306e-12; // fresh noise, 2^{-24.8...} - using T = uint64_t; // Torus representation + using T = uint64_t; // Torus representation static constexpr std::make_signed_t μ = 1ULL << 61; static constexpr uint32_t plain_modulus = 2; static constexpr double Δ = diff --git a/include/trgsw.hpp b/include/trgsw.hpp index b7c0a05..7a85856 100644 --- a/include/trgsw.hpp +++ b/include/trgsw.hpp @@ -21,8 +21,8 @@ constexpr typename P::T offsetgen() } template -inline void Decomposition(DecomposedPolynomial

&decpoly, const Polynomial

&poly, - typename P::T randbits = 0) +inline void Decomposition(DecomposedPolynomial

&decpoly, + const Polynomial

&poly, typename P::T randbits = 0) { #ifdef USE_OPTIMAL_DECOMPOSITION // https://eprint.iacr.org/2021/1161 diff --git a/include/utils.hpp b/include/utils.hpp index 2507650..836f9f7 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -7,10 +7,10 @@ #include #include #include +#include #include #include #include -#include namespace TFHEpp { #ifdef USE_RANDEN @@ -26,17 +26,10 @@ constexpr bool false_v = false; // https://qiita.com/negi-drums/items/a527c05050781a5af523 template -concept hasq = requires -{ - T::q; -}; +concept hasq = requires { T::q; }; template -concept hasqbit = requires -{ - T::qbit; -}; - +concept hasqbit = requires { T::qbit; }; // https://github.com/zhourrr/aligned-memory-allocator/blob/main/aligned_allocator.h // A minimal implementation of an allocator for C++ Standard Library, which @@ -45,50 +38,63 @@ concept hasqbit = requires // A minimal custom allocator is preferred because C++ allocator_traits class // provides default implementation for you. Take a look at Microsoft's // documentation about Allocators and allocator class. -template class AlignedAllocator { - public: +template +class AlignedAllocator { +public: using value_type = T; - public: - // According to Microsoft's documentation, default constructor is not required - // by C++ Standard Library. +public: + // According to Microsoft's documentation, default constructor is not + // required by C++ Standard Library. AlignedAllocator() noexcept {}; - template AlignedAllocator(const AlignedAllocator& other) noexcept {}; + template + AlignedAllocator(const AlignedAllocator &other) noexcept {}; template - inline bool operator==(const AlignedAllocator& other) const noexcept { + inline bool operator==( + const AlignedAllocator &other) const noexcept + { return true; } template - inline bool operator!=(const AlignedAllocator& other) const noexcept { + inline bool operator!=( + const AlignedAllocator &other) const noexcept + { return false; } - template struct rebind { + template + struct rebind { using other = AlignedAllocator; }; - // STL containers call this function to allocate uninitialized memory block to - // store (no more than n) elements of type T (value_type). - inline value_type* allocate(const std::size_t n) const { + // STL containers call this function to allocate uninitialized memory block + // to store (no more than n) elements of type T (value_type). + inline value_type *allocate(const std::size_t n) const + { auto size = n; /* - If you wish, for some strange reason, that the size of allocated buffer is - also aligned to alignment, uncomment the following statement. + If you wish, for some strange reason, that the size of allocated + buffer is also aligned to alignment, uncomment the following + statement. Note: this increases the size of underlying memory, but STL containers - still treat it as a memory block of size n, i.e., STL containers will not - put more than n elements into the returned memory. + still treat it as a memory block of size n, i.e., STL containers will + not put more than n elements into the returned memory. */ // size = (n + alignment - 1) / alignment * alignment; - return static_cast(std::aligned_alloc(alignment, sizeof(T) * size)); + return static_cast( + std::aligned_alloc(alignment, sizeof(T) * size)); }; // STL containers call this function to free a memory block beginning at a // specified position. - inline void deallocate(value_type* const ptr, std::size_t n) const noexcept { std::free(ptr); } + inline void deallocate(value_type *const ptr, std::size_t n) const noexcept + { + std::free(ptr); + } }; // Double to Torus(32bit fixed-point number) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 925951b..b947b97 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,7 +46,8 @@ elseif(USE_CONCRETE_FFT) else() if(USE_MKL) target_link_libraries(tfhe++ INTERFACE mklproc) - target_include_directories(tfhe++ PUBLIC ${MKLROOT}/include ${PROJECT_SOURCE_DIR}/thirdparties/mkl) + target_include_directories( + tfhe++ PUBLIC ${MKLROOT}/include ${PROJECT_SOURCE_DIR}/thirdparties/mkl) else() target_link_libraries(tfhe++ INTERFACE spqlios) endif() diff --git a/test/cereal.cpp b/test/cereal.cpp index 99fdb0c..8668fc7 100644 --- a/test/cereal.cpp +++ b/test/cereal.cpp @@ -24,8 +24,7 @@ int main() assert(sk.key.lvl1[i] == ski.key.lvl1[i]); for (int i = 0; i < TFHEpp::lvl2param::n; i++) assert(sk.key.lvl2[i] == ski.key.lvl2[i]); - std::cout << "n" - << ":" << ski.params.lvl0.n << std::endl; + std::cout << "n" << ":" << ski.params.lvl0.n << std::endl; assert(sk.params == ski.params); } diff --git a/test/circuitbootstrapping.cpp b/test/circuitbootstrapping.cpp index 03f3edb..2f8429c 100644 --- a/test/circuitbootstrapping.cpp +++ b/test/circuitbootstrapping.cpp @@ -36,8 +36,10 @@ int main() for (int j = 0; j < privksP::targetP::n; j++) pmu[i][j] = pa[i][j] ? privksP::targetP::μ : -privksP::targetP::μ; for (int i = 0; i < num_test; i++) pones[i] = true; - alignas(64) std::vector> ca(num_test); - alignas(64) std::vector> cones(num_test); + alignas(64) std::vector> ca( + num_test); + alignas(64) std::vector> cones( + num_test); std::vector> bootedTGSW( num_test); diff --git a/test/circuitbootstrappingsub.cpp b/test/circuitbootstrappingsub.cpp index b6f6747..dd8437b 100644 --- a/test/circuitbootstrappingsub.cpp +++ b/test/circuitbootstrappingsub.cpp @@ -39,8 +39,10 @@ int main() for (int i = 0; i < num_test; i++) pones[i] = true; std::vector> ca(num_test); std::vector> cones(num_test); - std::vector,TFHEpp::AlignedAllocator,64>> bootedTGSW( - num_test); + std::vector, + TFHEpp::AlignedAllocator< + TFHEpp::TRGSWFFT, 64>> + bootedTGSW(num_test); for (int i = 0; i < num_test; i++) ca[i] = TFHEpp::trlweSymEncrypt( diff --git a/test/cmux.cpp b/test/cmux.cpp index eddcc84..845e004 100644 --- a/test/cmux.cpp +++ b/test/cmux.cpp @@ -35,7 +35,9 @@ int main() for (int i = 0; i < num_test; i++) for (int j = 0; j < lvl1param::n; j++) pmu0[i][j] = (p0[i][j] > 0) ? lvl1param::μ : -lvl1param::μ; - vector,TFHEpp::AlignedAllocator,64>> cs(num_test); + vector, + TFHEpp::AlignedAllocator, 64>> + cs(num_test); vector> c1(num_test); vector> c0(num_test); vector> cres(num_test); diff --git a/test/cmuxpmbxmo.cpp b/test/cmuxpmbxmo.cpp index 204d2e7..4052b5e 100644 --- a/test/cmuxpmbxmo.cpp +++ b/test/cmuxpmbxmo.cpp @@ -33,7 +33,10 @@ int main() for (int i = 0; i < num_test; i++) for (int j = 0; j < lvl1param::n; j++) pmu1[i][j] = (p1[i][j] > 0) ? lvl1param::μ : -lvl1param::μ; - std::vector,TFHEpp::AlignedAllocator,64>> cs(num_test); + std::vector, + TFHEpp::AlignedAllocator< + TFHEpp::BootstrappingKeyElementFFT, 64>> + cs(num_test); std::vector> c1(num_test); std::vector> cres(num_test); diff --git a/test/combinedmem.cpp b/test/combinedmem.cpp index d62557d..cd27c34 100644 --- a/test/combinedmem.cpp +++ b/test/combinedmem.cpp @@ -158,10 +158,10 @@ int main() writep[i] = ramp[addressint * words + i] > 0 ? 0 : 1; std::array, address_bit - 1>, 2> - *bootedTGSW = - new (std::align_val_t(64)) array, address_bit - 1>, - 2>; // MSB of address is evaluated by HomMUX, not - // CMUX. + *bootedTGSW = new (std::align_val_t(64)) + array, address_bit - 1>, + 2>; // MSB of address is evaluated by HomMUX, not + // CMUX. vector> encaddress(address_bit); std::vector> encrom(numromtrlwe); std::vector, numramtrlwe>> encram(words); diff --git a/test/gatebootstrapping.cpp b/test/gatebootstrapping.cpp index a3a3337..6d07dcc 100644 --- a/test/gatebootstrapping.cpp +++ b/test/gatebootstrapping.cpp @@ -22,7 +22,8 @@ int main() TFHEpp::EvalKey ek; ek.emplacebkfft(sk); ek.emplaceiksk(sk); - std::vector> tlwe(num_test), bootedtlwe(num_test); + std::vector> tlwe(num_test), + bootedtlwe(num_test); std::array p; for (int i = 0; i < num_test; i++) p[i] = binary(engine) > 0; for (int i = 0; i < num_test; i++) diff --git a/test/invcircuitbootstrapping.cpp b/test/invcircuitbootstrapping.cpp index 3550301..f618af3 100644 --- a/test/invcircuitbootstrapping.cpp +++ b/test/invcircuitbootstrapping.cpp @@ -33,10 +33,16 @@ int main() for (int j = 0; j < lvl1param::n; j++) pmu[i][j] = pa[i][j] ? lvl1param::μ : -lvl1param::μ; for (int i = 0; i < num_test; i++) pzeros[i] = false; - vector,TFHEpp::AlignedAllocator,64>> ca(num_test); + vector, + TFHEpp::AlignedAllocator, 64>> + ca(num_test); vector> czeros(num_test); - vector,TFHEpp::AlignedAllocator,64>> bootedTGSW(num_test); - vector,TFHEpp::AlignedAllocator,64>> invbootedTGSW(num_test); + vector, + TFHEpp::AlignedAllocator, 64>> + bootedTGSW(num_test); + vector, + TFHEpp::AlignedAllocator, 64>> + invbootedTGSW(num_test); for (int i = 0; i < num_test; i++) ca[i] = trlweSymEncrypt(pmu[i], sk->key.lvl1); diff --git a/test/nested_cmux.cpp b/test/nested_cmux.cpp index 4699ec2..2829bd0 100644 --- a/test/nested_cmux.cpp +++ b/test/nested_cmux.cpp @@ -49,7 +49,9 @@ int main() SecretKey skey; - std::vector,64>> guard; + std::vector, 64>> + guard; TFHEpp::Polynomial plainpoly = {}; plainpoly[0] = 1; for (size_t i = 0; i < N; i++) @@ -57,7 +59,7 @@ int main() TFHEpp::trgswfftSymEncrypt(plainpoly, skey.key.lvl1)); alignas(64) TRLWELvl1 c1 = trivial_TRLWELvl1(uint2weight(1)), - c0 = trivial_TRLWELvl1(uint2weight(0)); + c0 = trivial_TRLWELvl1(uint2weight(0)); alignas(64) TRLWELvl1 res = c1; dump_histgram_of_phase_of_TRLWELvl1( std::cout, TFHEpp::trlwePhase(res, skey.key.lvl1)); diff --git a/test/nested_cmux_from_cb.cpp b/test/nested_cmux_from_cb.cpp index 681eaa5..dcaddbe 100644 --- a/test/nested_cmux_from_cb.cpp +++ b/test/nested_cmux_from_cb.cpp @@ -53,7 +53,9 @@ int main() ekey.emplacebkfft(skey); ekey.emplaceprivksk4cb(skey); - std::vector,64>> guard; + std::vector, 64>> + guard; for (size_t i = 0; i < N; i++) { TFHEpp::TRGSWFFT trgsw; TFHEpp::TLWE tlwe = diff --git a/test/polymul.cpp b/test/polymul.cpp index ff521d2..a567fee 100644 --- a/test/polymul.cpp +++ b/test/polymul.cpp @@ -15,10 +15,9 @@ int main() uniform_int_distribution Bgdist(0, lvl1param::Bg); uniform_int_distribution Torus32dist(0, UINT32_MAX); - #ifdef USE_INTERLEAVED_FORMAT +#ifdef USE_INTERLEAVED_FORMAT std::cout << "USE_INTERLEAVED_FORMAT" << std::endl; - #endif - +#endif cout << "Start LVL1 test." << endl; for (int test = 0; test < num_test; test++) { diff --git a/test/ram.cpp b/test/ram.cpp index e6829e3..e70abd2 100644 --- a/test/ram.cpp +++ b/test/ram.cpp @@ -51,12 +51,13 @@ int main() wrflag = binary(engine); writep = pmemory[addressint] > 0 ? 0 : 1; - array, address_bit>, - 2> *bootedTGSW = - new (std::align_val_t(64)) array, address_bit>, 2>; + array, address_bit>, 2> + *bootedTGSW = new (std::align_val_t(64)) + array, address_bit>, 2>; vector> encaddress(address_bit); array, memsize> *encmemory = - new (std::align_val_t(64)) array, memsize>; + new (std::align_val_t(64)) + array, memsize>; TLWE encreadres; TRLWE encumemory; TLWE cs; diff --git a/thirdparties/fftw/fft_processor_fftw.cpp b/thirdparties/fftw/fft_processor_fftw.cpp index 77bc864..50caee2 100644 --- a/thirdparties/fftw/fft_processor_fftw.cpp +++ b/thirdparties/fftw/fft_processor_fftw.cpp @@ -17,8 +17,10 @@ FFT_Processor_FFTW::FFT_Processor_FFTW(const int32_t N) { inbuf = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * Ns2); outbuf = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * Ns2); - plan_forward = fftw_plan_dft_1d(Ns2, inbuf, outbuf, FFTW_FORWARD, FFTW_MEASURE); - plan_backward = fftw_plan_dft_1d(Ns2, inbuf, outbuf, FFTW_BACKWARD, FFTW_MEASURE); + plan_forward = + fftw_plan_dft_1d(Ns2, inbuf, outbuf, FFTW_FORWARD, FFTW_MEASURE); + plan_backward = + fftw_plan_dft_1d(Ns2, inbuf, outbuf, FFTW_BACKWARD, FFTW_MEASURE); for (int i = 0; i < Ns2; i++) { double value = (double)i * M_PI / (double)N; @@ -68,8 +70,8 @@ void FFT_Processor_FFTW::execute_direct_torus32(uint32_t *res, const double *a) } fftw_execute_dft(plan_backward, inbuf, outbuf); for (int i = 0; i < Ns2; i++) { - auto res_tmp = - std::complex(outbuf[i][0], outbuf[i][1]) * std::conj(twist[i]); + auto res_tmp = std::complex(outbuf[i][0], outbuf[i][1]) * + std::conj(twist[i]); res[i] = CAST_DOUBLE_TO_UINT32(res_tmp.real()); res[i + Ns2] = CAST_DOUBLE_TO_UINT32(res_tmp.imag()); } @@ -85,8 +87,8 @@ void FFT_Processor_FFTW::execute_direct_torus32_rescale(uint32_t *res, } fftw_execute_dft(plan_backward, inbuf, outbuf); for (int i = 0; i < Ns2; i++) { - auto res_tmp = - std::complex(outbuf[i][0], outbuf[i][1]) * std::conj(twist[i]); + auto res_tmp = std::complex(outbuf[i][0], outbuf[i][1]) * + std::conj(twist[i]); res[i] = CAST_DOUBLE_TO_UINT32(res_tmp.real() / (Δ / 4)); res[i + Ns2] = CAST_DOUBLE_TO_UINT32(res_tmp.imag() / (Δ / 4)); } @@ -101,8 +103,8 @@ void FFT_Processor_FFTW::execute_direct_torus64(uint64_t *res, const double *a) fftw_execute_dft(plan_backward, inbuf, outbuf); double tmp[N]; for (int i = 0; i < Ns2; i++) { - auto res_tmp = - std::complex(outbuf[i][0], outbuf[i][1]) * std::conj(twist[i]); + auto res_tmp = std::complex(outbuf[i][0], outbuf[i][1]) * + std::conj(twist[i]); tmp[i] = res_tmp.real(); tmp[i + Ns2] = res_tmp.imag(); } @@ -121,7 +123,10 @@ void FFT_Processor_FFTW::execute_direct_torus64(uint64_t *res, const double *a) } } -void FFT_Processor_FFTW::execute_direct_torus64_rescale(uint64_t* res, const double* a, const double Δ) { +void FFT_Processor_FFTW::execute_direct_torus64_rescale(uint64_t *res, + const double *a, + const double Δ) +{ for (int i = 0; i < Ns2; i++) { inbuf[i][0] = a[i] / Ns2; inbuf[i][1] = a[Ns2 + i] / Ns2; @@ -129,12 +134,12 @@ void FFT_Processor_FFTW::execute_direct_torus64_rescale(uint64_t* res, const dou fftw_execute_dft(plan_backward, inbuf, outbuf); double tmp[N]; for (int i = 0; i < Ns2; i++) { - auto res_tmp = - std::complex(outbuf[i][0], outbuf[i][1]) * std::conj(twist[i]); + auto res_tmp = std::complex(outbuf[i][0], outbuf[i][1]) * + std::conj(twist[i]); tmp[i] = res_tmp.real(); tmp[i + Ns2] = res_tmp.imag(); } - for (int i=0; i> twist; fftw_plan plan_forward; fftw_plan plan_backward; - fftw_complex * inbuf; - fftw_complex * outbuf; + fftw_complex *inbuf; + fftw_complex *outbuf; public: FFT_Processor_FFTW(const int32_t N); @@ -38,7 +38,8 @@ class FFT_Processor_FFTW { void execute_direct_torus64(uint64_t *res, const double *a); - void execute_direct_torus64_rescale(uint64_t *res, const double *a, const double Δ); + void execute_direct_torus64_rescale(uint64_t *res, const double *a, + const double Δ); ~FFT_Processor_FFTW(); };