#include #include #include #include #include int main() { constexpr uint32_t num_test = 1000; std::random_device seed_gen; std::default_random_engine engine(seed_gen()); std::uniform_int_distribution Bgdist(0, TFHEpp::lvl1param::Bg); std::uniform_int_distribution Torus32dist(0, UINT32_MAX); std::uniform_int_distribution ldist(1, TFHEpp::lvl1param::nbit + 1); std::cout << "Automorphism test" << std::endl; for (int test = 0; test < num_test; test++) { TFHEpp::Polynomial a, b; for (typename TFHEpp::lvl1param::T &i : a) i = Bgdist(engine) - TFHEpp::lvl1param::Bg / 2; for (typename TFHEpp::lvl1param::T &i : b) i = Torus32dist(engine); const uint d = (1U << ldist(engine)) + 1; TFHEpp::Polynomial beforeautomul, autoaftermul; TFHEpp::PolyMul(beforeautomul, a, b); TFHEpp::Automorphism(autoaftermul, beforeautomul, d); TFHEpp::Polynomial autoa, autob; TFHEpp::Automorphism(autoa, a, d); TFHEpp::Automorphism(autob, b, d); TFHEpp::Polynomial mulafterauto; TFHEpp::PolyMul(mulafterauto, autoa, autob); for (int i = 0; i < TFHEpp::lvl1param::n; i++) assert(abs(static_cast(mulafterauto[i] - autoaftermul[i])) <= 2); } std::cout << "PASS" << std::endl; }