Browse Source

Adding 6 new functions

Hovsep Papoyan 8 months ago
parent
commit
4de3c5a3cf
3 changed files with 46 additions and 1 deletions
  1. 32 1
      src/CryptoContext.cc
  2. 7 0
      src/CryptoContext.h
  3. 7 0
      src/lib.rs

+ 32 - 1
src/CryptoContext.cc

@@ -420,19 +420,28 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::Rescale(
     return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->Rescale(
         ciphertext.GetInternal()));
 }
+void CryptoContextDCRTPoly::RescaleInPlace(const CiphertextDCRTPoly& ciphertext) const
+{
+    std::shared_ptr<CiphertextImpl> c = ciphertext.GetInternal();
+    m_cryptoContextImplSharedPtr->RescaleInPlace(c);
+}
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::ModReduce(
     const CiphertextDCRTPoly& ciphertext) const
 {
     return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->ModReduce(
         ciphertext.GetInternal()));
 }
+void CryptoContextDCRTPoly::ModReduceInPlace(const CiphertextDCRTPoly& ciphertext) const
+{
+    std::shared_ptr<CiphertextImpl> c = ciphertext.GetInternal();
+    m_cryptoContextImplSharedPtr->ModReduceInPlace(c);
+}
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalSum(
     const CiphertextDCRTPoly& ciphertext, const uint32_t batchSize) const
 {
     return std::make_unique<CiphertextDCRTPoly>(m_cryptoContextImplSharedPtr->EvalSum(
         ciphertext.GetInternal(), batchSize));
 }
-
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalPolyLinear(
     const CiphertextDCRTPoly& ciphertext, const std::vector<double>& coefficients) const
 {
@@ -582,12 +591,29 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalNegate(
     return std::make_unique<CiphertextDCRTPoly>(
         m_cryptoContextImplSharedPtr->EvalNegate(ciphertext.GetInternal()));
 }
+void CryptoContextDCRTPoly::EvalNegateInPlace(const CiphertextDCRTPoly& ciphertext) const
+{
+    std::shared_ptr<CiphertextImpl> c = ciphertext.GetInternal();
+    m_cryptoContextImplSharedPtr->EvalNegateInPlace(c);
+}
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalSquare(
     const CiphertextDCRTPoly& ciphertext) const
 {
     return std::make_unique<CiphertextDCRTPoly>(
         m_cryptoContextImplSharedPtr->EvalSquare(ciphertext.GetInternal()));
 }
+std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalSquareMutable(
+    const CiphertextDCRTPoly& ciphertext) const
+{
+    std::shared_ptr<CiphertextImpl> c = ciphertext.GetInternal();
+    return std::make_unique<CiphertextDCRTPoly>(
+        m_cryptoContextImplSharedPtr->EvalSquareMutable(c));
+}
+void CryptoContextDCRTPoly::EvalSquareInPlace(const CiphertextDCRTPoly& ciphertext) const
+{
+    std::shared_ptr<CiphertextImpl> c = ciphertext.GetInternal();
+    m_cryptoContextImplSharedPtr->EvalSquareInPlace(c);
+}
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalAtIndex(
     const CiphertextDCRTPoly& ciphertext, const uint32_t index) const
 {
@@ -607,6 +633,11 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::Relinearize(
     return std::make_unique<CiphertextDCRTPoly>(
         m_cryptoContextImplSharedPtr->Relinearize(ciphertext.GetInternal()));
 }
+void CryptoContextDCRTPoly::RelinearizeInPlace(const CiphertextDCRTPoly& ciphertext) const
+{
+    std::shared_ptr<CiphertextImpl> c = ciphertext.GetInternal();
+    m_cryptoContextImplSharedPtr->RelinearizeInPlace(c);
+}
 std::unique_ptr<std::vector<uint32_t>> CryptoContextDCRTPoly::FindAutomorphismIndices(
     const std::vector<uint32_t>& idxList) const
 {

+ 7 - 0
src/CryptoContext.h

@@ -191,14 +191,19 @@ public:
         const CiphertextDCRTPoly& ciphertext, const uint32_t towersLeft /* 1 */) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalNegate(
         const CiphertextDCRTPoly& ciphertext) const;
+    void EvalNegateInPlace(const CiphertextDCRTPoly& ciphertext) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalSquare(
         const CiphertextDCRTPoly& ciphertext) const;
+    [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalSquareMutable(
+        const CiphertextDCRTPoly& ciphertext) const;
+    void EvalSquareInPlace(const CiphertextDCRTPoly& ciphertext) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalAtIndex(
         const CiphertextDCRTPoly& ciphertext, const uint32_t index) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> ComposedEvalMult(
         const CiphertextDCRTPoly& ciphertext1, const CiphertextDCRTPoly& ciphertext2) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> Relinearize(
         const CiphertextDCRTPoly& ciphertext) const;
+    void RelinearizeInPlace(const CiphertextDCRTPoly& ciphertext) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalChebyshevSeries(
         const CiphertextDCRTPoly& ciphertext, const std::vector<double>& coefficients,
         const double a, const double b) const;
@@ -210,8 +215,10 @@ public:
         const uint32_t precision /* 0 */) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> Rescale(
         const CiphertextDCRTPoly& ciphertext) const;
+    void RescaleInPlace(const CiphertextDCRTPoly& ciphertext) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> ModReduce(
         const CiphertextDCRTPoly& ciphertext) const;
+    void ModReduceInPlace(const CiphertextDCRTPoly& ciphertext) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalSum(const CiphertextDCRTPoly& ciphertext,
         const uint32_t batchSize) const;
     [[nodiscard]] std::unique_ptr<CiphertextDCRTPoly> EvalPolyLinear(

+ 7 - 0
src/lib.rs

@@ -679,8 +679,10 @@ pub mod ffi
                          -> UniquePtr<CiphertextDCRTPoly>;
         fn Rescale(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
                    -> UniquePtr<CiphertextDCRTPoly>;
+        fn RescaleInPlace(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly);
         fn ModReduce(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
                      -> UniquePtr<CiphertextDCRTPoly>;
+        fn ModReduceInPlace(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly);
         fn EvalSum(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, batchSize: u32)
                    -> UniquePtr<CiphertextDCRTPoly>;
         fn IntMPBootAdjustScale(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
@@ -751,14 +753,19 @@ pub mod ffi
                    degree: u32) -> UniquePtr<CiphertextDCRTPoly>;
         fn EvalNegate(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
                       -> UniquePtr<CiphertextDCRTPoly>;
+        fn EvalNegateInPlace(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly);
         fn EvalSquare(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
                       -> UniquePtr<CiphertextDCRTPoly>;
+        fn EvalSquareMutable(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
+                             -> UniquePtr<CiphertextDCRTPoly>;
+        fn EvalSquareInPlace(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly);
         fn EvalAtIndex(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, index: u32)
                        -> UniquePtr<CiphertextDCRTPoly>;
         fn ComposedEvalMult(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly,
                             ciphertext2: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>;
         fn Relinearize(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
                        -> UniquePtr<CiphertextDCRTPoly>;
+        fn RelinearizeInPlace(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly);
         fn KeySwitchDown(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
                          -> UniquePtr<CiphertextDCRTPoly>;
         fn KeySwitchExt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,