Browse Source

Adding VectorOfEvalKeys and related functions

Hovsep Papoyan 6 months ago
parent
commit
8528e07ac1

+ 12 - 6
src/CryptoContext.cc

@@ -6,8 +6,6 @@
 #include "openfhe/pke/scheme/bgvrns/gen-cryptocontext-bgvrns.h"
 #include "openfhe/pke/scheme/ckksrns/gen-cryptocontext-ckksrns.h"
 
-
-
 #include "openfhe/src/lib.rs.h" // ComplexPair
 
 #include "AssociativeContainerOfOpaqueTypes.h"
@@ -1003,21 +1001,21 @@ std::unique_ptr<MapFromIndexToEvalKey> CryptoContextDCRTPoly::MultiAddEvalAutomo
         m_cryptoContextImplSharedPtr->MultiAddEvalAutomorphismKeys(evalKeyMap1.GetInternal(),
         evalKeyMap2.GetInternal(), keyId));
 }
-std::unique_ptr<VectorOfDCRTPoly> CryptoContextDCRTPoly::EvalFastRotationPrecompute(
+std::unique_ptr<VectorOfDCRTPolys> CryptoContextDCRTPoly::EvalFastRotationPrecompute(
     const CiphertextDCRTPoly& ciphertext) const
 {
-    return std::make_unique<VectorOfDCRTPoly>(
+    return std::make_unique<VectorOfDCRTPolys>(
         m_cryptoContextImplSharedPtr->EvalFastRotationPrecompute(ciphertext.GetInternal()));
 }
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalFastRotation(
     const CiphertextDCRTPoly& ciphertext, const uint32_t index, const uint32_t m,
-    const VectorOfDCRTPoly& digits) const
+    const VectorOfDCRTPolys& digits) const
 {
     return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalFastRotation(
         ciphertext.GetInternal(), index, m, digits.GetInternal()));
 }
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalFastRotationExt(
-    const CiphertextDCRTPoly& ciphertext, const uint32_t index, const VectorOfDCRTPoly& digits,
+    const CiphertextDCRTPoly& ciphertext, const uint32_t index, const VectorOfDCRTPolys& digits,
     const bool addFirst) const
 {
     return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalFastRotationExt(
@@ -1100,6 +1098,14 @@ void InsertEvalSumKey(const MapFromIndexToEvalKey& mapToInsert, const std::strin
 {
     CryptoContextImpl::InsertEvalSumKey(mapToInsert.GetInternal(), keyTag);
 }
+std::unique_ptr<VectorOfEvalKeys> GetCopyOfEvalMultKeyVector(const std::string& keyID)
+{
+    return std::make_unique<VectorOfEvalKeys>(CryptoContextImpl::GetEvalMultKeyVector(keyID));
+}
+void InsertEvalMultKey(const VectorOfEvalKeys& evalKeyVec)
+{
+    CryptoContextImpl::InsertEvalMultKey(evalKeyVec.GetInternal());
+}
 
 // Generator functions
 std::unique_ptr<CryptoContextDCRTPoly> GenNullCryptoContext()

+ 8 - 4
src/CryptoContext.h

@@ -39,7 +39,8 @@ class PrivateKeyDCRTPoly;
 class PublicKeyDCRTPoly;
 class UnorderedMapFromIndexToDCRTPoly;
 class VectorOfCiphertexts;
-class VectorOfDCRTPoly;
+class VectorOfDCRTPolys;
+class VectorOfEvalKeys;
 class VectorOfPrivateKeys;
 
 using SCHEME = lbcrypto::SCHEME;
@@ -415,13 +416,13 @@ public:
     [[nodiscard]] std::unique_ptr<MapFromIndexToEvalKey> MultiAddEvalAutomorphismKeys(
         const MapFromIndexToEvalKey& evalKeyMap1, const MapFromIndexToEvalKey& evalKeyMap2,
         const std::string& keyId /* "" */) const;
-    [[nodiscard]] std::unique_ptr<VectorOfDCRTPoly> EvalFastRotationPrecompute(
+    [[nodiscard]] std::unique_ptr<VectorOfDCRTPolys> EvalFastRotationPrecompute(
         const CiphertextDCRTPoly& ciphertext) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalFastRotation(
         const CiphertextDCRTPoly& ciphertext, const uint32_t index, const uint32_t m,
-        const VectorOfDCRTPoly& digits) const;
+        const VectorOfDCRTPolys& digits) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalFastRotationExt(
-        const CiphertextDCRTPoly& ciphertext, const uint32_t index, const VectorOfDCRTPoly& digits,
+        const CiphertextDCRTPoly& ciphertext, const uint32_t index, const VectorOfDCRTPolys& digits,
         const bool addFirst) const;
     [[nodiscard]] std::shared_ptr<CryptoContextImpl> GetInternal() const;
 };
@@ -448,6 +449,9 @@ void ClearEvalAutomorphismKeysByCryptoContext(const CryptoContextDCRTPoly& crypt
 void InsertEvalAutomorphismKey(const MapFromIndexToEvalKey& evalKeyMap,
     const std::string& keyTag /* "" */);
 void InsertEvalSumKey(const MapFromIndexToEvalKey& mapToInsert, const std::string& keyTag /* "" */);
+[[nodiscard]] std::unique_ptr<VectorOfEvalKeys> GetCopyOfEvalMultKeyVector(
+    const std::string& keyID);
+void InsertEvalMultKey(const VectorOfEvalKeys& evalKeyVec);
 
 // Generator functions
 [[nodiscard]] std::unique_ptr<CryptoContextDCRTPoly> GenNullCryptoContext();

+ 11 - 2
src/SequenceContainerOfOpaqueTypes.cc

@@ -23,12 +23,21 @@ const std::vector<std::shared_ptr<PrivateKeyImpl>>& VectorOfPrivateKeys::GetInte
     return m_privateKeys;
 }
 
-VectorOfDCRTPoly::VectorOfDCRTPoly(const std::shared_ptr<std::vector<lbcrypto::DCRTPoly>> elements)
+VectorOfDCRTPolys::VectorOfDCRTPolys(
+    const std::shared_ptr<std::vector<lbcrypto::DCRTPoly>> elements)
     : m_elements(elements)
 { }
-std::shared_ptr<std::vector<lbcrypto::DCRTPoly>> VectorOfDCRTPoly::GetInternal() const
+std::shared_ptr<std::vector<lbcrypto::DCRTPoly>> VectorOfDCRTPolys::GetInternal() const
 {
     return m_elements;
 }
 
+VectorOfEvalKeys::VectorOfEvalKeys(std::vector<std::shared_ptr<EvalKeyImpl>> evalKeys)
+    : m_evalKeys(std::move(evalKeys))
+{ }
+const std::vector<std::shared_ptr<EvalKeyImpl>>& VectorOfEvalKeys::GetInternal() const
+{
+    return m_evalKeys;
+}
+
 } // openfhe

+ 13 - 2
src/SequenceContainerOfOpaqueTypes.h

@@ -2,6 +2,7 @@
 
 #include "openfhe/core/lattice/hal/lat-backend.h"
 #include "openfhe/pke/ciphertext-fwd.h"
+#include "openfhe/pke/key/evalkey-fwd.h"
 #include "openfhe/pke/key/privatekey-fwd.h"
 
 #include <vector>
@@ -32,12 +33,22 @@ public:
     [[nodiscard]] const std::vector<std::shared_ptr<PrivateKeyImpl>>& GetInternal() const;
 };
 
