浏览代码

feat: add `DCRTPolyGenFromDug`

Enrico Bottazzi 9 月之前
父节点
当前提交
232441745a
共有 4 个文件被更改,包括 26 次插入2 次删除
  1. 3 2
      examples/trapdoor.rs
  2. 8 0
      src/DCRTPoly.cc
  3. 8 0
      src/DCRTPoly.h
  4. 7 0
      src/lib.rs

+ 3 - 2
examples/trapdoor.rs

@@ -1,11 +1,12 @@
 use openfhe::ffi;
 
 fn main() {
-
     // Parameters based on https://github.com/openfheorg/openfhe-development/blob/7b8346f4eac27121543e36c17237b919e03ec058/src/core/unittest/UnitTestTrapdoor.cpp#L314
     let n = 16;
     let size = 4;
     let k_res = 51;
 
-    let _params = ffi::GenILDCRTParamsByOrderSizeBits(2 * n, size, k_res);
+    let params = ffi::GenILDCRTParamsByOrderSizeBits(2 * n, size, k_res);
+
+    let u = ffi::DCRTPolyGenFromDug(&params);
 }

+ 8 - 0
src/DCRTPoly.cc

@@ -1,4 +1,5 @@
 #include "DCRTPoly.h"
+#include "openfhe/src/lib.rs.h"
 
 namespace openfhe
 {
@@ -21,4 +22,11 @@ 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::COEFFICIENT);
+}
+
 } // openfhe

+ 8 - 0
src/DCRTPoly.h

@@ -1,6 +1,9 @@
 #pragma once
 
 #include "openfhe/core/lattice/hal/lat-backend.h"
+#include "openfhe/core/lattice/hal/default/dcrtpoly.h"
+#include "openfhe/core/math/math-hal.h"
+#include "Params.h"
 
 namespace openfhe
 {
@@ -33,4 +36,9 @@ public:
 // Generator functions
 [[nodiscard]] std::unique_ptr<DCRTPolyParams> DCRTPolyGenNullParams();
 
+using DCRTPolyImpl = lbcrypto::DCRTPolyImpl<lbcrypto::BigVector>;
+
+// Generator functions
+[[nodiscard]] std::unique_ptr<DCRTPolyImpl> DCRTPolyGenFromDug(const ILDCRTParams& params);
+
 } // openfhe

+ 7 - 0
src/lib.rs

@@ -197,6 +197,7 @@ pub mod ffi
         type CryptoContextDCRTPoly;
         type CryptoParametersBaseDCRTPoly;
         type DCRTPoly;
+        type DCRTPolyImpl;
         type DCRTPolyParams;
         type DecryptResult;
         type EncodingParams;
@@ -727,6 +728,12 @@ pub mod ffi
         fn DCRTPolyGenNullParams() -> UniquePtr<DCRTPolyParams>;
     }
 
+    // DCRTPolyImpl
+    unsafe extern "C++"
+    {
+        fn DCRTPolyGenFromDug(params: &ILDCRTParams) -> UniquePtr<DCRTPolyImpl>;
+    }
+
     // KeyPairDCRTPoly
     unsafe extern "C++"
     {