Ver código fonte

Adding first part of map, unordered_map related functional

Hovsep Papoyan 5 meses atrás
pai
commit
093cc02a70

+ 6 - 3
build.rs

@@ -11,7 +11,8 @@ fn main()
         .file("src/SerialDeserial.cc")
         .file("src/EvalKey.cc")
         .file("src/LWEPrivateKey.cc")
-        .file("src/VectorOfCiphertexts.cc")
+        .file("src/SequenceContainerOfOpaqueTypes.cc")
+        .file("src/AssociativeContainerOfOpaqueTypes.cc")
         .include("/usr/local/include/openfhe")
         .include("/usr/local/include/openfhe/third-party/include")
         .include("/usr/local/include/openfhe/core")
@@ -49,8 +50,10 @@ fn main()
     println!("cargo::rerun-if-changed=src/EvalKey.cc");
     println!("cargo::rerun-if-changed=src/LWEPrivateKey.h");
     println!("cargo::rerun-if-changed=src/LWEPrivateKey.cc");
-    println!("cargo::rerun-if-changed=src/VectorOfCiphertexts.h");
-    println!("cargo::rerun-if-changed=src/VectorOfCiphertexts.cc");
+    println!("cargo::rerun-if-changed=src/SequenceContainerOfOpaqueTypes.h");
+    println!("cargo::rerun-if-changed=src/SequenceContainerOfOpaqueTypes.cc");
+    println!("cargo::rerun-if-changed=src/AssociativeContainerOfOpaqueTypes.h");
+    println!("cargo::rerun-if-changed=src/AssociativeContainerOfOpaqueTypes.cc");
 
     // linking openFHE
     println!("cargo::rustc-link-arg=-L/usr/local/lib");

+ 24 - 0
src/AssociativeContainerOfOpaqueTypes.cc

@@ -0,0 +1,24 @@
+#include "AssociativeContainerOfOpaqueTypes.h"
+
+namespace openfhe
+{
+
+UnorderedMapFromIndexToDCRTPoly::UnorderedMapFromIndexToDCRTPoly(
+    std::unordered_map<uint32_t, DCRTPoly> indexToDCRTPolyUnorderedMap)
+    : m_indexToDCRTPolyUnorderedMap(std::move(indexToDCRTPolyUnorderedMap))
+{ }
+std::unordered_map<uint32_t, DCRTPoly>& UnorderedMapFromIndexToDCRTPoly::GetInternal()
+{
+    return m_indexToDCRTPolyUnorderedMap;
+}
+
+MapFromIndexToEvalKey::MapFromIndexToEvalKey(
+    std::map<uint32_t, std::shared_ptr<EvalKeyImpl>> indexToEvalKeyDCRTPolyMap)
+    : m_indexToEvalKeyDCRTPolyMap(std::move(indexToEvalKeyDCRTPolyMap))
+{ }
+const std::map<uint32_t, std::shared_ptr<EvalKeyImpl>>& MapFromIndexToEvalKey::GetInternal() const
+{
+    return m_indexToEvalKeyDCRTPolyMap;
+}
+
+} // openfhe

+ 39 - 0
src/AssociativeContainerOfOpaqueTypes.h

