Prechádzať zdrojové kódy

Adding VectorOfLWECiphertexts and related functions

Hovsep Papoyan 6 mesiacov pred
rodič
commit
6421f80d53

+ 13 - 0
src/CryptoContext.cc

@@ -1021,6 +1021,19 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalFastRotationExt(
     return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalFastRotationExt(
         ciphertext.GetInternal(), index, digits.GetInternal(), addFirst));
 }
+std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalFHEWtoCKKS(
+    VectorOfLWECiphertexts& LWECiphertexts, const uint32_t numCtxts, const uint32_t numSlots,
+    const uint32_t p, const double pmin, const double pmax, const uint32_t dim1) const
+{
+    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalFHEWtoCKKS(
+        LWECiphertexts.GetInternal(), numCtxts, numSlots, p, pmin, pmax, dim1));
+}
+std::unique_ptr<VectorOfLWECiphertexts> CryptoContextDCRTPoly::EvalCKKStoFHEW(
+    const CiphertextDCRTPoly& ciphertext, const uint32_t numCtxts) const
+{
+    return std::make_unique<VectorOfLWECiphertexts>(m_cryptoContextImplSharedPtr->EvalCKKStoFHEW(
+        ciphertext.GetInternal(), numCtxts));
+}
 std::shared_ptr<CryptoContextImpl> CryptoContextDCRTPoly::GetInternal() const
 {
     return m_cryptoContextImplSharedPtr;

+ 7 - 0
src/CryptoContext.h

@@ -41,6 +41,7 @@ class UnorderedMapFromIndexToDCRTPoly;
 class VectorOfCiphertexts;
 class VectorOfDCRTPolys;
 class VectorOfEvalKeys;
+class VectorOfLWECiphertexts;
 class VectorOfPrivateKeys;
 
 using SCHEME = lbcrypto::SCHEME;
@@ -424,6 +425,12 @@ public:
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalFastRotationExt(
         const CiphertextDCRTPoly& ciphertext, const uint32_t index, const VectorOfDCRTPolys& digits,
         const bool addFirst) const;
+    [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalFHEWtoCKKS(
+        VectorOfLWECiphertexts& LWECiphertexts, const uint32_t numCtxts /* 0 */,
+        const uint32_t numSlots /* 0 */, const uint32_t p /* 4 */, const double pmin /* 0.0 */,
+		const double pmax /* 2.0 */, const uint32_t dim1 /* 0 */) const;
+    [[nodiscard]] std::unique_ptr<VectorOfLWECiphertexts> EvalCKKStoFHEW(
+        const CiphertextDCRTPoly& ciphertext, const uint32_t numCtxts /* 0 */) const;
     [[nodiscard]] std::shared_ptr<CryptoContextImpl> GetInternal() const;
 };
 

+ 9 - 0
src/SequenceContainerOfOpaqueTypes.cc

@@ -40,4 +40,13 @@ const std::vector<std::shared_ptr<EvalKeyImpl>>& VectorOfEvalKeys::GetInternal()
     return m_evalKeys;
 }
 
+VectorOfLWECiphertexts::VectorOfLWECiphertexts(
+    std::vector<std::shared_ptr<LWECiphertextImpl>> lweCiphertexts)
+    : m_lweCiphertexts(std::move(lweCiphertexts))
+{ }
+std::vector<std::shared_ptr<LWECiphertextImpl>>& VectorOfLWECiphertexts::GetInternal()
+{
+    return m_lweCiphertexts;
+}
+
 } // openfhe

+ 11 - 0
src/SequenceContainerOfOpaqueTypes.h

@@ -1,5 +1,6 @@
 #pragma once
 
+#include "openfhe/binfhe/lwe-ciphertext-fwd.h"
 #include "openfhe/core/lattice/hal/lat-backend.h"
 #include "openfhe/pke/ciphertext-fwd.h"
 #include "openfhe/pke/key/evalkey-fwd.h"
@@ -51,4 +52,14 @@ public:
     [[nodiscard]] const std::vector<std::shared_ptr<EvalKeyImpl>>& GetInternal() const;
 };
 
+using LWECiphertextImpl = lbcrypto::LWECiphertextImpl;
+
+class VectorOfLWECiphertexts final
+{
+    std::vector<std::shared_ptr<LWECiphertextImpl>> m_lweCiphertexts;
+public:
+    explicit VectorOfLWECiphertexts(std::vector<std::shared_ptr<LWECiphertextImpl>> lweCiphertexts);
+    [[nodiscard]] std::vector<std::shared_ptr<LWECiphertextImpl>>& GetInternal();
+};
+
 } // openfhe

+ 7 - 0
src/lib.rs

@@ -194,6 +194,7 @@ pub mod ffi
         type VectorOfCiphertexts;
         type VectorOfDCRTPolys;
         type VectorOfEvalKeys;
+        type VectorOfLWECiphertexts;
         type VectorOfPrivateKeys;
     }
 
@@ -943,6 +944,12 @@ pub mod ffi
                                ciphertext: &CiphertextDCRTPoly, index: u32,
                                digits: &VectorOfDCRTPolys, addFirst: bool)
                                -> 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 EvalCKKStoFHEW(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
+                          numCtxts: /* 0 */ u32) -> UniquePtr<VectorOfLWECiphertexts>;
 
         // cxx currently does not support static class methods
         fn ClearEvalMultKeys();