From fac450b2cca0428b0a571e468cb202ee5d096658 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 10:13:55 +0800 Subject: [PATCH 01/24] feat: add `DCRTPolyGenFromConst` --- examples/dcrt_poly.rs | 11 +++++++++++ src/DCRTPoly.cc | 19 +++++++++++++++++++ src/DCRTPoly.h | 9 +++++++++ src/lib.rs | 8 ++++++++ 4 files changed, 47 insertions(+) create mode 100644 examples/dcrt_poly.rs diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs new file mode 100644 index 0000000..86473c2 --- /dev/null +++ b/examples/dcrt_poly.rs @@ -0,0 +1,11 @@ +use openfhe::ffi; + +fn main() { + let val = String::from("123456789099999"); + // Parameters based on https://github.com/openfheorg/openfhe-development/blob/7b8346f4eac27121543e36c17237b919e03ec058/src/core/unittest/UnitTestTrapdoor.cpp#L314 + let n: u32 = 16; + let size: usize = 4; // Number of CRT + let k_res: usize = 51; + + let poly = ffi::DCRTPolyGenFromConst(n, size, k_res, &val); +} diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 001a1eb..2568d0c 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -7,6 +7,25 @@ DCRTPoly::DCRTPoly(lbcrypto::DCRTPoly&& poly) noexcept : m_poly(std::move(poly)) { } +std::unique_ptr DCRTPolyGenFromConst( + usint n, + size_t size, + size_t kRes, + const rust::String& value) +{ + auto params = std::make_shared>(2 * n, size, kRes); + + lbcrypto::PolyImpl polyLarge(params, Format::COEFFICIENT); + + polyLarge = {std::string(value)}; + + lbcrypto::DCRTPolyImpl dcrtPoly(polyLarge, params); + + dcrtPoly.SetFormat(Format::EVALUATION); + + return std::make_unique(std::move(dcrtPoly)); +} + DCRTPolyParams::DCRTPolyParams(const std::shared_ptr& params) noexcept : m_params(params) { } diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index 1d691e2..fe6c2d6 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -1,6 +1,7 @@ #pragma once #include "openfhe/core/lattice/hal/lat-backend.h" +#include "rust/cxx.h" namespace openfhe { @@ -16,6 +17,14 @@ class DCRTPoly final DCRTPoly& operator=(DCRTPoly&&) = delete; }; +// Generator functions +[[nodiscard]] std::unique_ptr DCRTPolyGenFromConst( + usint n, + size_t size, + size_t kRes, + const rust::String& value +); + class DCRTPolyParams final { std::shared_ptr m_params; diff --git a/src/lib.rs b/src/lib.rs index 00726ea..619743e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -719,6 +719,14 @@ pub mod ffi fn DCRTPolyGenNullCryptoContext() -> UniquePtr; } + // DCRTPoly + unsafe extern "C++" + { + // Generator functions + fn DCRTPolyGenFromConst(n: u32, size: usize, kRes: usize, value: &String) + -> UniquePtr; + } + // DCRTPolyParams unsafe extern "C++" { From abd39d6ea0d8fedf120f68da0e747569107d1c37 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 10:23:25 +0800 Subject: [PATCH 02/24] feat: add debugging tools --- examples/dcrt_poly.rs | 11 ++++++++++- src/DCRTPoly.cc | 15 +++++++++++++++ src/DCRTPoly.h | 4 ++++ src/lib.rs | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 86473c2..04f6e4e 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -7,5 +7,14 @@ fn main() { let size: usize = 4; // Number of CRT let k_res: usize = 51; - let poly = ffi::DCRTPolyGenFromConst(n, size, k_res, &val); + let const_poly = ffi::DCRTPolyGenFromConst(n, size, k_res, &val); + // print the const_poly + println!("const_poly: {:?}", const_poly); + + let const_poly_2 = ffi::DCRTPolyGenFromConst(n, size, k_res, &val); + // print the const_poly_2 + println!("const_poly_2: {:?}", const_poly_2); + + // assert that the two const_poly are equal + assert_eq!(const_poly, const_poly_2); } diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 2568d0c..35d19d5 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -1,4 +1,5 @@ #include "DCRTPoly.h" +#include namespace openfhe { @@ -7,6 +8,20 @@ DCRTPoly::DCRTPoly(lbcrypto::DCRTPoly&& poly) noexcept : m_poly(std::move(poly)) { } +rust::String DCRTPoly::GetString() const +{ + std::stringstream stream; + stream << m_poly; + return rust::String(stream.str()); +} + +bool DCRTPoly::IsEqual(const DCRTPoly& other) const noexcept +{ + // Compare the internal DCRTPoly objects for equality + return m_poly == other.m_poly; +} + +// Generator functions std::unique_ptr DCRTPolyGenFromConst( usint n, size_t size, diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index fe6c2d6..4a9665e 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -15,6 +15,10 @@ class DCRTPoly final DCRTPoly(DCRTPoly&&) = delete; DCRTPoly& operator=(const DCRTPoly&) = delete; DCRTPoly& operator=(DCRTPoly&&) = delete; + + [[nodiscard]] const lbcrypto::DCRTPoly& GetPoly() const noexcept; + [[nodiscard]] rust::String GetString() const; + [[nodiscard]] bool IsEqual(const DCRTPoly& other) const noexcept; }; // Generator functions diff --git a/src/lib.rs b/src/lib.rs index 619743e..ba1d9cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -722,6 +722,9 @@ pub mod ffi // DCRTPoly unsafe extern "C++" { + fn GetString(self: &DCRTPoly) -> String; + fn IsEqual(self: &DCRTPoly, other: &DCRTPoly) -> bool; + // Generator functions fn DCRTPolyGenFromConst(n: u32, size: usize, kRes: usize, value: &String) -> UniquePtr; @@ -1136,6 +1139,22 @@ pub mod ffi } } + +use crate::ffi::DCRTPoly; +use std::fmt; + +impl fmt::Debug for DCRTPoly { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.GetString()) + } +} + +impl PartialEq for DCRTPoly { + fn eq(&self, other: &Self) -> bool { + self.IsEqual(other) + } +} + #[cfg(test)] mod tests { From ec254411c227522ee1a576bc6a4857d7ee76303e Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 11:01:25 +0800 Subject: [PATCH 03/24] feat: add `DCRTPolyGenFromVec` --- examples/dcrt_poly.rs | 13 +++++++++++++ src/DCRTPoly.cc | 42 ++++++++++++++++++++++++++++++++++++++---- src/DCRTPoly.h | 8 +++++++- src/lib.rs | 3 +++ 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 04f6e4e..a6b9bd0 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -17,4 +17,17 @@ fn main() { // assert that the two const_poly are equal assert_eq!(const_poly, const_poly_2); + + let coeffs = vec![ + String::from("123456789099999"), + String::from("1234567842539099999"), + String::from("31232189328123893128912983"), + String::from("24535423544252452453"), + ]; + + let poly = ffi::DCRTPolyGenFromVec(n, size, k_res, &coeffs); + let poly_2 = ffi::DCRTPolyGenFromVec(n, size, k_res, &coeffs); + + // assert that the two poly are equal + assert_eq!(poly, poly_2); } diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 35d19d5..74989ad 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -17,7 +17,6 @@ rust::String DCRTPoly::GetString() const bool DCRTPoly::IsEqual(const DCRTPoly& other) const noexcept { - // Compare the internal DCRTPoly objects for equality return m_poly == other.m_poly; } @@ -27,15 +26,50 @@ std::unique_ptr DCRTPolyGenFromConst( size_t size, size_t kRes, const rust::String& value) -{ +{ + // Create params auto params = std::make_shared>(2 * n, size, kRes); + // Create a BigVector + lbcrypto::BigVector bigVec(params -> GetRingDimension(), params ->GetModulus()); + bigVec[0] = lbcrypto::BigInteger(std::string(value)); + + // Create a Poly that supports BigInteger coefficients) lbcrypto::PolyImpl polyLarge(params, Format::COEFFICIENT); + polyLarge.SetValues(bigVec, Format::COEFFICIENT); + + // Convert polyLarge to a DCRTPoly + lbcrypto::DCRTPoly dcrtPoly(polyLarge, params); + + // switch dcrtPoly to EVALUATION format + dcrtPoly.SetFormat(Format::EVALUATION); + + return std::make_unique(std::move(dcrtPoly)); +} - polyLarge = {std::string(value)}; +std::unique_ptr DCRTPolyGenFromVec( + usint n, + size_t size, + size_t kRes, + const rust::Vec& values) +{ + // Create params + auto params = std::make_shared>(2 * n, size, kRes); + + // Create a BigVector + lbcrypto::BigVector bigVec(params->GetRingDimension(), params->GetModulus()); + for (size_t i = 0; i < values.size() && i < params->GetRingDimension(); i++) { + bigVec[i] = lbcrypto::BigInteger(std::string(values[i])); + } + + // Create a Poly that supports BigInteger coefficients + lbcrypto::PolyImpl polyLarge(params, Format::COEFFICIENT); + polyLarge.SetValues(bigVec, Format::COEFFICIENT); - lbcrypto::DCRTPolyImpl dcrtPoly(polyLarge, params); + // Convert polyLarge to a DCRTPoly + lbcrypto::DCRTPoly dcrtPoly(polyLarge, params); + // switch dcrtPoly to EVALUATION format dcrtPoly.SetFormat(Format::EVALUATION); return std::make_unique(std::move(dcrtPoly)); diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index 4a9665e..4b4f391 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -29,6 +29,13 @@ class DCRTPoly final const rust::String& value ); +[[nodiscard]] std::unique_ptr DCRTPolyGenFromVec( + usint n, + size_t size, + size_t kRes, + const rust::Vec& values +); + class DCRTPolyParams final { std::shared_ptr m_params; @@ -45,5 +52,4 @@ class DCRTPolyParams final // Generator functions [[nodiscard]] std::unique_ptr DCRTPolyGenNullParams(); - } // openfhe diff --git a/src/lib.rs b/src/lib.rs index ba1d9cb..070635a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -728,6 +728,9 @@ pub mod ffi // Generator functions fn DCRTPolyGenFromConst(n: u32, size: usize, kRes: usize, value: &String) -> UniquePtr; + fn DCRTPolyGenFromVec(n: u32, size: usize, kRes: usize, values: &Vec) + -> UniquePtr; + } // DCRTPolyParams From 8368d7888b301dfaba967aa998406892887aa0ad Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:01:54 +0800 Subject: [PATCH 04/24] feat: add `GenModulus` --- examples/dcrt_poly.rs | 3 +++ src/Params.cc | 8 ++++++++ src/Params.h | 6 ++++-- src/lib.rs | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index a6b9bd0..06e4271 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -11,6 +11,9 @@ fn main() { // print the const_poly println!("const_poly: {:?}", const_poly); + let modulus = ffi::GenModulus(n, size, k_res); + println!("modulus: {:?}", modulus); + let const_poly_2 = ffi::DCRTPolyGenFromConst(n, size, k_res, &val); // print the const_poly_2 println!("const_poly_2: {:?}", const_poly_2); diff --git a/src/Params.cc b/src/Params.cc index 89ef180..e04aaae 100644 --- a/src/Params.cc +++ b/src/Params.cc @@ -1,4 +1,5 @@ #include "Params.h" +#include "DCRTPoly.h" namespace openfhe { @@ -37,4 +38,11 @@ std::unique_ptr GenParamsCKKSRNSbyVectorOfString( return std::make_unique(vals); } +rust::String GenModulus( + usint n, size_t size, size_t kRes) +{ + auto params = std::make_shared>(2 * n, size, kRes); + return rust::String(params->GetModulus().ToString()); +} + } // openfhe diff --git a/src/Params.h b/src/Params.h index b062fb0..432655f 100644 --- a/src/Params.h +++ b/src/Params.h @@ -6,6 +6,8 @@ #include "openfhe/pke/scheme/bgvrns/gen-cryptocontext-bgvrns-params.h" #include "openfhe/pke/scheme/ckksrns/gen-cryptocontext-ckksrns-params.h" +#include "rust/cxx.h" + #include namespace openfhe @@ -42,6 +44,6 @@ using ParamsCKKSRNS = lbcrypto::CCParams; [[nodiscard]] std::unique_ptr GenParamsCKKSRNS(); [[nodiscard]] std::unique_ptr GenParamsCKKSRNSbyVectorOfString( const std::vector& vals); - - +[[nodiscard]] rust::String GenModulus( + usint n, size_t size, size_t kRes); } // openfhe diff --git a/src/lib.rs b/src/lib.rs index 070635a..bc9f3c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -730,7 +730,6 @@ pub mod ffi -> UniquePtr; fn DCRTPolyGenFromVec(n: u32, size: usize, kRes: usize, values: &Vec) -> UniquePtr; - } // DCRTPolyParams @@ -815,6 +814,7 @@ pub mod ffi // Generator functions fn GenParamsByScheme(scheme: SCHEME) -> UniquePtr; fn GenParamsByVectorOfString(vals: &CxxVector) -> UniquePtr; + fn GenModulus(n: u32, size: usize, k_res: usize) -> String; } // ParamsBFVRNS From fed8a5c4c08a3b341997cbc95d6d803a10f3d509 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:11:00 +0800 Subject: [PATCH 05/24] feat: add arithmetic on `DCRTPoly` --- examples/dcrt_poly.rs | 8 ++++++++ src/DCRTPoly.cc | 18 ++++++++++++++++++ src/DCRTPoly.h | 4 ++++ src/lib.rs | 4 ++++ 4 files changed, 34 insertions(+) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 06e4271..d106df9 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -33,4 +33,12 @@ fn main() { // assert that the two poly are equal assert_eq!(poly, poly_2); + + // perform polynomial addition + let poly_add = ffi::DCRTPolyAdd(&poly, &poly_2); + println!("poly_add: {:?}", poly_add); + + // perform polynomial multiplication + let poly_mul = ffi::DCRTPolyMul(&poly, &poly_2); + println!("poly_mul: {:?}", poly_mul); } diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 74989ad..82d07e8 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -8,6 +8,12 @@ DCRTPoly::DCRTPoly(lbcrypto::DCRTPoly&& poly) noexcept : m_poly(std::move(poly)) { } +const lbcrypto::DCRTPoly& DCRTPoly::GetPoly() const noexcept +{ + return m_poly; +} + + rust::String DCRTPoly::GetString() const { std::stringstream stream; @@ -75,6 +81,18 @@ std::unique_ptr DCRTPolyGenFromVec( return std::make_unique(std::move(dcrtPoly)); } +// Arithmetic +std::unique_ptr DCRTPolyAdd(const DCRTPoly& rhs, const DCRTPoly& lhs) +{ + return std::make_unique(rhs.GetPoly() + lhs.GetPoly()); +} + +std::unique_ptr DCRTPolyMul(const DCRTPoly& rhs, const DCRTPoly& lhs) +{ + return std::make_unique(rhs.GetPoly() * lhs.GetPoly()); +} + + DCRTPolyParams::DCRTPolyParams(const std::shared_ptr& params) noexcept : m_params(params) { } diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index 4b4f391..885747d 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -36,6 +36,10 @@ class DCRTPoly final const rust::Vec& values ); +// Arithmetic +[[nodiscard]] std::unique_ptr DCRTPolyAdd(const DCRTPoly& rhs, const DCRTPoly& lhs); +[[nodiscard]] std::unique_ptr DCRTPolyMul(const DCRTPoly& rhs, const DCRTPoly& lhs); + class DCRTPolyParams final { std::shared_ptr m_params; diff --git a/src/lib.rs b/src/lib.rs index bc9f3c6..45eeffa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -730,6 +730,10 @@ pub mod ffi -> UniquePtr; fn DCRTPolyGenFromVec(n: u32, size: usize, kRes: usize, values: &Vec) -> UniquePtr; + + // Arithmetic + fn DCRTPolyAdd(rhs: &DCRTPoly, lhs: &DCRTPoly) -> UniquePtr; + fn DCRTPolyMul(rhs: &DCRTPoly, lhs: &DCRTPoly) -> UniquePtr; } // DCRTPolyParams From e519969dd1ff281f0dab6431922bbd56dd36b37c Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:18:18 +0800 Subject: [PATCH 06/24] feat: add `GetCoefficients()` --- examples/dcrt_poly.rs | 11 +++++++++++ src/DCRTPoly.cc | 18 ++++++++++++++++++ src/DCRTPoly.h | 1 + src/lib.rs | 1 + 4 files changed, 31 insertions(+) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index d106df9..cc000ac 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -41,4 +41,15 @@ fn main() { // perform polynomial multiplication let poly_mul = ffi::DCRTPolyMul(&poly, &poly_2); println!("poly_mul: {:?}", poly_mul); + + // get the coefficients of the polynomials + let coeffs_poly = poly.GetCoefficients(); + println!("coeffs_poly: {:?}", coeffs_poly); + let coeffs_poly_2 = poly_2.GetCoefficients(); + println!("coeffs_poly_2: {:?}", coeffs_poly_2); + let coeffs_poly_add = poly_add.GetCoefficients(); + println!("coeffs_poly_add: {:?}", coeffs_poly_add); + + // the format of the poly should still be in evaluation format + println!("poly_add: {:?}", poly_add); } diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 82d07e8..0f793b2 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -26,6 +26,24 @@ bool DCRTPoly::IsEqual(const DCRTPoly& other) const noexcept return m_poly == other.m_poly; } +rust::Vec DCRTPoly::GetCoefficients() const +{ + auto tempPoly = m_poly; + tempPoly.SetFormat(Format::COEFFICIENT); + + lbcrypto::DCRTPoly::PolyLargeType polyLarge = tempPoly.CRTInterpolate(); + + const lbcrypto::BigVector &coeffs = polyLarge.GetValues(); + + rust::Vec result; + for (size_t i = 0; i < coeffs.GetLength(); ++i) + { + result.push_back(rust::String(coeffs[i].ToString())); + } + + return result; +} + // Generator functions std::unique_ptr DCRTPolyGenFromConst( usint n, diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index 885747d..c090668 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -19,6 +19,7 @@ class DCRTPoly final [[nodiscard]] const lbcrypto::DCRTPoly& GetPoly() const noexcept; [[nodiscard]] rust::String GetString() const; [[nodiscard]] bool IsEqual(const DCRTPoly& other) const noexcept; + [[nodiscard]] rust::Vec GetCoefficients() const; }; // Generator functions diff --git a/src/lib.rs b/src/lib.rs index 45eeffa..4f9a6fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -724,6 +724,7 @@ pub mod ffi { fn GetString(self: &DCRTPoly) -> String; fn IsEqual(self: &DCRTPoly, other: &DCRTPoly) -> bool; + fn GetCoefficients(self: &DCRTPoly) -> Vec; // Generator functions fn DCRTPolyGenFromConst(n: u32, size: usize, kRes: usize, value: &String) From 41ab7af5f6aaa3dadc090bfdfa97f37a15e545fb Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:39:33 +0800 Subject: [PATCH 07/24] feat: add `GetModulus` --- examples/dcrt_poly.rs | 4 ++-- src/DCRTPoly.cc | 5 +++++ src/DCRTPoly.h | 1 + src/lib.rs | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index cc000ac..940231c 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -50,6 +50,6 @@ fn main() { let coeffs_poly_add = poly_add.GetCoefficients(); println!("coeffs_poly_add: {:?}", coeffs_poly_add); - // the format of the poly should still be in evaluation format - println!("poly_add: {:?}", poly_add); + let poly_modulus = poly.GetModulus(); + assert_eq!(poly_modulus, modulus); } diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 0f793b2..470c0de 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -21,6 +21,11 @@ rust::String DCRTPoly::GetString() const return rust::String(stream.str()); } +rust::String DCRTPoly::GetModulus() const +{ + return m_poly.GetModulus().ToString(); +} + bool DCRTPoly::IsEqual(const DCRTPoly& other) const noexcept { return m_poly == other.m_poly; diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index c090668..a95d3e9 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -20,6 +20,7 @@ class DCRTPoly final [[nodiscard]] rust::String GetString() const; [[nodiscard]] bool IsEqual(const DCRTPoly& other) const noexcept; [[nodiscard]] rust::Vec GetCoefficients() const; + [[nodiscard]] rust::String GetModulus() const; }; // Generator functions diff --git a/src/lib.rs b/src/lib.rs index 4f9a6fe..39d998c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -725,6 +725,7 @@ pub mod ffi fn GetString(self: &DCRTPoly) -> String; fn IsEqual(self: &DCRTPoly, other: &DCRTPoly) -> bool; fn GetCoefficients(self: &DCRTPoly) -> Vec; + fn GetModulus(self: &DCRTPoly) -> String; // Generator functions fn DCRTPolyGenFromConst(n: u32, size: usize, kRes: usize, value: &String) From 5a7ea3b1ff341e1387107ce171d1b30153986abe Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 12:46:07 +0800 Subject: [PATCH 08/24] feat: add `Negate` --- examples/dcrt_poly.rs | 4 ++++ src/DCRTPoly.cc | 5 +++++ src/DCRTPoly.h | 1 + src/lib.rs | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 940231c..c811cd1 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -21,6 +21,10 @@ fn main() { // assert that the two const_poly are equal assert_eq!(const_poly, const_poly_2); + let const_poly_one = ffi::DCRTPolyGenFromConst(n, size, k_res, &String::from("1")); + let negated_poly_one = const_poly_one.Negate(); + println!("negated_poly_one: {:?}", negated_poly_one); + let coeffs = vec![ String::from("123456789099999"), String::from("1234567842539099999"), diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 470c0de..7f3a575 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -49,6 +49,11 @@ rust::Vec DCRTPoly::GetCoefficients() const return result; } +std::unique_ptr DCRTPoly::Negate() const +{ + return std::make_unique(-m_poly); +} + // Generator functions std::unique_ptr DCRTPolyGenFromConst( usint n, diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index a95d3e9..6694a2a 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -21,6 +21,7 @@ class DCRTPoly final [[nodiscard]] bool IsEqual(const DCRTPoly& other) const noexcept; [[nodiscard]] rust::Vec GetCoefficients() const; [[nodiscard]] rust::String GetModulus() const; + [[nodiscard]] std::unique_ptr Negate() const; }; // Generator functions diff --git a/src/lib.rs b/src/lib.rs index 39d998c..f95524a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -726,7 +726,7 @@ pub mod ffi fn IsEqual(self: &DCRTPoly, other: &DCRTPoly) -> bool; fn GetCoefficients(self: &DCRTPoly) -> Vec; fn GetModulus(self: &DCRTPoly) -> String; - + fn Negate(self: &DCRTPoly) -> UniquePtr; // Generator functions fn DCRTPolyGenFromConst(n: u32, size: usize, kRes: usize, value: &String) -> UniquePtr; From 233e347ec76f6d0845a178a8d4e2c4c03e369207 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 13:25:32 +0800 Subject: [PATCH 09/24] feat: add samplers --- src/DCRTPoly.cc | 34 +++++++++++++++++++++++++++++----- src/DCRTPoly.h | 4 ++++ src/lib.rs | 4 ++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 7f3a575..2119708 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -54,6 +54,17 @@ std::unique_ptr DCRTPoly::Negate() const return std::make_unique(-m_poly); } +// Arithmetic +std::unique_ptr DCRTPolyAdd(const DCRTPoly& rhs, const DCRTPoly& lhs) +{ + return std::make_unique(rhs.GetPoly() + lhs.GetPoly()); +} + +std::unique_ptr DCRTPolyMul(const DCRTPoly& rhs, const DCRTPoly& lhs) +{ + return std::make_unique(rhs.GetPoly() * lhs.GetPoly()); +} + // Generator functions std::unique_ptr DCRTPolyGenFromConst( usint n, @@ -109,15 +120,28 @@ std::unique_ptr DCRTPolyGenFromVec( return std::make_unique(std::move(dcrtPoly)); } -// Arithmetic -std::unique_ptr DCRTPolyAdd(const DCRTPoly& rhs, const DCRTPoly& lhs) +std::unique_ptr DCRTPolyGenFromBug(usint n, size_t size, size_t kRes) { - return std::make_unique(rhs.GetPoly() + lhs.GetPoly()); + auto params = std::make_shared>(2 * n, size, kRes); + typename lbcrypto::DCRTPoly::BugType bug; + auto poly = lbcrypto::DCRTPoly(bug, params, Format::EVALUATION); + return std::make_unique(std::move(poly)); } -std::unique_ptr DCRTPolyMul(const DCRTPoly& rhs, const DCRTPoly& lhs) +std::unique_ptr DCRTPolyGenFromDug(usint n, size_t size, size_t kRes) { - return std::make_unique(rhs.GetPoly() * lhs.GetPoly()); + auto params = std::make_shared>(2 * n, size, kRes); + typename lbcrypto::DCRTPoly::DugType dug; + auto poly = lbcrypto::DCRTPoly(dug, params, Format::EVALUATION); + return std::make_unique(std::move(poly)); +} + +std::unique_ptr DCRTPolyGenFromDgg(usint n, size_t size, size_t kRes, double sigma) +{ + auto params = std::make_shared>(2 * n, size, kRes); + typename lbcrypto::DCRTPoly::DggType dgg(sigma); + auto poly = lbcrypto::DCRTPoly(dgg, params, Format::EVALUATION); + return std::make_unique(std::move(poly)); } diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index 6694a2a..e7ce254 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -39,6 +39,10 @@ class DCRTPoly final const rust::Vec& values ); +[[nodiscard]] std::unique_ptr DCRTPolyGenFromBug(usint n, size_t size, size_t kRes); +[[nodiscard]] std::unique_ptr DCRTPolyGenFromDug(usint n, size_t size, size_t kRes); +[[nodiscard]] std::unique_ptr DCRTPolyGenFromDgg(usint n, size_t size, size_t kRes, double sigma); + // Arithmetic [[nodiscard]] std::unique_ptr DCRTPolyAdd(const DCRTPoly& rhs, const DCRTPoly& lhs); [[nodiscard]] std::unique_ptr DCRTPolyMul(const DCRTPoly& rhs, const DCRTPoly& lhs); diff --git a/src/lib.rs b/src/lib.rs index f95524a..0c1be8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -727,11 +727,15 @@ pub mod ffi fn GetCoefficients(self: &DCRTPoly) -> Vec; fn GetModulus(self: &DCRTPoly) -> String; fn Negate(self: &DCRTPoly) -> UniquePtr; + // Generator functions fn DCRTPolyGenFromConst(n: u32, size: usize, kRes: usize, value: &String) -> UniquePtr; fn DCRTPolyGenFromVec(n: u32, size: usize, kRes: usize, values: &Vec) -> UniquePtr; + fn DCRTPolyGenFromBug(n: u32, size: usize, kRes: usize) -> UniquePtr; + fn DCRTPolyGenFromDug(n: u32, size: usize, kRes: usize) -> UniquePtr; + fn DCRTPolyGenFromDgg(n: u32, size: usize, kRes: usize, sigma: f64) -> UniquePtr; // Arithmetic fn DCRTPolyAdd(rhs: &DCRTPoly, lhs: &DCRTPoly) -> UniquePtr; From ca117d0702e5777ad7b67e70c008ca64a2edbbc9 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 15:03:16 +0800 Subject: [PATCH 10/24] feat: add `DCRTMatrix` --- build.rs | 1 + src/DCRTMatrix.cc | 18 ++++++++++++++++++ src/DCRTMatrix.h | 27 +++++++++++++++++++++++++++ src/lib.rs | 8 ++++++++ 4 files changed, 54 insertions(+) create mode 100644 src/DCRTMatrix.cc create mode 100644 src/DCRTMatrix.h diff --git a/build.rs b/build.rs index 089907a..79a03c5 100644 --- a/build.rs +++ b/build.rs @@ -5,6 +5,7 @@ fn main() .file("src/Ciphertext.cc") .file("src/CryptoContext.cc") .file("src/CryptoParametersBase.cc") + .file("src/DCRTMatrix.cc") .file("src/DCRTPoly.cc") .file("src/DecryptResult.cc") .file("src/EncodingParams.cc") diff --git a/src/DCRTMatrix.cc b/src/DCRTMatrix.cc new file mode 100644 index 0000000..81944ee --- /dev/null +++ b/src/DCRTMatrix.cc @@ -0,0 +1,18 @@ +#include "DCRTMatrix.h" + +namespace openfhe +{ + +DCRTMatrix::DCRTMatrix(Matrix&& matrix) noexcept + : m_matrix(std::move(matrix)) +{ } + +std::unique_ptr DCRTMatrix::GetElement(size_t row, size_t col) const +{ + if (row >= m_matrix.GetRows() || col >= m_matrix.GetCols()) { + return nullptr; + } + +return std::make_unique(lbcrypto::DCRTPoly(m_matrix(row, col))); +} +} // namespace openfhe \ No newline at end of file diff --git a/src/DCRTMatrix.h b/src/DCRTMatrix.h new file mode 100644 index 0000000..bd5be1f --- /dev/null +++ b/src/DCRTMatrix.h @@ -0,0 +1,27 @@ +#pragma once + +#include "openfhe/core/math/matrix.h" +#include "DCRTPoly.h" + +namespace openfhe +{ + +using Matrix = lbcrypto::Matrix; + +class DCRTMatrix final +{ + Matrix m_matrix; +public: + DCRTMatrix() = default; + DCRTMatrix(Matrix&& matrix) noexcept; + DCRTMatrix(const DCRTMatrix&) = delete; + DCRTMatrix(DCRTMatrix&&) = delete; + DCRTMatrix& operator=(const DCRTMatrix&) = delete; + DCRTMatrix& operator=(DCRTMatrix&&) = delete; + + [[nodiscard]] std::unique_ptr GetElement(size_t row, size_t col) const; +}; + +// // Generator functions +// [[nodiscard]] std::unique_ptr DCRTMatrixGenNull(usint n, size_t size, size_t kRes, size_t rows, size_t cols); +} // namespace openfhe \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 0c1be8e..8425fa4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,6 +160,7 @@ pub mod ffi include!("openfhe/src/Ciphertext.h"); include!("openfhe/src/CryptoContext.h"); include!("openfhe/src/CryptoParametersBase.h"); + include!("openfhe/src/DCRTMatrix.h"); include!("openfhe/src/DCRTPoly.h"); include!("openfhe/src/DecryptResult.h"); include!("openfhe/src/EncodingParams.h"); @@ -196,6 +197,7 @@ pub mod ffi type CiphertextDCRTPoly; type CryptoContextDCRTPoly; type CryptoParametersBaseDCRTPoly; + type DCRTMatrix; type DCRTPoly; type DCRTPolyParams; type DecryptResult; @@ -719,6 +721,12 @@ pub mod ffi fn DCRTPolyGenNullCryptoContext() -> UniquePtr; } + // DCRTMatrix + unsafe extern "C++" + { + fn GetElement(self: &DCRTMatrix, row: usize, col: usize) -> UniquePtr; + } + // DCRTPoly unsafe extern "C++" { From fc9785f2d8a09a16155a856e45c7ece3398e56e8 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 15:39:39 +0800 Subject: [PATCH 11/24] feat: add `Trapdoor` --- .vscode/settings.json | 60 +++++++++++++++++++++++++++++++++++++++++++ build.rs | 1 + src/DCRTMatrix.cc | 9 +++++++ src/DCRTMatrix.h | 3 ++- src/Trapdoor.cc | 20 +++++++++++++++ src/Trapdoor.h | 36 ++++++++++++++++++++++++++ src/lib.rs | 10 ++++++++ 7 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 src/Trapdoor.cc create mode 100644 src/Trapdoor.h diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7d417dd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,60 @@ +{ + "files.associations": { + "*.mpc": "python", + "__bit_reference": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "execution": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "locale": "cpp", + "map": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "print": "cpp", + "queue": "cpp", + "ratio": "cpp", + "set": "cpp", + "span": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "variant": "cpp", + "vector": "cpp", + "memory": "cpp", + "algorithm": "cpp" + } +} \ No newline at end of file diff --git a/build.rs b/build.rs index 79a03c5..b13cbd0 100644 --- a/build.rs +++ b/build.rs @@ -19,6 +19,7 @@ fn main() .file("src/SchemeBase.cc") .file("src/SequenceContainers.cc") .file("src/SerialDeserial.cc") + .file("src/Trapdoor.cc") .include("/usr/local/include/openfhe") .include("/usr/local/include/openfhe/third-party/include") .include("/usr/local/include/openfhe/core") diff --git a/src/DCRTMatrix.cc b/src/DCRTMatrix.cc index 81944ee..23568ee 100644 --- a/src/DCRTMatrix.cc +++ b/src/DCRTMatrix.cc @@ -7,6 +7,15 @@ DCRTMatrix::DCRTMatrix(Matrix&& matrix) noexcept : m_matrix(std::move(matrix)) { } +DCRTMatrix::DCRTMatrix(const DCRTMatrix& other) + : m_matrix(other.m_matrix) // deep copy +{ } + +[[nodiscard]] const Matrix& DCRTMatrix::GetMatrix() const noexcept +{ + return m_matrix; +} + std::unique_ptr DCRTMatrix::GetElement(size_t row, size_t col) const { if (row >= m_matrix.GetRows() || col >= m_matrix.GetCols()) { diff --git a/src/DCRTMatrix.h b/src/DCRTMatrix.h index bd5be1f..666d2b2 100644 --- a/src/DCRTMatrix.h +++ b/src/DCRTMatrix.h @@ -14,12 +14,13 @@ class DCRTMatrix final public: DCRTMatrix() = default; DCRTMatrix(Matrix&& matrix) noexcept; - DCRTMatrix(const DCRTMatrix&) = delete; + DCRTMatrix(const DCRTMatrix& other); DCRTMatrix(DCRTMatrix&&) = delete; DCRTMatrix& operator=(const DCRTMatrix&) = delete; DCRTMatrix& operator=(DCRTMatrix&&) = delete; [[nodiscard]] std::unique_ptr GetElement(size_t row, size_t col) const; + [[nodiscard]] const Matrix& GetMatrix() const noexcept; }; // // Generator functions diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc new file mode 100644 index 0000000..f2a4302 --- /dev/null +++ b/src/Trapdoor.cc @@ -0,0 +1,20 @@ +#include "Trapdoor.h" + +namespace openfhe +{ + +DCRTTrapdoor::DCRTTrapdoor(DCRTMatrix& publicMatrix, RLWETrapdoorPair&& trapdoorPair) noexcept + : m_publicMatrix(publicMatrix), m_trapdoorPair(std::move(trapdoorPair)) +{ } + +std::unique_ptr DCRTTrapdoor::GetTrapdoorPair() const +{ + return std::make_unique(m_trapdoorPair); +} + +std::unique_ptr DCRTTrapdoor::GetPublicMatrix() const +{ + return std::make_unique(m_publicMatrix); +} + +} // openfhe \ No newline at end of file diff --git a/src/Trapdoor.h b/src/Trapdoor.h new file mode 100644 index 0000000..5d6074a --- /dev/null +++ b/src/Trapdoor.h @@ -0,0 +1,36 @@ +#pragma once +#include "openfhe/core/lattice/trapdoor.h" +#include "DCRTPoly.h" +#include "DCRTMatrix.h" + +namespace openfhe +{ + +using RLWETrapdoorPair = lbcrypto::RLWETrapdoorPair; + +class DCRTTrapdoor final +{ + DCRTMatrix m_publicMatrix; + RLWETrapdoorPair m_trapdoorPair; +public: + DCRTTrapdoor() = default; + DCRTTrapdoor(DCRTMatrix& publicMatrix, RLWETrapdoorPair&& trapdoorPair) noexcept; + DCRTTrapdoor(const DCRTTrapdoor&) = delete; + DCRTTrapdoor(DCRTTrapdoor&&) = delete; + DCRTTrapdoor& operator=(const DCRTTrapdoor&) = delete; + DCRTTrapdoor& operator=(DCRTTrapdoor&&) = delete; + + [[nodiscard]] std::unique_ptr GetTrapdoorPair() const; + [[nodiscard]] std::unique_ptr GetPublicMatrix() const; +}; + +// // Generator functions +// [[nodiscard]] std::unique_ptr DCRTTrapdoorGen( +// usint n, +// size_t size, +// size_t kRes, +// double sigma, +// size_t d, +// int64_t base, +// bool balanced); +} // openfhe \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 8425fa4..9ae6c41 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,6 +174,7 @@ pub mod ffi include!("openfhe/src/SchemeBase.h"); include!("openfhe/src/SequenceContainers.h"); include!("openfhe/src/SerialDeserial.h"); + include!("openfhe/src/Trapdoor.h"); // enums type COMPRESSION_LEVEL; @@ -200,6 +201,7 @@ pub mod ffi type DCRTMatrix; type DCRTPoly; type DCRTPolyParams; + type DCRTTrapdoor; type DecryptResult; type EncodingParams; type EvalKeyDCRTPoly; @@ -215,6 +217,7 @@ pub mod ffi type Plaintext; type PrivateKeyDCRTPoly; type PublicKeyDCRTPoly; + type RLWETrapdoorPair; type SchemeBaseDCRTPoly; type SetOfUints; type UnorderedMapFromIndexToDCRTPoly; @@ -1158,6 +1161,13 @@ pub mod ffi privateKey: &PrivateKeyDCRTPoly, serialMode: SerialMode) -> bool; } + + // Trapdoor + unsafe extern "C++" + { + fn GetPublicMatrix(self: &DCRTTrapdoor) -> UniquePtr; + fn GetTrapdoorPair(self: &DCRTTrapdoor) -> UniquePtr; + } } From da27e82962c40ecc8a7f6db3827a9ac1bdbf1fc8 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:15:16 +0800 Subject: [PATCH 12/24] feat: add `DCRTTrapdoorGen` --- .vscode/settings.json | 60 ------------------------------------------- build.rs | 1 - examples/dcrt_poly.rs | 4 +++ src/DCRTMatrix.cc | 27 ------------------- src/DCRTMatrix.h | 28 -------------------- src/Trapdoor.cc | 32 ++++++++++++++++++++--- src/Trapdoor.h | 26 +++++++++---------- src/lib.rs | 31 ++++++++++++---------- 8 files changed, 62 insertions(+), 147 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 src/DCRTMatrix.cc delete mode 100644 src/DCRTMatrix.h diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7d417dd..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "files.associations": { - "*.mpc": "python", - "__bit_reference": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__node_handle": "cpp", - "__split_buffer": "cpp", - "__threading_support": "cpp", - "__tree": "cpp", - "__verbose_abort": "cpp", - "array": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "execution": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "locale": "cpp", - "map": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "print": "cpp", - "queue": "cpp", - "ratio": "cpp", - "set": "cpp", - "span": "cpp", - "sstream": "cpp", - "stack": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "string_view": "cpp", - "tuple": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "variant": "cpp", - "vector": "cpp", - "memory": "cpp", - "algorithm": "cpp" - } -} \ No newline at end of file diff --git a/build.rs b/build.rs index b13cbd0..b88551d 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,6 @@ fn main() .file("src/Ciphertext.cc") .file("src/CryptoContext.cc") .file("src/CryptoParametersBase.cc") - .file("src/DCRTMatrix.cc") .file("src/DCRTPoly.cc") .file("src/DecryptResult.cc") .file("src/EncodingParams.cc") diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index c811cd1..b7b44ae 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -56,4 +56,8 @@ fn main() { let poly_modulus = poly.GetModulus(); assert_eq!(poly_modulus, modulus); + + // sample trapdoor + let sigma = 4.57825; + let trapdoor = ffi::DCRTTrapdoorGen(n, size, k_res, sigma, 2, false); } diff --git a/src/DCRTMatrix.cc b/src/DCRTMatrix.cc deleted file mode 100644 index 23568ee..0000000 --- a/src/DCRTMatrix.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "DCRTMatrix.h" - -namespace openfhe -{ - -DCRTMatrix::DCRTMatrix(Matrix&& matrix) noexcept - : m_matrix(std::move(matrix)) -{ } - -DCRTMatrix::DCRTMatrix(const DCRTMatrix& other) - : m_matrix(other.m_matrix) // deep copy -{ } - -[[nodiscard]] const Matrix& DCRTMatrix::GetMatrix() const noexcept -{ - return m_matrix; -} - -std::unique_ptr DCRTMatrix::GetElement(size_t row, size_t col) const -{ - if (row >= m_matrix.GetRows() || col >= m_matrix.GetCols()) { - return nullptr; - } - -return std::make_unique(lbcrypto::DCRTPoly(m_matrix(row, col))); -} -} // namespace openfhe \ No newline at end of file diff --git a/src/DCRTMatrix.h b/src/DCRTMatrix.h deleted file mode 100644 index 666d2b2..0000000 --- a/src/DCRTMatrix.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "openfhe/core/math/matrix.h" -#include "DCRTPoly.h" - -namespace openfhe -{ - -using Matrix = lbcrypto::Matrix; - -class DCRTMatrix final -{ - Matrix m_matrix; -public: - DCRTMatrix() = default; - DCRTMatrix(Matrix&& matrix) noexcept; - DCRTMatrix(const DCRTMatrix& other); - DCRTMatrix(DCRTMatrix&&) = delete; - DCRTMatrix& operator=(const DCRTMatrix&) = delete; - DCRTMatrix& operator=(DCRTMatrix&&) = delete; - - [[nodiscard]] std::unique_ptr GetElement(size_t row, size_t col) const; - [[nodiscard]] const Matrix& GetMatrix() const noexcept; -}; - -// // Generator functions -// [[nodiscard]] std::unique_ptr DCRTMatrixGenNull(usint n, size_t size, size_t kRes, size_t rows, size_t cols); -} // namespace openfhe \ No newline at end of file diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index f2a4302..591b84b 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -1,10 +1,11 @@ #include "Trapdoor.h" +#include "Params.h" namespace openfhe { -DCRTTrapdoor::DCRTTrapdoor(DCRTMatrix& publicMatrix, RLWETrapdoorPair&& trapdoorPair) noexcept - : m_publicMatrix(publicMatrix), m_trapdoorPair(std::move(trapdoorPair)) +DCRTTrapdoor::DCRTTrapdoor(Matrix&& publicMatrix, RLWETrapdoorPair&& trapdoorPair) noexcept + : m_publicMatrix(std::move(publicMatrix)), m_trapdoorPair(std::move(trapdoorPair)) { } std::unique_ptr DCRTTrapdoor::GetTrapdoorPair() const @@ -12,9 +13,32 @@ std::unique_ptr DCRTTrapdoor::GetTrapdoorPair() const return std::make_unique(m_trapdoorPair); } -std::unique_ptr DCRTTrapdoor::GetPublicMatrix() const +std::unique_ptr DCRTTrapdoor::GetPublicMatrix() const { - return std::make_unique(m_publicMatrix); + return std::make_unique(m_publicMatrix); } +// Generator functions +std::unique_ptr DCRTTrapdoorGen( + usint n, + size_t size, + size_t kRes, + double sigma, + int64_t base, + bool balanced) +{ + auto params = std::make_shared>(2 * n, size, kRes); + + auto trapdoor = lbcrypto::RLWETrapdoorUtility::TrapdoorGen( + params, + sigma, + base, + balanced + ); + + return std::make_unique( + std::move(trapdoor.first), + std::move(trapdoor.second) + ); +} } // openfhe \ No newline at end of file diff --git a/src/Trapdoor.h b/src/Trapdoor.h index 5d6074a..019bc9a 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -1,36 +1,36 @@ #pragma once #include "openfhe/core/lattice/trapdoor.h" +#include "openfhe/core/math/matrix.h" #include "DCRTPoly.h" -#include "DCRTMatrix.h" namespace openfhe { using RLWETrapdoorPair = lbcrypto::RLWETrapdoorPair; +using Matrix = lbcrypto::Matrix; class DCRTTrapdoor final { - DCRTMatrix m_publicMatrix; + Matrix m_publicMatrix; RLWETrapdoorPair m_trapdoorPair; public: DCRTTrapdoor() = default; - DCRTTrapdoor(DCRTMatrix& publicMatrix, RLWETrapdoorPair&& trapdoorPair) noexcept; + DCRTTrapdoor(Matrix&& publicMatrix, RLWETrapdoorPair&& trapdoorPair) noexcept; DCRTTrapdoor(const DCRTTrapdoor&) = delete; DCRTTrapdoor(DCRTTrapdoor&&) = delete; DCRTTrapdoor& operator=(const DCRTTrapdoor&) = delete; DCRTTrapdoor& operator=(DCRTTrapdoor&&) = delete; [[nodiscard]] std::unique_ptr GetTrapdoorPair() const; - [[nodiscard]] std::unique_ptr GetPublicMatrix() const; + [[nodiscard]] std::unique_ptr GetPublicMatrix() const; }; -// // Generator functions -// [[nodiscard]] std::unique_ptr DCRTTrapdoorGen( -// usint n, -// size_t size, -// size_t kRes, -// double sigma, -// size_t d, -// int64_t base, -// bool balanced); +// Generator functions +[[nodiscard]] std::unique_ptr DCRTTrapdoorGen( + usint n, + size_t size, + size_t kRes, + double sigma, + int64_t base, + bool balanced); } // openfhe \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 9ae6c41..4536277 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,7 +160,6 @@ pub mod ffi include!("openfhe/src/Ciphertext.h"); include!("openfhe/src/CryptoContext.h"); include!("openfhe/src/CryptoParametersBase.h"); - include!("openfhe/src/DCRTMatrix.h"); include!("openfhe/src/DCRTPoly.h"); include!("openfhe/src/DecryptResult.h"); include!("openfhe/src/EncodingParams.h"); @@ -198,7 +197,6 @@ pub mod ffi type CiphertextDCRTPoly; type CryptoContextDCRTPoly; type CryptoParametersBaseDCRTPoly; - type DCRTMatrix; type DCRTPoly; type DCRTPolyParams; type DCRTTrapdoor; @@ -210,6 +208,7 @@ pub mod ffi type MapFromIndexToEvalKey; type MapFromStringToMapFromIndexToEvalKey; type MapFromStringToVectorOfEvalKeys; + type Matrix; type Params; type ParamsBFVRNS; type ParamsBGVRNS; @@ -724,12 +723,6 @@ pub mod ffi fn DCRTPolyGenNullCryptoContext() -> UniquePtr; } - // DCRTMatrix - unsafe extern "C++" - { - fn GetElement(self: &DCRTMatrix, row: usize, col: usize) -> UniquePtr; - } - // DCRTPoly unsafe extern "C++" { @@ -740,13 +733,13 @@ pub mod ffi fn Negate(self: &DCRTPoly) -> UniquePtr; // Generator functions - fn DCRTPolyGenFromConst(n: u32, size: usize, kRes: usize, value: &String) + fn DCRTPolyGenFromConst(n: u32, size: usize, k_res: usize, value: &String) -> UniquePtr; - fn DCRTPolyGenFromVec(n: u32, size: usize, kRes: usize, values: &Vec) + fn DCRTPolyGenFromVec(n: u32, size: usize, k_res: usize, values: &Vec) -> UniquePtr; - fn DCRTPolyGenFromBug(n: u32, size: usize, kRes: usize) -> UniquePtr; - fn DCRTPolyGenFromDug(n: u32, size: usize, kRes: usize) -> UniquePtr; - fn DCRTPolyGenFromDgg(n: u32, size: usize, kRes: usize, sigma: f64) -> UniquePtr; + fn DCRTPolyGenFromBug(n: u32, size: usize, k_res: usize) -> UniquePtr; + fn DCRTPolyGenFromDug(n: u32, size: usize, k_res: usize) -> UniquePtr; + fn DCRTPolyGenFromDgg(n: u32, size: usize, k_res: usize, sigma: f64) -> UniquePtr; // Arithmetic fn DCRTPolyAdd(rhs: &DCRTPoly, lhs: &DCRTPoly) -> UniquePtr; @@ -1165,8 +1158,18 @@ pub mod ffi // Trapdoor unsafe extern "C++" { - fn GetPublicMatrix(self: &DCRTTrapdoor) -> UniquePtr; + fn GetPublicMatrix(self: &DCRTTrapdoor) -> UniquePtr; fn GetTrapdoorPair(self: &DCRTTrapdoor) -> UniquePtr; + + // Generator functions + fn DCRTTrapdoorGen( + n: u32, + size: usize, + k_res: usize, + sigma: f64, + base: i64, + balanced: bool + ) -> UniquePtr; } } From f352d85b822d148f9c70149a08ec62786f086cb7 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:26:36 +0800 Subject: [PATCH 13/24] feat: update --- examples/dcrt_poly.rs | 3 +++ src/Trapdoor.cc | 9 +++++++-- src/Trapdoor.h | 2 +- src/lib.rs | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index b7b44ae..e328aef 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -60,4 +60,7 @@ fn main() { // sample trapdoor let sigma = 4.57825; let trapdoor = ffi::DCRTTrapdoorGen(n, size, k_res, sigma, 2, false); + // fetch a polynomial from the trapdoor public matrix + let public_matrix_poly_0_0 = trapdoor.GetPublicMatrixElement(0, 0); + println!("public_matrix_poly_0_0: {:?}", public_matrix_poly_0_0); } diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index 591b84b..270c047 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -13,9 +13,14 @@ std::unique_ptr DCRTTrapdoor::GetTrapdoorPair() const return std::make_unique(m_trapdoorPair); } -std::unique_ptr DCRTTrapdoor::GetPublicMatrix() const +std::unique_ptr DCRTTrapdoor::GetPublicMatrixElement(size_t row, size_t col) const { - return std::make_unique(m_publicMatrix); + if (row >= m_publicMatrix.GetRows() || col >= m_publicMatrix.GetCols()) { + return nullptr; + } + + lbcrypto::DCRTPoly copy = m_publicMatrix(row, col); + return std::make_unique(std::move(copy)); } // Generator functions diff --git a/src/Trapdoor.h b/src/Trapdoor.h index 019bc9a..a392d3b 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -22,7 +22,7 @@ class DCRTTrapdoor final DCRTTrapdoor& operator=(DCRTTrapdoor&&) = delete; [[nodiscard]] std::unique_ptr GetTrapdoorPair() const; - [[nodiscard]] std::unique_ptr GetPublicMatrix() const; + [[nodiscard]] std::unique_ptr GetPublicMatrixElement(size_t row, size_t col) const; }; // Generator functions diff --git a/src/lib.rs b/src/lib.rs index 4536277..2e57f40 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1158,7 +1158,7 @@ pub mod ffi // Trapdoor unsafe extern "C++" { - fn GetPublicMatrix(self: &DCRTTrapdoor) -> UniquePtr; + fn GetPublicMatrixElement(self: &DCRTTrapdoor, row: usize, col: usize) -> UniquePtr; fn GetTrapdoorPair(self: &DCRTTrapdoor) -> UniquePtr; // Generator functions From 32990d847b3e4b33d16b356f737428c207c8c358 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:36:40 +0800 Subject: [PATCH 14/24] feat: add `MatrixGen` --- .vscode/settings.json | 60 +++++++++++++++++++++++++++++++++++++++++++ examples/dcrt_poly.rs | 4 +++ src/Trapdoor.cc | 15 +++++++++++ src/Trapdoor.h | 8 ++++++ src/lib.rs | 6 +++++ 5 files changed, 93 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7d417dd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,60 @@ +{ + "files.associations": { + "*.mpc": "python", + "__bit_reference": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "execution": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "locale": "cpp", + "map": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "print": "cpp", + "queue": "cpp", + "ratio": "cpp", + "set": "cpp", + "span": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "variant": "cpp", + "vector": "cpp", + "memory": "cpp", + "algorithm": "cpp" + } +} \ No newline at end of file diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index e328aef..5e8816b 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -63,4 +63,8 @@ fn main() { // fetch a polynomial from the trapdoor public matrix let public_matrix_poly_0_0 = trapdoor.GetPublicMatrixElement(0, 0); println!("public_matrix_poly_0_0: {:?}", public_matrix_poly_0_0); + + // Generate an empty matrix + let matrix_empty = ffi::MatrixGen(n, size, k_res, 2, 2); + } diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index 270c047..a6456b1 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -46,4 +46,19 @@ std::unique_ptr DCRTTrapdoorGen( std::move(trapdoor.second) ); } + +// Matrix functions +std::unique_ptr MatrixGen( + usint n, + size_t size, + size_t kRes, + size_t nrow, + size_t ncol) +{ + auto params = std::make_shared>(2 * n, size, kRes); + auto zero_alloc = lbcrypto::DCRTPoly::Allocator(params, Format::EVALUATION); + Matrix matrix(zero_alloc, nrow, ncol); + return std::make_unique(std::move(matrix)); +} + } // openfhe \ No newline at end of file diff --git a/src/Trapdoor.h b/src/Trapdoor.h index a392d3b..78160d1 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -33,4 +33,12 @@ class DCRTTrapdoor final double sigma, int64_t base, bool balanced); + +// Matrix functions +[[nodiscard]] std::unique_ptr MatrixGen( + usint n, + size_t size, + size_t kRes, + size_t nrow, + size_t ncol); } // openfhe \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 2e57f40..0e8b192 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -753,6 +753,12 @@ pub mod ffi fn DCRTPolyGenNullParams() -> UniquePtr; } + // Matrix + unsafe extern "C++" + { + fn MatrixGen(n: u32, size: usize, k_res: usize, nrow: usize, ncol: usize) -> UniquePtr; + } + // KeyPairDCRTPoly unsafe extern "C++" { From 6c9746b5a0c4da575e4b7956644e1fc3398cb45b Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:47:21 +0800 Subject: [PATCH 15/24] feat: add `SetMatrixElement` --- examples/dcrt_poly.rs | 4 +++- src/Trapdoor.cc | 8 ++++++++ src/Trapdoor.h | 6 ++++++ src/lib.rs | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 5e8816b..974348f 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -65,6 +65,8 @@ fn main() { println!("public_matrix_poly_0_0: {:?}", public_matrix_poly_0_0); // Generate an empty matrix - let matrix_empty = ffi::MatrixGen(n, size, k_res, 2, 2); + let mut matrix_empty = ffi::MatrixGen(n, size, k_res, 2, 2); + // set the 0, 0 element of the matrix + ffi::SetMatrixElement(matrix_empty.as_mut().unwrap(), 0, 0, &poly_add); } diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index a6456b1..7243246 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -61,4 +61,12 @@ std::unique_ptr MatrixGen( return std::make_unique(std::move(matrix)); } +void SetMatrixElement( + Matrix& matrix, + size_t row, + size_t col, + const DCRTPoly& element) +{ + matrix(row, col) = element.GetPoly(); +} } // openfhe \ No newline at end of file diff --git a/src/Trapdoor.h b/src/Trapdoor.h index 78160d1..c038238 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -41,4 +41,10 @@ class DCRTTrapdoor final size_t kRes, size_t nrow, size_t ncol); + +void SetMatrixElement( + Matrix& matrix, + size_t row, + size_t col, + const DCRTPoly& element); } // openfhe \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 0e8b192..d49086d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -757,6 +757,7 @@ pub mod ffi unsafe extern "C++" { fn MatrixGen(n: u32, size: usize, k_res: usize, nrow: usize, ncol: usize) -> UniquePtr; + fn SetMatrixElement(matrix: Pin<&mut Matrix>, row: usize, col: usize, element: &DCRTPoly); } // KeyPairDCRTPoly From 8da85ba9f37879ada6620d881022c13001e04c5e Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:54:31 +0800 Subject: [PATCH 16/24] faet: add `GetMatrixElement` --- examples/dcrt_poly.rs | 8 ++++++-- src/Trapdoor.cc | 9 +++++++++ src/Trapdoor.h | 5 +++++ src/lib.rs | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 974348f..35f6750 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -65,8 +65,12 @@ fn main() { println!("public_matrix_poly_0_0: {:?}", public_matrix_poly_0_0); // Generate an empty matrix - let mut matrix_empty = ffi::MatrixGen(n, size, k_res, 2, 2); + let mut matrix = ffi::MatrixGen(n, size, k_res, 2, 2); // set the 0, 0 element of the matrix - ffi::SetMatrixElement(matrix_empty.as_mut().unwrap(), 0, 0, &poly_add); + ffi::SetMatrixElement(matrix.as_mut().unwrap(), 0, 0, &poly_add); + + // get the 0, 0 element of the matrix + let matrix_poly_0_0 = ffi::GetMatrixElement(&matrix, 0, 0); + assert_eq!(matrix_poly_0_0, poly_add); } diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index 7243246..5626b43 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -69,4 +69,13 @@ void SetMatrixElement( { matrix(row, col) = element.GetPoly(); } + +std::unique_ptr GetMatrixElement( + const Matrix& matrix, + size_t row, + size_t col) +{ + lbcrypto::DCRTPoly copy = matrix(row, col); + return std::make_unique(std::move(copy)); +} } // openfhe \ No newline at end of file diff --git a/src/Trapdoor.h b/src/Trapdoor.h index c038238..09ef0b4 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -47,4 +47,9 @@ void SetMatrixElement( size_t row, size_t col, const DCRTPoly& element); + +[[nodiscard]] std::unique_ptr GetMatrixElement( + const Matrix& matrix, + size_t row, + size_t col); } // openfhe \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d49086d..90f2329 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -758,6 +758,7 @@ pub mod ffi { fn MatrixGen(n: u32, size: usize, k_res: usize, nrow: usize, ncol: usize) -> UniquePtr; fn SetMatrixElement(matrix: Pin<&mut Matrix>, row: usize, col: usize, element: &DCRTPoly); + fn GetMatrixElement(matrix: &Matrix, row: usize, col: usize) -> UniquePtr; } // KeyPairDCRTPoly From 7639f088c55ca2ff26af8883e7a7396051851d15 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 18:01:25 +0800 Subject: [PATCH 17/24] feat: add `DCRTSquareMatTrapdoorGen` --- examples/dcrt_poly.rs | 4 + src/Trapdoor.cc | 25 + src/Trapdoor.h | 9 + src/lib.rs | 1867 ++++++++++++++++++++++++++--------------- 4 files changed, 1247 insertions(+), 658 deletions(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 35f6750..96a6d7e 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -73,4 +73,8 @@ fn main() { // get the 0, 0 element of the matrix let matrix_poly_0_0 = ffi::GetMatrixElement(&matrix, 0, 0); assert_eq!(matrix_poly_0_0, poly_add); + + // sample trapdoor for a square matrix target of size 2x2 + let d = 2; + let trapdoor_square = ffi::DCRTSquareMatTrapdoorGen(n, size, k_res, d, sigma, 2, false); } diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index 5626b43..86b3e3e 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -47,6 +47,31 @@ std::unique_ptr DCRTTrapdoorGen( ); } +std::unique_ptr DCRTSquareMatTrapdoorGen( + usint n, + size_t size, + size_t kRes, + size_t d, + double sigma, + int64_t base, + bool balanced) +{ + auto params = std::make_shared>(2 * n, size, kRes); + + auto trapdoor = lbcrypto::RLWETrapdoorUtility::TrapdoorGenSquareMat( + params, + sigma, + d, + base, + balanced + ); + + return std::make_unique( + std::move(trapdoor.first), + std::move(trapdoor.second) + ); +} + // Matrix functions std::unique_ptr MatrixGen( usint n, diff --git a/src/Trapdoor.h b/src/Trapdoor.h index 09ef0b4..a95c5cb 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -34,6 +34,15 @@ class DCRTTrapdoor final int64_t base, bool balanced); +[[nodiscard]] std::unique_ptr DCRTSquareMatTrapdoorGen( + usint n, + size_t size, + size_t kRes, + size_t d, + double sigma, + int64_t base, + bool balanced); + // Matrix functions [[nodiscard]] std::unique_ptr MatrixGen( usint n, diff --git a/src/lib.rs b/src/lib.rs index 90f2329..d4e3de9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,66 +2,57 @@ #![allow(non_snake_case)] #![allow(unused_imports)] -use cxx::{CxxVector, let_cxx_string}; pub use cxx; +use cxx::{let_cxx_string, CxxVector}; #[cxx::bridge(namespace = "openfhe")] -pub mod ffi -{ +pub mod ffi { #[repr(i32)] - enum COMPRESSION_LEVEL - { + enum COMPRESSION_LEVEL { COMPACT = 2, - SLACK = 3, + SLACK = 3, } #[repr(i32)] - enum DecryptionNoiseMode - { + enum DecryptionNoiseMode { FIXED_NOISE_DECRYPT = 0, NOISE_FLOODING_DECRYPT, } #[repr(i32)] - enum EncryptionTechnique - { + enum EncryptionTechnique { STANDARD = 0, EXTENDED, } #[repr(i32)] - enum ExecutionMode - { + enum ExecutionMode { EXEC_EVALUATION = 0, EXEC_NOISE_ESTIMATION, } #[repr(i32)] - enum Format - { + enum Format { EVALUATION = 0, - COEFFICIENT = 1 + COEFFICIENT = 1, } - #[repr(i32)] - enum KeySwitchTechnique - { + #[repr(i32)] + enum KeySwitchTechnique { INVALID_KS_TECH = 0, BV, HYBRID, } #[repr(i32)] - enum MultipartyMode - { + enum MultipartyMode { INVALID_MULTIPARTY_MODE = 0, FIXED_NOISE_MULTIPARTY, NOISE_FLOODING_MULTIPARTY, } #[repr(i32)] - enum MultiplicationTechnique - { + enum MultiplicationTechnique { BEHZ = 0, HPS, HPSPOVERQ, @@ -69,21 +60,19 @@ pub mod ffi } #[repr(i32)] - enum PKESchemeFeature - { - PKE = 0x01, - KEYSWITCH = 0x02, - PRE = 0x04, - LEVELEDSHE = 0x08, - ADVANCEDSHE = 0x10, - MULTIPARTY = 0x20, - FHE = 0x40, + enum PKESchemeFeature { + PKE = 0x01, + KEYSWITCH = 0x02, + PRE = 0x04, + LEVELEDSHE = 0x08, + ADVANCEDSHE = 0x10, + MULTIPARTY = 0x20, + FHE = 0x40, SCHEMESWITCH = 0x80, } #[repr(i32)] - enum PlaintextEncodings - { + enum PlaintextEncodings { INVALID_ENCODING = 0, COEF_PACKED_ENCODING, PACKED_ENCODING, @@ -92,8 +81,7 @@ pub mod ffi } #[repr(i32)] - enum ProxyReEncryptionMode - { + enum ProxyReEncryptionMode { NOT_SET = 0, INDCPA, FIXED_NOISE_HRA, @@ -101,8 +89,7 @@ pub mod ffi } #[repr(i32)] - enum ScalingTechnique - { + enum ScalingTechnique { FIXEDMANUAL = 0, FIXEDAUTO, FLEXIBLEAUTO, @@ -112,8 +99,7 @@ pub mod ffi } #[repr(i32)] - enum SCHEME - { + enum SCHEME { INVALID_SCHEME = 0, CKKSRNS_SCHEME, BFVRNS_SCHEME, @@ -121,16 +107,14 @@ pub mod ffi } #[repr(i32)] - enum SecretKeyDist - { - GAUSSIAN = 0, + enum SecretKeyDist { + GAUSSIAN = 0, UNIFORM_TERNARY = 1, - SPARSE_TERNARY = 2, + SPARSE_TERNARY = 2, } #[repr(i32)] - enum SecurityLevel - { + enum SecurityLevel { HEStd_128_classic, HEStd_192_classic, HEStd_256_classic, @@ -141,20 +125,17 @@ pub mod ffi } #[repr(i32)] - enum SerialMode - { + enum SerialMode { BINARY = 0, JSON = 1, } - struct ComplexPair - { + struct ComplexPair { re: f64, im: f64, } - unsafe extern "C++" - { + unsafe extern "C++" { // includes include!("openfhe/src/AssociativeContainers.h"); include!("openfhe/src/Ciphertext.h"); @@ -229,320 +210,581 @@ pub mod ffi } // CiphertextDCRTPoly - unsafe extern "C++" - { + unsafe extern "C++" { // Generator functions fn DCRTPolyGenNullCiphertext() -> UniquePtr; } // CryptoContextDCRTPoly - unsafe extern "C++" - { - fn ComposedEvalMult(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly) -> UniquePtr; - fn Compress(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - towersLeft: /* 1 */ u32) -> UniquePtr; - fn DecryptByCiphertextAndPrivateKey(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - plaintext: Pin<&mut Plaintext>) - -> UniquePtr; - fn DecryptByPrivateKeyAndCiphertext(self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - plaintext: Pin<&mut Plaintext>) - -> UniquePtr; + unsafe extern "C++" { + fn ComposedEvalMult( + self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn Compress( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + towersLeft: /* 1 */ u32, + ) -> UniquePtr; + fn DecryptByCiphertextAndPrivateKey( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + plaintext: Pin<&mut Plaintext>, + ) -> UniquePtr; + fn DecryptByPrivateKeyAndCiphertext( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + plaintext: Pin<&mut Plaintext>, + ) -> UniquePtr; fn EnableByFeature(self: &CryptoContextDCRTPoly, feature: PKESchemeFeature); fn EnableByMask(self: &CryptoContextDCRTPoly, featureMask: u32); - fn EncryptByPrivateKey(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - plaintext: &Plaintext) -> UniquePtr; - fn EncryptByPublicKey(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly, - plaintext: &Plaintext) -> UniquePtr; - fn EvalAddByCiphertextAndConst(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, constant: f64) - -> UniquePtr; - fn EvalAddByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext) - -> UniquePtr; - fn EvalAddByCiphertexts(self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly,ciphertext2: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalAddByConstAndCiphertext(self: &CryptoContextDCRTPoly, - constant: f64, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalAddByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalAddInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - constant: f64); - fn EvalAddInPlaceByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - plaintext: &Plaintext); - fn EvalAddInPlaceByCiphertexts(self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: &CiphertextDCRTPoly); - fn EvalAddInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, - ciphertext: Pin<&mut CiphertextDCRTPoly>); - fn EvalAddInPlaceByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: Pin<&mut CiphertextDCRTPoly>); - fn EvalAddMany(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts) - -> UniquePtr; - fn EvalAddManyInPlace(self: &CryptoContextDCRTPoly, - ciphertextVec: Pin<&mut VectorOfCiphertexts>) - -> UniquePtr; - fn EvalAddMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - plaintext: &Plaintext) - -> UniquePtr; - fn EvalAddMutableByCiphertexts(self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>) - -> UniquePtr; - fn EvalAddMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: Pin<&mut CiphertextDCRTPoly>) - -> UniquePtr; - fn EvalAddMutableInPlace(self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>); - fn EvalAtIndex(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, index: u32) - -> UniquePtr; - fn EvalAtIndexKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - indexList: &CxxVector, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly); - fn EvalAutomorphism(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, i: u32, - evalKeyMap: &MapFromIndexToEvalKey) -> UniquePtr; - fn EvalAutomorphismKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - indexList: &CxxVector) -> UniquePtr; - fn EvalBootstrap(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - numIterations: /* 1 */ u32, precision: /* 0 */ u32) - -> UniquePtr; - fn EvalBootstrapKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - slots: u32); + fn EncryptByPrivateKey( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + plaintext: &Plaintext, + ) -> UniquePtr; + fn EncryptByPublicKey( + self: &CryptoContextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, + plaintext: &Plaintext, + ) -> UniquePtr; + fn EvalAddByCiphertextAndConst( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + constant: f64, + ) -> UniquePtr; + fn EvalAddByCiphertextAndPlaintext( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + plaintext: &Plaintext, + ) -> UniquePtr; + fn EvalAddByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalAddByConstAndCiphertext( + self: &CryptoContextDCRTPoly, + constant: f64, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalAddByPlaintextAndCiphertext( + self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalAddInPlaceByCiphertextAndConst( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + constant: f64, + ); + fn EvalAddInPlaceByCiphertextAndPlaintext( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + plaintext: &Plaintext, + ); + fn EvalAddInPlaceByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: &CiphertextDCRTPoly, + ); + fn EvalAddInPlaceByConstAndCiphertext( + self: &CryptoContextDCRTPoly, + constant: f64, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ); + fn EvalAddInPlaceByPlaintextAndCiphertext( + self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ); + fn EvalAddMany( + self: &CryptoContextDCRTPoly, + ciphertextVec: &VectorOfCiphertexts, + ) -> UniquePtr; + fn EvalAddManyInPlace( + self: &CryptoContextDCRTPoly, + ciphertextVec: Pin<&mut VectorOfCiphertexts>, + ) -> UniquePtr; + fn EvalAddMutableByCiphertextAndPlaintext( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + plaintext: &Plaintext, + ) -> UniquePtr; + fn EvalAddMutableByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>, + ) -> UniquePtr; + fn EvalAddMutableByPlaintextAndCiphertext( + self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ) -> UniquePtr; + fn EvalAddMutableInPlace( + self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>, + ); + fn EvalAtIndex( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + index: u32, + ) -> UniquePtr; + fn EvalAtIndexKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + indexList: &CxxVector, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, + ); + fn EvalAutomorphism( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + i: u32, + evalKeyMap: &MapFromIndexToEvalKey, + ) -> UniquePtr; + fn EvalAutomorphismKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + indexList: &CxxVector, + ) -> UniquePtr; + fn EvalBootstrap( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + numIterations: /* 1 */ u32, + precision: /* 0 */ u32, + ) -> UniquePtr; + fn EvalBootstrapKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + slots: u32, + ); fn EvalBootstrapPrecompute(self: &CryptoContextDCRTPoly, slots: /* 0 */ u32); - fn EvalBootstrapSetup(self: &CryptoContextDCRTPoly, - levelBudget: /* {5, 4} */ &CxxVector, - dim1: /* {0, 0} */ &CxxVector, slots: /* 0 */ u32, - correctionFactor: /* 0 */ u32, precompute: /* true */ bool); - fn EvalCKKStoFHEW(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - numCtxts: /* 0 */ u32) -> UniquePtr; - fn EvalCKKStoFHEWKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly, - lwesk: &LWEPrivateKey); + fn EvalBootstrapSetup( + self: &CryptoContextDCRTPoly, + levelBudget: /* {5, 4} */ &CxxVector, + dim1: /* {0, 0} */ &CxxVector, + slots: /* 0 */ u32, + correctionFactor: /* 0 */ u32, + precompute: /* true */ bool, + ); + fn EvalCKKStoFHEW( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + numCtxts: /* 0 */ u32, + ) -> UniquePtr; + fn EvalCKKStoFHEWKeyGen( + self: &CryptoContextDCRTPoly, + keyPair: &KeyPairDCRTPoly, + lwesk: &LWEPrivateKey, + ); fn EvalCKKStoFHEWPrecompute(self: &CryptoContextDCRTPoly, scale: /* 1.0 */ f64); - fn EvalChebyshevFunction(self: &CryptoContextDCRTPoly, func: fn(f64, ret: &mut f64), - ciphertext: &CiphertextDCRTPoly, a: f64, b: f64, degree: u32) - -> UniquePtr; - fn EvalChebyshevSeries(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector, a: f64, b: f64) - -> UniquePtr; - fn EvalChebyshevSeriesLinear(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector, a: f64, b: f64) - -> UniquePtr; - fn EvalChebyshevSeriesPS(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector, a: f64, b: f64) - -> UniquePtr; - fn EvalCompareSchemeSwitching(self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, numCtxts: /* 0 */ u32, - numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64, unit: /* false */ bool) - -> UniquePtr; - fn EvalCompareSwitchPrecompute(self: &CryptoContextDCRTPoly, pLWE: u32, scaleSign: f64, - unit: bool); - fn EvalCos(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, b: f64, - degree: u32) -> UniquePtr; - fn EvalDivide(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, - b: f64, degree: u32) -> UniquePtr; - fn EvalFHEWtoCKKS(self: &CryptoContextDCRTPoly, - LWECiphertexts: Pin<&mut VectorOfLWECiphertexts>, numCtxts: /* 0 */ u32, - numSlots: /* 0 */ u32, p: /* 4 */ u32, pmin: /* 0.0 */ f64, - pmax: /* 2.0 */ f64, dim1: /* 0 */ u32) -> UniquePtr; - fn EvalFHEWtoCKKSKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly, - lwesk: &LWEPrivateKey, numSlots: /* 0 */ u32, - numCtxts: /* 0 */ u32, dim1: /* 0 */ u32, L: /* 0 */ u32); - fn EvalFastRotation(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - index: u32, m: u32, digits: &VectorOfDCRTPolys) - -> UniquePtr; - fn EvalFastRotationExt(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, index: u32, - digits: &VectorOfDCRTPolys, addFirst: bool) - -> UniquePtr; - fn EvalFastRotationPrecompute(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalInnerProductByCiphertexts(self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, batchSize: u32) - -> UniquePtr; - fn EvalInnerProductByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - plaintext: &Plaintext, batchSize: u32) - -> UniquePtr; - fn EvalInnerProductByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: &CiphertextDCRTPoly, - batchSize: u32) - -> UniquePtr; - fn EvalLinearWSumMutableByConstantsAndVectorOfCiphertexts(self: &CryptoContextDCRTPoly, - constantsVec: &CxxVector, - ciphertextVec: - Pin<&mut VectorOfCiphertexts>) - -> UniquePtr; - fn EvalLinearWSumMutableByVectorOfCiphertextsAndConstants(self: &CryptoContextDCRTPoly, - ciphertextVec: - Pin<&mut VectorOfCiphertexts>, - constantsVec: &CxxVector) - -> UniquePtr; - fn EvalLogistic(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, - b: f64, degree: u32) -> UniquePtr; - fn EvalMaxSchemeSwitching(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32, - numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64) -> UniquePtr; - fn EvalMaxSchemeSwitchingAlt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32, - numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64) -> UniquePtr; - fn EvalMerge(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts) - -> UniquePtr; - fn EvalMinSchemeSwitching(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32, - numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64) -> UniquePtr; - fn EvalMinSchemeSwitchingAlt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32, - numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64) -> UniquePtr; - fn EvalMultAndRelinearize(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalMultByCiphertextAndConst(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, constant: f64) - -> UniquePtr; - fn EvalMultByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext) - -> UniquePtr; - fn EvalMultByCiphertexts(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalMultByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, - ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalMultByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, plaintext: &Plaintext, - ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalMultInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - constant: f64); - fn EvalMultInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, - ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn EvalChebyshevFunction( + self: &CryptoContextDCRTPoly, + func: fn(f64, ret: &mut f64), + ciphertext: &CiphertextDCRTPoly, + a: f64, + b: f64, + degree: u32, + ) -> UniquePtr; + fn EvalChebyshevSeries( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector, + a: f64, + b: f64, + ) -> UniquePtr; + fn EvalChebyshevSeriesLinear( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector, + a: f64, + b: f64, + ) -> UniquePtr; + fn EvalChebyshevSeriesPS( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector, + a: f64, + b: f64, + ) -> UniquePtr; + fn EvalCompareSchemeSwitching( + self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, + numCtxts: /* 0 */ u32, + numSlots: /* 0 */ u32, + pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64, + unit: /* false */ bool, + ) -> UniquePtr; + fn EvalCompareSwitchPrecompute( + self: &CryptoContextDCRTPoly, + pLWE: u32, + scaleSign: f64, + unit: bool, + ); + fn EvalCos( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + a: f64, + b: f64, + degree: u32, + ) -> UniquePtr; + fn EvalDivide( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + a: f64, + b: f64, + degree: u32, + ) -> UniquePtr; + fn EvalFHEWtoCKKS( + self: &CryptoContextDCRTPoly, + LWECiphertexts: Pin<&mut VectorOfLWECiphertexts>, + numCtxts: /* 0 */ u32, + numSlots: /* 0 */ u32, + p: /* 4 */ u32, + pmin: /* 0.0 */ f64, + pmax: /* 2.0 */ f64, + dim1: /* 0 */ u32, + ) -> UniquePtr; + fn EvalFHEWtoCKKSKeyGen( + self: &CryptoContextDCRTPoly, + keyPair: &KeyPairDCRTPoly, + lwesk: &LWEPrivateKey, + numSlots: /* 0 */ u32, + numCtxts: /* 0 */ u32, + dim1: /* 0 */ u32, + L: /* 0 */ u32, + ); + fn EvalFastRotation( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + index: u32, + m: u32, + digits: &VectorOfDCRTPolys, + ) -> UniquePtr; + fn EvalFastRotationExt( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + index: u32, + digits: &VectorOfDCRTPolys, + addFirst: bool, + ) -> UniquePtr; + fn EvalFastRotationPrecompute( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalInnerProductByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, + batchSize: u32, + ) -> UniquePtr; + fn EvalInnerProductByCiphertextAndPlaintext( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + plaintext: &Plaintext, + batchSize: u32, + ) -> UniquePtr; + fn EvalInnerProductByPlaintextAndCiphertext( + self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: &CiphertextDCRTPoly, + batchSize: u32, + ) -> UniquePtr; + fn EvalLinearWSumMutableByConstantsAndVectorOfCiphertexts( + self: &CryptoContextDCRTPoly, + constantsVec: &CxxVector, + ciphertextVec: Pin<&mut VectorOfCiphertexts>, + ) -> UniquePtr; + fn EvalLinearWSumMutableByVectorOfCiphertextsAndConstants( + self: &CryptoContextDCRTPoly, + ciphertextVec: Pin<&mut VectorOfCiphertexts>, + constantsVec: &CxxVector, + ) -> UniquePtr; + fn EvalLogistic( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + a: f64, + b: f64, + degree: u32, + ) -> UniquePtr; + fn EvalMaxSchemeSwitching( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, + numValues: /* 0 */ u32, + numSlots: /* 0 */ u32, + pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64, + ) -> UniquePtr; + fn EvalMaxSchemeSwitchingAlt( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, + numValues: /* 0 */ u32, + numSlots: /* 0 */ u32, + pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64, + ) -> UniquePtr; + fn EvalMerge( + self: &CryptoContextDCRTPoly, + ciphertextVec: &VectorOfCiphertexts, + ) -> UniquePtr; + fn EvalMinSchemeSwitching( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, + numValues: /* 0 */ u32, + numSlots: /* 0 */ u32, + pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64, + ) -> UniquePtr; + fn EvalMinSchemeSwitchingAlt( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, + numValues: /* 0 */ u32, + numSlots: /* 0 */ u32, + pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64, + ) -> UniquePtr; + fn EvalMultAndRelinearize( + self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalMultByCiphertextAndConst( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + constant: f64, + ) -> UniquePtr; + fn EvalMultByCiphertextAndPlaintext( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + plaintext: &Plaintext, + ) -> UniquePtr; + fn EvalMultByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalMultByConstAndCiphertext( + self: &CryptoContextDCRTPoly, + constant: f64, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalMultByPlaintextAndCiphertext( + self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalMultInPlaceByCiphertextAndConst( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + constant: f64, + ); + fn EvalMultInPlaceByConstAndCiphertext( + self: &CryptoContextDCRTPoly, + constant: f64, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ); fn EvalMultKeyGen(self: &CryptoContextDCRTPoly, key: &PrivateKeyDCRTPoly); fn EvalMultKeysGen(self: &CryptoContextDCRTPoly, key: &PrivateKeyDCRTPoly); - fn EvalMultMany(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts) - -> UniquePtr; - fn EvalMultMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - plaintext: &Plaintext) - -> UniquePtr; - fn EvalMultMutableByCiphertexts(self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>) - -> UniquePtr; - fn EvalMultMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: Pin<&mut CiphertextDCRTPoly>) - -> UniquePtr; - fn EvalMultMutableInPlace(self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>); - fn EvalMultNoRelin(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly) -> UniquePtr; - fn EvalNegate(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalNegateInPlace(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>); - fn EvalPoly(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector) -> UniquePtr; - fn EvalPolyLinear(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector)-> UniquePtr; - fn EvalPolyPS(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector) -> UniquePtr; - fn EvalRotate(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, index: i32) - -> UniquePtr; - fn EvalRotateKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - indexList: &CxxVector, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly); - fn EvalSchemeSwitchingKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly, - lwesk: &LWEPrivateKey); - fn EvalSin(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, b: f64, - degree: u32) -> UniquePtr; - fn EvalSquare(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalSquareInPlace(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>); - fn EvalSquareMutable(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>) - -> UniquePtr; - fn EvalSubByCiphertextAndConst(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, constant: f64) - -> UniquePtr; - fn EvalSubByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext) - -> UniquePtr; - fn EvalSubByCiphertexts(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly) -> UniquePtr; - fn EvalSubByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, - ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalSubByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn EvalSubInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - constant: f64); - fn EvalSubInPlaceByCiphertexts(self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: &CiphertextDCRTPoly); - fn EvalSubInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, - ciphertext: Pin<&mut CiphertextDCRTPoly>); - fn EvalSubMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - plaintext: &Plaintext) - -> UniquePtr; - fn EvalSubMutableByCiphertexts(self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>) - -> UniquePtr; - fn EvalSubMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: Pin<&mut CiphertextDCRTPoly>) - -> UniquePtr; - fn EvalSubMutableInPlace(self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>); - fn EvalSum(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, batchSize: u32) - -> UniquePtr; - fn EvalSumCols(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, rowSize: u32, - evalSumKeyMap: &MapFromIndexToEvalKey) -> UniquePtr; - fn EvalSumColsKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly) - -> UniquePtr; - fn EvalSumKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly); - fn EvalSumRows(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, rowSize: u32, - evalSumKeyMap: &MapFromIndexToEvalKey, subringDim: /* 0 */ u32) - -> UniquePtr; - fn EvalSumRowsKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, - rowSize: /* 0 */ u32, subringDim: /* 0 */ u32) - -> UniquePtr; + fn EvalMultMany( + self: &CryptoContextDCRTPoly, + ciphertextVec: &VectorOfCiphertexts, + ) -> UniquePtr; + fn EvalMultMutableByCiphertextAndPlaintext( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + plaintext: &Plaintext, + ) -> UniquePtr; + fn EvalMultMutableByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>, + ) -> UniquePtr; + fn EvalMultMutableByPlaintextAndCiphertext( + self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ) -> UniquePtr; + fn EvalMultMutableInPlace( + self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>, + ); + fn EvalMultNoRelin( + self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalNegate( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalNegateInPlace( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ); + fn EvalPoly( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector, + ) -> UniquePtr; + fn EvalPolyLinear( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector, + ) -> UniquePtr; + fn EvalPolyPS( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector, + ) -> UniquePtr; + fn EvalRotate( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + index: i32, + ) -> UniquePtr; + fn EvalRotateKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + indexList: &CxxVector, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, + ); + fn EvalSchemeSwitchingKeyGen( + self: &CryptoContextDCRTPoly, + keyPair: &KeyPairDCRTPoly, + lwesk: &LWEPrivateKey, + ); + fn EvalSin( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + a: f64, + b: f64, + degree: u32, + ) -> UniquePtr; + fn EvalSquare( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalSquareInPlace( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ); + fn EvalSquareMutable( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ) -> UniquePtr; + fn EvalSubByCiphertextAndConst( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + constant: f64, + ) -> UniquePtr; + fn EvalSubByCiphertextAndPlaintext( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + plaintext: &Plaintext, + ) -> UniquePtr; + fn EvalSubByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalSubByConstAndCiphertext( + self: &CryptoContextDCRTPoly, + constant: f64, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalSubByPlaintextAndCiphertext( + self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn EvalSubInPlaceByCiphertextAndConst( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + constant: f64, + ); + fn EvalSubInPlaceByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: &CiphertextDCRTPoly, + ); + fn EvalSubInPlaceByConstAndCiphertext( + self: &CryptoContextDCRTPoly, + constant: f64, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ); + fn EvalSubMutableByCiphertextAndPlaintext( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + plaintext: &Plaintext, + ) -> UniquePtr; + fn EvalSubMutableByCiphertexts( + self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>, + ) -> UniquePtr; + fn EvalSubMutableByPlaintextAndCiphertext( + self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ) -> UniquePtr; + fn EvalSubMutableInPlace( + self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>, + ); + fn EvalSum( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + batchSize: u32, + ) -> UniquePtr; + fn EvalSumCols( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + rowSize: u32, + evalSumKeyMap: &MapFromIndexToEvalKey, + ) -> UniquePtr; + fn EvalSumColsKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, + ) -> UniquePtr; + fn EvalSumKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, + ); + fn EvalSumRows( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + rowSize: u32, + evalSumKeyMap: &MapFromIndexToEvalKey, + subringDim: /* 0 */ u32, + ) -> UniquePtr; + fn EvalSumRowsKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, + rowSize: /* 0 */ u32, + subringDim: /* 0 */ u32, + ) -> UniquePtr; fn FindAutomorphismIndex(self: &CryptoContextDCRTPoly, idx: u32) -> u32; - fn FindAutomorphismIndices(self: &CryptoContextDCRTPoly, idxList: &CxxVector) - -> UniquePtr>; - fn GetCryptoParameters(self: &CryptoContextDCRTPoly) - -> UniquePtr; + fn FindAutomorphismIndices( + self: &CryptoContextDCRTPoly, + idxList: &CxxVector, + ) -> UniquePtr>; + fn GetCryptoParameters( + self: &CryptoContextDCRTPoly, + ) -> UniquePtr; fn GetCyclotomicOrder(self: &CryptoContextDCRTPoly) -> u32; fn GetElementParams(self: &CryptoContextDCRTPoly) -> UniquePtr; fn GetEncodingParams(self: &CryptoContextDCRTPoly) -> UniquePtr; @@ -553,134 +795,237 @@ pub mod ffi fn GetScheme(self: &CryptoContextDCRTPoly) -> UniquePtr; fn GetSchemeId(self: &CryptoContextDCRTPoly) -> SCHEME; fn GetSwkFC(self: &CryptoContextDCRTPoly) -> UniquePtr; - fn IntMPBootAdd(self: &CryptoContextDCRTPoly, - sharesPairVec: Pin<&mut VectorOfVectorOfCiphertexts>) - -> UniquePtr; - fn IntMPBootAdjustScale(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn IntMPBootDecrypt(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - ciphertext: &CiphertextDCRTPoly, a: &CiphertextDCRTPoly) - -> UniquePtr; - fn IntMPBootEncrypt(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly, - sharesPair: &VectorOfCiphertexts, a: &CiphertextDCRTPoly, - ciphertext: &CiphertextDCRTPoly) -> UniquePtr; - fn IntMPBootRandomElementGen(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly) - -> UniquePtr; + fn IntMPBootAdd( + self: &CryptoContextDCRTPoly, + sharesPairVec: Pin<&mut VectorOfVectorOfCiphertexts>, + ) -> UniquePtr; + fn IntMPBootAdjustScale( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn IntMPBootDecrypt( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + a: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn IntMPBootEncrypt( + self: &CryptoContextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, + sharesPair: &VectorOfCiphertexts, + a: &CiphertextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr; + fn IntMPBootRandomElementGen( + self: &CryptoContextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, + ) -> UniquePtr; fn KeyGen(self: &CryptoContextDCRTPoly) -> UniquePtr; - fn KeySwitch(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - evalKey: &EvalKeyDCRTPoly) -> UniquePtr; - fn KeySwitchDown(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn KeySwitchDownFirstElement(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr; - fn KeySwitchExt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - addFirst: bool) -> UniquePtr; - fn KeySwitchGen(self: &CryptoContextDCRTPoly, oldPrivateKey: &PrivateKeyDCRTPoly, - newPrivateKey: &PrivateKeyDCRTPoly) -> UniquePtr; - fn KeySwitchInPlace(self: &CryptoContextDCRTPoly, ciphertext: Pin<&mut CiphertextDCRTPoly>, - evalKey: &EvalKeyDCRTPoly); - fn LevelReduce(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - evalKey: &EvalKeyDCRTPoly, levels: /* 1 */ usize) - -> UniquePtr; - fn LevelReduceInPlace(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, evalKey: &EvalKeyDCRTPoly, - levels: /* 1 */ usize); - fn MakeCKKSPackedPlaintextByVectorOfDouble(self: &CryptoContextDCRTPoly, - value: &CxxVector, - scaleDeg: /* 1 */ usize, level: /* 0 */ u32, - params: - /* DCRTPolyGenNullParams() */ &DCRTPolyParams, - slots: /* 0 */ u32) -> UniquePtr; - fn MakeCKKSPackedPlaintextByVectorOfComplex(self: &CryptoContextDCRTPoly, - value: &CxxVector<ComplexPair>, - scaleDeg: /* 1 */ usize, level: /* 0 */ u32, - params: - /* DCRTPolyGenNullParams() */ &DCRTPolyParams, - slots: /* 0 */ u32) -> UniquePtr<Plaintext>; - fn MakeCoefPackedPlaintext(self: &CryptoContextDCRTPoly, value: &CxxVector<i64>, - noiseScaleDeg: /* 1 */ usize, level: /* 0 */ u32) - -> UniquePtr<Plaintext>; - fn MakePackedPlaintext(self: &CryptoContextDCRTPoly, value: &CxxVector<i64>, - noiseScaleDeg: /* 1 */ usize, level: /* 0 */ u32) - -> UniquePtr<Plaintext>; + fn KeySwitch( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + evalKey: &EvalKeyDCRTPoly, + ) -> UniquePtr<CiphertextDCRTPoly>; + fn KeySwitchDown( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr<CiphertextDCRTPoly>; + fn KeySwitchDownFirstElement( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr<DCRTPoly>; + fn KeySwitchExt( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + addFirst: bool, + ) -> UniquePtr<CiphertextDCRTPoly>; + fn KeySwitchGen( + self: &CryptoContextDCRTPoly, + oldPrivateKey: &PrivateKeyDCRTPoly, + newPrivateKey: &PrivateKeyDCRTPoly, + ) -> UniquePtr<EvalKeyDCRTPoly>; + fn KeySwitchInPlace( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + evalKey: &EvalKeyDCRTPoly, + ); + fn LevelReduce( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + evalKey: &EvalKeyDCRTPoly, + levels: /* 1 */ usize, + ) -> UniquePtr<CiphertextDCRTPoly>; + fn LevelReduceInPlace( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + evalKey: &EvalKeyDCRTPoly, + levels: /* 1 */ usize, + ); + fn MakeCKKSPackedPlaintextByVectorOfDouble( + self: &CryptoContextDCRTPoly, + value: &CxxVector<f64>, + scaleDeg: /* 1 */ usize, + level: /* 0 */ u32, + params: /* DCRTPolyGenNullParams() */ &DCRTPolyParams, + slots: /* 0 */ u32, + ) -> UniquePtr<Plaintext>; + fn MakeCKKSPackedPlaintextByVectorOfComplex( + self: &CryptoContextDCRTPoly, + value: &CxxVector<ComplexPair>, + scaleDeg: /* 1 */ usize, + level: /* 0 */ u32, + params: /* DCRTPolyGenNullParams() */ &DCRTPolyParams, + slots: /* 0 */ u32, + ) -> UniquePtr<Plaintext>; + fn MakeCoefPackedPlaintext( + self: &CryptoContextDCRTPoly, + value: &CxxVector<i64>, + noiseScaleDeg: /* 1 */ usize, + level: /* 0 */ u32, + ) -> UniquePtr<Plaintext>; + fn MakePackedPlaintext( + self: &CryptoContextDCRTPoly, + value: &CxxVector<i64>, + noiseScaleDeg: /* 1 */ usize, + level: /* 0 */ u32, + ) -> UniquePtr<Plaintext>; fn MakeStringPlaintext(self: &CryptoContextDCRTPoly, s: &CxxString) - -> UniquePtr<Plaintext>; - fn ModReduce(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr<CiphertextDCRTPoly>; - fn ModReduceInPlace(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>); - fn MultiAddEvalAutomorphismKeys(self: &CryptoContextDCRTPoly, - evalKeyMap1: &MapFromIndexToEvalKey, - evalKeyMap2: &MapFromIndexToEvalKey, - keyId: /* "" */ &CxxString) - -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiAddEvalKeys(self: &CryptoContextDCRTPoly, evalKey1: &EvalKeyDCRTPoly, - evalKey2: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString) - -> UniquePtr<EvalKeyDCRTPoly>; - fn MultiAddEvalMultKeys(self: &CryptoContextDCRTPoly, evalKey1: &EvalKeyDCRTPoly, - evalKey2: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString) - -> UniquePtr<EvalKeyDCRTPoly>; - fn MultiAddEvalSumKeys(self: &CryptoContextDCRTPoly, evalKeyMap1: &MapFromIndexToEvalKey, - evalKeyMap2: &MapFromIndexToEvalKey, keyId: /* "" */ &CxxString) - -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiAddPubKeys(self: &CryptoContextDCRTPoly, publicKey1: &PublicKeyDCRTPoly, - publicKey2: &PublicKeyDCRTPoly, keyId: /* "" */ &CxxString) - -> UniquePtr<PublicKeyDCRTPoly>; - fn MultiEvalAtIndexKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - evalKeyMap: &MapFromIndexToEvalKey, indexList: &CxxVector<i32>, - keyId: /* "" */ &CxxString) -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiEvalAutomorphismKeyGen(self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - evalKeyMap: &MapFromIndexToEvalKey, - indexList: &CxxVector<u32>, keyId: /* "" */ &CxxString) - -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiEvalSumKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - evalKeyMap: &MapFromIndexToEvalKey, keyId: /* "" */ &CxxString) - -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiKeySwitchGen(self: &CryptoContextDCRTPoly, - originalPrivateKey: &PrivateKeyDCRTPoly, - newPrivateKey: &PrivateKeyDCRTPoly, evalKey: &EvalKeyDCRTPoly) - -> UniquePtr<EvalKeyDCRTPoly>; - fn MultiMultEvalKey(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, - evalKey: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString) - -> UniquePtr<EvalKeyDCRTPoly>; - fn MultipartyDecryptFusion(self: &CryptoContextDCRTPoly, - partialCiphertextVec: &VectorOfCiphertexts, - plaintext: Pin<&mut Plaintext>) -> UniquePtr<DecryptResult>; - fn MultipartyDecryptLead(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts, - privateKey: &PrivateKeyDCRTPoly) - -> UniquePtr<VectorOfCiphertexts>; - fn MultipartyDecryptMain(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts, - privateKey: &PrivateKeyDCRTPoly) - -> UniquePtr<VectorOfCiphertexts>; - fn MultipartyKeyGenByPublicKey(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly, - makeSparse: /* false */ bool, fresh: /* false */ bool) - -> UniquePtr<KeyPairDCRTPoly>; - fn MultipartyKeyGenByVectorOfPrivateKeys(self: &CryptoContextDCRTPoly, - privateKeyVec: &VectorOfPrivateKeys) - -> UniquePtr<KeyPairDCRTPoly>; - fn ReEncrypt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, - evalKey: &EvalKeyDCRTPoly, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly) - -> UniquePtr<CiphertextDCRTPoly>; - fn ReKeyGen(self: &CryptoContextDCRTPoly, oldPrivateKey: &PrivateKeyDCRTPoly, - newPublicKey: &PublicKeyDCRTPoly) -> UniquePtr<EvalKeyDCRTPoly>; - fn RecoverSharedKey(self: &CryptoContextDCRTPoly, sk: Pin<&mut PrivateKeyDCRTPoly>, - sk_shares: Pin<&mut UnorderedMapFromIndexToDCRTPoly>, N: u32, - threshold: u32, shareType: &CxxString); - fn Relinearize(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr<CiphertextDCRTPoly>; - fn RelinearizeInPlace(self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>); - fn Rescale(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) - -> UniquePtr<CiphertextDCRTPoly>; + -> UniquePtr<Plaintext>; + fn ModReduce( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr<CiphertextDCRTPoly>; + fn ModReduceInPlace(self: &CryptoContextDCRTPoly, ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn MultiAddEvalAutomorphismKeys( + self: &CryptoContextDCRTPoly, + evalKeyMap1: &MapFromIndexToEvalKey, + evalKeyMap2: &MapFromIndexToEvalKey, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiAddEvalKeys( + self: &CryptoContextDCRTPoly, + evalKey1: &EvalKeyDCRTPoly, + evalKey2: &EvalKeyDCRTPoly, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<EvalKeyDCRTPoly>; + fn MultiAddEvalMultKeys( + self: &CryptoContextDCRTPoly, + evalKey1: &EvalKeyDCRTPoly, + evalKey2: &EvalKeyDCRTPoly, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<EvalKeyDCRTPoly>; + fn MultiAddEvalSumKeys( + self: &CryptoContextDCRTPoly, + evalKeyMap1: &MapFromIndexToEvalKey, + evalKeyMap2: &MapFromIndexToEvalKey, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiAddPubKeys( + self: &CryptoContextDCRTPoly, + publicKey1: &PublicKeyDCRTPoly, + publicKey2: &PublicKeyDCRTPoly, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<PublicKeyDCRTPoly>; + fn MultiEvalAtIndexKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + evalKeyMap: &MapFromIndexToEvalKey, + indexList: &CxxVector<i32>, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiEvalAutomorphismKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + evalKeyMap: &MapFromIndexToEvalKey, + indexList: &CxxVector<u32>, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiEvalSumKeyGen( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + evalKeyMap: &MapFromIndexToEvalKey, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiKeySwitchGen( + self: &CryptoContextDCRTPoly, + originalPrivateKey: &PrivateKeyDCRTPoly, + newPrivateKey: &PrivateKeyDCRTPoly, + evalKey: &EvalKeyDCRTPoly, + ) -> UniquePtr<EvalKeyDCRTPoly>; + fn MultiMultEvalKey( + self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + evalKey: &EvalKeyDCRTPoly, + keyId: /* "" */ &CxxString, + ) -> UniquePtr<EvalKeyDCRTPoly>; + fn MultipartyDecryptFusion( + self: &CryptoContextDCRTPoly, + partialCiphertextVec: &VectorOfCiphertexts, + plaintext: Pin<&mut Plaintext>, + ) -> UniquePtr<DecryptResult>; + fn MultipartyDecryptLead( + self: &CryptoContextDCRTPoly, + ciphertextVec: &VectorOfCiphertexts, + privateKey: &PrivateKeyDCRTPoly, + ) -> UniquePtr<VectorOfCiphertexts>; + fn MultipartyDecryptMain( + self: &CryptoContextDCRTPoly, + ciphertextVec: &VectorOfCiphertexts, + privateKey: &PrivateKeyDCRTPoly, + ) -> UniquePtr<VectorOfCiphertexts>; + fn MultipartyKeyGenByPublicKey( + self: &CryptoContextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, + makeSparse: /* false */ bool, + fresh: /* false */ bool, + ) -> UniquePtr<KeyPairDCRTPoly>; + fn MultipartyKeyGenByVectorOfPrivateKeys( + self: &CryptoContextDCRTPoly, + privateKeyVec: &VectorOfPrivateKeys, + ) -> UniquePtr<KeyPairDCRTPoly>; + fn ReEncrypt( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + evalKey: &EvalKeyDCRTPoly, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, + ) -> UniquePtr<CiphertextDCRTPoly>; + fn ReKeyGen( + self: &CryptoContextDCRTPoly, + oldPrivateKey: &PrivateKeyDCRTPoly, + newPublicKey: &PublicKeyDCRTPoly, + ) -> UniquePtr<EvalKeyDCRTPoly>; + fn RecoverSharedKey( + self: &CryptoContextDCRTPoly, + sk: Pin<&mut PrivateKeyDCRTPoly>, + sk_shares: Pin<&mut UnorderedMapFromIndexToDCRTPoly>, + N: u32, + threshold: u32, + shareType: &CxxString, + ); + fn Relinearize( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr<CiphertextDCRTPoly>; + fn RelinearizeInPlace( + self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + ); + fn Rescale( + self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + ) -> UniquePtr<CiphertextDCRTPoly>; fn RescaleInPlace(self: &CryptoContextDCRTPoly, ciphertext: Pin<&mut CiphertextDCRTPoly>); fn SetKeyGenLevel(self: &CryptoContextDCRTPoly, level: usize); fn SetSchemeId(self: &CryptoContextDCRTPoly, schemeTag: SCHEME); fn SetSwkFC(self: &CryptoContextDCRTPoly, FHEWtoCKKSswk: &CiphertextDCRTPoly); - fn ShareKeys(self: &CryptoContextDCRTPoly, sk: &PrivateKeyDCRTPoly, N: u32, threshold: u32, - index: u32, shareType: &CxxString) - -> UniquePtr<UnorderedMapFromIndexToDCRTPoly>; + fn ShareKeys( + self: &CryptoContextDCRTPoly, + sk: &PrivateKeyDCRTPoly, + N: u32, + threshold: u32, + index: u32, + shareType: &CxxString, + ) -> UniquePtr<UnorderedMapFromIndexToDCRTPoly>; fn SparseKeyGen(self: &CryptoContextDCRTPoly) -> UniquePtr<KeyPairDCRTPoly>; // cxx currently does not support static class methods @@ -693,39 +1038,52 @@ pub mod ffi fn DCRTPolyClearEvalSumKeys(); fn DCRTPolyClearEvalSumKeysByCryptoContext(cryptoContext: &CryptoContextDCRTPoly); fn DCRTPolyClearEvalSumKeysById(id: &CxxString); - fn DCRTPolyGetCopyOfAllEvalAutomorphismKeys() - -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>; + fn DCRTPolyGetCopyOfAllEvalAutomorphismKeys( + ) -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>; fn DCRTPolyGetCopyOfAllEvalMultKeys() -> UniquePtr<MapFromStringToVectorOfEvalKeys>; fn DCRTPolyGetCopyOfAllEvalSumKeys() -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>; - fn DCRTPolyGetCopyOfEvalAutomorphismKeyMap(keyID: &CxxString) - -> UniquePtr<MapFromIndexToEvalKey>; + fn DCRTPolyGetCopyOfEvalAutomorphismKeyMap( + keyID: &CxxString, + ) -> UniquePtr<MapFromIndexToEvalKey>; fn DCRTPolyGetCopyOfEvalMultKeyVector(keyID: &CxxString) -> UniquePtr<VectorOfEvalKeys>; fn DCRTPolyGetCopyOfEvalSumKeyMap(id: &CxxString) -> UniquePtr<MapFromIndexToEvalKey>; - fn DCRTPolyGetExistingEvalAutomorphismKeyIndices(keyTag: &CxxString) - -> UniquePtr<SetOfUints>; - fn DCRTPolyGetPlaintextForDecrypt(pte: PlaintextEncodings, evp: &DCRTPolyParams, - ep: &EncodingParams) -> UniquePtr<Plaintext>; - fn DCRTPolyGetUniqueValues(oldValues: &SetOfUints, newValues: &SetOfUints) - -> UniquePtr<SetOfUints>; - fn DCRTPolyInsertEvalAutomorphismKey(evalKeyMap: &MapFromIndexToEvalKey, - keyTag: /* "" */ &CxxString); + fn DCRTPolyGetExistingEvalAutomorphismKeyIndices( + keyTag: &CxxString, + ) -> UniquePtr<SetOfUints>; + fn DCRTPolyGetPlaintextForDecrypt( + pte: PlaintextEncodings, + evp: &DCRTPolyParams, + ep: &EncodingParams, + ) -> UniquePtr<Plaintext>; + fn DCRTPolyGetUniqueValues( + oldValues: &SetOfUints, + newValues: &SetOfUints, + ) -> UniquePtr<SetOfUints>; + fn DCRTPolyInsertEvalAutomorphismKey( + evalKeyMap: &MapFromIndexToEvalKey, + keyTag: /* "" */ &CxxString, + ); fn DCRTPolyInsertEvalMultKey(evalKeyVec: &VectorOfEvalKeys); - fn DCRTPolyInsertEvalSumKey(mapToInsert: &MapFromIndexToEvalKey, - keyTag: /* "" */ &CxxString); + fn DCRTPolyInsertEvalSumKey( + mapToInsert: &MapFromIndexToEvalKey, + keyTag: /* "" */ &CxxString, + ); // Generator functions - fn DCRTPolyGenCryptoContextByParamsCKKSRNS(params: &ParamsCKKSRNS) - -> UniquePtr<CryptoContextDCRTPoly>; - fn DCRTPolyGenCryptoContextByParamsBFVRNS(params: &ParamsBFVRNS) - -> UniquePtr<CryptoContextDCRTPoly>; - fn DCRTPolyGenCryptoContextByParamsBGVRNS(params: &ParamsBGVRNS) - -> UniquePtr<CryptoContextDCRTPoly>; + fn DCRTPolyGenCryptoContextByParamsCKKSRNS( + params: &ParamsCKKSRNS, + ) -> UniquePtr<CryptoContextDCRTPoly>; + fn DCRTPolyGenCryptoContextByParamsBFVRNS( + params: &ParamsBFVRNS, + ) -> UniquePtr<CryptoContextDCRTPoly>; + fn DCRTPolyGenCryptoContextByParamsBGVRNS( + params: &ParamsBGVRNS, + ) -> UniquePtr<CryptoContextDCRTPoly>; fn DCRTPolyGenNullCryptoContext() -> UniquePtr<CryptoContextDCRTPoly>; } // DCRTPoly - unsafe extern "C++" - { + unsafe extern "C++" { fn GetString(self: &DCRTPoly) -> String; fn IsEqual(self: &DCRTPoly, other: &DCRTPoly) -> bool; fn GetCoefficients(self: &DCRTPoly) -> Vec<String>; @@ -733,13 +1091,22 @@ pub mod ffi fn Negate(self: &DCRTPoly) -> UniquePtr<DCRTPoly>; // Generator functions - fn DCRTPolyGenFromConst(n: u32, size: usize, k_res: usize, value: &String) - -> UniquePtr<DCRTPoly>; - fn DCRTPolyGenFromVec(n: u32, size: usize, k_res: usize, values: &Vec<String>) - -> UniquePtr<DCRTPoly>; + fn DCRTPolyGenFromConst( + n: u32, + size: usize, + k_res: usize, + value: &String, + ) -> UniquePtr<DCRTPoly>; + fn DCRTPolyGenFromVec( + n: u32, + size: usize, + k_res: usize, + values: &Vec<String>, + ) -> UniquePtr<DCRTPoly>; fn DCRTPolyGenFromBug(n: u32, size: usize, k_res: usize) -> UniquePtr<DCRTPoly>; fn DCRTPolyGenFromDug(n: u32, size: usize, k_res: usize) -> UniquePtr<DCRTPoly>; - fn DCRTPolyGenFromDgg(n: u32, size: usize, k_res: usize, sigma: f64) -> UniquePtr<DCRTPoly>; + fn DCRTPolyGenFromDgg(n: u32, size: usize, k_res: usize, sigma: f64) + -> UniquePtr<DCRTPoly>; // Arithmetic fn DCRTPolyAdd(rhs: &DCRTPoly, lhs: &DCRTPoly) -> UniquePtr<DCRTPoly>; @@ -747,30 +1114,32 @@ pub mod ffi } // DCRTPolyParams - unsafe extern "C++" - { + unsafe extern "C++" { // Generator functions fn DCRTPolyGenNullParams() -> UniquePtr<DCRTPolyParams>; } // Matrix - unsafe extern "C++" - { - fn MatrixGen(n: u32, size: usize, k_res: usize, nrow: usize, ncol: usize) -> UniquePtr<Matrix>; + unsafe extern "C++" { + fn MatrixGen( + n: u32, + size: usize, + k_res: usize, + nrow: usize, + ncol: usize, + ) -> UniquePtr<Matrix>; fn SetMatrixElement(matrix: Pin<&mut Matrix>, row: usize, col: usize, element: &DCRTPoly); fn GetMatrixElement(matrix: &Matrix, row: usize, col: usize) -> UniquePtr<DCRTPoly>; } // KeyPairDCRTPoly - unsafe extern "C++" - { + unsafe extern "C++" { fn GetPrivateKey(self: &KeyPairDCRTPoly) -> UniquePtr<PrivateKeyDCRTPoly>; fn GetPublicKey(self: &KeyPairDCRTPoly) -> UniquePtr<PublicKeyDCRTPoly>; } // Params - unsafe extern "C++" - { + unsafe extern "C++" { fn GetBatchSize(self: &Params) -> u32; fn GetDecryptionNoiseMode(self: &Params) -> DecryptionNoiseMode; fn GetDesiredPrecision(self: &Params) -> f64; @@ -801,23 +1170,31 @@ pub mod ffi fn GetStatisticalSecurity(self: &Params) -> f64; fn GetThresholdNumOfParties(self: &Params) -> u32; fn SetBatchSize(self: Pin<&mut Params>, batchSize0: u32); - fn SetDecryptionNoiseMode(self: Pin<&mut Params>, - decryptionNoiseMode0: DecryptionNoiseMode); + fn SetDecryptionNoiseMode( + self: Pin<&mut Params>, + decryptionNoiseMode0: DecryptionNoiseMode, + ); fn SetDesiredPrecision(self: Pin<&mut Params>, desiredPrecision0: f64); fn SetDigitSize(self: Pin<&mut Params>, digitSize0: u32); - fn SetEncryptionTechnique(self: Pin<&mut Params>, - encryptionTechnique0: EncryptionTechnique); + fn SetEncryptionTechnique( + self: Pin<&mut Params>, + encryptionTechnique0: EncryptionTechnique, + ); fn SetEvalAddCount(self: Pin<&mut Params>, evalAddCount0: u32); fn SetExecutionMode(self: Pin<&mut Params>, executionMode0: ExecutionMode); fn SetFirstModSize(self: Pin<&mut Params>, firstModSize0: u32); - fn SetInteractiveBootCompressionLevel(self: Pin<&mut Params>, - interactiveBootCompressionLevel0: COMPRESSION_LEVEL); + fn SetInteractiveBootCompressionLevel( + self: Pin<&mut Params>, + interactiveBootCompressionLevel0: COMPRESSION_LEVEL, + ); fn SetKeySwitchCount(self: Pin<&mut Params>, keySwitchCount0: u32); fn SetKeySwitchTechnique(self: Pin<&mut Params>, ksTech0: KeySwitchTechnique); fn SetMaxRelinSkDeg(self: Pin<&mut Params>, maxRelinSkDeg0: u32); fn SetMultipartyMode(self: Pin<&mut Params>, multipartyMode0: MultipartyMode); - fn SetMultiplicationTechnique(self: Pin<&mut Params>, - multiplicationTechnique0: MultiplicationTechnique); + fn SetMultiplicationTechnique( + self: Pin<&mut Params>, + multiplicationTechnique0: MultiplicationTechnique, + ); fn SetMultiplicativeDepth(self: Pin<&mut Params>, multiplicativeDepth0: u32); fn SetNoiseEstimate(self: Pin<&mut Params>, noiseEstimate0: f64); fn SetNumAdversarialQueries(self: Pin<&mut Params>, numAdversarialQueries0: u32); @@ -840,8 +1217,7 @@ pub mod ffi } // ParamsBFVRNS - unsafe extern "C++" - { + unsafe extern "C++" { fn GetBatchSize(self: &ParamsBFVRNS) -> u32; fn GetDecryptionNoiseMode(self: &ParamsBFVRNS) -> DecryptionNoiseMode; fn GetDesiredPrecision(self: &ParamsBFVRNS) -> f64; @@ -872,23 +1248,31 @@ pub mod ffi fn GetStatisticalSecurity(self: &ParamsBFVRNS) -> f64; fn GetThresholdNumOfParties(self: &ParamsBFVRNS) -> u32; fn SetBatchSize(self: Pin<&mut ParamsBFVRNS>, batchSize0: u32); - fn SetDecryptionNoiseMode(self: Pin<&mut ParamsBFVRNS>, - decryptionNoiseMode0: DecryptionNoiseMode); + fn SetDecryptionNoiseMode( + self: Pin<&mut ParamsBFVRNS>, + decryptionNoiseMode0: DecryptionNoiseMode, + ); fn SetDesiredPrecision(self: Pin<&mut ParamsBFVRNS>, desiredPrecision0: f64); fn SetDigitSize(self: Pin<&mut ParamsBFVRNS>, digitSize0: u32); - fn SetEncryptionTechnique(self: Pin<&mut ParamsBFVRNS>, - encryptionTechnique0: EncryptionTechnique); + fn SetEncryptionTechnique( + self: Pin<&mut ParamsBFVRNS>, + encryptionTechnique0: EncryptionTechnique, + ); fn SetEvalAddCount(self: Pin<&mut ParamsBFVRNS>, evalAddCount0: u32); fn SetExecutionMode(self: Pin<&mut ParamsBFVRNS>, executionMode0: ExecutionMode); fn SetFirstModSize(self: Pin<&mut ParamsBFVRNS>, firstModSize0: u32); - fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsBFVRNS>, - interactiveBootCompressionLevel0: COMPRESSION_LEVEL); + fn SetInteractiveBootCompressionLevel( + self: Pin<&mut ParamsBFVRNS>, + interactiveBootCompressionLevel0: COMPRESSION_LEVEL, + ); fn SetKeySwitchCount(self: Pin<&mut ParamsBFVRNS>, keySwitchCount0: u32); fn SetKeySwitchTechnique(self: Pin<&mut ParamsBFVRNS>, ksTech0: KeySwitchTechnique); fn SetMaxRelinSkDeg(self: Pin<&mut ParamsBFVRNS>, maxRelinSkDeg0: u32); fn SetMultipartyMode(self: Pin<&mut ParamsBFVRNS>, multipartyMode0: MultipartyMode); - fn SetMultiplicationTechnique(self: Pin<&mut ParamsBFVRNS>, - multiplicationTechnique0: MultiplicationTechnique); + fn SetMultiplicationTechnique( + self: Pin<&mut ParamsBFVRNS>, + multiplicationTechnique0: MultiplicationTechnique, + ); fn SetMultiplicativeDepth(self: Pin<&mut ParamsBFVRNS>, multiplicativeDepth0: u32); fn SetNoiseEstimate(self: Pin<&mut ParamsBFVRNS>, noiseEstimate0: f64); fn SetNumAdversarialQueries(self: Pin<&mut ParamsBFVRNS>, numAdversarialQueries0: u32); @@ -910,8 +1294,7 @@ pub mod ffi } // ParamsBGVRNS - unsafe extern "C++" - { + unsafe extern "C++" { fn GetBatchSize(self: &ParamsBGVRNS) -> u32; fn GetDecryptionNoiseMode(self: &ParamsBGVRNS) -> DecryptionNoiseMode; fn GetDesiredPrecision(self: &ParamsBGVRNS) -> f64; @@ -942,23 +1325,31 @@ pub mod ffi fn GetStatisticalSecurity(self: &ParamsBGVRNS) -> f64; fn GetThresholdNumOfParties(self: &ParamsBGVRNS) -> u32; fn SetBatchSize(self: Pin<&mut ParamsBGVRNS>, batchSize0: u32); - fn SetDecryptionNoiseMode(self: Pin<&mut ParamsBGVRNS>, - decryptionNoiseMode0: DecryptionNoiseMode); + fn SetDecryptionNoiseMode( + self: Pin<&mut ParamsBGVRNS>, + decryptionNoiseMode0: DecryptionNoiseMode, + ); fn SetDesiredPrecision(self: Pin<&mut ParamsBGVRNS>, desiredPrecision0: f64); fn SetDigitSize(self: Pin<&mut ParamsBGVRNS>, digitSize0: u32); - fn SetEncryptionTechnique(self: Pin<&mut ParamsBGVRNS>, - encryptionTechnique0: EncryptionTechnique); + fn SetEncryptionTechnique( + self: Pin<&mut ParamsBGVRNS>, + encryptionTechnique0: EncryptionTechnique, + ); fn SetEvalAddCount(self: Pin<&mut ParamsBGVRNS>, evalAddCount0: u32); fn SetExecutionMode(self: Pin<&mut ParamsBGVRNS>, executionMode0: ExecutionMode); fn SetFirstModSize(self: Pin<&mut ParamsBGVRNS>, firstModSize0: u32); - fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsBGVRNS>, - interactiveBootCompressionLevel0: COMPRESSION_LEVEL); + fn SetInteractiveBootCompressionLevel( + self: Pin<&mut ParamsBGVRNS>, + interactiveBootCompressionLevel0: COMPRESSION_LEVEL, + ); fn SetKeySwitchCount(self: Pin<&mut ParamsBGVRNS>, keySwitchCount0: u32); fn SetKeySwitchTechnique(self: Pin<&mut ParamsBGVRNS>, ksTech0: KeySwitchTechnique); fn SetMaxRelinSkDeg(self: Pin<&mut ParamsBGVRNS>, maxRelinSkDeg0: u32); fn SetMultipartyMode(self: Pin<&mut ParamsBGVRNS>, multipartyMode0: MultipartyMode); - fn SetMultiplicationTechnique(self: Pin<&mut ParamsBGVRNS>, - multiplicationTechnique0: MultiplicationTechnique); + fn SetMultiplicationTechnique( + self: Pin<&mut ParamsBGVRNS>, + multiplicationTechnique0: MultiplicationTechnique, + ); fn SetMultiplicativeDepth(self: Pin<&mut ParamsBGVRNS>, multiplicativeDepth0: u32); fn SetNoiseEstimate(self: Pin<&mut ParamsBGVRNS>, noiseEstimate0: f64); fn SetNumAdversarialQueries(self: Pin<&mut ParamsBGVRNS>, numAdversarialQueries0: u32); @@ -980,8 +1371,7 @@ pub mod ffi } // ParamsCKKSRNS - unsafe extern "C++" - { + unsafe extern "C++" { fn GetBatchSize(self: &ParamsCKKSRNS) -> u32; fn GetDecryptionNoiseMode(self: &ParamsCKKSRNS) -> DecryptionNoiseMode; fn GetDesiredPrecision(self: &ParamsCKKSRNS) -> f64; @@ -1012,23 +1402,31 @@ pub mod ffi fn GetStatisticalSecurity(self: &ParamsCKKSRNS) -> f64; fn GetThresholdNumOfParties(self: &ParamsCKKSRNS) -> u32; fn SetBatchSize(self: Pin<&mut ParamsCKKSRNS>, batchSize0: u32); - fn SetDecryptionNoiseMode(self: Pin<&mut ParamsCKKSRNS>, - decryptionNoiseMode0: DecryptionNoiseMode); + fn SetDecryptionNoiseMode( + self: Pin<&mut ParamsCKKSRNS>, + decryptionNoiseMode0: DecryptionNoiseMode, + ); fn SetDesiredPrecision(self: Pin<&mut ParamsCKKSRNS>, desiredPrecision0: f64); fn SetDigitSize(self: Pin<&mut ParamsCKKSRNS>, digitSize0: u32); - fn SetEncryptionTechnique(self: Pin<&mut ParamsCKKSRNS>, - encryptionTechnique0: EncryptionTechnique); + fn SetEncryptionTechnique( + self: Pin<&mut ParamsCKKSRNS>, + encryptionTechnique0: EncryptionTechnique, + ); fn SetEvalAddCount(self: Pin<&mut ParamsCKKSRNS>, evalAddCount0: u32); fn SetExecutionMode(self: Pin<&mut ParamsCKKSRNS>, executionMode0: ExecutionMode); fn SetFirstModSize(self: Pin<&mut ParamsCKKSRNS>, firstModSize0: u32); - fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsCKKSRNS>, - interactiveBootCompressionLevel0: COMPRESSION_LEVEL); + fn SetInteractiveBootCompressionLevel( + self: Pin<&mut ParamsCKKSRNS>, + interactiveBootCompressionLevel0: COMPRESSION_LEVEL, + ); fn SetKeySwitchCount(self: Pin<&mut ParamsCKKSRNS>, keySwitchCount0: u32); fn SetKeySwitchTechnique(self: Pin<&mut ParamsCKKSRNS>, ksTech0: KeySwitchTechnique); fn SetMaxRelinSkDeg(self: Pin<&mut ParamsCKKSRNS>, maxRelinSkDeg0: u32); fn SetMultipartyMode(self: Pin<&mut ParamsCKKSRNS>, multipartyMode0: MultipartyMode); - fn SetMultiplicationTechnique(self: Pin<&mut ParamsCKKSRNS>, - multiplicationTechnique0: MultiplicationTechnique); + fn SetMultiplicationTechnique( + self: Pin<&mut ParamsCKKSRNS>, + multiplicationTechnique0: MultiplicationTechnique, + ); fn SetMultiplicativeDepth(self: Pin<&mut ParamsCKKSRNS>, multiplicativeDepth0: u32); fn SetNoiseEstimate(self: Pin<&mut ParamsCKKSRNS>, noiseEstimate0: f64); fn SetNumAdversarialQueries(self: Pin<&mut ParamsCKKSRNS>, numAdversarialQueries0: u32); @@ -1046,13 +1444,13 @@ pub mod ffi // Generator functions fn GenParamsCKKSRNS() -> UniquePtr<ParamsCKKSRNS>; - fn GenParamsCKKSRNSbyVectorOfString(vals: &CxxVector<CxxString>) - -> UniquePtr<ParamsCKKSRNS>; + fn GenParamsCKKSRNSbyVectorOfString( + vals: &CxxVector<CxxString>, + ) -> UniquePtr<ParamsCKKSRNS>; } // Plaintext - unsafe extern "C++" - { + unsafe extern "C++" { fn Decode(self: &Plaintext) -> bool; fn Encode(self: &Plaintext) -> bool; fn GetCoefPackedValue(self: &Plaintext) -> &CxxVector<i64>; @@ -1086,87 +1484,123 @@ pub mod ffi } // PublicKeyDCRTPoly - unsafe extern "C++" - { + unsafe extern "C++" { // Generator functions fn DCRTPolyGenNullPublicKey() -> UniquePtr<PublicKeyDCRTPoly>; } // PrivateKeyDCRTPoly - unsafe extern "C++" - { + unsafe extern "C++" { // Generator functions fn DCRTPolyGenNullPrivateKey() -> UniquePtr<PrivateKeyDCRTPoly>; } // Serialize / Deserialize - unsafe extern "C++" - { + unsafe extern "C++" { // Ciphertext - fn DCRTPolyDeserializeCiphertextFromFile(ciphertextLocation: &CxxString, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - serialMode: SerialMode) -> bool; - fn DCRTPolySerializeCiphertextToFile(ciphertextLocation: &CxxString, - ciphertext: &CiphertextDCRTPoly, - serialMode: SerialMode) -> bool; + fn DCRTPolyDeserializeCiphertextFromFile( + ciphertextLocation: &CxxString, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + serialMode: SerialMode, + ) -> bool; + fn DCRTPolySerializeCiphertextToFile( + ciphertextLocation: &CxxString, + ciphertext: &CiphertextDCRTPoly, + serialMode: SerialMode, + ) -> bool; // CryptoContextDCRTPoly - fn DCRTPolyDeserializeCryptoContextFromFile(ccLocation: &CxxString, - cryptoContext: Pin<&mut CryptoContextDCRTPoly>, - serialMode: SerialMode) -> bool; - fn DCRTPolySerializeCryptoContextToFile(ccLocation: &CxxString, - cryptoContext: &CryptoContextDCRTPoly, - serialMode: SerialMode) -> bool; + fn DCRTPolyDeserializeCryptoContextFromFile( + ccLocation: &CxxString, + cryptoContext: Pin<&mut CryptoContextDCRTPoly>, + serialMode: SerialMode, + ) -> bool; + fn DCRTPolySerializeCryptoContextToFile( + ccLocation: &CxxString, + cryptoContext: &CryptoContextDCRTPoly, + serialMode: SerialMode, + ) -> bool; // EvalAutomorphismKey - fn DCRTPolyDeserializeEvalAutomorphismKeyFromFile(automorphismKeyLocation: &CxxString, - serialMode: SerialMode) -> bool; - fn DCRTPolySerializeEvalAutomorphismKeyByIdToFile(automorphismKeyLocation: &CxxString, - serialMode: SerialMode, id: &CxxString) - -> bool; - fn DCRTPolySerializeEvalAutomorphismKeyToFile(automorphismKeyLocation: &CxxString, - cryptoContext: &CryptoContextDCRTPoly, - serialMode: SerialMode) -> bool; + fn DCRTPolyDeserializeEvalAutomorphismKeyFromFile( + automorphismKeyLocation: &CxxString, + serialMode: SerialMode, + ) -> bool; + fn DCRTPolySerializeEvalAutomorphismKeyByIdToFile( + automorphismKeyLocation: &CxxString, + serialMode: SerialMode, + id: &CxxString, + ) -> bool; + fn DCRTPolySerializeEvalAutomorphismKeyToFile( + automorphismKeyLocation: &CxxString, + cryptoContext: &CryptoContextDCRTPoly, + serialMode: SerialMode, + ) -> bool; // EvalMultKey - fn DCRTPolyDeserializeEvalMultKeyFromFile(multKeyLocation: &CxxString, - serialMode: SerialMode) -> bool; - fn DCRTPolySerializeEvalMultKeyByIdToFile(multKeyLocation: &CxxString, - serialMode: SerialMode, id: &CxxString) -> bool; - fn DCRTPolySerializeEvalMultKeyToFile(multKeyLocation: &CxxString, - cryptoContext: &CryptoContextDCRTPoly, - serialMode: SerialMode) -> bool; + fn DCRTPolyDeserializeEvalMultKeyFromFile( + multKeyLocation: &CxxString, + serialMode: SerialMode, + ) -> bool; + fn DCRTPolySerializeEvalMultKeyByIdToFile( + multKeyLocation: &CxxString, + serialMode: SerialMode, + id: &CxxString, + ) -> bool; + fn DCRTPolySerializeEvalMultKeyToFile( + multKeyLocation: &CxxString, + cryptoContext: &CryptoContextDCRTPoly, + serialMode: SerialMode, + ) -> bool; // EvalSumKey - fn DCRTPolyDeserializeEvalSumKeyFromFile(sumKeyLocation: &CxxString, - serialMode: SerialMode) -> bool; - fn DCRTPolySerializeEvalSumKeyByIdToFile(sumKeyLocation: &CxxString, - serialMode: SerialMode, id: &CxxString) -> bool; - fn DCRTPolySerializeEvalSumKeyToFile(sumKeyLocation: &CxxString, - cryptoContext: &CryptoContextDCRTPoly, - serialMode: SerialMode) -> bool; + fn DCRTPolyDeserializeEvalSumKeyFromFile( + sumKeyLocation: &CxxString, + serialMode: SerialMode, + ) -> bool; + fn DCRTPolySerializeEvalSumKeyByIdToFile( + sumKeyLocation: &CxxString, + serialMode: SerialMode, + id: &CxxString, + ) -> bool; + fn DCRTPolySerializeEvalSumKeyToFile( + sumKeyLocation: &CxxString, + cryptoContext: &CryptoContextDCRTPoly, + serialMode: SerialMode, + ) -> bool; // PublicKey - fn DCRTPolyDeserializePublicKeyFromFile(publicKeyLocation: &CxxString, - publicKey: Pin<&mut PublicKeyDCRTPoly>, - serialMode: SerialMode) -> bool; - fn DCRTPolySerializePublicKeyToFile(publicKeyLocation: &CxxString, - publicKey: &PublicKeyDCRTPoly, - serialMode: SerialMode) -> bool; + fn DCRTPolyDeserializePublicKeyFromFile( + publicKeyLocation: &CxxString, + publicKey: Pin<&mut PublicKeyDCRTPoly>, + serialMode: SerialMode, + ) -> bool; + fn DCRTPolySerializePublicKeyToFile( + publicKeyLocation: &CxxString, + publicKey: &PublicKeyDCRTPoly, + serialMode: SerialMode, + ) -> bool; // PrivateKey - fn DCRTPolyDeserializePrivateKeyFromFile(privateKeyLocation: &CxxString, - privateKey: Pin<&mut PrivateKeyDCRTPoly>, - serialMode: SerialMode) -> bool; - fn DCRTPolySerializePrivateKeyToFile(privateKeyLocation: &CxxString, - privateKey: &PrivateKeyDCRTPoly, - serialMode: SerialMode) -> bool; + fn DCRTPolyDeserializePrivateKeyFromFile( + privateKeyLocation: &CxxString, + privateKey: Pin<&mut PrivateKeyDCRTPoly>, + serialMode: SerialMode, + ) -> bool; + fn DCRTPolySerializePrivateKeyToFile( + privateKeyLocation: &CxxString, + privateKey: &PrivateKeyDCRTPoly, + serialMode: SerialMode, + ) -> bool; } // Trapdoor - unsafe extern "C++" - { - fn GetPublicMatrixElement(self: &DCRTTrapdoor, row: usize, col: usize) -> UniquePtr<DCRTPoly>; + unsafe extern "C++" { + fn GetPublicMatrixElement( + self: &DCRTTrapdoor, + row: usize, + col: usize, + ) -> UniquePtr<DCRTPoly>; fn GetTrapdoorPair(self: &DCRTTrapdoor) -> UniquePtr<RLWETrapdoorPair>; // Generator functions @@ -1176,12 +1610,21 @@ pub mod ffi k_res: usize, sigma: f64, base: i64, - balanced: bool + balanced: bool, + ) -> UniquePtr<DCRTTrapdoor>; + + fn DCRTSquareMatTrapdoorGen( + n: u32, + size: usize, + k_res: usize, + d: usize, + sigma: f64, + base: i64, + balanced: bool, ) -> UniquePtr<DCRTTrapdoor>; } } - use crate::ffi::DCRTPoly; use std::fmt; @@ -1198,14 +1641,12 @@ impl PartialEq for DCRTPoly { } #[cfg(test)] -mod tests -{ +mod tests { use super::*; // TODO: add more tests #[test] - fn SimpleIntegersExample() - { + fn SimpleIntegersExample() { let mut _cc_params_bfvrns = ffi::GenParamsBFVRNS(); _cc_params_bfvrns.pin_mut().SetPlaintextModulus(65537); _cc_params_bfvrns.pin_mut().SetMultiplicativeDepth(2); @@ -1223,7 +1664,11 @@ mod tests _index_list.pin_mut().push(2); _index_list.pin_mut().push(-1); _index_list.pin_mut().push(-2); - _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::DCRTPolyGenNullPublicKey()); + _cc.EvalRotateKeyGen( + &_key_pair.GetPrivateKey(), + &_index_list, + &ffi::DCRTPolyGenNullPublicKey(), + ); let mut _vector_of_ints_1 = CxxVector::<i64>::new(); _vector_of_ints_1.pin_mut().push(1); @@ -1275,10 +1720,12 @@ mod tests let _cipher_text_3 = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_plain_text_3); let _cipher_text_add_1_2 = _cc.EvalAddByCiphertexts(&_cipher_text_1, &_cipher_text_2); - let _cipher_text_add_result = _cc.EvalAddByCiphertexts(&_cipher_text_add_1_2, &_cipher_text_3); + let _cipher_text_add_result = + _cc.EvalAddByCiphertexts(&_cipher_text_add_1_2, &_cipher_text_3); let _cipher_text_mul_1_2 = _cc.EvalMultByCiphertexts(&_cipher_text_1, &_cipher_text_2); - let _cipher_text_mult_result = _cc.EvalMultByCiphertexts(&_cipher_text_mul_1_2, &_cipher_text_3); + let _cipher_text_mult_result = + _cc.EvalMultByCiphertexts(&_cipher_text_mul_1_2, &_cipher_text_3); let _cipher_text_rot_1 = _cc.EvalRotate(&_cipher_text_1, 1); let _cipher_text_rot_2 = _cc.EvalRotate(&_cipher_text_1, 2); @@ -1286,17 +1733,41 @@ mod tests let _cipher_text_rot_4 = _cc.EvalRotate(&_cipher_text_1, -2); let mut _plain_text_add_result = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_add_result, _plain_text_add_result.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_cipher_text_add_result, + _plain_text_add_result.pin_mut(), + ); let mut _plain_text_mult_result = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_mult_result, _plain_text_mult_result.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_cipher_text_mult_result, + _plain_text_mult_result.pin_mut(), + ); let mut _plain_text_rot_1 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_1, _plain_text_rot_1.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_cipher_text_rot_1, + _plain_text_rot_1.pin_mut(), + ); let mut _plain_text_rot_2 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_2, _plain_text_rot_2.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_cipher_text_rot_2, + _plain_text_rot_2.pin_mut(), + ); let mut _plain_text_rot_3 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_3, _plain_text_rot_3.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_cipher_text_rot_3, + _plain_text_rot_3.pin_mut(), + ); let mut _plain_text_rot_4 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_4, _plain_text_rot_4.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_cipher_text_rot_4, + _plain_text_rot_4.pin_mut(), + ); _plain_text_rot_1.SetLength(_vector_of_ints_1.len()); _plain_text_rot_2.SetLength(_vector_of_ints_1.len()); @@ -1310,22 +1781,37 @@ mod tests println!("\nResults of homomorphic computations"); println!("#1 + #2 + #3: {}", _plain_text_add_result.GetString()); println!("#1 * #2 * #3: {}", _plain_text_mult_result.GetString()); - println!("Left rotation of #1 by 1: {}", _plain_text_rot_1.GetString()); - println!("Left rotation of #1 by 2: {}", _plain_text_rot_2.GetString()); - println!("Right rotation of #1 by -1: {}", _plain_text_rot_3.GetString()); - println!("Right rotation of #1 by -2: {}", _plain_text_rot_4.GetString()); + println!( + "Left rotation of #1 by 1: {}", + _plain_text_rot_1.GetString() + ); + println!( + "Left rotation of #1 by 2: {}", + _plain_text_rot_2.GetString() + ); + println!( + "Right rotation of #1 by -1: {}", + _plain_text_rot_3.GetString() + ); + println!( + "Right rotation of #1 by -2: {}", + _plain_text_rot_4.GetString() + ); } #[test] - fn SimpleRealNumbersExample() - { + fn SimpleRealNumbersExample() { let _mult_depth: u32 = 1; let _scale_mod_size: u32 = 50; let _batch_size: u32 = 8; let mut _cc_params_ckksrns = ffi::GenParamsCKKSRNS(); - _cc_params_ckksrns.pin_mut().SetMultiplicativeDepth(_mult_depth); - _cc_params_ckksrns.pin_mut().SetScalingModSize(_scale_mod_size); + _cc_params_ckksrns + .pin_mut() + .SetMultiplicativeDepth(_mult_depth); + _cc_params_ckksrns + .pin_mut() + .SetScalingModSize(_scale_mod_size); _cc_params_ckksrns.pin_mut().SetBatchSize(_batch_size); let _cc = ffi::DCRTPolyGenCryptoContextByParamsCKKSRNS(&_cc_params_ckksrns); @@ -1333,14 +1819,21 @@ mod tests _cc.EnableByFeature(ffi::PKESchemeFeature::KEYSWITCH); _cc.EnableByFeature(ffi::PKESchemeFeature::LEVELEDSHE); - println!("CKKS scheme is using ring dimension {}\n", _cc.GetRingDimension()); + println!( + "CKKS scheme is using ring dimension {}\n", + _cc.GetRingDimension() + ); let _key_pair = _cc.KeyGen(); _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey()); let mut _index_list = CxxVector::<i32>::new(); _index_list.pin_mut().push(1); _index_list.pin_mut().push(-2); - _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::DCRTPolyGenNullPublicKey()); + _cc.EvalRotateKeyGen( + &_key_pair.GetPrivateKey(), + &_index_list, + &ffi::DCRTPolyGenNullPublicKey(), + ); let mut _x_1 = CxxVector::<f64>::new(); _x_1.pin_mut().push(0.25); @@ -1363,8 +1856,10 @@ mod tests _x_2.pin_mut().push(0.25); let _dcrt_poly_params = ffi::DCRTPolyGenNullParams(); - let _p_txt_1 = _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_1, 1, 0, &_dcrt_poly_params, 0); - let _p_txt_2 = _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_2, 1, 0, &_dcrt_poly_params, 0); + let _p_txt_1 = + _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_1, 1, 0, &_dcrt_poly_params, 0); + let _p_txt_2 = + _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_2, 1, 0, &_dcrt_poly_params, 0); println!("Input x1: {}", _p_txt_1.GetString()); println!("Input x2: {}", _p_txt_2.GetString()); @@ -1384,37 +1879,68 @@ mod tests _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c1, _result.pin_mut()); _result.SetLength(_batch_size.try_into().unwrap()); - println!("x1 = {}Estimated precision in bits: {}", _result.GetString(), _result.GetLogPrecision()); - - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_add, _result.pin_mut()); + println!( + "x1 = {}Estimated precision in bits: {}", + _result.GetString(), + _result.GetLogPrecision() + ); + + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_c_add, + _result.pin_mut(), + ); _result.SetLength(_batch_size.try_into().unwrap()); - println!("x1 + x2 = {}Estimated precision in bits: {}",_result.GetString(), _result.GetLogPrecision()); - - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_sub, _result.pin_mut()); + println!( + "x1 + x2 = {}Estimated precision in bits: {}", + _result.GetString(), + _result.GetLogPrecision() + ); + + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_c_sub, + _result.pin_mut(), + ); _result.SetLength(_batch_size.try_into().unwrap()); println!("x1 - x2 = {}", _result.GetString()); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_scalar, _result.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_c_scalar, + _result.pin_mut(), + ); _result.SetLength(_batch_size.try_into().unwrap()); println!("4 * x1 = {}", _result.GetString()); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_mul, _result.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_c_mul, + _result.pin_mut(), + ); _result.SetLength(_batch_size.try_into().unwrap()); println!("x1 * x2 = {}", _result.GetString()); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_rot_1, _result.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_c_rot_1, + _result.pin_mut(), + ); _result.SetLength(_batch_size.try_into().unwrap()); println!("\nIn rotations, very small outputs (~10^-10 here) correspond to 0's:"); println!("x1 rotate by 1 = {}", _result.GetString()); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_rot_2, _result.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_c_rot_2, + _result.pin_mut(), + ); _result.SetLength(_batch_size.try_into().unwrap()); println!("x1 rotate by -2 = {}", _result.GetString()); } #[test] - fn PolynomialEvaluationExample() - { + fn PolynomialEvaluationExample() { use std::time::Instant; println!("\n======EXAMPLE FOR EVALPOLY========\n"); @@ -1429,11 +1955,15 @@ mod tests _cc.EnableByFeature(ffi::PKESchemeFeature::ADVANCEDSHE); let mut _input = CxxVector::<ffi::ComplexPair>::new(); - _input.pin_mut().push(ffi::ComplexPair{re: 0.5, im: 0.0}); - _input.pin_mut().push(ffi::ComplexPair{re: 0.7, im: 0.0}); - _input.pin_mut().push(ffi::ComplexPair{re: 0.9, im: 0.0}); - _input.pin_mut().push(ffi::ComplexPair{re: 0.95, im: 0.0}); - _input.pin_mut().push(ffi::ComplexPair{re: 0.93, im: 0.0}); + _input.pin_mut().push(ffi::ComplexPair { re: 0.5, im: 0.0 }); + _input.pin_mut().push(ffi::ComplexPair { re: 0.7, im: 0.0 }); + _input.pin_mut().push(ffi::ComplexPair { re: 0.9, im: 0.0 }); + _input + .pin_mut() + .push(ffi::ComplexPair { re: 0.95, im: 0.0 }); + _input + .pin_mut() + .push(ffi::ComplexPair { re: 0.93, im: 0.0 }); let _encoded_length = _input.len(); let mut _coefficients_1 = CxxVector::<f64>::new(); @@ -1488,7 +2018,8 @@ mod tests _coefficients_2.pin_mut().push(-0.5); let _dcrt_poly_params = ffi::DCRTPolyGenNullParams(); - let _plain_text_1 = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0); + let _plain_text_1 = + _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0); let _key_pair = _cc.KeyGen(); print!("Generating evaluation key for homomorphic multiplication..."); _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey()); @@ -1504,19 +2035,39 @@ mod tests let _time_eval_poly_2 = _start.elapsed(); let mut _plain_text_dec = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_result, _plain_text_dec.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_result, + _plain_text_dec.pin_mut(), + ); _plain_text_dec.SetLength(_encoded_length); let mut _plain_text_dec_2 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_result_2, _plain_text_dec_2.pin_mut()); + _cc.DecryptByPrivateKeyAndCiphertext( + &_key_pair.GetPrivateKey(), + &_result_2, + _plain_text_dec_2.pin_mut(), + ); _plain_text_dec_2.SetLength(_encoded_length); println!("\n Original Plaintext #1:"); println!("{}", _plain_text_1.GetString()); - println!("\n Result of evaluating a polynomial with coefficients [{} ]", _coefficients_1.iter().fold(String::new(), |acc, &arg| acc + " " + &arg.to_string())); + println!( + "\n Result of evaluating a polynomial with coefficients [{} ]", + _coefficients_1 + .iter() + .fold(String::new(), |acc, &arg| acc + " " + &arg.to_string()) + ); println!("{}", _plain_text_dec.GetString()); - println!("\n Expected result: (0.70519107, 1.38285078, 3.97211180, 5.60215665, 4.86357575)"); + println!( + "\n Expected result: (0.70519107, 1.38285078, 3.97211180, 5.60215665, 4.86357575)" + ); println!("\n Evaluation time: {:.0?}", _time_eval_poly_1); - println!("\n Result of evaluating a polynomial with coefficients [{} ]", _coefficients_2.iter().fold(String::new(), |acc, &arg| acc + " " + &arg.to_string())); + println!( + "\n Result of evaluating a polynomial with coefficients [{} ]", + _coefficients_2 + .iter() + .fold(String::new(), |acc, &arg| acc + " " + &arg.to_string()) + ); println!("{}\n", _plain_text_dec_2.GetString()); println!(" Expected result: (3.4515092326, 5.3752765397, 4.8993108833, 3.2495023573, 4.0485229982)"); print!("\n Evaluation time: {:.0?}\n", _time_eval_poly_2); From 9cfc7f3d5f8ba980c8394e8dd7e45c139f65d301 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 18:33:33 +0800 Subject: [PATCH 18/24] feat: add `DCRTSquareMatGaussSamp` --- examples/dcrt_poly.rs | 13 ++++++++----- src/Trapdoor.cc | 23 +++++++++++++++++++++++ src/Trapdoor.h | 10 ++++++++++ src/lib.rs | 11 +++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 96a6d7e..5bbbfed 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -57,11 +57,13 @@ fn main() { let poly_modulus = poly.GetModulus(); assert_eq!(poly_modulus, modulus); - // sample trapdoor + // gen trapdoor let sigma = 4.57825; - let trapdoor = ffi::DCRTTrapdoorGen(n, size, k_res, sigma, 2, false); + let trapdoor_output = ffi::DCRTTrapdoorGen(n, size, k_res, sigma, 2, false); + let _trapdoor = trapdoor_output.GetTrapdoorPair(); + // fetch a polynomial from the trapdoor public matrix - let public_matrix_poly_0_0 = trapdoor.GetPublicMatrixElement(0, 0); + let public_matrix_poly_0_0 = trapdoor_output.GetPublicMatrixElement(0, 0); println!("public_matrix_poly_0_0: {:?}", public_matrix_poly_0_0); // Generate an empty matrix @@ -74,7 +76,8 @@ fn main() { let matrix_poly_0_0 = ffi::GetMatrixElement(&matrix, 0, 0); assert_eq!(matrix_poly_0_0, poly_add); - // sample trapdoor for a square matrix target of size 2x2 + // gen trapdoor for a square matrix target of size 2x2 let d = 2; - let trapdoor_square = ffi::DCRTSquareMatTrapdoorGen(n, size, k_res, d, sigma, 2, false); + let trapdoor_output = ffi::DCRTSquareMatTrapdoorGen(n, size, k_res, d, sigma, 2, false); + let _trapdoor = trapdoor_output.GetTrapdoorPair(); } diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index 86b3e3e..8e90a25 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -72,6 +72,29 @@ std::unique_ptr<DCRTTrapdoor> DCRTSquareMatTrapdoorGen( ); } +// Gauss sample functions +std::unique_ptr<Matrix> DCRTSquareMatGaussSamp(usint n, usint k, const Matrix& publicMatrix, const RLWETrapdoorPair& trapdoor, const Matrix& U, int64_t base, double sigma) +{ + lbcrypto::DCRTPoly::DggType dgg(sigma); + + double c = (base + 1) * lbcrypto::SIGMA; + double s = lbcrypto::SPECTRAL_BOUND(n, k, base); + lbcrypto::DCRTPoly::DggType dggLargeSigma(sqrt(s * s - c * c)); + + auto result = lbcrypto::RLWETrapdoorUtility<lbcrypto::DCRTPoly>::GaussSampSquareMat( + n, + k, + publicMatrix, + trapdoor, + U, + dgg, + dggLargeSigma, + base + ); + + return std::make_unique<Matrix>(std::move(result)); +} + // Matrix functions std::unique_ptr<Matrix> MatrixGen( usint n, diff --git a/src/Trapdoor.h b/src/Trapdoor.h index a95c5cb..1228a36 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -43,6 +43,16 @@ class DCRTTrapdoor final int64_t base, bool balanced); +// Gauss sample functions +[[nodiscard]] std::unique_ptr<Matrix> DCRTSquareMatGaussSamp( + usint n, + usint k, + const Matrix& publicMatrix, + const RLWETrapdoorPair& trapdoor, + const Matrix& U, + int64_t base, + double sigma); + // Matrix functions [[nodiscard]] std::unique_ptr<Matrix> MatrixGen( usint n, diff --git a/src/lib.rs b/src/lib.rs index d4e3de9..a7c3fcb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1622,6 +1622,17 @@ pub mod ffi { base: i64, balanced: bool, ) -> UniquePtr<DCRTTrapdoor>; + + // Gauss sample functions + fn DCRTSquareMatGaussSamp( + n: u32, + k: u32, + public_matrix: &Matrix, + trapdoor: &RLWETrapdoorPair, + u: &Matrix, + base: i64, + sigma: f64, + ) -> UniquePtr<Matrix>; } } From 82e29fb9492ea5d53ddf8e1177321a558c00dc84 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Wed, 5 Mar 2025 19:45:03 +0800 Subject: [PATCH 19/24] chore: rename --- src/Trapdoor.cc | 2 +- src/Trapdoor.h | 2 +- src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index 8e90a25..1a3fbab 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -73,7 +73,7 @@ std::unique_ptr<DCRTTrapdoor> DCRTSquareMatTrapdoorGen( } // Gauss sample functions -std::unique_ptr<Matrix> DCRTSquareMatGaussSamp(usint n, usint k, const Matrix& publicMatrix, const RLWETrapdoorPair& trapdoor, const Matrix& U, int64_t base, double sigma) +std::unique_ptr<Matrix> DCRTSquareMatTrapdoorGaussSamp(usint n, usint k, const Matrix& publicMatrix, const RLWETrapdoorPair& trapdoor, const Matrix& U, int64_t base, double sigma) { lbcrypto::DCRTPoly::DggType dgg(sigma); diff --git a/src/Trapdoor.h b/src/Trapdoor.h index 1228a36..30d2d82 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -44,7 +44,7 @@ class DCRTTrapdoor final bool balanced); // Gauss sample functions -[[nodiscard]] std::unique_ptr<Matrix> DCRTSquareMatGaussSamp( +[[nodiscard]] std::unique_ptr<Matrix> DCRTSquareMatTrapdoorGaussSamp( usint n, usint k, const Matrix& publicMatrix, diff --git a/src/lib.rs b/src/lib.rs index a7c3fcb..b43d1d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1624,7 +1624,7 @@ pub mod ffi { ) -> UniquePtr<DCRTTrapdoor>; // Gauss sample functions - fn DCRTSquareMatGaussSamp( + fn DCRTSquareMatTrapdoorGaussSamp( n: u32, k: u32, public_matrix: &Matrix, From d4c4ea02c37de43320aa8de1359bda0cfdfbf5b6 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Thu, 6 Mar 2025 10:25:35 +0800 Subject: [PATCH 20/24] feat: update --- Cargo.toml | 2 ++ examples/dcrt_poly.rs | 56 ++++++++++++++++++++++++++++++------------- src/Trapdoor.cc | 29 +++++++++++++++++++++- src/Trapdoor.h | 10 ++++++++ src/lib.rs | 11 +++++++++ 5 files changed, 90 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22fc81f..7fb2031 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ repository = "https://github.com/fairmath/openfhe-rs" [dependencies] cxx = "1.0" +num-bigint = { version = "0.4", default-features = false } +num-traits = "0.2" [build-dependencies] cxx-build = "1.0" diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index 5bbbfed..f9a8bd3 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -1,3 +1,5 @@ +use num_bigint::BigUint; +use num_traits::Num; use openfhe::ffi; fn main() { @@ -57,27 +59,47 @@ fn main() { let poly_modulus = poly.GetModulus(); assert_eq!(poly_modulus, modulus); - // gen trapdoor let sigma = 4.57825; - let trapdoor_output = ffi::DCRTTrapdoorGen(n, size, k_res, sigma, 2, false); - let _trapdoor = trapdoor_output.GetTrapdoorPair(); + let base = 2; + let modulus_big_uint = BigUint::from_str_radix(&modulus, 10).unwrap(); + let k = modulus_big_uint.bits() as u32; - // fetch a polynomial from the trapdoor public matrix - let public_matrix_poly_0_0 = trapdoor_output.GetPublicMatrixElement(0, 0); - println!("public_matrix_poly_0_0: {:?}", public_matrix_poly_0_0); + // ** gen trapdoor ** + let trapdoor_output = ffi::DCRTTrapdoorGen(n, size, k_res, sigma, base, false); + let trapdoor = trapdoor_output.GetTrapdoorPair(); + let public_matrix = trapdoor_output.GetPublicMatrix(); - // Generate an empty matrix - let mut matrix = ffi::MatrixGen(n, size, k_res, 2, 2); + // sample a target polynomial + let u = ffi::DCRTPolyGenFromDug(n, size, k_res); - // set the 0, 0 element of the matrix - ffi::SetMatrixElement(matrix.as_mut().unwrap(), 0, 0, &poly_add); + // generate a preimage such that public_matrix * preimage = target_polynomial + let _preimage = ffi::DCRTTrapdoorGaussSamp(n, k, &public_matrix, &trapdoor, &u, base, sigma); - // get the 0, 0 element of the matrix - let matrix_poly_0_0 = ffi::GetMatrixElement(&matrix, 0, 0); - assert_eq!(matrix_poly_0_0, poly_add); - - // gen trapdoor for a square matrix target of size 2x2 + // ** gen trapdoor for a square matrix target of size 2x2 ** let d = 2; - let trapdoor_output = ffi::DCRTSquareMatTrapdoorGen(n, size, k_res, d, sigma, 2, false); - let _trapdoor = trapdoor_output.GetTrapdoorPair(); + let trapdoor_output_square = + ffi::DCRTSquareMatTrapdoorGen(n, size, k_res, d, sigma, base, false); + + let trapdoor_square = trapdoor_output_square.GetTrapdoorPair(); + let public_matrix_square = trapdoor_output_square.GetPublicMatrix(); + + // build the target matrix by sampling a random polynomial for each element + let mut target_matrix = ffi::MatrixGen(n, size, k_res, d, d); + for i in 0..d { + for j in 0..d { + let poly = ffi::DCRTPolyGenFromDug(n, size, k_res); + ffi::SetMatrixElement(target_matrix.as_mut().unwrap(), i, j, &poly); + } + } + + // generate a preimage such that public_matrix_square * preimage = target_matrix + let _preimage_square = ffi::DCRTSquareMatTrapdoorGaussSamp( + n, + k, + &public_matrix_square, + &trapdoor_square, + &target_matrix, + base, + sigma, + ); } diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index 1a3fbab..4945092 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -13,6 +13,11 @@ std::unique_ptr<RLWETrapdoorPair> DCRTTrapdoor::GetTrapdoorPair() const return std::make_unique<RLWETrapdoorPair>(m_trapdoorPair); } +std::unique_ptr<Matrix> DCRTTrapdoor::GetPublicMatrix() const +{ + return std::make_unique<Matrix>(m_publicMatrix); +} + std::unique_ptr<DCRTPoly> DCRTTrapdoor::GetPublicMatrixElement(size_t row, size_t col) const { if (row >= m_publicMatrix.GetRows() || col >= m_publicMatrix.GetCols()) { @@ -73,11 +78,33 @@ std::unique_ptr<DCRTTrapdoor> DCRTSquareMatTrapdoorGen( } // Gauss sample functions +std::unique_ptr<Matrix> DCRTTrapdoorGaussSamp(usint n, usint k, const Matrix& publicMatrix, const RLWETrapdoorPair& trapdoor, const DCRTPoly& u, int64_t base, double sigma) +{ + lbcrypto::DCRTPoly::DggType dgg(sigma); + + double c = (base + 1) * sigma; + double s = lbcrypto::SPECTRAL_BOUND(n, k, base); + lbcrypto::DCRTPoly::DggType dggLargeSigma(sqrt(s * s - c * c)); + + auto result = lbcrypto::RLWETrapdoorUtility<lbcrypto::DCRTPoly>::GaussSamp( + n, + k, + publicMatrix, + trapdoor, + u.GetPoly(), + dgg, + dggLargeSigma, + base + ); + + return std::make_unique<Matrix>(std::move(result)); +} + std::unique_ptr<Matrix> DCRTSquareMatTrapdoorGaussSamp(usint n, usint k, const Matrix& publicMatrix, const RLWETrapdoorPair& trapdoor, const Matrix& U, int64_t base, double sigma) { lbcrypto::DCRTPoly::DggType dgg(sigma); - double c = (base + 1) * lbcrypto::SIGMA; + double c = (base + 1) * sigma; double s = lbcrypto::SPECTRAL_BOUND(n, k, base); lbcrypto::DCRTPoly::DggType dggLargeSigma(sqrt(s * s - c * c)); diff --git a/src/Trapdoor.h b/src/Trapdoor.h index 30d2d82..3a20163 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -22,6 +22,7 @@ class DCRTTrapdoor final DCRTTrapdoor& operator=(DCRTTrapdoor&&) = delete; [[nodiscard]] std::unique_ptr<RLWETrapdoorPair> GetTrapdoorPair() const; + [[nodiscard]] std::unique_ptr<Matrix> GetPublicMatrix() const; [[nodiscard]] std::unique_ptr<DCRTPoly> GetPublicMatrixElement(size_t row, size_t col) const; }; @@ -44,6 +45,15 @@ class DCRTTrapdoor final bool balanced); // Gauss sample functions +[[nodiscard]] std::unique_ptr<Matrix> DCRTTrapdoorGaussSamp( + usint n, + usint k, + const Matrix& publicMatrix, + const RLWETrapdoorPair& trapdoor, + const DCRTPoly& u, + int64_t base, + double sigma); + [[nodiscard]] std::unique_ptr<Matrix> DCRTSquareMatTrapdoorGaussSamp( usint n, usint k, diff --git a/src/lib.rs b/src/lib.rs index b43d1d3..a1ae5e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1596,6 +1596,7 @@ pub mod ffi { // Trapdoor unsafe extern "C++" { + fn GetPublicMatrix(self: &DCRTTrapdoor) -> UniquePtr<Matrix>; fn GetPublicMatrixElement( self: &DCRTTrapdoor, row: usize, @@ -1624,6 +1625,16 @@ pub mod ffi { ) -> UniquePtr<DCRTTrapdoor>; // Gauss sample functions + fn DCRTTrapdoorGaussSamp( + n: u32, + k: u32, + public_matrix: &Matrix, + trapdoor: &RLWETrapdoorPair, + u: &DCRTPoly, + base: i64, + sigma: f64, + ) -> UniquePtr<Matrix>; + fn DCRTSquareMatTrapdoorGaussSamp( n: u32, k: u32, From 7fc7b7c69787ea9f7edfaadb5c7e05065c7b3b0c Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Thu, 6 Mar 2025 10:27:52 +0800 Subject: [PATCH 21/24] Delete settings.json --- .vscode/settings.json | 60 ------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7d417dd..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "files.associations": { - "*.mpc": "python", - "__bit_reference": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__node_handle": "cpp", - "__split_buffer": "cpp", - "__threading_support": "cpp", - "__tree": "cpp", - "__verbose_abort": "cpp", - "array": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "execution": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "locale": "cpp", - "map": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "print": "cpp", - "queue": "cpp", - "ratio": "cpp", - "set": "cpp", - "span": "cpp", - "sstream": "cpp", - "stack": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "string_view": "cpp", - "tuple": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "variant": "cpp", - "vector": "cpp", - "memory": "cpp", - "algorithm": "cpp" - } -} \ No newline at end of file From 96590beadbb05574feaf5829cda96831480f8cce Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Thu, 6 Mar 2025 10:31:59 +0800 Subject: [PATCH 22/24] Update lib.rs --- src/lib.rs | 1846 +++++++++++++++++++--------------------------------- 1 file changed, 654 insertions(+), 1192 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a1ae5e7..21b4dd3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,57 +2,66 @@ #![allow(non_snake_case)] #![allow(unused_imports)] +use cxx::{CxxVector, let_cxx_string}; pub use cxx; -use cxx::{let_cxx_string, CxxVector}; #[cxx::bridge(namespace = "openfhe")] -pub mod ffi { +pub mod ffi +{ #[repr(i32)] - enum COMPRESSION_LEVEL { + enum COMPRESSION_LEVEL + { COMPACT = 2, - SLACK = 3, + SLACK = 3, } #[repr(i32)] - enum DecryptionNoiseMode { + enum DecryptionNoiseMode + { FIXED_NOISE_DECRYPT = 0, NOISE_FLOODING_DECRYPT, } #[repr(i32)] - enum EncryptionTechnique { + enum EncryptionTechnique + { STANDARD = 0, EXTENDED, } #[repr(i32)] - enum ExecutionMode { + enum ExecutionMode + { EXEC_EVALUATION = 0, EXEC_NOISE_ESTIMATION, } #[repr(i32)] - enum Format { + enum Format + { EVALUATION = 0, - COEFFICIENT = 1, + COEFFICIENT = 1 } - #[repr(i32)] - enum KeySwitchTechnique { + #[repr(i32)] + enum KeySwitchTechnique + { INVALID_KS_TECH = 0, BV, HYBRID, } #[repr(i32)] - enum MultipartyMode { + enum MultipartyMode + { INVALID_MULTIPARTY_MODE = 0, FIXED_NOISE_MULTIPARTY, NOISE_FLOODING_MULTIPARTY, } #[repr(i32)] - enum MultiplicationTechnique { + enum MultiplicationTechnique + { BEHZ = 0, HPS, HPSPOVERQ, @@ -60,19 +69,21 @@ pub mod ffi { } #[repr(i32)] - enum PKESchemeFeature { - PKE = 0x01, - KEYSWITCH = 0x02, - PRE = 0x04, - LEVELEDSHE = 0x08, - ADVANCEDSHE = 0x10, - MULTIPARTY = 0x20, - FHE = 0x40, + enum PKESchemeFeature + { + PKE = 0x01, + KEYSWITCH = 0x02, + PRE = 0x04, + LEVELEDSHE = 0x08, + ADVANCEDSHE = 0x10, + MULTIPARTY = 0x20, + FHE = 0x40, SCHEMESWITCH = 0x80, } #[repr(i32)] - enum PlaintextEncodings { + enum PlaintextEncodings + { INVALID_ENCODING = 0, COEF_PACKED_ENCODING, PACKED_ENCODING, @@ -81,7 +92,8 @@ pub mod ffi { } #[repr(i32)] - enum ProxyReEncryptionMode { + enum ProxyReEncryptionMode + { NOT_SET = 0, INDCPA, FIXED_NOISE_HRA, @@ -89,7 +101,8 @@ pub mod ffi { } #[repr(i32)] - enum ScalingTechnique { + enum ScalingTechnique + { FIXEDMANUAL = 0, FIXEDAUTO, FLEXIBLEAUTO, @@ -99,7 +112,8 @@ pub mod ffi { } #[repr(i32)] - enum SCHEME { + enum SCHEME + { INVALID_SCHEME = 0, CKKSRNS_SCHEME, BFVRNS_SCHEME, @@ -107,14 +121,16 @@ pub mod ffi { } #[repr(i32)] - enum SecretKeyDist { - GAUSSIAN = 0, + enum SecretKeyDist + { + GAUSSIAN = 0, UNIFORM_TERNARY = 1, - SPARSE_TERNARY = 2, + SPARSE_TERNARY = 2, } #[repr(i32)] - enum SecurityLevel { + enum SecurityLevel + { HEStd_128_classic, HEStd_192_classic, HEStd_256_classic, @@ -125,17 +141,20 @@ pub mod ffi { } #[repr(i32)] - enum SerialMode { + enum SerialMode + { BINARY = 0, JSON = 1, } - struct ComplexPair { + struct ComplexPair + { re: f64, im: f64, } - unsafe extern "C++" { + unsafe extern "C++" + { // includes include!("openfhe/src/AssociativeContainers.h"); include!("openfhe/src/Ciphertext.h"); @@ -210,581 +229,320 @@ pub mod ffi { } // CiphertextDCRTPoly - unsafe extern "C++" { + unsafe extern "C++" + { // Generator functions fn DCRTPolyGenNullCiphertext() -> UniquePtr<CiphertextDCRTPoly>; } // CryptoContextDCRTPoly - unsafe extern "C++" { - fn ComposedEvalMult( - self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn Compress( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - towersLeft: /* 1 */ u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn DecryptByCiphertextAndPrivateKey( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - plaintext: Pin<&mut Plaintext>, - ) -> UniquePtr<DecryptResult>; - fn DecryptByPrivateKeyAndCiphertext( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - plaintext: Pin<&mut Plaintext>, - ) -> UniquePtr<DecryptResult>; + unsafe extern "C++" + { + fn ComposedEvalMult(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>; + fn Compress(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + towersLeft: /* 1 */ u32) -> UniquePtr<CiphertextDCRTPoly>; + fn DecryptByCiphertextAndPrivateKey(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + plaintext: Pin<&mut Plaintext>) + -> UniquePtr<DecryptResult>; + fn DecryptByPrivateKeyAndCiphertext(self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + plaintext: Pin<&mut Plaintext>) + -> UniquePtr<DecryptResult>; fn EnableByFeature(self: &CryptoContextDCRTPoly, feature: PKESchemeFeature); fn EnableByMask(self: &CryptoContextDCRTPoly, featureMask: u32); - fn EncryptByPrivateKey( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - plaintext: &Plaintext, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EncryptByPublicKey( - self: &CryptoContextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, - plaintext: &Plaintext, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddByCiphertextAndConst( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - constant: f64, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddByCiphertextAndPlaintext( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - plaintext: &Plaintext, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddByConstAndCiphertext( - self: &CryptoContextDCRTPoly, - constant: f64, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddByPlaintextAndCiphertext( - self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddInPlaceByCiphertextAndConst( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - constant: f64, - ); - fn EvalAddInPlaceByCiphertextAndPlaintext( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - plaintext: &Plaintext, - ); - fn EvalAddInPlaceByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: &CiphertextDCRTPoly, - ); - fn EvalAddInPlaceByConstAndCiphertext( - self: &CryptoContextDCRTPoly, - constant: f64, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ); - fn EvalAddInPlaceByPlaintextAndCiphertext( - self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ); - fn EvalAddMany( - self: &CryptoContextDCRTPoly, - ciphertextVec: &VectorOfCiphertexts, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddManyInPlace( - self: &CryptoContextDCRTPoly, - ciphertextVec: Pin<&mut VectorOfCiphertexts>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddMutableByCiphertextAndPlaintext( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - plaintext: &Plaintext, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddMutableByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddMutableByPlaintextAndCiphertext( - self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAddMutableInPlace( - self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>, - ); - fn EvalAtIndex( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - index: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAtIndexKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - indexList: &CxxVector<i32>, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, - ); - fn EvalAutomorphism( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - i: u32, - evalKeyMap: &MapFromIndexToEvalKey, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalAutomorphismKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - indexList: &CxxVector<u32>, - ) -> UniquePtr<MapFromIndexToEvalKey>; - fn EvalBootstrap( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - numIterations: /* 1 */ u32, - precision: /* 0 */ u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalBootstrapKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - slots: u32, - ); + fn EncryptByPrivateKey(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + plaintext: &Plaintext) -> UniquePtr<CiphertextDCRTPoly>; + fn EncryptByPublicKey(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly, + plaintext: &Plaintext) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddByCiphertextAndConst(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, constant: f64) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddByCiphertexts(self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly,ciphertext2: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddByConstAndCiphertext(self: &CryptoContextDCRTPoly, + constant: f64, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + constant: f64); + fn EvalAddInPlaceByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + plaintext: &Plaintext); + fn EvalAddInPlaceByCiphertexts(self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: &CiphertextDCRTPoly); + fn EvalAddInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, + ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn EvalAddInPlaceByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn EvalAddMany(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddManyInPlace(self: &CryptoContextDCRTPoly, + ciphertextVec: Pin<&mut VectorOfCiphertexts>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + plaintext: &Plaintext) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddMutableByCiphertexts(self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: Pin<&mut CiphertextDCRTPoly>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAddMutableInPlace(self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>); + fn EvalAtIndex(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, index: u32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAtIndexKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + indexList: &CxxVector<i32>, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly); + fn EvalAutomorphism(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, i: u32, + evalKeyMap: &MapFromIndexToEvalKey) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalAutomorphismKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + indexList: &CxxVector<u32>) -> UniquePtr<MapFromIndexToEvalKey>; + fn EvalBootstrap(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + numIterations: /* 1 */ u32, precision: /* 0 */ u32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalBootstrapKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + slots: u32); fn EvalBootstrapPrecompute(self: &CryptoContextDCRTPoly, slots: /* 0 */ u32); - fn EvalBootstrapSetup( - self: &CryptoContextDCRTPoly, - levelBudget: /* {5, 4} */ &CxxVector<u32>, - dim1: /* {0, 0} */ &CxxVector<u32>, - slots: /* 0 */ u32, - correctionFactor: /* 0 */ u32, - precompute: /* true */ bool, - ); - fn EvalCKKStoFHEW( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - numCtxts: /* 0 */ u32, - ) -> UniquePtr<VectorOfLWECiphertexts>; - fn EvalCKKStoFHEWKeyGen( - self: &CryptoContextDCRTPoly, - keyPair: &KeyPairDCRTPoly, - lwesk: &LWEPrivateKey, - ); + fn EvalBootstrapSetup(self: &CryptoContextDCRTPoly, + levelBudget: /* {5, 4} */ &CxxVector<u32>, + dim1: /* {0, 0} */ &CxxVector<u32>, slots: /* 0 */ u32, + correctionFactor: /* 0 */ u32, precompute: /* true */ bool); + fn EvalCKKStoFHEW(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + numCtxts: /* 0 */ u32) -> UniquePtr<VectorOfLWECiphertexts>; + fn EvalCKKStoFHEWKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly, + lwesk: &LWEPrivateKey); fn EvalCKKStoFHEWPrecompute(self: &CryptoContextDCRTPoly, scale: /* 1.0 */ f64); - fn EvalChebyshevFunction( - self: &CryptoContextDCRTPoly, - func: fn(f64, ret: &mut f64), - ciphertext: &CiphertextDCRTPoly, - a: f64, - b: f64, - degree: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalChebyshevSeries( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector<f64>, - a: f64, - b: f64, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalChebyshevSeriesLinear( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector<f64>, - a: f64, - b: f64, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalChebyshevSeriesPS( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector<f64>, - a: f64, - b: f64, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalCompareSchemeSwitching( - self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, - numCtxts: /* 0 */ u32, - numSlots: /* 0 */ u32, - pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64, - unit: /* false */ bool, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalCompareSwitchPrecompute( - self: &CryptoContextDCRTPoly, - pLWE: u32, - scaleSign: f64, - unit: bool, - ); - fn EvalCos( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - a: f64, - b: f64, - degree: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalDivide( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - a: f64, - b: f64, - degree: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalFHEWtoCKKS( - self: &CryptoContextDCRTPoly, - LWECiphertexts: Pin<&mut VectorOfLWECiphertexts>, - numCtxts: /* 0 */ u32, - numSlots: /* 0 */ u32, - p: /* 4 */ u32, - pmin: /* 0.0 */ f64, - pmax: /* 2.0 */ f64, - dim1: /* 0 */ u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalFHEWtoCKKSKeyGen( - self: &CryptoContextDCRTPoly, - keyPair: &KeyPairDCRTPoly, - lwesk: &LWEPrivateKey, - numSlots: /* 0 */ u32, - numCtxts: /* 0 */ u32, - dim1: /* 0 */ u32, - L: /* 0 */ u32, - ); - fn EvalFastRotation( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - index: u32, - m: u32, - digits: &VectorOfDCRTPolys, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalFastRotationExt( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - index: u32, - digits: &VectorOfDCRTPolys, - addFirst: bool, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalFastRotationPrecompute( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<VectorOfDCRTPolys>; - fn EvalInnerProductByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, - batchSize: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalInnerProductByCiphertextAndPlaintext( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - plaintext: &Plaintext, - batchSize: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalInnerProductByPlaintextAndCiphertext( - self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: &CiphertextDCRTPoly, - batchSize: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalLinearWSumMutableByConstantsAndVectorOfCiphertexts( - self: &CryptoContextDCRTPoly, - constantsVec: &CxxVector<f64>, - ciphertextVec: Pin<&mut VectorOfCiphertexts>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalLinearWSumMutableByVectorOfCiphertextsAndConstants( - self: &CryptoContextDCRTPoly, - ciphertextVec: Pin<&mut VectorOfCiphertexts>, - constantsVec: &CxxVector<f64>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalLogistic( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - a: f64, - b: f64, - degree: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMaxSchemeSwitching( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, - numValues: /* 0 */ u32, - numSlots: /* 0 */ u32, - pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64, - ) -> UniquePtr<VectorOfCiphertexts>; - fn EvalMaxSchemeSwitchingAlt( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, - numValues: /* 0 */ u32, - numSlots: /* 0 */ u32, - pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64, - ) -> UniquePtr<VectorOfCiphertexts>; - fn EvalMerge( - self: &CryptoContextDCRTPoly, - ciphertextVec: &VectorOfCiphertexts, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMinSchemeSwitching( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, - numValues: /* 0 */ u32, - numSlots: /* 0 */ u32, - pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64, - ) -> UniquePtr<VectorOfCiphertexts>; - fn EvalMinSchemeSwitchingAlt( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, - numValues: /* 0 */ u32, - numSlots: /* 0 */ u32, - pLWE: /* 0 */ u32, - scaleSign: /* 1.0 */ f64, - ) -> UniquePtr<VectorOfCiphertexts>; - fn EvalMultAndRelinearize( - self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultByCiphertextAndConst( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - constant: f64, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultByCiphertextAndPlaintext( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - plaintext: &Plaintext, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultByConstAndCiphertext( - self: &CryptoContextDCRTPoly, - constant: f64, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultByPlaintextAndCiphertext( - self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultInPlaceByCiphertextAndConst( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - constant: f64, - ); - fn EvalMultInPlaceByConstAndCiphertext( - self: &CryptoContextDCRTPoly, - constant: f64, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ); + fn EvalChebyshevFunction(self: &CryptoContextDCRTPoly, func: fn(f64, ret: &mut f64), + ciphertext: &CiphertextDCRTPoly, a: f64, b: f64, degree: u32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalChebyshevSeries(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector<f64>, a: f64, b: f64) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalChebyshevSeriesLinear(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector<f64>, a: f64, b: f64) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalChebyshevSeriesPS(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector<f64>, a: f64, b: f64) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalCompareSchemeSwitching(self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, numCtxts: /* 0 */ u32, + numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64, unit: /* false */ bool) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalCompareSwitchPrecompute(self: &CryptoContextDCRTPoly, pLWE: u32, scaleSign: f64, + unit: bool); + fn EvalCos(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, b: f64, + degree: u32) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalDivide(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, + b: f64, degree: u32) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalFHEWtoCKKS(self: &CryptoContextDCRTPoly, + LWECiphertexts: Pin<&mut VectorOfLWECiphertexts>, numCtxts: /* 0 */ u32, + numSlots: /* 0 */ u32, p: /* 4 */ u32, pmin: /* 0.0 */ f64, + pmax: /* 2.0 */ f64, dim1: /* 0 */ u32) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalFHEWtoCKKSKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly, + lwesk: &LWEPrivateKey, numSlots: /* 0 */ u32, + numCtxts: /* 0 */ u32, dim1: /* 0 */ u32, L: /* 0 */ u32); + fn EvalFastRotation(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + index: u32, m: u32, digits: &VectorOfDCRTPolys) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalFastRotationExt(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, index: u32, + digits: &VectorOfDCRTPolys, addFirst: bool) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalFastRotationPrecompute(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<VectorOfDCRTPolys>; + fn EvalInnerProductByCiphertexts(self: &CryptoContextDCRTPoly, + ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly, batchSize: u32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalInnerProductByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, + plaintext: &Plaintext, batchSize: u32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalInnerProductByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: &CiphertextDCRTPoly, + batchSize: u32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalLinearWSumMutableByConstantsAndVectorOfCiphertexts(self: &CryptoContextDCRTPoly, + constantsVec: &CxxVector<f64>, + ciphertextVec: + Pin<&mut VectorOfCiphertexts>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalLinearWSumMutableByVectorOfCiphertextsAndConstants(self: &CryptoContextDCRTPoly, + ciphertextVec: + Pin<&mut VectorOfCiphertexts>, + constantsVec: &CxxVector<f64>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalLogistic(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, + b: f64, degree: u32) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMaxSchemeSwitching(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32, + numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64) -> UniquePtr<VectorOfCiphertexts>; + fn EvalMaxSchemeSwitchingAlt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32, + numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64) -> UniquePtr<VectorOfCiphertexts>; + fn EvalMerge(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMinSchemeSwitching(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32, + numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64) -> UniquePtr<VectorOfCiphertexts>; + fn EvalMinSchemeSwitchingAlt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32, + numSlots: /* 0 */ u32, pLWE: /* 0 */ u32, + scaleSign: /* 1.0 */ f64) -> UniquePtr<VectorOfCiphertexts>; + fn EvalMultAndRelinearize(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultByCiphertextAndConst(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, constant: f64) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultByCiphertexts(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, + ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, plaintext: &Plaintext, + ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + constant: f64); + fn EvalMultInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, + ciphertext: Pin<&mut CiphertextDCRTPoly>); fn EvalMultKeyGen(self: &CryptoContextDCRTPoly, key: &PrivateKeyDCRTPoly); fn EvalMultKeysGen(self: &CryptoContextDCRTPoly, key: &PrivateKeyDCRTPoly); - fn EvalMultMany( - self: &CryptoContextDCRTPoly, - ciphertextVec: &VectorOfCiphertexts, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultMutableByCiphertextAndPlaintext( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - plaintext: &Plaintext, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultMutableByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultMutableByPlaintextAndCiphertext( - self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalMultMutableInPlace( - self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>, - ); - fn EvalMultNoRelin( - self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalNegate( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalNegateInPlace( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ); - fn EvalPoly( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector<f64>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalPolyLinear( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector<f64>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalPolyPS( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - coefficients: &CxxVector<f64>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalRotate( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - index: i32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalRotateKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - indexList: &CxxVector<i32>, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, - ); - fn EvalSchemeSwitchingKeyGen( - self: &CryptoContextDCRTPoly, - keyPair: &KeyPairDCRTPoly, - lwesk: &LWEPrivateKey, - ); - fn EvalSin( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - a: f64, - b: f64, - degree: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSquare( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSquareInPlace( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ); - fn EvalSquareMutable( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubByCiphertextAndConst( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - constant: f64, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubByCiphertextAndPlaintext( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - plaintext: &Plaintext, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: &CiphertextDCRTPoly, - ciphertext2: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubByConstAndCiphertext( - self: &CryptoContextDCRTPoly, - constant: f64, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubByPlaintextAndCiphertext( - self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubInPlaceByCiphertextAndConst( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - constant: f64, - ); - fn EvalSubInPlaceByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: &CiphertextDCRTPoly, - ); - fn EvalSubInPlaceByConstAndCiphertext( - self: &CryptoContextDCRTPoly, - constant: f64, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ); - fn EvalSubMutableByCiphertextAndPlaintext( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - plaintext: &Plaintext, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubMutableByCiphertexts( - self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubMutableByPlaintextAndCiphertext( - self: &CryptoContextDCRTPoly, - plaintext: &Plaintext, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSubMutableInPlace( - self: &CryptoContextDCRTPoly, - ciphertext1: Pin<&mut CiphertextDCRTPoly>, - ciphertext2: Pin<&mut CiphertextDCRTPoly>, - ); - fn EvalSum( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - batchSize: u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSumCols( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - rowSize: u32, - evalSumKeyMap: &MapFromIndexToEvalKey, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSumColsKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, - ) -> UniquePtr<MapFromIndexToEvalKey>; - fn EvalSumKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, - ); - fn EvalSumRows( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - rowSize: u32, - evalSumKeyMap: &MapFromIndexToEvalKey, - subringDim: /* 0 */ u32, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn EvalSumRowsKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, - rowSize: /* 0 */ u32, - subringDim: /* 0 */ u32, - ) -> UniquePtr<MapFromIndexToEvalKey>; + fn EvalMultMany(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + plaintext: &Plaintext) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultMutableByCiphertexts(self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: Pin<&mut CiphertextDCRTPoly>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalMultMutableInPlace(self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>); + fn EvalMultNoRelin(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalNegate(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalNegateInPlace(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn EvalPoly(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector<f64>) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalPolyLinear(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector<f64>)-> UniquePtr<CiphertextDCRTPoly>; + fn EvalPolyPS(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + coefficients: &CxxVector<f64>) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalRotate(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, index: i32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalRotateKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + indexList: &CxxVector<i32>, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly); + fn EvalSchemeSwitchingKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly, + lwesk: &LWEPrivateKey); + fn EvalSin(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, b: f64, + degree: u32) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSquare(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSquareInPlace(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn EvalSquareMutable(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubByCiphertextAndConst(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, constant: f64) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, + ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubByCiphertexts(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly, + ciphertext2: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, + ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + constant: f64); + fn EvalSubInPlaceByCiphertexts(self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: &CiphertextDCRTPoly); + fn EvalSubInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64, + ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn EvalSubMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + plaintext: &Plaintext) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubMutableByCiphertexts(self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, + plaintext: &Plaintext, + ciphertext: Pin<&mut CiphertextDCRTPoly>) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSubMutableInPlace(self: &CryptoContextDCRTPoly, + ciphertext1: Pin<&mut CiphertextDCRTPoly>, + ciphertext2: Pin<&mut CiphertextDCRTPoly>); + fn EvalSum(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, batchSize: u32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSumCols(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, rowSize: u32, + evalSumKeyMap: &MapFromIndexToEvalKey) -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSumColsKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly) + -> UniquePtr<MapFromIndexToEvalKey>; + fn EvalSumKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly); + fn EvalSumRows(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, rowSize: u32, + evalSumKeyMap: &MapFromIndexToEvalKey, subringDim: /* 0 */ u32) + -> UniquePtr<CiphertextDCRTPoly>; + fn EvalSumRowsKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, + rowSize: /* 0 */ u32, subringDim: /* 0 */ u32) + -> UniquePtr<MapFromIndexToEvalKey>; fn FindAutomorphismIndex(self: &CryptoContextDCRTPoly, idx: u32) -> u32; - fn FindAutomorphismIndices( - self: &CryptoContextDCRTPoly, - idxList: &CxxVector<u32>, - ) -> UniquePtr<CxxVector<u32>>; - fn GetCryptoParameters( - self: &CryptoContextDCRTPoly, - ) -> UniquePtr<CryptoParametersBaseDCRTPoly>; + fn FindAutomorphismIndices(self: &CryptoContextDCRTPoly, idxList: &CxxVector<u32>) + -> UniquePtr<CxxVector<u32>>; + fn GetCryptoParameters(self: &CryptoContextDCRTPoly) + -> UniquePtr<CryptoParametersBaseDCRTPoly>; fn GetCyclotomicOrder(self: &CryptoContextDCRTPoly) -> u32; fn GetElementParams(self: &CryptoContextDCRTPoly) -> UniquePtr<DCRTPolyParams>; fn GetEncodingParams(self: &CryptoContextDCRTPoly) -> UniquePtr<EncodingParams>; @@ -795,237 +553,134 @@ pub mod ffi { fn GetScheme(self: &CryptoContextDCRTPoly) -> UniquePtr<SchemeBaseDCRTPoly>; fn GetSchemeId(self: &CryptoContextDCRTPoly) -> SCHEME; fn GetSwkFC(self: &CryptoContextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>; - fn IntMPBootAdd( - self: &CryptoContextDCRTPoly, - sharesPairVec: Pin<&mut VectorOfVectorOfCiphertexts>, - ) -> UniquePtr<VectorOfCiphertexts>; - fn IntMPBootAdjustScale( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn IntMPBootDecrypt( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - a: &CiphertextDCRTPoly, - ) -> UniquePtr<VectorOfCiphertexts>; - fn IntMPBootEncrypt( - self: &CryptoContextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, - sharesPair: &VectorOfCiphertexts, - a: &CiphertextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn IntMPBootRandomElementGen( - self: &CryptoContextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; + fn IntMPBootAdd(self: &CryptoContextDCRTPoly, + sharesPairVec: Pin<&mut VectorOfVectorOfCiphertexts>) + -> UniquePtr<VectorOfCiphertexts>; + fn IntMPBootAdjustScale(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn IntMPBootDecrypt(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + ciphertext: &CiphertextDCRTPoly, a: &CiphertextDCRTPoly) + -> UniquePtr<VectorOfCiphertexts>; + fn IntMPBootEncrypt(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly, + sharesPair: &VectorOfCiphertexts, a: &CiphertextDCRTPoly, + ciphertext: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>; + fn IntMPBootRandomElementGen(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; fn KeyGen(self: &CryptoContextDCRTPoly) -> UniquePtr<KeyPairDCRTPoly>; - fn KeySwitch( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - evalKey: &EvalKeyDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn KeySwitchDown( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn KeySwitchDownFirstElement( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<DCRTPoly>; - fn KeySwitchExt( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - addFirst: bool, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn KeySwitchGen( - self: &CryptoContextDCRTPoly, - oldPrivateKey: &PrivateKeyDCRTPoly, - newPrivateKey: &PrivateKeyDCRTPoly, - ) -> UniquePtr<EvalKeyDCRTPoly>; - fn KeySwitchInPlace( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - evalKey: &EvalKeyDCRTPoly, - ); - fn LevelReduce( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - evalKey: &EvalKeyDCRTPoly, - levels: /* 1 */ usize, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn LevelReduceInPlace( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - evalKey: &EvalKeyDCRTPoly, - levels: /* 1 */ usize, - ); - fn MakeCKKSPackedPlaintextByVectorOfDouble( - self: &CryptoContextDCRTPoly, - value: &CxxVector<f64>, - scaleDeg: /* 1 */ usize, - level: /* 0 */ u32, - params: /* DCRTPolyGenNullParams() */ &DCRTPolyParams, - slots: /* 0 */ u32, - ) -> UniquePtr<Plaintext>; - fn MakeCKKSPackedPlaintextByVectorOfComplex( - self: &CryptoContextDCRTPoly, - value: &CxxVector<ComplexPair>, - scaleDeg: /* 1 */ usize, - level: /* 0 */ u32, - params: /* DCRTPolyGenNullParams() */ &DCRTPolyParams, - slots: /* 0 */ u32, - ) -> UniquePtr<Plaintext>; - fn MakeCoefPackedPlaintext( - self: &CryptoContextDCRTPoly, - value: &CxxVector<i64>, - noiseScaleDeg: /* 1 */ usize, - level: /* 0 */ u32, - ) -> UniquePtr<Plaintext>; - fn MakePackedPlaintext( - self: &CryptoContextDCRTPoly, - value: &CxxVector<i64>, - noiseScaleDeg: /* 1 */ usize, - level: /* 0 */ u32, - ) -> UniquePtr<Plaintext>; + fn KeySwitch(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + evalKey: &EvalKeyDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>; + fn KeySwitchDown(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn KeySwitchDownFirstElement(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<DCRTPoly>; + fn KeySwitchExt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + addFirst: bool) -> UniquePtr<CiphertextDCRTPoly>; + fn KeySwitchGen(self: &CryptoContextDCRTPoly, oldPrivateKey: &PrivateKeyDCRTPoly, + newPrivateKey: &PrivateKeyDCRTPoly) -> UniquePtr<EvalKeyDCRTPoly>; + fn KeySwitchInPlace(self: &CryptoContextDCRTPoly, ciphertext: Pin<&mut CiphertextDCRTPoly>, + evalKey: &EvalKeyDCRTPoly); + fn LevelReduce(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + evalKey: &EvalKeyDCRTPoly, levels: /* 1 */ usize) + -> UniquePtr<CiphertextDCRTPoly>; + fn LevelReduceInPlace(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>, evalKey: &EvalKeyDCRTPoly, + levels: /* 1 */ usize); + fn MakeCKKSPackedPlaintextByVectorOfDouble(self: &CryptoContextDCRTPoly, + value: &CxxVector<f64>, + scaleDeg: /* 1 */ usize, level: /* 0 */ u32, + params: + /* DCRTPolyGenNullParams() */ &DCRTPolyParams, + slots: /* 0 */ u32) -> UniquePtr<Plaintext>; + fn MakeCKKSPackedPlaintextByVectorOfComplex(self: &CryptoContextDCRTPoly, + value: &CxxVector<ComplexPair>, + scaleDeg: /* 1 */ usize, level: /* 0 */ u32, + params: + /* DCRTPolyGenNullParams() */ &DCRTPolyParams, + slots: /* 0 */ u32) -> UniquePtr<Plaintext>; + fn MakeCoefPackedPlaintext(self: &CryptoContextDCRTPoly, value: &CxxVector<i64>, + noiseScaleDeg: /* 1 */ usize, level: /* 0 */ u32) + -> UniquePtr<Plaintext>; + fn MakePackedPlaintext(self: &CryptoContextDCRTPoly, value: &CxxVector<i64>, + noiseScaleDeg: /* 1 */ usize, level: /* 0 */ u32) + -> UniquePtr<Plaintext>; fn MakeStringPlaintext(self: &CryptoContextDCRTPoly, s: &CxxString) - -> UniquePtr<Plaintext>; - fn ModReduce( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn ModReduceInPlace(self: &CryptoContextDCRTPoly, ciphertext: Pin<&mut CiphertextDCRTPoly>); - fn MultiAddEvalAutomorphismKeys( - self: &CryptoContextDCRTPoly, - evalKeyMap1: &MapFromIndexToEvalKey, - evalKeyMap2: &MapFromIndexToEvalKey, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiAddEvalKeys( - self: &CryptoContextDCRTPoly, - evalKey1: &EvalKeyDCRTPoly, - evalKey2: &EvalKeyDCRTPoly, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<EvalKeyDCRTPoly>; - fn MultiAddEvalMultKeys( - self: &CryptoContextDCRTPoly, - evalKey1: &EvalKeyDCRTPoly, - evalKey2: &EvalKeyDCRTPoly, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<EvalKeyDCRTPoly>; - fn MultiAddEvalSumKeys( - self: &CryptoContextDCRTPoly, - evalKeyMap1: &MapFromIndexToEvalKey, - evalKeyMap2: &MapFromIndexToEvalKey, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiAddPubKeys( - self: &CryptoContextDCRTPoly, - publicKey1: &PublicKeyDCRTPoly, - publicKey2: &PublicKeyDCRTPoly, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<PublicKeyDCRTPoly>; - fn MultiEvalAtIndexKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - evalKeyMap: &MapFromIndexToEvalKey, - indexList: &CxxVector<i32>, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiEvalAutomorphismKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - evalKeyMap: &MapFromIndexToEvalKey, - indexList: &CxxVector<u32>, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiEvalSumKeyGen( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - evalKeyMap: &MapFromIndexToEvalKey, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<MapFromIndexToEvalKey>; - fn MultiKeySwitchGen( - self: &CryptoContextDCRTPoly, - originalPrivateKey: &PrivateKeyDCRTPoly, - newPrivateKey: &PrivateKeyDCRTPoly, - evalKey: &EvalKeyDCRTPoly, - ) -> UniquePtr<EvalKeyDCRTPoly>; - fn MultiMultEvalKey( - self: &CryptoContextDCRTPoly, - privateKey: &PrivateKeyDCRTPoly, - evalKey: &EvalKeyDCRTPoly, - keyId: /* "" */ &CxxString, - ) -> UniquePtr<EvalKeyDCRTPoly>; - fn MultipartyDecryptFusion( - self: &CryptoContextDCRTPoly, - partialCiphertextVec: &VectorOfCiphertexts, - plaintext: Pin<&mut Plaintext>, - ) -> UniquePtr<DecryptResult>; - fn MultipartyDecryptLead( - self: &CryptoContextDCRTPoly, - ciphertextVec: &VectorOfCiphertexts, - privateKey: &PrivateKeyDCRTPoly, - ) -> UniquePtr<VectorOfCiphertexts>; - fn MultipartyDecryptMain( - self: &CryptoContextDCRTPoly, - ciphertextVec: &VectorOfCiphertexts, - privateKey: &PrivateKeyDCRTPoly, - ) -> UniquePtr<VectorOfCiphertexts>; - fn MultipartyKeyGenByPublicKey( - self: &CryptoContextDCRTPoly, - publicKey: &PublicKeyDCRTPoly, - makeSparse: /* false */ bool, - fresh: /* false */ bool, - ) -> UniquePtr<KeyPairDCRTPoly>; - fn MultipartyKeyGenByVectorOfPrivateKeys( - self: &CryptoContextDCRTPoly, - privateKeyVec: &VectorOfPrivateKeys, - ) -> UniquePtr<KeyPairDCRTPoly>; - fn ReEncrypt( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - evalKey: &EvalKeyDCRTPoly, - publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn ReKeyGen( - self: &CryptoContextDCRTPoly, - oldPrivateKey: &PrivateKeyDCRTPoly, - newPublicKey: &PublicKeyDCRTPoly, - ) -> UniquePtr<EvalKeyDCRTPoly>; - fn RecoverSharedKey( - self: &CryptoContextDCRTPoly, - sk: Pin<&mut PrivateKeyDCRTPoly>, - sk_shares: Pin<&mut UnorderedMapFromIndexToDCRTPoly>, - N: u32, - threshold: u32, - shareType: &CxxString, - ); - fn Relinearize( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; - fn RelinearizeInPlace( - self: &CryptoContextDCRTPoly, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - ); - fn Rescale( - self: &CryptoContextDCRTPoly, - ciphertext: &CiphertextDCRTPoly, - ) -> UniquePtr<CiphertextDCRTPoly>; + -> UniquePtr<Plaintext>; + fn ModReduce(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn ModReduceInPlace(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn MultiAddEvalAutomorphismKeys(self: &CryptoContextDCRTPoly, + evalKeyMap1: &MapFromIndexToEvalKey, + evalKeyMap2: &MapFromIndexToEvalKey, + keyId: /* "" */ &CxxString) + -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiAddEvalKeys(self: &CryptoContextDCRTPoly, evalKey1: &EvalKeyDCRTPoly, + evalKey2: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString) + -> UniquePtr<EvalKeyDCRTPoly>; + fn MultiAddEvalMultKeys(self: &CryptoContextDCRTPoly, evalKey1: &EvalKeyDCRTPoly, + evalKey2: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString) + -> UniquePtr<EvalKeyDCRTPoly>; + fn MultiAddEvalSumKeys(self: &CryptoContextDCRTPoly, evalKeyMap1: &MapFromIndexToEvalKey, + evalKeyMap2: &MapFromIndexToEvalKey, keyId: /* "" */ &CxxString) + -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiAddPubKeys(self: &CryptoContextDCRTPoly, publicKey1: &PublicKeyDCRTPoly, + publicKey2: &PublicKeyDCRTPoly, keyId: /* "" */ &CxxString) + -> UniquePtr<PublicKeyDCRTPoly>; + fn MultiEvalAtIndexKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + evalKeyMap: &MapFromIndexToEvalKey, indexList: &CxxVector<i32>, + keyId: /* "" */ &CxxString) -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiEvalAutomorphismKeyGen(self: &CryptoContextDCRTPoly, + privateKey: &PrivateKeyDCRTPoly, + evalKeyMap: &MapFromIndexToEvalKey, + indexList: &CxxVector<u32>, keyId: /* "" */ &CxxString) + -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiEvalSumKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + evalKeyMap: &MapFromIndexToEvalKey, keyId: /* "" */ &CxxString) + -> UniquePtr<MapFromIndexToEvalKey>; + fn MultiKeySwitchGen(self: &CryptoContextDCRTPoly, + originalPrivateKey: &PrivateKeyDCRTPoly, + newPrivateKey: &PrivateKeyDCRTPoly, evalKey: &EvalKeyDCRTPoly) + -> UniquePtr<EvalKeyDCRTPoly>; + fn MultiMultEvalKey(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly, + evalKey: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString) + -> UniquePtr<EvalKeyDCRTPoly>; + fn MultipartyDecryptFusion(self: &CryptoContextDCRTPoly, + partialCiphertextVec: &VectorOfCiphertexts, + plaintext: Pin<&mut Plaintext>) -> UniquePtr<DecryptResult>; + fn MultipartyDecryptLead(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts, + privateKey: &PrivateKeyDCRTPoly) + -> UniquePtr<VectorOfCiphertexts>; + fn MultipartyDecryptMain(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts, + privateKey: &PrivateKeyDCRTPoly) + -> UniquePtr<VectorOfCiphertexts>; + fn MultipartyKeyGenByPublicKey(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly, + makeSparse: /* false */ bool, fresh: /* false */ bool) + -> UniquePtr<KeyPairDCRTPoly>; + fn MultipartyKeyGenByVectorOfPrivateKeys(self: &CryptoContextDCRTPoly, + privateKeyVec: &VectorOfPrivateKeys) + -> UniquePtr<KeyPairDCRTPoly>; + fn ReEncrypt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, + evalKey: &EvalKeyDCRTPoly, + publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn ReKeyGen(self: &CryptoContextDCRTPoly, oldPrivateKey: &PrivateKeyDCRTPoly, + newPublicKey: &PublicKeyDCRTPoly) -> UniquePtr<EvalKeyDCRTPoly>; + fn RecoverSharedKey(self: &CryptoContextDCRTPoly, sk: Pin<&mut PrivateKeyDCRTPoly>, + sk_shares: Pin<&mut UnorderedMapFromIndexToDCRTPoly>, N: u32, + threshold: u32, shareType: &CxxString); + fn Relinearize(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; + fn RelinearizeInPlace(self: &CryptoContextDCRTPoly, + ciphertext: Pin<&mut CiphertextDCRTPoly>); + fn Rescale(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly) + -> UniquePtr<CiphertextDCRTPoly>; fn RescaleInPlace(self: &CryptoContextDCRTPoly, ciphertext: Pin<&mut CiphertextDCRTPoly>); fn SetKeyGenLevel(self: &CryptoContextDCRTPoly, level: usize); fn SetSchemeId(self: &CryptoContextDCRTPoly, schemeTag: SCHEME); fn SetSwkFC(self: &CryptoContextDCRTPoly, FHEWtoCKKSswk: &CiphertextDCRTPoly); - fn ShareKeys( - self: &CryptoContextDCRTPoly, - sk: &PrivateKeyDCRTPoly, - N: u32, - threshold: u32, - index: u32, - shareType: &CxxString, - ) -> UniquePtr<UnorderedMapFromIndexToDCRTPoly>; + fn ShareKeys(self: &CryptoContextDCRTPoly, sk: &PrivateKeyDCRTPoly, N: u32, threshold: u32, + index: u32, shareType: &CxxString) + -> UniquePtr<UnorderedMapFromIndexToDCRTPoly>; fn SparseKeyGen(self: &CryptoContextDCRTPoly) -> UniquePtr<KeyPairDCRTPoly>; // cxx currently does not support static class methods @@ -1038,52 +693,39 @@ pub mod ffi { fn DCRTPolyClearEvalSumKeys(); fn DCRTPolyClearEvalSumKeysByCryptoContext(cryptoContext: &CryptoContextDCRTPoly); fn DCRTPolyClearEvalSumKeysById(id: &CxxString); - fn DCRTPolyGetCopyOfAllEvalAutomorphismKeys( - ) -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>; + fn DCRTPolyGetCopyOfAllEvalAutomorphismKeys() + -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>; fn DCRTPolyGetCopyOfAllEvalMultKeys() -> UniquePtr<MapFromStringToVectorOfEvalKeys>; fn DCRTPolyGetCopyOfAllEvalSumKeys() -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>; - fn DCRTPolyGetCopyOfEvalAutomorphismKeyMap( - keyID: &CxxString, - ) -> UniquePtr<MapFromIndexToEvalKey>; + fn DCRTPolyGetCopyOfEvalAutomorphismKeyMap(keyID: &CxxString) + -> UniquePtr<MapFromIndexToEvalKey>; fn DCRTPolyGetCopyOfEvalMultKeyVector(keyID: &CxxString) -> UniquePtr<VectorOfEvalKeys>; fn DCRTPolyGetCopyOfEvalSumKeyMap(id: &CxxString) -> UniquePtr<MapFromIndexToEvalKey>; - fn DCRTPolyGetExistingEvalAutomorphismKeyIndices( - keyTag: &CxxString, - ) -> UniquePtr<SetOfUints>; - fn DCRTPolyGetPlaintextForDecrypt( - pte: PlaintextEncodings, - evp: &DCRTPolyParams, - ep: &EncodingParams, - ) -> UniquePtr<Plaintext>; - fn DCRTPolyGetUniqueValues( - oldValues: &SetOfUints, - newValues: &SetOfUints, - ) -> UniquePtr<SetOfUints>; - fn DCRTPolyInsertEvalAutomorphismKey( - evalKeyMap: &MapFromIndexToEvalKey, - keyTag: /* "" */ &CxxString, - ); + fn DCRTPolyGetExistingEvalAutomorphismKeyIndices(keyTag: &CxxString) + -> UniquePtr<SetOfUints>; + fn DCRTPolyGetPlaintextForDecrypt(pte: PlaintextEncodings, evp: &DCRTPolyParams, + ep: &EncodingParams) -> UniquePtr<Plaintext>; + fn DCRTPolyGetUniqueValues(oldValues: &SetOfUints, newValues: &SetOfUints) + -> UniquePtr<SetOfUints>; + fn DCRTPolyInsertEvalAutomorphismKey(evalKeyMap: &MapFromIndexToEvalKey, + keyTag: /* "" */ &CxxString); fn DCRTPolyInsertEvalMultKey(evalKeyVec: &VectorOfEvalKeys); - fn DCRTPolyInsertEvalSumKey( - mapToInsert: &MapFromIndexToEvalKey, - keyTag: /* "" */ &CxxString, - ); + fn DCRTPolyInsertEvalSumKey(mapToInsert: &MapFromIndexToEvalKey, + keyTag: /* "" */ &CxxString); // Generator functions - fn DCRTPolyGenCryptoContextByParamsCKKSRNS( - params: &ParamsCKKSRNS, - ) -> UniquePtr<CryptoContextDCRTPoly>; - fn DCRTPolyGenCryptoContextByParamsBFVRNS( - params: &ParamsBFVRNS, - ) -> UniquePtr<CryptoContextDCRTPoly>; - fn DCRTPolyGenCryptoContextByParamsBGVRNS( - params: &ParamsBGVRNS, - ) -> UniquePtr<CryptoContextDCRTPoly>; + fn DCRTPolyGenCryptoContextByParamsCKKSRNS(params: &ParamsCKKSRNS) + -> UniquePtr<CryptoContextDCRTPoly>; + fn DCRTPolyGenCryptoContextByParamsBFVRNS(params: &ParamsBFVRNS) + -> UniquePtr<CryptoContextDCRTPoly>; + fn DCRTPolyGenCryptoContextByParamsBGVRNS(params: &ParamsBGVRNS) + -> UniquePtr<CryptoContextDCRTPoly>; fn DCRTPolyGenNullCryptoContext() -> UniquePtr<CryptoContextDCRTPoly>; } // DCRTPoly - unsafe extern "C++" { + unsafe extern "C++" + { fn GetString(self: &DCRTPoly) -> String; fn IsEqual(self: &DCRTPoly, other: &DCRTPoly) -> bool; fn GetCoefficients(self: &DCRTPoly) -> Vec<String>; @@ -1091,22 +733,13 @@ pub mod ffi { fn Negate(self: &DCRTPoly) -> UniquePtr<DCRTPoly>; // Generator functions - fn DCRTPolyGenFromConst( - n: u32, - size: usize, - k_res: usize, - value: &String, - ) -> UniquePtr<DCRTPoly>; - fn DCRTPolyGenFromVec( - n: u32, - size: usize, - k_res: usize, - values: &Vec<String>, - ) -> UniquePtr<DCRTPoly>; + fn DCRTPolyGenFromConst(n: u32, size: usize, k_res: usize, value: &String) + -> UniquePtr<DCRTPoly>; + fn DCRTPolyGenFromVec(n: u32, size: usize, k_res: usize, values: &Vec<String>) + -> UniquePtr<DCRTPoly>; fn DCRTPolyGenFromBug(n: u32, size: usize, k_res: usize) -> UniquePtr<DCRTPoly>; fn DCRTPolyGenFromDug(n: u32, size: usize, k_res: usize) -> UniquePtr<DCRTPoly>; - fn DCRTPolyGenFromDgg(n: u32, size: usize, k_res: usize, sigma: f64) - -> UniquePtr<DCRTPoly>; + fn DCRTPolyGenFromDgg(n: u32, size: usize, k_res: usize, sigma: f64) -> UniquePtr<DCRTPoly>; // Arithmetic fn DCRTPolyAdd(rhs: &DCRTPoly, lhs: &DCRTPoly) -> UniquePtr<DCRTPoly>; @@ -1114,32 +747,30 @@ pub mod ffi { } // DCRTPolyParams - unsafe extern "C++" { + unsafe extern "C++" + { // Generator functions fn DCRTPolyGenNullParams() -> UniquePtr<DCRTPolyParams>; } // Matrix - unsafe extern "C++" { - fn MatrixGen( - n: u32, - size: usize, - k_res: usize, - nrow: usize, - ncol: usize, - ) -> UniquePtr<Matrix>; + unsafe extern "C++" + { + fn MatrixGen(n: u32, size: usize, k_res: usize, nrow: usize, ncol: usize) -> UniquePtr<Matrix>; fn SetMatrixElement(matrix: Pin<&mut Matrix>, row: usize, col: usize, element: &DCRTPoly); fn GetMatrixElement(matrix: &Matrix, row: usize, col: usize) -> UniquePtr<DCRTPoly>; } // KeyPairDCRTPoly - unsafe extern "C++" { + unsafe extern "C++" + { fn GetPrivateKey(self: &KeyPairDCRTPoly) -> UniquePtr<PrivateKeyDCRTPoly>; fn GetPublicKey(self: &KeyPairDCRTPoly) -> UniquePtr<PublicKeyDCRTPoly>; } // Params - unsafe extern "C++" { + unsafe extern "C++" + { fn GetBatchSize(self: &Params) -> u32; fn GetDecryptionNoiseMode(self: &Params) -> DecryptionNoiseMode; fn GetDesiredPrecision(self: &Params) -> f64; @@ -1170,31 +801,23 @@ pub mod ffi { fn GetStatisticalSecurity(self: &Params) -> f64; fn GetThresholdNumOfParties(self: &Params) -> u32; fn SetBatchSize(self: Pin<&mut Params>, batchSize0: u32); - fn SetDecryptionNoiseMode( - self: Pin<&mut Params>, - decryptionNoiseMode0: DecryptionNoiseMode, - ); + fn SetDecryptionNoiseMode(self: Pin<&mut Params>, + decryptionNoiseMode0: DecryptionNoiseMode); fn SetDesiredPrecision(self: Pin<&mut Params>, desiredPrecision0: f64); fn SetDigitSize(self: Pin<&mut Params>, digitSize0: u32); - fn SetEncryptionTechnique( - self: Pin<&mut Params>, - encryptionTechnique0: EncryptionTechnique, - ); + fn SetEncryptionTechnique(self: Pin<&mut Params>, + encryptionTechnique0: EncryptionTechnique); fn SetEvalAddCount(self: Pin<&mut Params>, evalAddCount0: u32); fn SetExecutionMode(self: Pin<&mut Params>, executionMode0: ExecutionMode); fn SetFirstModSize(self: Pin<&mut Params>, firstModSize0: u32); - fn SetInteractiveBootCompressionLevel( - self: Pin<&mut Params>, - interactiveBootCompressionLevel0: COMPRESSION_LEVEL, - ); + fn SetInteractiveBootCompressionLevel(self: Pin<&mut Params>, + interactiveBootCompressionLevel0: COMPRESSION_LEVEL); fn SetKeySwitchCount(self: Pin<&mut Params>, keySwitchCount0: u32); fn SetKeySwitchTechnique(self: Pin<&mut Params>, ksTech0: KeySwitchTechnique); fn SetMaxRelinSkDeg(self: Pin<&mut Params>, maxRelinSkDeg0: u32); fn SetMultipartyMode(self: Pin<&mut Params>, multipartyMode0: MultipartyMode); - fn SetMultiplicationTechnique( - self: Pin<&mut Params>, - multiplicationTechnique0: MultiplicationTechnique, - ); + fn SetMultiplicationTechnique(self: Pin<&mut Params>, + multiplicationTechnique0: MultiplicationTechnique); fn SetMultiplicativeDepth(self: Pin<&mut Params>, multiplicativeDepth0: u32); fn SetNoiseEstimate(self: Pin<&mut Params>, noiseEstimate0: f64); fn SetNumAdversarialQueries(self: Pin<&mut Params>, numAdversarialQueries0: u32); @@ -1217,7 +840,8 @@ pub mod ffi { } // ParamsBFVRNS - unsafe extern "C++" { + unsafe extern "C++" + { fn GetBatchSize(self: &ParamsBFVRNS) -> u32; fn GetDecryptionNoiseMode(self: &ParamsBFVRNS) -> DecryptionNoiseMode; fn GetDesiredPrecision(self: &ParamsBFVRNS) -> f64; @@ -1248,31 +872,23 @@ pub mod ffi { fn GetStatisticalSecurity(self: &ParamsBFVRNS) -> f64; fn GetThresholdNumOfParties(self: &ParamsBFVRNS) -> u32; fn SetBatchSize(self: Pin<&mut ParamsBFVRNS>, batchSize0: u32); - fn SetDecryptionNoiseMode( - self: Pin<&mut ParamsBFVRNS>, - decryptionNoiseMode0: DecryptionNoiseMode, - ); + fn SetDecryptionNoiseMode(self: Pin<&mut ParamsBFVRNS>, + decryptionNoiseMode0: DecryptionNoiseMode); fn SetDesiredPrecision(self: Pin<&mut ParamsBFVRNS>, desiredPrecision0: f64); fn SetDigitSize(self: Pin<&mut ParamsBFVRNS>, digitSize0: u32); - fn SetEncryptionTechnique( - self: Pin<&mut ParamsBFVRNS>, - encryptionTechnique0: EncryptionTechnique, - ); + fn SetEncryptionTechnique(self: Pin<&mut ParamsBFVRNS>, + encryptionTechnique0: EncryptionTechnique); fn SetEvalAddCount(self: Pin<&mut ParamsBFVRNS>, evalAddCount0: u32); fn SetExecutionMode(self: Pin<&mut ParamsBFVRNS>, executionMode0: ExecutionMode); fn SetFirstModSize(self: Pin<&mut ParamsBFVRNS>, firstModSize0: u32); - fn SetInteractiveBootCompressionLevel( - self: Pin<&mut ParamsBFVRNS>, - interactiveBootCompressionLevel0: COMPRESSION_LEVEL, - ); + fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsBFVRNS>, + interactiveBootCompressionLevel0: COMPRESSION_LEVEL); fn SetKeySwitchCount(self: Pin<&mut ParamsBFVRNS>, keySwitchCount0: u32); fn SetKeySwitchTechnique(self: Pin<&mut ParamsBFVRNS>, ksTech0: KeySwitchTechnique); fn SetMaxRelinSkDeg(self: Pin<&mut ParamsBFVRNS>, maxRelinSkDeg0: u32); fn SetMultipartyMode(self: Pin<&mut ParamsBFVRNS>, multipartyMode0: MultipartyMode); - fn SetMultiplicationTechnique( - self: Pin<&mut ParamsBFVRNS>, - multiplicationTechnique0: MultiplicationTechnique, - ); + fn SetMultiplicationTechnique(self: Pin<&mut ParamsBFVRNS>, + multiplicationTechnique0: MultiplicationTechnique); fn SetMultiplicativeDepth(self: Pin<&mut ParamsBFVRNS>, multiplicativeDepth0: u32); fn SetNoiseEstimate(self: Pin<&mut ParamsBFVRNS>, noiseEstimate0: f64); fn SetNumAdversarialQueries(self: Pin<&mut ParamsBFVRNS>, numAdversarialQueries0: u32); @@ -1294,7 +910,8 @@ pub mod ffi { } // ParamsBGVRNS - unsafe extern "C++" { + unsafe extern "C++" + { fn GetBatchSize(self: &ParamsBGVRNS) -> u32; fn GetDecryptionNoiseMode(self: &ParamsBGVRNS) -> DecryptionNoiseMode; fn GetDesiredPrecision(self: &ParamsBGVRNS) -> f64; @@ -1325,31 +942,23 @@ pub mod ffi { fn GetStatisticalSecurity(self: &ParamsBGVRNS) -> f64; fn GetThresholdNumOfParties(self: &ParamsBGVRNS) -> u32; fn SetBatchSize(self: Pin<&mut ParamsBGVRNS>, batchSize0: u32); - fn SetDecryptionNoiseMode( - self: Pin<&mut ParamsBGVRNS>, - decryptionNoiseMode0: DecryptionNoiseMode, - ); + fn SetDecryptionNoiseMode(self: Pin<&mut ParamsBGVRNS>, + decryptionNoiseMode0: DecryptionNoiseMode); fn SetDesiredPrecision(self: Pin<&mut ParamsBGVRNS>, desiredPrecision0: f64); fn SetDigitSize(self: Pin<&mut ParamsBGVRNS>, digitSize0: u32); - fn SetEncryptionTechnique( - self: Pin<&mut ParamsBGVRNS>, - encryptionTechnique0: EncryptionTechnique, - ); + fn SetEncryptionTechnique(self: Pin<&mut ParamsBGVRNS>, + encryptionTechnique0: EncryptionTechnique); fn SetEvalAddCount(self: Pin<&mut ParamsBGVRNS>, evalAddCount0: u32); fn SetExecutionMode(self: Pin<&mut ParamsBGVRNS>, executionMode0: ExecutionMode); fn SetFirstModSize(self: Pin<&mut ParamsBGVRNS>, firstModSize0: u32); - fn SetInteractiveBootCompressionLevel( - self: Pin<&mut ParamsBGVRNS>, - interactiveBootCompressionLevel0: COMPRESSION_LEVEL, - ); + fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsBGVRNS>, + interactiveBootCompressionLevel0: COMPRESSION_LEVEL); fn SetKeySwitchCount(self: Pin<&mut ParamsBGVRNS>, keySwitchCount0: u32); fn SetKeySwitchTechnique(self: Pin<&mut ParamsBGVRNS>, ksTech0: KeySwitchTechnique); fn SetMaxRelinSkDeg(self: Pin<&mut ParamsBGVRNS>, maxRelinSkDeg0: u32); fn SetMultipartyMode(self: Pin<&mut ParamsBGVRNS>, multipartyMode0: MultipartyMode); - fn SetMultiplicationTechnique( - self: Pin<&mut ParamsBGVRNS>, - multiplicationTechnique0: MultiplicationTechnique, - ); + fn SetMultiplicationTechnique(self: Pin<&mut ParamsBGVRNS>, + multiplicationTechnique0: MultiplicationTechnique); fn SetMultiplicativeDepth(self: Pin<&mut ParamsBGVRNS>, multiplicativeDepth0: u32); fn SetNoiseEstimate(self: Pin<&mut ParamsBGVRNS>, noiseEstimate0: f64); fn SetNumAdversarialQueries(self: Pin<&mut ParamsBGVRNS>, numAdversarialQueries0: u32); @@ -1371,7 +980,8 @@ pub mod ffi { } // ParamsCKKSRNS - unsafe extern "C++" { + unsafe extern "C++" + { fn GetBatchSize(self: &ParamsCKKSRNS) -> u32; fn GetDecryptionNoiseMode(self: &ParamsCKKSRNS) -> DecryptionNoiseMode; fn GetDesiredPrecision(self: &ParamsCKKSRNS) -> f64; @@ -1402,31 +1012,23 @@ pub mod ffi { fn GetStatisticalSecurity(self: &ParamsCKKSRNS) -> f64; fn GetThresholdNumOfParties(self: &ParamsCKKSRNS) -> u32; fn SetBatchSize(self: Pin<&mut ParamsCKKSRNS>, batchSize0: u32); - fn SetDecryptionNoiseMode( - self: Pin<&mut ParamsCKKSRNS>, - decryptionNoiseMode0: DecryptionNoiseMode, - ); + fn SetDecryptionNoiseMode(self: Pin<&mut ParamsCKKSRNS>, + decryptionNoiseMode0: DecryptionNoiseMode); fn SetDesiredPrecision(self: Pin<&mut ParamsCKKSRNS>, desiredPrecision0: f64); fn SetDigitSize(self: Pin<&mut ParamsCKKSRNS>, digitSize0: u32); - fn SetEncryptionTechnique( - self: Pin<&mut ParamsCKKSRNS>, - encryptionTechnique0: EncryptionTechnique, - ); + fn SetEncryptionTechnique(self: Pin<&mut ParamsCKKSRNS>, + encryptionTechnique0: EncryptionTechnique); fn SetEvalAddCount(self: Pin<&mut ParamsCKKSRNS>, evalAddCount0: u32); fn SetExecutionMode(self: Pin<&mut ParamsCKKSRNS>, executionMode0: ExecutionMode); fn SetFirstModSize(self: Pin<&mut ParamsCKKSRNS>, firstModSize0: u32); - fn SetInteractiveBootCompressionLevel( - self: Pin<&mut ParamsCKKSRNS>, - interactiveBootCompressionLevel0: COMPRESSION_LEVEL, - ); + fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsCKKSRNS>, + interactiveBootCompressionLevel0: COMPRESSION_LEVEL); fn SetKeySwitchCount(self: Pin<&mut ParamsCKKSRNS>, keySwitchCount0: u32); fn SetKeySwitchTechnique(self: Pin<&mut ParamsCKKSRNS>, ksTech0: KeySwitchTechnique); fn SetMaxRelinSkDeg(self: Pin<&mut ParamsCKKSRNS>, maxRelinSkDeg0: u32); fn SetMultipartyMode(self: Pin<&mut ParamsCKKSRNS>, multipartyMode0: MultipartyMode); - fn SetMultiplicationTechnique( - self: Pin<&mut ParamsCKKSRNS>, - multiplicationTechnique0: MultiplicationTechnique, - ); + fn SetMultiplicationTechnique(self: Pin<&mut ParamsCKKSRNS>, + multiplicationTechnique0: MultiplicationTechnique); fn SetMultiplicativeDepth(self: Pin<&mut ParamsCKKSRNS>, multiplicativeDepth0: u32); fn SetNoiseEstimate(self: Pin<&mut ParamsCKKSRNS>, noiseEstimate0: f64); fn SetNumAdversarialQueries(self: Pin<&mut ParamsCKKSRNS>, numAdversarialQueries0: u32); @@ -1444,13 +1046,13 @@ pub mod ffi { // Generator functions fn GenParamsCKKSRNS() -> UniquePtr<ParamsCKKSRNS>; - fn GenParamsCKKSRNSbyVectorOfString( - vals: &CxxVector<CxxString>, - ) -> UniquePtr<ParamsCKKSRNS>; + fn GenParamsCKKSRNSbyVectorOfString(vals: &CxxVector<CxxString>) + -> UniquePtr<ParamsCKKSRNS>; } // Plaintext - unsafe extern "C++" { + unsafe extern "C++" + { fn Decode(self: &Plaintext) -> bool; fn Encode(self: &Plaintext) -> bool; fn GetCoefPackedValue(self: &Plaintext) -> &CxxVector<i64>; @@ -1484,114 +1086,81 @@ pub mod ffi { } // PublicKeyDCRTPoly - unsafe extern "C++" { + unsafe extern "C++" + { // Generator functions fn DCRTPolyGenNullPublicKey() -> UniquePtr<PublicKeyDCRTPoly>; } // PrivateKeyDCRTPoly - unsafe extern "C++" { + unsafe extern "C++" + { // Generator functions fn DCRTPolyGenNullPrivateKey() -> UniquePtr<PrivateKeyDCRTPoly>; } // Serialize / Deserialize - unsafe extern "C++" { + unsafe extern "C++" + { // Ciphertext - fn DCRTPolyDeserializeCiphertextFromFile( - ciphertextLocation: &CxxString, - ciphertext: Pin<&mut CiphertextDCRTPoly>, - serialMode: SerialMode, - ) -> bool; - fn DCRTPolySerializeCiphertextToFile( - ciphertextLocation: &CxxString, - ciphertext: &CiphertextDCRTPoly, - serialMode: SerialMode, - ) -> bool; + fn DCRTPolyDeserializeCiphertextFromFile(ciphertextLocation: &CxxString, + ciphertext: Pin<&mut CiphertextDCRTPoly>, + serialMode: SerialMode) -> bool; + fn DCRTPolySerializeCiphertextToFile(ciphertextLocation: &CxxString, + ciphertext: &CiphertextDCRTPoly, + serialMode: SerialMode) -> bool; // CryptoContextDCRTPoly - fn DCRTPolyDeserializeCryptoContextFromFile( - ccLocation: &CxxString, - cryptoContext: Pin<&mut CryptoContextDCRTPoly>, - serialMode: SerialMode, - ) -> bool; - fn DCRTPolySerializeCryptoContextToFile( - ccLocation: &CxxString, - cryptoContext: &CryptoContextDCRTPoly, - serialMode: SerialMode, - ) -> bool; + fn DCRTPolyDeserializeCryptoContextFromFile(ccLocation: &CxxString, + cryptoContext: Pin<&mut CryptoContextDCRTPoly>, + serialMode: SerialMode) -> bool; + fn DCRTPolySerializeCryptoContextToFile(ccLocation: &CxxString, + cryptoContext: &CryptoContextDCRTPoly, + serialMode: SerialMode) -> bool; // EvalAutomorphismKey - fn DCRTPolyDeserializeEvalAutomorphismKeyFromFile( - automorphismKeyLocation: &CxxString, - serialMode: SerialMode, - ) -> bool; - fn DCRTPolySerializeEvalAutomorphismKeyByIdToFile( - automorphismKeyLocation: &CxxString, - serialMode: SerialMode, - id: &CxxString, - ) -> bool; - fn DCRTPolySerializeEvalAutomorphismKeyToFile( - automorphismKeyLocation: &CxxString, - cryptoContext: &CryptoContextDCRTPoly, - serialMode: SerialMode, - ) -> bool; + fn DCRTPolyDeserializeEvalAutomorphismKeyFromFile(automorphismKeyLocation: &CxxString, + serialMode: SerialMode) -> bool; + fn DCRTPolySerializeEvalAutomorphismKeyByIdToFile(automorphismKeyLocation: &CxxString, + serialMode: SerialMode, id: &CxxString) + -> bool; + fn DCRTPolySerializeEvalAutomorphismKeyToFile(automorphismKeyLocation: &CxxString, + cryptoContext: &CryptoContextDCRTPoly, + serialMode: SerialMode) -> bool; // EvalMultKey - fn DCRTPolyDeserializeEvalMultKeyFromFile( - multKeyLocation: &CxxString, - serialMode: SerialMode, - ) -> bool; - fn DCRTPolySerializeEvalMultKeyByIdToFile( - multKeyLocation: &CxxString, - serialMode: SerialMode, - id: &CxxString, - ) -> bool; - fn DCRTPolySerializeEvalMultKeyToFile( - multKeyLocation: &CxxString, - cryptoContext: &CryptoContextDCRTPoly, - serialMode: SerialMode, - ) -> bool; + fn DCRTPolyDeserializeEvalMultKeyFromFile(multKeyLocation: &CxxString, + serialMode: SerialMode) -> bool; + fn DCRTPolySerializeEvalMultKeyByIdToFile(multKeyLocation: &CxxString, + serialMode: SerialMode, id: &CxxString) -> bool; + fn DCRTPolySerializeEvalMultKeyToFile(multKeyLocation: &CxxString, + cryptoContext: &CryptoContextDCRTPoly, + serialMode: SerialMode) -> bool; // EvalSumKey - fn DCRTPolyDeserializeEvalSumKeyFromFile( - sumKeyLocation: &CxxString, - serialMode: SerialMode, - ) -> bool; - fn DCRTPolySerializeEvalSumKeyByIdToFile( - sumKeyLocation: &CxxString, - serialMode: SerialMode, - id: &CxxString, - ) -> bool; - fn DCRTPolySerializeEvalSumKeyToFile( - sumKeyLocation: &CxxString, - cryptoContext: &CryptoContextDCRTPoly, - serialMode: SerialMode, - ) -> bool; + fn DCRTPolyDeserializeEvalSumKeyFromFile(sumKeyLocation: &CxxString, + serialMode: SerialMode) -> bool; + fn DCRTPolySerializeEvalSumKeyByIdToFile(sumKeyLocation: &CxxString, + serialMode: SerialMode, id: &CxxString) -> bool; + fn DCRTPolySerializeEvalSumKeyToFile(sumKeyLocation: &CxxString, + cryptoContext: &CryptoContextDCRTPoly, + serialMode: SerialMode) -> bool; // PublicKey - fn DCRTPolyDeserializePublicKeyFromFile( - publicKeyLocation: &CxxString, - publicKey: Pin<&mut PublicKeyDCRTPoly>, - serialMode: SerialMode, - ) -> bool; - fn DCRTPolySerializePublicKeyToFile( - publicKeyLocation: &CxxString, - publicKey: &PublicKeyDCRTPoly, - serialMode: SerialMode, - ) -> bool; + fn DCRTPolyDeserializePublicKeyFromFile(publicKeyLocation: &CxxString, + publicKey: Pin<&mut PublicKeyDCRTPoly>, + serialMode: SerialMode) -> bool; + fn DCRTPolySerializePublicKeyToFile(publicKeyLocation: &CxxString, + publicKey: &PublicKeyDCRTPoly, + serialMode: SerialMode) -> bool; // PrivateKey - fn DCRTPolyDeserializePrivateKeyFromFile( - privateKeyLocation: &CxxString, - privateKey: Pin<&mut PrivateKeyDCRTPoly>, - serialMode: SerialMode, - ) -> bool; - fn DCRTPolySerializePrivateKeyToFile( - privateKeyLocation: &CxxString, - privateKey: &PrivateKeyDCRTPoly, - serialMode: SerialMode, - ) -> bool; + fn DCRTPolyDeserializePrivateKeyFromFile(privateKeyLocation: &CxxString, + privateKey: Pin<&mut PrivateKeyDCRTPoly>, + serialMode: SerialMode) -> bool; + fn DCRTPolySerializePrivateKeyToFile(privateKeyLocation: &CxxString, + privateKey: &PrivateKeyDCRTPoly, + serialMode: SerialMode) -> bool; } // Trapdoor @@ -1647,6 +1216,7 @@ pub mod ffi { } } + use crate::ffi::DCRTPoly; use std::fmt; @@ -1663,12 +1233,14 @@ impl PartialEq for DCRTPoly { } #[cfg(test)] -mod tests { +mod tests +{ use super::*; // TODO: add more tests #[test] - fn SimpleIntegersExample() { + fn SimpleIntegersExample() + { let mut _cc_params_bfvrns = ffi::GenParamsBFVRNS(); _cc_params_bfvrns.pin_mut().SetPlaintextModulus(65537); _cc_params_bfvrns.pin_mut().SetMultiplicativeDepth(2); @@ -1686,11 +1258,7 @@ mod tests { _index_list.pin_mut().push(2); _index_list.pin_mut().push(-1); _index_list.pin_mut().push(-2); - _cc.EvalRotateKeyGen( - &_key_pair.GetPrivateKey(), - &_index_list, - &ffi::DCRTPolyGenNullPublicKey(), - ); + _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::DCRTPolyGenNullPublicKey()); let mut _vector_of_ints_1 = CxxVector::<i64>::new(); _vector_of_ints_1.pin_mut().push(1); @@ -1742,12 +1310,10 @@ mod tests { let _cipher_text_3 = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_plain_text_3); let _cipher_text_add_1_2 = _cc.EvalAddByCiphertexts(&_cipher_text_1, &_cipher_text_2); - let _cipher_text_add_result = - _cc.EvalAddByCiphertexts(&_cipher_text_add_1_2, &_cipher_text_3); + let _cipher_text_add_result = _cc.EvalAddByCiphertexts(&_cipher_text_add_1_2, &_cipher_text_3); let _cipher_text_mul_1_2 = _cc.EvalMultByCiphertexts(&_cipher_text_1, &_cipher_text_2); - let _cipher_text_mult_result = - _cc.EvalMultByCiphertexts(&_cipher_text_mul_1_2, &_cipher_text_3); + let _cipher_text_mult_result = _cc.EvalMultByCiphertexts(&_cipher_text_mul_1_2, &_cipher_text_3); let _cipher_text_rot_1 = _cc.EvalRotate(&_cipher_text_1, 1); let _cipher_text_rot_2 = _cc.EvalRotate(&_cipher_text_1, 2); @@ -1755,41 +1321,17 @@ mod tests { let _cipher_text_rot_4 = _cc.EvalRotate(&_cipher_text_1, -2); let mut _plain_text_add_result = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_cipher_text_add_result, - _plain_text_add_result.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_add_result, _plain_text_add_result.pin_mut()); let mut _plain_text_mult_result = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_cipher_text_mult_result, - _plain_text_mult_result.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_mult_result, _plain_text_mult_result.pin_mut()); let mut _plain_text_rot_1 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_cipher_text_rot_1, - _plain_text_rot_1.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_1, _plain_text_rot_1.pin_mut()); let mut _plain_text_rot_2 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_cipher_text_rot_2, - _plain_text_rot_2.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_2, _plain_text_rot_2.pin_mut()); let mut _plain_text_rot_3 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_cipher_text_rot_3, - _plain_text_rot_3.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_3, _plain_text_rot_3.pin_mut()); let mut _plain_text_rot_4 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_cipher_text_rot_4, - _plain_text_rot_4.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_4, _plain_text_rot_4.pin_mut()); _plain_text_rot_1.SetLength(_vector_of_ints_1.len()); _plain_text_rot_2.SetLength(_vector_of_ints_1.len()); @@ -1803,37 +1345,22 @@ mod tests { println!("\nResults of homomorphic computations"); println!("#1 + #2 + #3: {}", _plain_text_add_result.GetString()); println!("#1 * #2 * #3: {}", _plain_text_mult_result.GetString()); - println!( - "Left rotation of #1 by 1: {}", - _plain_text_rot_1.GetString() - ); - println!( - "Left rotation of #1 by 2: {}", - _plain_text_rot_2.GetString() - ); - println!( - "Right rotation of #1 by -1: {}", - _plain_text_rot_3.GetString() - ); - println!( - "Right rotation of #1 by -2: {}", - _plain_text_rot_4.GetString() - ); + println!("Left rotation of #1 by 1: {}", _plain_text_rot_1.GetString()); + println!("Left rotation of #1 by 2: {}", _plain_text_rot_2.GetString()); + println!("Right rotation of #1 by -1: {}", _plain_text_rot_3.GetString()); + println!("Right rotation of #1 by -2: {}", _plain_text_rot_4.GetString()); } #[test] - fn SimpleRealNumbersExample() { + fn SimpleRealNumbersExample() + { let _mult_depth: u32 = 1; let _scale_mod_size: u32 = 50; let _batch_size: u32 = 8; let mut _cc_params_ckksrns = ffi::GenParamsCKKSRNS(); - _cc_params_ckksrns - .pin_mut() - .SetMultiplicativeDepth(_mult_depth); - _cc_params_ckksrns - .pin_mut() - .SetScalingModSize(_scale_mod_size); + _cc_params_ckksrns.pin_mut().SetMultiplicativeDepth(_mult_depth); + _cc_params_ckksrns.pin_mut().SetScalingModSize(_scale_mod_size); _cc_params_ckksrns.pin_mut().SetBatchSize(_batch_size); let _cc = ffi::DCRTPolyGenCryptoContextByParamsCKKSRNS(&_cc_params_ckksrns); @@ -1841,21 +1368,14 @@ mod tests { _cc.EnableByFeature(ffi::PKESchemeFeature::KEYSWITCH); _cc.EnableByFeature(ffi::PKESchemeFeature::LEVELEDSHE); - println!( - "CKKS scheme is using ring dimension {}\n", - _cc.GetRingDimension() - ); + println!("CKKS scheme is using ring dimension {}\n", _cc.GetRingDimension()); let _key_pair = _cc.KeyGen(); _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey()); let mut _index_list = CxxVector::<i32>::new(); _index_list.pin_mut().push(1); _index_list.pin_mut().push(-2); - _cc.EvalRotateKeyGen( - &_key_pair.GetPrivateKey(), - &_index_list, - &ffi::DCRTPolyGenNullPublicKey(), - ); + _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::DCRTPolyGenNullPublicKey()); let mut _x_1 = CxxVector::<f64>::new(); _x_1.pin_mut().push(0.25); @@ -1878,10 +1398,8 @@ mod tests { _x_2.pin_mut().push(0.25); let _dcrt_poly_params = ffi::DCRTPolyGenNullParams(); - let _p_txt_1 = - _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_1, 1, 0, &_dcrt_poly_params, 0); - let _p_txt_2 = - _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_2, 1, 0, &_dcrt_poly_params, 0); + let _p_txt_1 = _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_1, 1, 0, &_dcrt_poly_params, 0); + let _p_txt_2 = _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_2, 1, 0, &_dcrt_poly_params, 0); println!("Input x1: {}", _p_txt_1.GetString()); println!("Input x2: {}", _p_txt_2.GetString()); @@ -1901,68 +1419,37 @@ mod tests { _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c1, _result.pin_mut()); _result.SetLength(_batch_size.try_into().unwrap()); - println!( - "x1 = {}Estimated precision in bits: {}", - _result.GetString(), - _result.GetLogPrecision() - ); - - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_c_add, - _result.pin_mut(), - ); + println!("x1 = {}Estimated precision in bits: {}", _result.GetString(), _result.GetLogPrecision()); + + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_add, _result.pin_mut()); _result.SetLength(_batch_size.try_into().unwrap()); - println!( - "x1 + x2 = {}Estimated precision in bits: {}", - _result.GetString(), - _result.GetLogPrecision() - ); - - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_c_sub, - _result.pin_mut(), - ); + println!("x1 + x2 = {}Estimated precision in bits: {}",_result.GetString(), _result.GetLogPrecision()); + + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_sub, _result.pin_mut()); _result.SetLength(_batch_size.try_into().unwrap()); println!("x1 - x2 = {}", _result.GetString()); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_c_scalar, - _result.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_scalar, _result.pin_mut()); _result.SetLength(_batch_size.try_into().unwrap()); println!("4 * x1 = {}", _result.GetString()); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_c_mul, - _result.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_mul, _result.pin_mut()); _result.SetLength(_batch_size.try_into().unwrap()); println!("x1 * x2 = {}", _result.GetString()); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_c_rot_1, - _result.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_rot_1, _result.pin_mut()); _result.SetLength(_batch_size.try_into().unwrap()); println!("\nIn rotations, very small outputs (~10^-10 here) correspond to 0's:"); println!("x1 rotate by 1 = {}", _result.GetString()); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_c_rot_2, - _result.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_rot_2, _result.pin_mut()); _result.SetLength(_batch_size.try_into().unwrap()); println!("x1 rotate by -2 = {}", _result.GetString()); } #[test] - fn PolynomialEvaluationExample() { + fn PolynomialEvaluationExample() + { use std::time::Instant; println!("\n======EXAMPLE FOR EVALPOLY========\n"); @@ -1977,15 +1464,11 @@ mod tests { _cc.EnableByFeature(ffi::PKESchemeFeature::ADVANCEDSHE); let mut _input = CxxVector::<ffi::ComplexPair>::new(); - _input.pin_mut().push(ffi::ComplexPair { re: 0.5, im: 0.0 }); - _input.pin_mut().push(ffi::ComplexPair { re: 0.7, im: 0.0 }); - _input.pin_mut().push(ffi::ComplexPair { re: 0.9, im: 0.0 }); - _input - .pin_mut() - .push(ffi::ComplexPair { re: 0.95, im: 0.0 }); - _input - .pin_mut() - .push(ffi::ComplexPair { re: 0.93, im: 0.0 }); + _input.pin_mut().push(ffi::ComplexPair{re: 0.5, im: 0.0}); + _input.pin_mut().push(ffi::ComplexPair{re: 0.7, im: 0.0}); + _input.pin_mut().push(ffi::ComplexPair{re: 0.9, im: 0.0}); + _input.pin_mut().push(ffi::ComplexPair{re: 0.95, im: 0.0}); + _input.pin_mut().push(ffi::ComplexPair{re: 0.93, im: 0.0}); let _encoded_length = _input.len(); let mut _coefficients_1 = CxxVector::<f64>::new(); @@ -2040,8 +1523,7 @@ mod tests { _coefficients_2.pin_mut().push(-0.5); let _dcrt_poly_params = ffi::DCRTPolyGenNullParams(); - let _plain_text_1 = - _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0); + let _plain_text_1 = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0); let _key_pair = _cc.KeyGen(); print!("Generating evaluation key for homomorphic multiplication..."); _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey()); @@ -2057,39 +1539,19 @@ mod tests { let _time_eval_poly_2 = _start.elapsed(); let mut _plain_text_dec = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_result, - _plain_text_dec.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_result, _plain_text_dec.pin_mut()); _plain_text_dec.SetLength(_encoded_length); let mut _plain_text_dec_2 = ffi::GenNullPlainText(); - _cc.DecryptByPrivateKeyAndCiphertext( - &_key_pair.GetPrivateKey(), - &_result_2, - _plain_text_dec_2.pin_mut(), - ); + _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_result_2, _plain_text_dec_2.pin_mut()); _plain_text_dec_2.SetLength(_encoded_length); println!("\n Original Plaintext #1:"); println!("{}", _plain_text_1.GetString()); - println!( - "\n Result of evaluating a polynomial with coefficients [{} ]", - _coefficients_1 - .iter() - .fold(String::new(), |acc, &arg| acc + " " + &arg.to_string()) - ); + println!("\n Result of evaluating a polynomial with coefficients [{} ]", _coefficients_1.iter().fold(String::new(), |acc, &arg| acc + " " + &arg.to_string())); println!("{}", _plain_text_dec.GetString()); - println!( - "\n Expected result: (0.70519107, 1.38285078, 3.97211180, 5.60215665, 4.86357575)" - ); + println!("\n Expected result: (0.70519107, 1.38285078, 3.97211180, 5.60215665, 4.86357575)"); println!("\n Evaluation time: {:.0?}", _time_eval_poly_1); - println!( - "\n Result of evaluating a polynomial with coefficients [{} ]", - _coefficients_2 - .iter() - .fold(String::new(), |acc, &arg| acc + " " + &arg.to_string()) - ); + println!("\n Result of evaluating a polynomial with coefficients [{} ]", _coefficients_2.iter().fold(String::new(), |acc, &arg| acc + " " + &arg.to_string())); println!("{}\n", _plain_text_dec_2.GetString()); println!(" Expected result: (3.4515092326, 5.3752765397, 4.8993108833, 3.2495023573, 4.0485229982)"); print!("\n Evaluation time: {:.0?}\n", _time_eval_poly_2); From 4438ee215acc637fecb4ef08400bdb11cae24613 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Thu, 6 Mar 2025 10:44:27 +0800 Subject: [PATCH 23/24] fix: merge conflicts --- examples/trapdoor.rs | 19 ------------------- src/DCRTPoly.cc | 8 -------- src/Params.h | 3 --- src/lib.rs | 9 --------- 4 files changed, 39 deletions(-) delete mode 100644 examples/trapdoor.rs diff --git a/examples/trapdoor.rs b/examples/trapdoor.rs deleted file mode 100644 index bbfb06a..0000000 --- a/examples/trapdoor.rs +++ /dev/null @@ -1,19 +0,0 @@ -use openfhe::ffi; - -fn main() { - // Parameters based on https://github.com/openfheorg/openfhe-development/blob/7b8346f4eac27121543e36c17237b919e03ec058/src/core/unittest/UnitTestTrapdoor.cpp#L314 - let n: u32 = 16; - let size: u32 = 4; - let k_res: u32 = 51; - let base: i64 = 8; - - let params = ffi::GenILDCRTParamsByOrderSizeBits(2 * n, size, k_res); - - let u = ffi::DCRTPolyGenFromDug(&params); - - let trapdoor = ffi::DCRTPolyTrapdoorGen(&params, base, false); - - let k = 68; // to calculate - - let _res = ffi::DCRTPolyGaussSamp(n.try_into().unwrap(), k, &trapdoor, &u, base); -} diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 905574a..5466339 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -158,12 +158,4 @@ std::unique_ptr<DCRTPolyParams> DCRTPolyGenNullParams() { return std::make_unique<DCRTPolyParams>(); } - -std::unique_ptr<DCRTPolyImpl> DCRTPolyGenFromDug(const ILDCRTParams& params) -{ - std::shared_ptr<ILDCRTParams> params_ptr = std::make_shared<ILDCRTParams>(params); - typename DCRTPolyImpl::DugType dug; - return std::make_unique<DCRTPolyImpl>(dug, params_ptr, Format::EVALUATION); -} - } // openfhe diff --git a/src/Params.h b/src/Params.h index d146b3f..432655f 100644 --- a/src/Params.h +++ b/src/Params.h @@ -5,8 +5,6 @@ #include "openfhe/pke/scheme/bfvrns/gen-cryptocontext-bfvrns-params.h" #include "openfhe/pke/scheme/bgvrns/gen-cryptocontext-bgvrns-params.h" #include "openfhe/pke/scheme/ckksrns/gen-cryptocontext-ckksrns-params.h" -#include "openfhe/core/lattice/hal/default/ildcrtparams.h" -#include "openfhe/core/math/math-hal.h" #include "rust/cxx.h" @@ -32,7 +30,6 @@ using Params = lbcrypto::Params; using ParamsBFVRNS = lbcrypto::CCParams<lbcrypto::CryptoContextBFVRNS>; using ParamsBGVRNS = lbcrypto::CCParams<lbcrypto::CryptoContextBGVRNS>; using ParamsCKKSRNS = lbcrypto::CCParams<lbcrypto::CryptoContextCKKSRNS>; -using ILDCRTParams = lbcrypto::ILDCRTParams<lbcrypto::BigInteger>; // Generator functions [[nodiscard]] std::unique_ptr<ParamsBFVRNS> GenParamsBFVRNS(); diff --git a/src/lib.rs b/src/lib.rs index 39c1e4a..21b4dd3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -198,14 +198,12 @@ pub mod ffi type CryptoContextDCRTPoly; type CryptoParametersBaseDCRTPoly; type DCRTPoly; - type DCRTPolyImpl; type DCRTPolyParams; type DCRTTrapdoor; type DecryptResult; type EncodingParams; type EvalKeyDCRTPoly; type KeyPairDCRTPoly; - type ILDCRTParams; type LWEPrivateKey; type MapFromIndexToEvalKey; type MapFromStringToMapFromIndexToEvalKey; @@ -228,7 +226,6 @@ pub mod ffi type VectorOfLWECiphertexts; type VectorOfPrivateKeys; type VectorOfVectorOfCiphertexts; - type TrapdoorOutput; } // CiphertextDCRTPoly @@ -771,12 +768,6 @@ pub mod ffi fn GetPublicKey(self: &KeyPairDCRTPoly) -> UniquePtr<PublicKeyDCRTPoly>; } - // ILDCRTParams - unsafe extern "C++" - { - fn GenILDCRTParamsByOrderSizeBits(corder: u32, depth: u32, bits: u32) -> UniquePtr<ILDCRTParams>; - } - // Params unsafe extern "C++" { From 622355b0bc5b4f0acb3ada338d2aea25977707ee Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Sun, 16 Mar 2025 18:39:13 +0800 Subject: [PATCH 24/24] feat: add `Decompose` --- examples/dcrt_poly.rs | 6 +++++- src/DCRTPoly.cc | 47 +++++++++++++++++++++++++++++++++++++++++++ src/DCRTPoly.h | 23 +++++++++++++++++++++ src/Trapdoor.cc | 32 ----------------------------- src/Trapdoor.h | 21 ------------------- src/lib.rs | 1 + 6 files changed, 76 insertions(+), 54 deletions(-) diff --git a/examples/dcrt_poly.rs b/examples/dcrt_poly.rs index f9a8bd3..0accea5 100644 --- a/examples/dcrt_poly.rs +++ b/examples/dcrt_poly.rs @@ -1,6 +1,6 @@ use num_bigint::BigUint; use num_traits::Num; -use openfhe::ffi; +use openfhe::ffi::{self, GetMatrixElement}; fn main() { let val = String::from("123456789099999"); @@ -102,4 +102,8 @@ fn main() { base, sigma, ); + + let dummy_poly = ffi::DCRTPolyGenFromDug(n, size, k_res); + let decomposed_poly = dummy_poly.Decompose(); + let poly_0_0 = GetMatrixElement(&decomposed_poly, 0, 0); } diff --git a/src/DCRTPoly.cc b/src/DCRTPoly.cc index 5466339..474d34d 100644 --- a/src/DCRTPoly.cc +++ b/src/DCRTPoly.cc @@ -54,6 +54,20 @@ std::unique_ptr<DCRTPoly> DCRTPoly::Negate() const return std::make_unique<DCRTPoly>(-m_poly); } +std::unique_ptr<Matrix> DCRTPoly::Decompose() const +{ + std::vector<lbcrypto::DCRTPoly> decomposed = m_poly.CRTDecompose(1); + + auto zero_alloc = lbcrypto::DCRTPoly::Allocator(m_poly.GetParams(), Format::COEFFICIENT); + lbcrypto::Matrix<lbcrypto::DCRTPoly> decomposedMatrix(zero_alloc, 1, decomposed.size()); + + for (size_t i = 0; i < decomposed.size(); i++) { + decomposedMatrix(0, i) = decomposed[i]; + } + + return std::make_unique<Matrix>(std::move(decomposedMatrix)); +} + // Arithmetic std::unique_ptr<DCRTPoly> DCRTPolyAdd(const DCRTPoly& rhs, const DCRTPoly& lhs) { @@ -158,4 +172,37 @@ std::unique_ptr<DCRTPolyParams> DCRTPolyGenNullParams() { return std::make_unique<DCRTPolyParams>(); } + +// Matrix functions +std::unique_ptr<Matrix> MatrixGen( + usint n, + size_t size, + size_t kRes, + size_t nrow, + size_t ncol) +{ + auto params = std::make_shared<lbcrypto::ILDCRTParams<lbcrypto::BigInteger>>(2 * n, size, kRes); + auto zero_alloc = lbcrypto::DCRTPoly::Allocator(params, Format::EVALUATION); + Matrix matrix(zero_alloc, nrow, ncol); + return std::make_unique<Matrix>(std::move(matrix)); +} + +void SetMatrixElement( + Matrix& matrix, + size_t row, + size_t col, + const DCRTPoly& element) +{ + matrix(row, col) = element.GetPoly(); +} + +std::unique_ptr<DCRTPoly> GetMatrixElement( + const Matrix& matrix, + size_t row, + size_t col) +{ + lbcrypto::DCRTPoly copy = matrix(row, col); + return std::make_unique<DCRTPoly>(std::move(copy)); +} + } // openfhe diff --git a/src/DCRTPoly.h b/src/DCRTPoly.h index e7ce254..13ad703 100644 --- a/src/DCRTPoly.h +++ b/src/DCRTPoly.h @@ -2,10 +2,13 @@ #include "openfhe/core/lattice/hal/lat-backend.h" #include "rust/cxx.h" +#include "openfhe/core/math/matrix.h" namespace openfhe { +using Matrix = lbcrypto::Matrix<lbcrypto::DCRTPoly>; + class DCRTPoly final { lbcrypto::DCRTPoly m_poly; @@ -22,6 +25,7 @@ class DCRTPoly final [[nodiscard]] rust::Vec<rust::String> GetCoefficients() const; [[nodiscard]] rust::String GetModulus() const; [[nodiscard]] std::unique_ptr<DCRTPoly> Negate() const; + [[nodiscard]] std::unique_ptr<Matrix> Decompose() const; }; // Generator functions @@ -63,4 +67,23 @@ class DCRTPolyParams final // Generator functions [[nodiscard]] std::unique_ptr<DCRTPolyParams> DCRTPolyGenNullParams(); + +// Matrix functions +[[nodiscard]] std::unique_ptr<Matrix> MatrixGen( + usint n, + size_t size, + size_t kRes, + size_t nrow, + size_t ncol); + +void SetMatrixElement( + Matrix& matrix, + size_t row, + size_t col, + const DCRTPoly& element); + +[[nodiscard]] std::unique_ptr<DCRTPoly> GetMatrixElement( + const Matrix& matrix, + size_t row, + size_t col); } // openfhe diff --git a/src/Trapdoor.cc b/src/Trapdoor.cc index 4945092..07948a7 100644 --- a/src/Trapdoor.cc +++ b/src/Trapdoor.cc @@ -121,36 +121,4 @@ std::unique_ptr<Matrix> DCRTSquareMatTrapdoorGaussSamp(usint n, usint k, const M return std::make_unique<Matrix>(std::move(result)); } - -// Matrix functions -std::unique_ptr<Matrix> MatrixGen( - usint n, - size_t size, - size_t kRes, - size_t nrow, - size_t ncol) -{ - auto params = std::make_shared<lbcrypto::ILDCRTParams<lbcrypto::BigInteger>>(2 * n, size, kRes); - auto zero_alloc = lbcrypto::DCRTPoly::Allocator(params, Format::EVALUATION); - Matrix matrix(zero_alloc, nrow, ncol); - return std::make_unique<Matrix>(std::move(matrix)); -} - -void SetMatrixElement( - Matrix& matrix, - size_t row, - size_t col, - const DCRTPoly& element) -{ - matrix(row, col) = element.GetPoly(); -} - -std::unique_ptr<DCRTPoly> GetMatrixElement( - const Matrix& matrix, - size_t row, - size_t col) -{ - lbcrypto::DCRTPoly copy = matrix(row, col); - return std::make_unique<DCRTPoly>(std::move(copy)); -} } // openfhe \ No newline at end of file diff --git a/src/Trapdoor.h b/src/Trapdoor.h index 3a20163..2a50fea 100644 --- a/src/Trapdoor.h +++ b/src/Trapdoor.h @@ -1,13 +1,11 @@ #pragma once #include "openfhe/core/lattice/trapdoor.h" -#include "openfhe/core/math/matrix.h" #include "DCRTPoly.h" namespace openfhe { using RLWETrapdoorPair = lbcrypto::RLWETrapdoorPair<lbcrypto::DCRTPoly>; -using Matrix = lbcrypto::Matrix<lbcrypto::DCRTPoly>; class DCRTTrapdoor final { @@ -62,23 +60,4 @@ class DCRTTrapdoor final const Matrix& U, int64_t base, double sigma); - -// Matrix functions -[[nodiscard]] std::unique_ptr<Matrix> MatrixGen( - usint n, - size_t size, - size_t kRes, - size_t nrow, - size_t ncol); - -void SetMatrixElement( - Matrix& matrix, - size_t row, - size_t col, - const DCRTPoly& element); - -[[nodiscard]] std::unique_ptr<DCRTPoly> GetMatrixElement( - const Matrix& matrix, - size_t row, - size_t col); } // openfhe \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 21b4dd3..88abd6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -731,6 +731,7 @@ pub mod ffi fn GetCoefficients(self: &DCRTPoly) -> Vec<String>; fn GetModulus(self: &DCRTPoly) -> String; fn Negate(self: &DCRTPoly) -> UniquePtr<DCRTPoly>; + fn Decompose(self: &DCRTPoly) -> UniquePtr<Matrix>; // Generator functions fn DCRTPolyGenFromConst(n: u32, size: usize, k_res: usize, value: &String)