@@ -0,0 +1,39 @@
+#pragma once
+
+#include "openfhe/core/lattice/hal/lat-backend.h"
+#include "openfhe/pke/key/evalkey-fwd.h"
+
+#include "EvalKey.h"
+
+#include <cstdint>
+#include <map>
+#include <unordered_map>
+
+// cxx currently does not support std::unordered_map and std::map
+
+namespace openfhe
+{
+
+using DCRTPoly = lbcrypto::DCRTPoly;
+
+class UnorderedMapFromIndexToDCRTPoly final
+{
+    std::unordered_map<uint32_t, DCRTPoly> m_indexToDCRTPolyUnorderedMap;
+public:
+    explicit UnorderedMapFromIndexToDCRTPoly(
+        std::unordered_map<uint32_t, DCRTPoly> indexToDCRTPolyUnorderedMap);
+    [[nodiscard]] std::unordered_map<uint32_t, DCRTPoly>& GetInternal();
+};
+
+using EvalKeyImpl = lbcrypto::EvalKeyImpl<lbcrypto::DCRTPoly>;
+
+class MapFromIndexToEvalKey final
+{
+    std::map<uint32_t, std::shared_ptr<EvalKeyImpl>> m_indexToEvalKeyDCRTPolyMap;
+public:
+    explicit MapFromIndexToEvalKey(std::map<uint32_t,
+        std::shared_ptr<EvalKeyImpl>> indexToEvalKeyDCRTPolyMap);
+    [[nodiscard]] const std::map<uint32_t, std::shared_ptr<EvalKeyImpl>>& GetInternal() const;
+};
+
+} // openfhe

+ 2 - 0
src/Ciphertext.cc

@@ -12,6 +12,8 @@ std::shared_ptr<CiphertextImpl> CiphertextDCRTPoly::GetInternal() const
 {
     return m_ciphertext;
 }
+
+// Generator functions
 std::unique_ptr<CiphertextDCRTPoly> GenNullCiphertext()
 {
     return std::make_unique<CiphertextDCRTPoly>();

+ 2 - 0
src/Ciphertext.h

@@ -28,6 +28,8 @@ public:
 
     [[nodiscard]] std::shared_ptr<CiphertextImpl> GetInternal() const;
 };
+
+// Generator functions
 [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> GenNullCiphertext();
 
 } // openfhe

+ 72 - 15
src/CryptoContext.cc

@@ -1,20 +1,24 @@
 #include "CryptoContext.h"
 
+#include "openfhe/core/utils/caller_info.h" // CALLER_INFO_ARGS_HDR
 #include "openfhe/pke/gen-cryptocontext.h"
 #include "openfhe/pke/scheme/bfvrns/gen-cryptocontext-bfvrns.h"
 #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"
 #include "Ciphertext.h"
+#include "EvalKey.h"
 #include "KeyPair.h"
+#include "LWEPrivateKey.h"
 #include "Plaintext.h"
 #include "PrivateKey.h"
 #include "PublicKey.h"