-class VectorOfDCRTPoly final
+class VectorOfDCRTPolys final
 {
     std::shared_ptr<std::vector<lbcrypto::DCRTPoly>> m_elements;
 public:
-    explicit VectorOfDCRTPoly(const std::shared_ptr<std::vector<lbcrypto::DCRTPoly>> elements);
+    explicit VectorOfDCRTPolys(const std::shared_ptr<std::vector<lbcrypto::DCRTPoly>> elements);
     [[nodiscard]] std::shared_ptr<std::vector<lbcrypto::DCRTPoly>> GetInternal() const;
 };
 
+using EvalKeyImpl = lbcrypto::EvalKeyImpl<lbcrypto::DCRTPoly>;
+
+class VectorOfEvalKeys final
+{
+    std::vector<std::shared_ptr<EvalKeyImpl>> m_evalKeys;
+public:
+    explicit VectorOfEvalKeys(std::vector<std::shared_ptr<EvalKeyImpl>> evalKeys);
+    [[nodiscard]] const std::vector<std::shared_ptr<EvalKeyImpl>>& GetInternal() const;
+};
+
 } // openfhe

+ 7 - 4
src/lib.rs

@@ -192,7 +192,8 @@ pub mod ffi
         type MapFromIndexToEvalKey;
         type UnorderedMapFromIndexToDCRTPoly;
         type VectorOfCiphertexts;
-        type VectorOfDCRTPoly;
+        type VectorOfDCRTPolys;
+        type VectorOfEvalKeys;
         type VectorOfPrivateKeys;
     }
 
@@ -934,13 +935,13 @@ pub mod ffi
                                         -> UniquePtr<MapFromIndexToEvalKey>;
         fn EvalFastRotationPrecompute(self: &CryptoContextDCRTPoly,
                                       ciphertext: &CiphertextDCRTPoly)
-                                      -> UniquePtr<VectorOfDCRTPoly>;
+                                      -> UniquePtr<VectorOfDCRTPolys>;
         fn EvalFastRotation(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
-                            index: u32, m: u32, digits: &VectorOfDCRTPoly)
+                            index: u32, m: u32, digits: &VectorOfDCRTPolys)
                             -> UniquePtr<CiphertextDCRTPoly>;
         fn EvalFastRotationExt(self: &CryptoContextDCRTPoly,
                                ciphertext: &CiphertextDCRTPoly, index: u32,
-                               digits: &VectorOfDCRTPoly, addFirst: bool)
+                               digits: &VectorOfDCRTPolys, addFirst: bool)
                                -> UniquePtr<CiphertextDCRTPoly>;
 
         // cxx currently does not support static class methods
@@ -962,6 +963,8 @@ pub mod ffi
         fn InsertEvalAutomorphismKey(evalKeyMap: &MapFromIndexToEvalKey,
                                      keyTag: /* "" */ &CxxString);
         fn InsertEvalSumKey(mapToInsert: &MapFromIndexToEvalKey, keyTag: /* "" */ &CxxString);
+        fn GetCopyOfEvalMultKeyVector(keyID: &CxxString) -> UniquePtr<VectorOfEvalKeys>;
+        fn InsertEvalMultKey(evalKeyVec: &VectorOfEvalKeys);
     }
 
     // Serialize / Deserialize