소스 검색

Adaptation to OpenFHE v1.2.0 release

Hovsep Papoyan 1 년 전
부모
커밋
4a1b880722
7개의 변경된 파일55개의 추가작업 그리고 54개의 파일을 삭제
  1. 1 1
      README.md
  2. 1 1
      docs/source/intro.rst
  3. 18 11
      src/AssociativeContainers.cc
  4. 9 0
      src/AssociativeContainers.h
  5. 14 18
      src/CryptoContext.cc
  6. 6 7
      src/CryptoContext.h
  7. 6 16
      src/lib.rs

+ 1 - 1
README.md

@@ -124,7 +124,7 @@ cargo test -- --test-threads=1
 cargo run --example function_evaluation
 cargo run --example polynomial_evaluation
 cargo run --example simple_integers
-cargo run --example simple_real_integers
+cargo run --example simple_real_numbers
 ```
 
 # Contributing

+ 1 - 1
docs/source/intro.rst

@@ -132,7 +132,7 @@ You can adjust the installation process by building the crate manually. In that
     cargo run --example function_evaluation
     cargo run --example polynomial_evaluation
     cargo run --example simple_integers
-    cargo run --example simple_real_integers
+    cargo run --example simple_real_numbers
 
 Contributing
 ============

+ 18 - 11
src/AssociativeContainers.cc

@@ -14,25 +14,32 @@ const std::shared_ptr<std::map<uint32_t, std::shared_ptr<EvalKeyImpl>>>&
     return m_sharedPtrToindexToEvalKeyDCRTPolyMap;
 }
 
-UnorderedMapFromIndexToDCRTPoly::UnorderedMapFromIndexToDCRTPoly(
-    std::unordered_map<uint32_t, lbcrypto::DCRTPoly>&& indexToDCRTPolyUnorderedMap) noexcept
-    : m_indexToDCRTPolyUnorderedMap(std::move(indexToDCRTPolyUnorderedMap))
-{ }
-std::unordered_map<uint32_t, lbcrypto::DCRTPoly>&
-    UnorderedMapFromIndexToDCRTPoly::GetRef() noexcept
-{
-    return m_indexToDCRTPolyUnorderedMap;
-}
-
 MapFromStringToMapFromIndexToEvalKey::MapFromStringToMapFromIndexToEvalKey(
     std::map<std::string, std::shared_ptr<std::map<uint32_t, std::shared_ptr<EvalKeyImpl>>>>
     stringToMapFromIndexToEvalKeyMap)
     : m_stringToMapFromIndexToEvalKeyMap(std::move(stringToMapFromIndexToEvalKeyMap))
 { }
-
 MapFromStringToVectorOfEvalKeys::MapFromStringToVectorOfEvalKeys(
     std::map<std::string, std::vector<std::shared_ptr<EvalKeyImpl>>> stringToVectorOfEvalKeysMap)
     : m_stringToVectorOfEvalKeysMap(std::move(stringToVectorOfEvalKeysMap))
 { }
 
+SetOfUints::SetOfUints(std::set<uint32_t>&& uintsSet) noexcept
+    : m_uintsSet(std::move(uintsSet))
+{ }
+const std::set<uint32_t>& SetOfUints::GetRef() const noexcept
+{
+    return m_uintsSet;
+}
+
+UnorderedMapFromIndexToDCRTPoly::UnorderedMapFromIndexToDCRTPoly(
+    std::unordered_map<uint32_t, lbcrypto::DCRTPoly>&& indexToDCRTPolyUnorderedMap) noexcept
+    : m_indexToDCRTPolyUnorderedMap(std::move(indexToDCRTPolyUnorderedMap))
+{ }
+std::unordered_map<uint32_t, lbcrypto::DCRTPoly>&
+    UnorderedMapFromIndexToDCRTPoly::GetRef() noexcept
+{
+    return m_indexToDCRTPolyUnorderedMap;
+}
+
 } // openfhe

+ 9 - 0
src/AssociativeContainers.h

@@ -4,6 +4,7 @@
 #include "openfhe/pke/key/evalkey-fwd.h"
 
 #include <map>
+#include <set>
 #include <unordered_map>
 
 // cxx currently does not support std::unordered_map and std::map
@@ -44,6 +45,14 @@ public:
         stringToVectorOfEvalKeysMap);
 };
 
+class SetOfUints final
+{
+    std::set<uint32_t> m_uintsSet;
+public:
+    explicit SetOfUints(std::set<uint32_t>&& uintsSet) noexcept;
+    [[nodiscard]] const std::set<uint32_t>& GetRef() const noexcept;
+};
+
 class UnorderedMapFromIndexToDCRTPoly final
 {
     std::unordered_map<uint32_t, lbcrypto::DCRTPoly> m_indexToDCRTPolyUnorderedMap;

+ 14 - 18
src/CryptoContext.cc

@@ -1099,6 +1099,13 @@ std::unique_ptr<MapFromStringToMapFromIndexToEvalKey> DCRTPolyGetCopyOfAllEvalSu
     return std::make_unique<MapFromStringToMapFromIndexToEvalKey>(
         CryptoContextImpl::GetAllEvalSumKeys());
 }
+std::unique_ptr<MapFromIndexToEvalKey> DCRTPolyGetCopyOfEvalAutomorphismKeyMap(
+    const std::string& keyID)
+{
+    return std::make_unique<MapFromIndexToEvalKey>(
+        std::make_shared<std::map<uint32_t, std::shared_ptr<EvalKeyImpl>>>(
+        CryptoContextImpl::GetEvalAutomorphismKeyMap(keyID)));
+}
 std::unique_ptr<VectorOfEvalKeys> DCRTPolyGetCopyOfEvalMultKeyVector(const std::string& keyID)
 {
     return std::make_unique<VectorOfEvalKeys>(CryptoContextImpl::GetEvalMultKeyVector(keyID));
@@ -1109,22 +1116,11 @@ std::unique_ptr<MapFromIndexToEvalKey> DCRTPolyGetCopyOfEvalSumKeyMap(const std:
         std::make_shared<std::map<uint32_t, std::shared_ptr<EvalKeyImpl>>>(
         CryptoContextImpl::GetEvalSumKeyMap(id)));
 }
-std::unique_ptr<MapFromIndexToEvalKey> DCRTPolyGetEvalAutomorphismKeyMap(const std::string& keyID)
-{
-    return std::make_unique<MapFromIndexToEvalKey>(CryptoContextImpl::GetEvalAutomorphismKeyMapPtr(
-        keyID));
-}
-std::unique_ptr<MapFromIndexToEvalKey> DCRTPolyGetEvalAutomorphismKeyMapPtr(
-    const std::string& keyID)
-{
-    return std::make_unique<MapFromIndexToEvalKey>(CryptoContextImpl::GetEvalAutomorphismKeyMapPtr(
-        keyID));
-}
-std::unique_ptr<std::vector<uint32_t>> DCRTPolyGetExistingEvalAutomorphismKeyIndices(
+std::unique_ptr<SetOfUints> DCRTPolyGetExistingEvalAutomorphismKeyIndices(
     const std::string& keyTag)
 {
-    return std::make_unique<std::vector<uint32_t>>(
-        CryptoContextImpl::GetExistingEvalAutomorphismKeyIndices(keyTag));
+    return std::make_unique<SetOfUints>(CryptoContextImpl::GetExistingEvalAutomorphismKeyIndices(
+        keyTag));
 }
 std::unique_ptr<Plaintext> DCRTPolyGetPlaintextForDecrypt(const PlaintextEncodings pte,
     const DCRTPolyParams& evp, const EncodingParams& ep)
@@ -1132,11 +1128,11 @@ std::unique_ptr<Plaintext> DCRTPolyGetPlaintextForDecrypt(const PlaintextEncodin
     return std::make_unique<Plaintext>(CryptoContextImpl::GetPlaintextForDecrypt(pte,
         evp.GetRef(), ep.GetRef()));
 }
-std::unique_ptr<std::vector<uint32_t>> DCRTPolyGetUniqueValues(
-    const std::vector<uint32_t>& oldValues, const std::vector<uint32_t>& newValues)
+std::unique_ptr<SetOfUints> DCRTPolyGetUniqueValues(const SetOfUints& oldValues,
+    const SetOfUints& newValues)
 {
-    return std::make_unique<std::vector<uint32_t>>(CryptoContextImpl::GetUniqueValues(oldValues,
-        newValues));
+    return std::make_unique<SetOfUints>(CryptoContextImpl::GetUniqueValues(oldValues.GetRef(),
+        newValues.GetRef()));
 }
 void DCRTPolyInsertEvalAutomorphismKey(const MapFromIndexToEvalKey& evalKeyMap,
     const std::string& keyTag)

+ 6 - 7
src/CryptoContext.h

@@ -40,6 +40,7 @@ class Plaintext;
 class PrivateKeyDCRTPoly;
 class PublicKeyDCRTPoly;
 class SchemeBaseDCRTPoly;
+class SetOfUints;
 class UnorderedMapFromIndexToDCRTPoly;
 class VectorOfCiphertexts;
 class VectorOfDCRTPolys;
@@ -451,20 +452,18 @@ void DCRTPolyClearEvalSumKeysById(const std::string& id);
 [[nodiscard]] std::unique_ptr<MapFromStringToVectorOfEvalKeys> DCRTPolyGetCopyOfAllEvalMultKeys();
 [[nodiscard]] std::unique_ptr<MapFromStringToMapFromIndexToEvalKey>
     DCRTPolyGetCopyOfAllEvalSumKeys();
+[[nodiscard]] std::unique_ptr<MapFromIndexToEvalKey> DCRTPolyGetCopyOfEvalAutomorphismKeyMap(
+    const std::string& keyID);
 [[nodiscard]] std::unique_ptr<VectorOfEvalKeys> DCRTPolyGetCopyOfEvalMultKeyVector(
     const std::string& keyID);
 [[nodiscard]] std::unique_ptr<MapFromIndexToEvalKey> DCRTPolyGetCopyOfEvalSumKeyMap(
     const std::string& id);
-[[nodiscard]] std::unique_ptr<MapFromIndexToEvalKey> DCRTPolyGetEvalAutomorphismKeyMap(
-    const std::string& keyID);
-[[nodiscard]] std::unique_ptr<MapFromIndexToEvalKey> DCRTPolyGetEvalAutomorphismKeyMapPtr(
-    const std::string& keyID);
-[[nodiscard]] std::unique_ptr<std::vector<uint32_t>> DCRTPolyGetExistingEvalAutomorphismKeyIndices(
+[[nodiscard]] std::unique_ptr<SetOfUints> DCRTPolyGetExistingEvalAutomorphismKeyIndices(
     const std::string& keyTag);
 [[nodiscard]] std::unique_ptr<Plaintext> DCRTPolyGetPlaintextForDecrypt(
     const PlaintextEncodings pte, const DCRTPolyParams& evp, const EncodingParams& ep);
-[[nodiscard]] std::unique_ptr<std::vector<uint32_t>> DCRTPolyGetUniqueValues(
-    const std::vector<uint32_t>& oldValues, const std::vector<uint32_t>& newValues);
+[[nodiscard]] std::unique_ptr<SetOfUints> DCRTPolyGetUniqueValues(
+    const SetOfUints& oldValues, const SetOfUints& newValues);
 void DCRTPolyInsertEvalAutomorphismKey(const MapFromIndexToEvalKey& evalKeyMap,
     const std::string& keyTag /* "" */);
 void DCRTPolyInsertEvalMultKey(const VectorOfEvalKeys& evalKeyVec);

+ 6 - 16
src/lib.rs

@@ -98,7 +98,6 @@ pub mod ffi
         INDCPA,
         FIXED_NOISE_HRA,
         NOISE_FLOODING_HRA,
-        DIVIDE_AND_ROUND_HRA,
     }
 
     #[repr(i32)]
@@ -215,6 +214,7 @@ pub mod ffi
         type PrivateKeyDCRTPoly;
         type PublicKeyDCRTPoly;
         type SchemeBaseDCRTPoly;
+        type SetOfUints;
         type UnorderedMapFromIndexToDCRTPoly;
         type VectorOfCiphertexts;
         type VectorOfDCRTPolys;
@@ -693,18 +693,16 @@ pub mod ffi
             -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>;
         fn DCRTPolyGetCopyOfAllEvalMultKeys() -> UniquePtr<MapFromStringToVectorOfEvalKeys>;
         fn DCRTPolyGetCopyOfAllEvalSumKeys() -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>;
+        fn DCRTPolyGetCopyOfEvalAutomorphismKeyMap(keyID: &CxxString)
+                                                   -> UniquePtr<MapFromIndexToEvalKey>;
         fn DCRTPolyGetCopyOfEvalMultKeyVector(keyID: &CxxString) -> UniquePtr<VectorOfEvalKeys>;
         fn DCRTPolyGetCopyOfEvalSumKeyMap(id: &CxxString) -> UniquePtr<MapFromIndexToEvalKey>;
-        fn DCRTPolyGetEvalAutomorphismKeyMap(keyID: &CxxString)
-                                             -> UniquePtr<MapFromIndexToEvalKey>;
-        fn DCRTPolyGetEvalAutomorphismKeyMapPtr(keyID: &CxxString)
-                                                -> UniquePtr<MapFromIndexToEvalKey>;
         fn DCRTPolyGetExistingEvalAutomorphismKeyIndices(keyTag: &CxxString)
-                                                         -> UniquePtr<CxxVector<u32>>;
+                                                         -> UniquePtr<SetOfUints>;
         fn DCRTPolyGetPlaintextForDecrypt(pte: PlaintextEncodings, evp: &DCRTPolyParams,
                                           ep: &EncodingParams) -> UniquePtr<Plaintext>;
-        fn DCRTPolyGetUniqueValues(oldValues: &CxxVector<u32>, newValues: &CxxVector<u32>)
-                                   -> UniquePtr<CxxVector<u32>>;
+        fn DCRTPolyGetUniqueValues(oldValues: &SetOfUints, newValues: &SetOfUints)
+                                   -> UniquePtr<SetOfUints>;
         fn DCRTPolyInsertEvalAutomorphismKey(evalKeyMap: &MapFromIndexToEvalKey,
                                              keyTag: /* "" */ &CxxString);
         fn DCRTPolyInsertEvalMultKey(evalKeyVec: &VectorOfEvalKeys);
@@ -750,7 +748,6 @@ pub mod ffi
         fn GetKeySwitchCount(self: &Params) -> u32;
         fn GetKeySwitchTechnique(self: &Params) -> KeySwitchTechnique;
         fn GetMaxRelinSkDeg(self: &Params) -> u32;
-        fn GetMultiHopModSize(self: &Params) -> u32;
         fn GetMultipartyMode(self: &Params) -> MultipartyMode;
         fn GetMultiplicationTechnique(self: &Params) -> MultiplicationTechnique;
         fn GetMultiplicativeDepth(self: &Params) -> u32;
@@ -783,7 +780,6 @@ pub mod ffi
         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 SetMultiHopModSize(self: Pin<&mut Params>, multiHopModSize0: u32);
         fn SetMultipartyMode(self: Pin<&mut Params>, multipartyMode0: MultipartyMode);
         fn SetMultiplicationTechnique(self: Pin<&mut Params>,
                                       multiplicationTechnique0: MultiplicationTechnique);
@@ -822,7 +818,6 @@ pub mod ffi
         fn GetKeySwitchCount(self: &ParamsBFVRNS) -> u32;
         fn GetKeySwitchTechnique(self: &ParamsBFVRNS) -> KeySwitchTechnique;
         fn GetMaxRelinSkDeg(self: &ParamsBFVRNS) -> u32;
-        fn GetMultiHopModSize(self: &ParamsBFVRNS) -> u32;
         fn GetMultipartyMode(self: &ParamsBFVRNS) -> MultipartyMode;
         fn GetMultiplicationTechnique(self: &ParamsBFVRNS) -> MultiplicationTechnique;
         fn GetMultiplicativeDepth(self: &ParamsBFVRNS) -> u32;
@@ -855,7 +850,6 @@ pub mod ffi
         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 SetMultiHopModSize(self: Pin<&mut ParamsBFVRNS>, multiHopModSize0: u32);
         fn SetMultipartyMode(self: Pin<&mut ParamsBFVRNS>, multipartyMode0: MultipartyMode);
         fn SetMultiplicationTechnique(self: Pin<&mut ParamsBFVRNS>,
                                       multiplicationTechnique0: MultiplicationTechnique);
@@ -894,7 +888,6 @@ pub mod ffi
         fn GetKeySwitchCount(self: &ParamsBGVRNS) -> u32;
         fn GetKeySwitchTechnique(self: &ParamsBGVRNS) -> KeySwitchTechnique;
         fn GetMaxRelinSkDeg(self: &ParamsBGVRNS) -> u32;
-        fn GetMultiHopModSize(self: &ParamsBGVRNS) -> u32;
         fn GetMultipartyMode(self: &ParamsBGVRNS) -> MultipartyMode;
         fn GetMultiplicationTechnique(self: &ParamsBGVRNS) -> MultiplicationTechnique;
         fn GetMultiplicativeDepth(self: &ParamsBGVRNS) -> u32;
@@ -927,7 +920,6 @@ pub mod ffi
         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 SetMultiHopModSize(self: Pin<&mut ParamsBGVRNS>, multiHopModSize0: u32);
         fn SetMultipartyMode(self: Pin<&mut ParamsBGVRNS>, multipartyMode0: MultipartyMode);
         fn SetMultiplicationTechnique(self: Pin<&mut ParamsBGVRNS>,
                                       multiplicationTechnique0: MultiplicationTechnique);
@@ -966,7 +958,6 @@ pub mod ffi
         fn GetKeySwitchCount(self: &ParamsCKKSRNS) -> u32;
         fn GetKeySwitchTechnique(self: &ParamsCKKSRNS) -> KeySwitchTechnique;
         fn GetMaxRelinSkDeg(self: &ParamsCKKSRNS) -> u32;
-        fn GetMultiHopModSize(self: &ParamsCKKSRNS) -> u32;
         fn GetMultipartyMode(self: &ParamsCKKSRNS) -> MultipartyMode;
         fn GetMultiplicationTechnique(self: &ParamsCKKSRNS) -> MultiplicationTechnique;
         fn GetMultiplicativeDepth(self: &ParamsCKKSRNS) -> u32;
@@ -999,7 +990,6 @@ pub mod ffi
         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 SetMultiHopModSize(self: Pin<&mut ParamsCKKSRNS>, multiHopModSize0: u32);
         fn SetMultipartyMode(self: Pin<&mut ParamsCKKSRNS>, multipartyMode0: MultipartyMode);
         fn SetMultiplicationTechnique(self: Pin<&mut ParamsCKKSRNS>,
                                       multiplicationTechnique0: MultiplicationTechnique);