-#include "EvalKey.h"
-#include "LWEPrivateKey.h"
-#include "VectorOfCiphertexts.h"
+#include "SequenceContainerOfOpaqueTypes.h"
 
 namespace openfhe
 {
@@ -40,8 +44,8 @@ std::unique_ptr<Plaintext> CryptoContextDCRTPoly::MakeCKKSPackedPlaintextByVecto
     {
         v.emplace_back(elem.re, elem.im);
     }
-    return std::make_unique<Plaintext>(m_cryptoContextImplSharedPtr->MakeCKKSPackedPlaintext(
-        v, scaleDeg, level, params, slots));
+    return std::make_unique<Plaintext>(m_cryptoContextImplSharedPtr->MakeCKKSPackedPlaintext(v,
+        scaleDeg, level, params, slots));
 }
 void CryptoContextDCRTPoly::SetSchemeId(const SCHEME schemeTag) const
 {
@@ -88,7 +92,7 @@ std::unique_ptr<KeyPairDCRTPoly> CryptoContextDCRTPoly::KeyGen() const
 {
     return std::make_unique<KeyPairDCRTPoly>(m_cryptoContextImplSharedPtr->KeyGen());
 }
-std::unique_ptr<KeyPairDCRTPoly> CryptoContextDCRTPoly::MultipartyKeyGen(
+std::unique_ptr<KeyPairDCRTPoly> CryptoContextDCRTPoly::MultipartyKeyGenByPublicKey(
     const PublicKeyDCRTPoly& publicKey, const bool makeSparse, const bool fresh) const
 {
     return std::make_unique<KeyPairDCRTPoly>(m_cryptoContextImplSharedPtr->MultipartyKeyGen(
@@ -117,13 +121,13 @@ void CryptoContextDCRTPoly::EvalRotateKeyGen(const PrivateKeyDCRTPoly& privateKe
     const std::vector<int32_t>& indexList, const PublicKeyDCRTPoly& publicKey) const
 {
     m_cryptoContextImplSharedPtr->EvalRotateKeyGen(privateKey.GetInternal(), indexList,
-    publicKey.GetInternal());
+        publicKey.GetInternal());
 }
 void CryptoContextDCRTPoly::EvalAtIndexKeyGen(const PrivateKeyDCRTPoly& privateKey,
     const std::vector<int32_t>& indexList, const PublicKeyDCRTPoly& publicKey) const
 {
     m_cryptoContextImplSharedPtr->EvalAtIndexKeyGen(privateKey.GetInternal(), indexList,
-    publicKey.GetInternal());
+        publicKey.GetInternal());
 }
 void CryptoContextDCRTPoly::EvalCKKStoFHEWPrecompute(const double scale) const
 {
@@ -193,8 +197,8 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalAddMutableByCiphe
 {
     std::shared_ptr<CiphertextImpl> c1 = ciphertext1.GetInternal();
     std::shared_ptr<CiphertextImpl> c2 = ciphertext2.GetInternal();
-    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalAddMutable(
-        c1, c2));
+    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalAddMutable(c1,
+        c2));
 }
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalAddMutableByCiphertextAndPlaintext(
     const CiphertextDCRTPoly& ciphertext, const Plaintext& plaintext) const
@@ -282,8 +286,8 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalSubMutableByCiphe
 {
     std::shared_ptr<CiphertextImpl> c1 = ciphertext1.GetInternal();
     std::shared_ptr<CiphertextImpl> c2 = ciphertext2.GetInternal();
-    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalSubMutable(
-        c1, c2));
+    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalSubMutable(c1,
+        c2));
 }
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalSubMutableByCiphertextAndPlaintext(
     const CiphertextDCRTPoly& ciphertext, const Plaintext& plaintext) const
@@ -359,8 +363,8 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalMultMutableByCiph
 {
     std::shared_ptr<CiphertextImpl> c1 = ciphertext1.GetInternal();
     std::shared_ptr<CiphertextImpl> c2 = ciphertext2.GetInternal();
-    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalMultMutable(
-        c1, c2));
+    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalMultMutable(c1,
+        c2));
 }
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalMultMutableByCiphertextAndPlaintext(
     const CiphertextDCRTPoly& ciphertext, const Plaintext& plaintext) const
@@ -701,7 +705,7 @@ void CryptoContextDCRTPoly::KeySwitchInPlace(const CiphertextDCRTPoly& ciphertex
     const EvalKeyDCRTPoly& evalKey) const
 {
     std::shared_ptr<CiphertextImpl> c = ciphertext.GetInternal();
-    m_cryptoContextImplSharedPtr->KeySwitchInPlace(c, evalKey.GetInternal());
+        m_cryptoContextImplSharedPtr->KeySwitchInPlace(c, evalKey.GetInternal());
 }
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::LevelReduce(
     const CiphertextDCRTPoly& ciphertext, const EvalKeyDCRTPoly& evalKey,
@@ -898,6 +902,48 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalLinearWSumMutable
         m_cryptoContextImplSharedPtr->EvalLinearWSumMutable(constantsVec,
         ciphertextVec.GetInternal()));
 }
+std::unique_ptr<KeyPairDCRTPoly> CryptoContextDCRTPoly::MultipartyKeyGenByVectorOfPrivateKeys(
+    const VectorOfPrivateKeys& privateKeyVec) const
+{
+    return std::make_unique<KeyPairDCRTPoly>(m_cryptoContextImplSharedPtr->MultipartyKeyGen(
+        privateKeyVec.GetInternal()));
+}
+std::unique_ptr<UnorderedMapFromIndexToDCRTPoly> CryptoContextDCRTPoly::ShareKeys(
+    const PrivateKeyDCRTPoly& sk, const uint32_t N, const uint32_t threshold, const uint32_t index,
+    const std::string& shareType) const
+{
+    return std::make_unique<UnorderedMapFromIndexToDCRTPoly>(
+        m_cryptoContextImplSharedPtr->ShareKeys(sk.GetInternal(), N, threshold, index, shareType));
+}
+void CryptoContextDCRTPoly::RecoverSharedKey(PrivateKeyDCRTPoly& sk,
+    UnorderedMapFromIndexToDCRTPoly& sk_shares, const uint32_t N, const uint32_t threshold,
+    const std::string& shareType) const
+{
+	std::shared_ptr<PrivateKeyImpl> p = sk.GetInternal();
+	m_cryptoContextImplSharedPtr->RecoverSharedKey(p, sk_shares.GetInternal(), N,
+        threshold, shareType);
+}
+std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalAutomorphism(
+    const CiphertextDCRTPoly& ciphertext, const uint32_t i,
+    const MapFromIndexToEvalKey& evalKeyMap) const
+{
+    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalAutomorphism(
+        ciphertext.GetInternal(), i, evalKeyMap.GetInternal()));
+}
+std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalSumRows(
+    const CiphertextDCRTPoly& ciphertext, const uint32_t rowSize,
+    const MapFromIndexToEvalKey& evalSumKeyMap, const uint32_t subringDim) const
+{
+    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalSumRows(
+        ciphertext.GetInternal(), rowSize, evalSumKeyMap.GetInternal(), subringDim));
+}
+std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalSumCols(
+    const CiphertextDCRTPoly& ciphertext, const uint32_t rowSize,
+    const MapFromIndexToEvalKey& evalSumKeyMap) const
+{
+    return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalSumCols(
+        ciphertext.GetInternal(), rowSize, evalSumKeyMap.GetInternal()));
+}
 std::shared_ptr<CryptoContextImpl> CryptoContextDCRTPoly::GetInternal() const
 {
     return m_cryptoContextImplSharedPtr;
@@ -952,6 +998,17 @@ std::unique_ptr<std::vector<uint32_t>> GetUniqueValues(const std::vector<uint32_
     return std::make_unique<std::vector<uint32_t>>(CryptoContextImpl::GetUniqueValues(oldValues,
         newValues));
 }
+std::unique_ptr<MapFromIndexToEvalKey> GetEvalAutomorphismKeyMap(const std::string& keyID)
+{
+    return std::make_unique<MapFromIndexToEvalKey>(std::move(
+        CryptoContextImpl::GetEvalAutomorphismKeyMap(keyID)));
+}
+std::unique_ptr<MapFromIndexToEvalKey> GetCopyOfEvalSumKeyMap(const std::string& id)
+{
+    return std::make_unique<MapFromIndexToEvalKey>(CryptoContextImpl::GetEvalSumKeyMap(id));
+}
+
+// Generator functions
 std::unique_ptr<CryptoContextDCRTPoly> GenNullCryptoContext()
 {
     return std::make_unique<CryptoContextDCRTPoly>();

+ 31 - 8
src/CryptoContext.h

@@ -29,14 +29,17 @@ namespace openfhe
 
 struct ComplexPair;
 
-class KeyPairDCRTPoly;
-class PrivateKeyDCRTPoly;
-class PublicKeyDCRTPoly;
-class Plaintext;
 class CiphertextDCRTPoly;
 class EvalKeyDCRTPoly;
+class KeyPairDCRTPoly;
 class LWEPrivateKey;
+class MapFromIndexToEvalKey;
+class Plaintext;
+class PrivateKeyDCRTPoly;
+class PublicKeyDCRTPoly;
+class UnorderedMapFromIndexToDCRTPoly;
 class VectorOfCiphertexts;
+class VectorOfPrivateKeys;
 
 using SCHEME = lbcrypto::SCHEME;
 using PKESchemeFeature = lbcrypto::PKESchemeFeature;
@@ -88,7 +91,7 @@ public:
     void Enable(const PKESchemeFeature feature) const;
     void EnableByMask(const uint32_t featureMask) const;
     [[nodiscard]] std::unique_ptr<KeyPairDCRTPoly> KeyGen() const;
-    [[nodiscard]] std::unique_ptr<KeyPairDCRTPoly> MultipartyKeyGen(
+    [[nodiscard]] std::unique_ptr<KeyPairDCRTPoly> MultipartyKeyGenByPublicKey(
         const PublicKeyDCRTPoly& publicKey, const bool makeSparse /* false */,
         const bool fresh /* false */) const;
     [[nodiscard]] std::unique_ptr<PublicKeyDCRTPoly> MultiAddPubKeys(
@@ -309,8 +312,8 @@ public:
         const PublicKeyDCRTPoly& publicKey /* GenNullPublicKey() */) const;
     [[nodiscard]] std::unique_ptr<EvalKeyDCRTPoly> KeySwitchGen(
         const PrivateKeyDCRTPoly& oldPrivateKey, const PrivateKeyDCRTPoly& newPrivateKey) const;
-    [[nodiscard]] std::unique_ptr<EvalKeyDCRTPoly> ReKeyGen(const PrivateKeyDCRTPoly& oldPrivateKey,
-        const PublicKeyDCRTPoly& newPublicKey) const;
+    [[nodiscard]] std::unique_ptr<EvalKeyDCRTPoly> ReKeyGen(
+        const PrivateKeyDCRTPoly& oldPrivateKey, const PublicKeyDCRTPoly& newPublicKey) const;
     [[nodiscard]] std::unique_ptr<EvalKeyDCRTPoly> MultiKeySwitchGen(
         const PrivateKeyDCRTPoly& originalPrivateKey, const PrivateKeyDCRTPoly& newPrivateKey,
         const EvalKeyDCRTPoly& evalKey) const;
@@ -371,9 +374,25 @@ public:
         VectorOfCiphertexts& ciphertextVec, const std::vector<double>& constantsVec) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalLinearWSumMutable(
         const std::vector<double>& constantsVec, VectorOfCiphertexts& ciphertextVec) const;
-
+    [[nodiscard]] std::unique_ptr<KeyPairDCRTPoly> MultipartyKeyGenByVectorOfPrivateKeys(
+        const VectorOfPrivateKeys& privateKeyVec) const;
+    [[nodiscard]] std::unique_ptr<UnorderedMapFromIndexToDCRTPoly> ShareKeys(
+        const PrivateKeyDCRTPoly& sk, const uint32_t N, const uint32_t threshold,
+        const uint32_t index, const std::string& shareType) const;
+    void RecoverSharedKey(PrivateKeyDCRTPoly& sk, UnorderedMapFromIndexToDCRTPoly& sk_shares,
+        const uint32_t N, const uint32_t threshold, const std::string& shareType) const;
+    [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalAutomorphism(
+        const CiphertextDCRTPoly& ciphertext, const uint32_t i,
+        const MapFromIndexToEvalKey& evalKeyMap) const;
+    [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalSumRows(
+        const CiphertextDCRTPoly& ciphertext, const uint32_t rowSize,
+        const MapFromIndexToEvalKey& evalSumKeyMap, const uint32_t subringDim /* 0 */) const;
+    [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalSumCols(
+        const CiphertextDCRTPoly& ciphertext, const uint32_t rowSize,
+        const MapFromIndexToEvalKey& evalSumKeyMap) const;
     [[nodiscard]] std::shared_ptr<CryptoContextImpl> GetInternal() const;
 };
+
 // cxx currently does not support static class methods
 void ClearEvalMultKeys();
 void ClearEvalMultKeysById(const std::string& id);
@@ -388,7 +407,11 @@ void ClearEvalAutomorphismKeysByCryptoContext(const CryptoContextDCRTPoly& crypt
     const std::string& keyTag);
 [[nodiscard]] std::unique_ptr<std::vector<uint32_t>> GetUniqueValues(
     const std::vector<uint32_t>& oldValues, const std::vector<uint32_t>& newValues);
+[[nodiscard]] std::unique_ptr<MapFromIndexToEvalKey> GetEvalAutomorphismKeyMap(
+    const std::string& keyID);
+[[nodiscard]] std::unique_ptr<MapFromIndexToEvalKey> GetCopyOfEvalSumKeyMap(const std::string& id);
 
+// Generator functions
 [[nodiscard]] std::unique_ptr<CryptoContextDCRTPoly> GenNullCryptoContext();
 [[nodiscard]] std::unique_ptr<CryptoContextDCRTPoly> GenCryptoContextByParamsBFVRNS(
     const ParamsBFVRNS& params);

+ 1 - 0
src/Params.h

@@ -26,6 +26,7 @@ using ParamsBFVRNS = lbcrypto::CCParams<lbcrypto::CryptoContextBFVRNS>;
 using ParamsBGVRNS = lbcrypto::CCParams<lbcrypto::CryptoContextBGVRNS>;
 using ParamsCKKSRNS = lbcrypto::CCParams<lbcrypto::CryptoContextCKKSRNS>;
 
+// Generator functions
 [[nodiscard]] std::unique_ptr<Params> GenParamsByScheme(const SCHEME scheme);
 [[nodiscard]] std::unique_ptr<Params> GenParamsByVectorOfString(
     const std::vector<std::string>& vals);

+ 2 - 0
src/Plaintext.cc

@@ -136,6 +136,8 @@ const std::string& Plaintext::GetStringValue() const
 {
     return m_plaintext->GetStringValue();
 }
+
+// Generator functions
 std::unique_ptr<Plaintext> GenNullPlainText()
 {
     return std::make_unique<Plaintext>();

+ 2 - 0
src/Plaintext.h

@@ -56,6 +56,8 @@ public:
     [[nodiscard]] const std::vector<int64_t>& GetCoefPackedValue() const;
     [[nodiscard]] const std::string& GetStringValue() const;
 };
+
+// Generator functions
 [[nodiscard]] std::unique_ptr<Plaintext> GenNullPlainText();
 
 } // openfhe

+ 2 - 0
src/PublicKey.cc

@@ -12,6 +12,8 @@ std::shared_ptr<PublicKeyImpl> PublicKeyDCRTPoly::GetInternal() const
 {
     return m_publicKey;
 }
+
+// Generator functions
 std::unique_ptr<PublicKeyDCRTPoly> GenNullPublicKey()
 {
     return std::make_unique<PublicKeyDCRTPoly>();

+ 2 - 1
src/PublicKey.h

@@ -21,7 +21,6 @@ public:
 
     PublicKeyDCRTPoly() = default;
     explicit PublicKeyDCRTPoly(const std::shared_ptr<PublicKeyImpl>& publicKey);
-
     PublicKeyDCRTPoly(const PublicKeyDCRTPoly&) = delete;
     PublicKeyDCRTPoly(PublicKeyDCRTPoly&&) = delete;
     PublicKeyDCRTPoly& operator=(const PublicKeyDCRTPoly&) = delete;
@@ -29,6 +28,8 @@ public:
 
     [[nodiscard]] std::shared_ptr<PublicKeyImpl> GetInternal() const;
 };
+
+// Generator functions
 [[nodiscard]] std::unique_ptr<PublicKeyDCRTPoly> GenNullPublicKey();
 
 } // openfhe

+ 9 - 1
src/VectorOfCiphertexts.cc → src/SequenceContainerOfOpaqueTypes.cc

@@ -1,4 +1,4 @@
-#include "VectorOfCiphertexts.h"
+#include "SequenceContainerOfOpaqueTypes.h"
 
 namespace openfhe
 {
@@ -15,4 +15,12 @@ std::vector<std::shared_ptr<CiphertextImpl>>& VectorOfCiphertexts::GetInternal()
     return m_ciphertexts;
 }
 
+VectorOfPrivateKeys::VectorOfPrivateKeys(std::vector<std::shared_ptr<PrivateKeyImpl>> privateKeys)
+    : m_privateKeys(std::move(privateKeys))
+{ }
+const std::vector<std::shared_ptr<PrivateKeyImpl>>& VectorOfPrivateKeys::GetInternal() const
+{
+    return m_privateKeys;
+}
+
 } // openfhe

+ 35 - 0
src/SequenceContainerOfOpaqueTypes.h

@@ -0,0 +1,35 @@
+#pragma once
+
+#include "openfhe/core/lattice/hal/lat-backend.h"
+#include "openfhe/pke/ciphertext-fwd.h"
+#include "openfhe/pke/key/privatekey-fwd.h"
+
+#include <vector>
+
+// cxx currently does not support std::vector of opaque type
+
+namespace openfhe
+{
+
+using CiphertextImpl = lbcrypto::CiphertextImpl<lbcrypto::DCRTPoly>;
+
+class VectorOfCiphertexts final
+{
+    std::vector<std::shared_ptr<CiphertextImpl>> m_ciphertexts;
+public:
+    explicit VectorOfCiphertexts(std::vector<std::shared_ptr<CiphertextImpl>> ciphertexts);
+    [[nodiscard]] const std::vector<std::shared_ptr<CiphertextImpl>>& GetInternal() const;
+    [[nodiscard]] std::vector<std::shared_ptr<CiphertextImpl>>& GetInternal();
+};
+
+using PrivateKeyImpl = lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>;
+
+class VectorOfPrivateKeys final
+{
+    std::vector<std::shared_ptr<PrivateKeyImpl>> m_privateKeys;
+public:
+    explicit VectorOfPrivateKeys(std::vector<std::shared_ptr<PrivateKeyImpl>> ciphertexts);
+    [[nodiscard]] const std::vector<std::shared_ptr<PrivateKeyImpl>>& GetInternal() const;
+};
+
+} // openfhe

+ 0 - 22
src/VectorOfCiphertexts.h

@@ -1,22 +0,0 @@
-#pragma once
-
-#include "openfhe/core/lattice/hal/lat-backend.h"
-#include "openfhe/pke/ciphertext-fwd.h"
-
-#include <vector>
-
-namespace openfhe
-{
-
-using CiphertextImpl = lbcrypto::CiphertextImpl<lbcrypto::DCRTPoly>;
-
-class VectorOfCiphertexts final
-{
-    std::vector<std::shared_ptr<CiphertextImpl>> m_ciphertexts;
-public:
-    VectorOfCiphertexts(std::vector<std::shared_ptr<CiphertextImpl>> ciphertexts);
-    [[nodiscard]] const std::vector<std::shared_ptr<CiphertextImpl>>& GetInternal() const;
-    [[nodiscard]] std::vector<std::shared_ptr<CiphertextImpl>>& GetInternal();
-};
-
-} // openfhe

+ 26 - 6
src/lib.rs

@@ -156,7 +156,8 @@ pub mod ffi
         include!("openfhe/src/SerialDeserial.h");
         include!("openfhe/src/EvalKey.h");
         include!("openfhe/src/LWEPrivateKey.h");
-        include!("openfhe/src/VectorOfCiphertexts.h");
+        include!("openfhe/src/SequenceContainerOfOpaqueTypes.h");
+        include!("openfhe/src/AssociativeContainerOfOpaqueTypes.h");
 
         type COMPRESSION_LEVEL;
         type DecryptionNoiseMode;
@@ -184,13 +185,14 @@ pub mod ffi
         type ParamsBGVRNS;
         type ParamsCKKSRNS;
         type Plaintext;
-        type PrivateKeyImpl;
         type PrivateKeyDCRTPoly;
         type PublicKeyDCRTPoly;
-        type PublicKeyImpl;
         type EvalKeyDCRTPoly;
         type LWEPrivateKey;
+        type MapFromIndexToEvalKey;
+        type UnorderedMapFromIndexToDCRTPoly;
         type VectorOfCiphertexts;
+        type VectorOfPrivateKeys;
     }
 
     // Params
@@ -548,9 +550,9 @@ pub mod ffi
 
         fn Enable(self: &CryptoContextDCRTPoly, feature: PKESchemeFeature);
         fn KeyGen(self: &CryptoContextDCRTPoly) -> UniquePtr<KeyPairDCRTPoly>;
-        fn MultipartyKeyGen(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly,
-                            makeSparse: /* false */ bool, fresh: /* false */ bool)
-                            -> UniquePtr<KeyPairDCRTPoly>;
+        fn MultipartyKeyGenByPublicKey(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly,
+                                       makeSparse: /* false */ bool, fresh: /* false */ bool)
+                                       -> UniquePtr<KeyPairDCRTPoly>;
         fn MultiAddPubKeys(self: &CryptoContextDCRTPoly, publicKey1: &PublicKeyDCRTPoly,
                            publicKey2: &PublicKeyDCRTPoly, keyId: /* "" */ &CxxString)
                            -> UniquePtr<PublicKeyDCRTPoly>;
@@ -885,6 +887,22 @@ pub mod ffi
         fn IntMPBootEncrypt(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly,
                             sharesPair: &VectorOfCiphertexts, a: &CiphertextDCRTPoly,
                             ciphertext: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>;
+        fn MultipartyKeyGenByVectorOfPrivateKeys(self: &CryptoContextDCRTPoly,
+                                                 privateKeyVec: &VectorOfPrivateKeys)
+                                                 -> UniquePtr<KeyPairDCRTPoly>;
+        fn ShareKeys(self: &CryptoContextDCRTPoly, sk: &PrivateKeyDCRTPoly, N: u32, threshold: u32,
+                     index: u32, shareType: &CxxString)
+                     -> UniquePtr<UnorderedMapFromIndexToDCRTPoly>;
+        fn RecoverSharedKey(self: &CryptoContextDCRTPoly, sk: Pin<&mut PrivateKeyDCRTPoly>,
+                            sk_shares: Pin<&mut UnorderedMapFromIndexToDCRTPoly>, N: u32,
+                            threshold: u32, shareType: &CxxString);
+        fn EvalAutomorphism(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, i: u32,
+                            evalKeyMap: &MapFromIndexToEvalKey) -> UniquePtr<CiphertextDCRTPoly>;
+        fn EvalSumRows(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, rowSize: u32,
+                       evalSumKeyMap: &MapFromIndexToEvalKey, subringDim: /* 0 */ u32)
+                       -> UniquePtr<CiphertextDCRTPoly>;
+        fn EvalSumCols(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, rowSize: u32,
+                       evalSumKeyMap: &MapFromIndexToEvalKey) -> UniquePtr<CiphertextDCRTPoly>;
 
         // cxx currently does not support static class methods
         fn ClearEvalMultKeys();
@@ -899,6 +917,8 @@ pub mod ffi
         fn GetExistingEvalAutomorphismKeyIndices(keyTag: &CxxString) -> UniquePtr<CxxVector<u32>>;
         fn GetUniqueValues(oldValues: &CxxVector<u32>, newValues: &CxxVector<u32>)
                            -> UniquePtr<CxxVector<u32>>;
+        fn GetEvalAutomorphismKeyMap(keyID: &CxxString) -> UniquePtr<MapFromIndexToEvalKey>;
+        fn GetCopyOfEvalSumKeyMap(id: &CxxString) -> UniquePtr<MapFromIndexToEvalKey>;
     }
 
     // Serialize / Deserialize