Browse Source

Some improvements and additions

Hovsep Papoyan 1 year ago
parent
commit
5445d1e5b5

+ 6 - 1
build.rs

@@ -5,6 +5,8 @@ fn main()
         .file("src/Ciphertext.cc")
         .file("src/CryptoContext.cc")
         .file("src/CryptoParametersBase.cc")
+        .file("src/DCRTPoly.cc")
+        .file("src/DecryptResult.cc")
         .file("src/EncodingParams.cc")
         .file("src/EvalKey.cc")
         .file("src/KeyPair.cc")
@@ -16,7 +18,6 @@ fn main()
         .file("src/SchemeBase.cc")
         .file("src/SequenceContainerOfOpaqueTypes.cc")
         .file("src/SerialDeserial.cc")
-
         .include("/usr/local/include/openfhe")
         .include("/usr/local/include/openfhe/third-party/include")
         .include("/usr/local/include/openfhe/core")
@@ -42,6 +43,10 @@ fn main()
     println!("cargo::rerun-if-changed=src/CryptoContext.cc");
     println!("cargo::rerun-if-changed=src/CryptoParametersBase.h");
     println!("cargo::rerun-if-changed=src/CryptoParametersBase.cc");
+    println!("cargo::rerun-if-changed=src/DCRTPoly.h");
+    println!("cargo::rerun-if-changed=src/DCRTPoly.cc");
+    println!("cargo::rerun-if-changed=src/DecryptResult.h");
+    println!("cargo::rerun-if-changed=src/DecryptResult.cc");
     println!("cargo::rerun-if-changed=src/EncodingParams.h");
     println!("cargo::rerun-if-changed=src/EncodingParams.cc");
     println!("cargo::rerun-if-changed=src/EvalKey.h");

+ 5 - 3
examples/function_evaluation.rs

@@ -1,5 +1,5 @@
 #![allow(non_snake_case)]
-use openfhe::cxx::{CxxVector, SharedPtr};
+use openfhe::cxx::{CxxVector};
 use openfhe::ffi as ffi;
 
 fn EvalLogisticExample()
@@ -39,7 +39,8 @@ fn EvalLogisticExample()
     _input.pin_mut().push(ffi::ComplexPair{re: 3.0, im: 0.0});
     _input.pin_mut().push(ffi::ComplexPair{re: 4.0, im: 0.0});
     let _encoded_length: usize = _input.len();
-    let _plain_text = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
+    let _dcrt_poly_params = ffi::GenNullDCRTPolyParams();
+    let _plain_text = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0);
     let _cipher_text = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_plain_text);
     let _lower_bound: f64 = -5.0;
     let _upper_bound: f64 = 5.0;
@@ -107,7 +108,8 @@ fn EvalFunctionExample()
     _input.pin_mut().push(ffi::ComplexPair{re: 9.0, im: 0.0});
 
     let _encoded_length: usize = _input.len();
-    let _plain_text = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
+    let _dcrt_poly_params = ffi::GenNullDCRTPolyParams();
+    let _plain_text = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0);
     let _cipher_text = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_plain_text);
     let _lower_bound: f64 = 0.0;
     let _upper_bound: f64 = 10.0;

+ 3 - 2
examples/polynomial_evaluation.rs

@@ -1,4 +1,4 @@
-use openfhe::cxx::{CxxVector, SharedPtr};
+use openfhe::cxx::{CxxVector};
 use openfhe::ffi as ffi;
 
 fn main()
@@ -75,7 +75,8 @@ fn main()
     _coefficients_2.pin_mut().push(-0.4);
     _coefficients_2.pin_mut().push(-0.5);
 
-    let _plain_text_1 = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
+    let _dcrt_poly_params = ffi::GenNullDCRTPolyParams();
+    let _plain_text_1 = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0);
     let _key_pair = _cc.KeyGen();
     print!("Generating evaluation key for homomorphic multiplication...");
     _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey());

+ 4 - 3
examples/simple_real_numbers.rs

@@ -1,4 +1,4 @@
-use openfhe::cxx::{CxxVector, SharedPtr};
+use openfhe::cxx::{CxxVector};
 use openfhe::ffi as ffi;
 
 fn main()
@@ -46,8 +46,9 @@ fn main()
     _x_2.pin_mut().push(0.5);
     _x_2.pin_mut().push(0.25);
 
-    let _p_txt_1 = _cc.MakeCKKSPackedPlaintext(&_x_1, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
-    let _p_txt_2 = _cc.MakeCKKSPackedPlaintext(&_x_2, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
+    let _dcrt_poly_params = ffi::GenNullDCRTPolyParams();
+    let _p_txt_1 = _cc.MakeCKKSPackedPlaintext(&_x_1, 1, 0, &_dcrt_poly_params, 0);
+    let _p_txt_2 = _cc.MakeCKKSPackedPlaintext(&_x_2, 1, 0, &_dcrt_poly_params, 0);
 
     println!("Input x1: {}", _p_txt_1.GetString());
     println!("Input x2: {}", _p_txt_2.GetString());

+ 2 - 2
src/AssociativeContainerOfOpaqueTypes.cc

@@ -4,10 +4,10 @@ namespace openfhe
 {
 
 UnorderedMapFromIndexToDCRTPoly::UnorderedMapFromIndexToDCRTPoly(
-    std::unordered_map<uint32_t, DCRTPoly> indexToDCRTPolyUnorderedMap)
+    std::unordered_map<uint32_t, lbcrypto::DCRTPoly> indexToDCRTPolyUnorderedMap)
     : m_indexToDCRTPolyUnorderedMap(std::move(indexToDCRTPolyUnorderedMap))
 { }
-std::unordered_map<uint32_t, DCRTPoly>& UnorderedMapFromIndexToDCRTPoly::GetInternal()
+std::unordered_map<uint32_t, lbcrypto::DCRTPoly>& UnorderedMapFromIndexToDCRTPoly::GetInternal()
 {
     return m_indexToDCRTPolyUnorderedMap;
 }

+ 3 - 5
src/AssociativeContainerOfOpaqueTypes.h

@@ -14,15 +14,13 @@
 namespace openfhe
 {
 
-using DCRTPoly = lbcrypto::DCRTPoly;
-
 class UnorderedMapFromIndexToDCRTPoly final
 {
-    std::unordered_map<uint32_t, DCRTPoly> m_indexToDCRTPolyUnorderedMap;
+    std::unordered_map<uint32_t, lbcrypto::DCRTPoly> m_indexToDCRTPolyUnorderedMap;
 public:
     explicit UnorderedMapFromIndexToDCRTPoly(
-        std::unordered_map<uint32_t, DCRTPoly> indexToDCRTPolyUnorderedMap);
-    [[nodiscard]] std::unordered_map<uint32_t, DCRTPoly>& GetInternal();
+        std::unordered_map<uint32_t, lbcrypto::DCRTPoly> indexToDCRTPolyUnorderedMap);
+    [[nodiscard]] std::unordered_map<uint32_t, lbcrypto::DCRTPoly>& GetInternal();
 };
 
 using EvalKeyImpl = lbcrypto::EvalKeyImpl<lbcrypto::DCRTPoly>;

+ 23 - 5
src/CryptoContext.cc

@@ -11,6 +11,8 @@
 #include "AssociativeContainerOfOpaqueTypes.h"
 #include "Ciphertext.h"
 #include "CryptoParametersBase.h"
+#include "DCRTPoly.h"
+#include "DecryptResult.h"
 #include "EncodingParams.h"
 #include "EvalKey.h"
 #include "KeyPair.h"
@@ -37,7 +39,7 @@ CryptoContextDCRTPoly::CryptoContextDCRTPoly(const ParamsCKKSRNS& params)
 { }
 std::unique_ptr<Plaintext> CryptoContextDCRTPoly::MakeCKKSPackedPlaintextByVectorOfComplex(
     const std::vector<ComplexPair>& value, const size_t scaleDeg, const uint32_t level,
-    const std::shared_ptr<DCRTPolyParams> params, const uint32_t slots) const
+    const DCRTPolyParams& params, const uint32_t slots) const
 {
     std::vector<std::complex<double>> v;
     v.reserve(value.size());
@@ -46,7 +48,7 @@ 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));
+        scaleDeg, level, params.GetInternal(), slots));
 }
 void CryptoContextDCRTPoly::SetSchemeId(const SCHEME schemeTag) const
 {
@@ -594,10 +596,10 @@ std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalCos(
 }
 std::unique_ptr<Plaintext> CryptoContextDCRTPoly::MakeCKKSPackedPlaintext(
     const std::vector<double>& value, const size_t scaleDeg, const uint32_t level,
-    const std::shared_ptr<DCRTPolyParams> params, const uint32_t slots) const
+    const DCRTPolyParams& params, const uint32_t slots) const
 {
     return std::make_unique<Plaintext>(m_cryptoContextImplSharedPtr->MakeCKKSPackedPlaintext(
-        value, scaleDeg, level, params, slots));
+        value, scaleDeg, level, params.GetInternal(), slots));
 }
 std::unique_ptr<CiphertextDCRTPoly> CryptoContextDCRTPoly::EvalPoly(
     const CiphertextDCRTPoly& ciphertext, const std::vector<double>& coefficients) const
@@ -920,7 +922,7 @@ 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();
+	auto p = sk.GetInternal();
 	m_cryptoContextImplSharedPtr->RecoverSharedKey(p, sk_shares.GetInternal(), N,
         threshold, shareType);
 }
@@ -1056,6 +1058,16 @@ std::unique_ptr<EncodingParams> CryptoContextDCRTPoly::GetEncodingParams() const
 {
     return std::make_unique<EncodingParams>(m_cryptoContextImplSharedPtr->GetEncodingParams());
 }
+std::unique_ptr<DCRTPoly> CryptoContextDCRTPoly::KeySwitchDownFirstElement(
+    const CiphertextDCRTPoly& ciphertext) const
+{
+    return std::make_unique<DCRTPoly>(m_cryptoContextImplSharedPtr->KeySwitchDownFirstElement(
+        ciphertext.GetInternal()));
+}
+std::unique_ptr<DCRTPolyParams> CryptoContextDCRTPoly::GetElementParams() const
+{
+    return std::make_unique<DCRTPolyParams>(m_cryptoContextImplSharedPtr->GetElementParams());
+}
 std::shared_ptr<CryptoContextImpl> CryptoContextDCRTPoly::GetInternal() const
 {
     return m_cryptoContextImplSharedPtr;
@@ -1157,6 +1169,12 @@ std::unique_ptr<MapFromStringToMapFromIndexToEvalKey> GetCopyOfAllEvalAutomorphi
     return std::make_unique<MapFromStringToMapFromIndexToEvalKey>(
         CryptoContextImpl::GetAllEvalAutomorphismKeys());
 }
+std::unique_ptr<Plaintext> GetPlaintextForDecrypt(const PlaintextEncodings pte,
+    const DCRTPolyParams& evp, const EncodingParams& ep)
+{
+    return std::make_unique<Plaintext>(CryptoContextImpl::GetPlaintextForDecrypt(pte,
+        evp.GetInternal(), ep.GetInternal()));
+}
 
 // Generator functions
 std::unique_ptr<CryptoContextDCRTPoly> GenNullCryptoContext()

+ 20 - 19
src/CryptoContext.h

@@ -1,15 +1,13 @@
 #pragma once
 
-#include "openfhe/pke/constants-fwd.h" // PKESchemeFeature
-#include "openfhe/pke/cryptocontext-fwd.h" // CryptoContextImpl
-#include "openfhe/pke/key/privatekey-fwd.h" // PrivateKeyImpl
-#include "openfhe/pke/key/publickey-fwd.h" // PublicKeyImpl
-#include "openfhe/pke/scheme/scheme-id.h" // SCHEME
-#include "openfhe/pke/schemebase/decrypt-result.h" // DecryptResult
+#include "openfhe/core/lattice/hal/lat-backend.h"
+#include "openfhe/pke/constants-fwd.h"
+#include "openfhe/pke/cryptocontext-fwd.h"
+#include "openfhe/pke/scheme/scheme-id.h"
 
-#include "rust/cxx.h" // rust::Fn
+#include "rust/cxx.h"
 
-#include "SerialMode.h" // SerialMode
+#include "SerialMode.h"
 
 namespace lbcrypto
 {
@@ -31,6 +29,9 @@ struct ComplexPair;
 
 class CiphertextDCRTPoly;
 class CryptoParametersBaseDCRTPoly;
+class DCRTPoly;
+class DCRTPolyParams;
+class DecryptResult;
 class EncodingParams;
 class EvalKeyDCRTPoly;
 class KeyPairDCRTPoly;
@@ -50,19 +51,14 @@ class VectorOfLWECiphertexts;
 class VectorOfPrivateKeys;
 class VectorOfVectorOfCiphertexts;
 
-using SCHEME = lbcrypto::SCHEME;
-using PKESchemeFeature = lbcrypto::PKESchemeFeature;
-
+using CryptoContextImpl = lbcrypto::CryptoContextImpl<lbcrypto::DCRTPoly>;
 using Params = lbcrypto::Params;
 using ParamsBFVRNS = lbcrypto::CCParams<lbcrypto::CryptoContextBFVRNS>;
 using ParamsBGVRNS = lbcrypto::CCParams<lbcrypto::CryptoContextBGVRNS>;
 using ParamsCKKSRNS = lbcrypto::CCParams<lbcrypto::CryptoContextCKKSRNS>;
-
-using CryptoContextImpl = lbcrypto::CryptoContextImpl<lbcrypto::DCRTPoly>;
-using PublicKeyImpl = lbcrypto::PublicKeyImpl<lbcrypto::DCRTPoly>;
-using PrivateKeyImpl = lbcrypto::PrivateKeyImpl<lbcrypto::DCRTPoly>;
-using DCRTPolyParams = lbcrypto::DCRTPoly::Params;
-using DecryptResult = lbcrypto::DecryptResult;
+using PKESchemeFeature = lbcrypto::PKESchemeFeature;
+using PlaintextEncodings = lbcrypto::PlaintextEncodings;
+using SCHEME = lbcrypto::SCHEME;
 
 class CryptoContextDCRTPoly final
 {
@@ -293,11 +289,11 @@ public:
         const uint32_t level /* 0 */) const;
     [[nodiscard]] std::unique_ptr<Plaintext> MakeCKKSPackedPlaintext(
         const std::vector<double>& value, const size_t scaleDeg /* 1 */,
-        const uint32_t level /* 0 */, const std::shared_ptr<DCRTPolyParams> params /* nullptr */,
+        const uint32_t level /* 0 */, const DCRTPolyParams& params /* GenNullDCRTPolyParams */,
         const uint32_t slots /* 0 */) const;
     [[nodiscard]] std::unique_ptr<Plaintext> MakeCKKSPackedPlaintextByVectorOfComplex(
         const std::vector<ComplexPair>& value, const size_t scaleDeg /* 1 */,
-        const uint32_t level /* 0 */, const std::shared_ptr<DCRTPolyParams> params /* nullptr */,
+        const uint32_t level /* 0 */, const DCRTPolyParams& params /* GenNullDCRTPolyParams */,
         const uint32_t slots /* 0 */) const;
     [[nodiscard]] std::unique_ptr<std::vector<uint32_t>> FindAutomorphismIndices(
         const std::vector<uint32_t>& idxList) const;
@@ -442,6 +438,9 @@ public:
     [[nodiscard]] std::unique_ptr<SchemeBaseDCRTPoly> GetScheme() const;
     [[nodiscard]] std::unique_ptr<CryptoParametersBaseDCRTPoly> GetCryptoParameters() const;
     [[nodiscard]] std::unique_ptr<EncodingParams> GetEncodingParams() const;
+    [[nodiscard]] std::unique_ptr<DCRTPoly> KeySwitchDownFirstElement(
+        const CiphertextDCRTPoly& ciphertext) const;
+    [[nodiscard]] std::unique_ptr<DCRTPolyParams> GetElementParams() const;
     [[nodiscard]] std::shared_ptr<CryptoContextImpl> GetInternal() const;
 };
 
@@ -475,6 +474,8 @@ void InsertEvalMultKey(const VectorOfEvalKeys& evalKeyVec);
 [[nodiscard]] std::unique_ptr<MapFromStringToMapFromIndexToEvalKey> GetCopyOfAllEvalSumKeys();
 [[nodiscard]] std::unique_ptr<MapFromStringToMapFromIndexToEvalKey>
     GetCopyOfAllEvalAutomorphismKeys();
+[[nodiscard]] std::unique_ptr<Plaintext> GetPlaintextForDecrypt(const PlaintextEncodings pte,
+    const DCRTPolyParams& evp, const EncodingParams& ep);
 
 // Generator functions
 [[nodiscard]] std::unique_ptr<CryptoContextDCRTPoly> GenNullCryptoContext();

+ 24 - 0
src/DCRTPoly.cc

@@ -0,0 +1,24 @@
+#include "DCRTPoly.h"
+
+namespace openfhe
+{
+
+DCRTPoly::DCRTPoly(lbcrypto::DCRTPoly&& poly) noexcept
+    : m_poly(std::move(poly))
+{ }
+
+DCRTPolyParams::DCRTPolyParams(const std::shared_ptr<lbcrypto::DCRTPoly::Params>& params)
+    : m_params(params)
+{ }
+std::shared_ptr<lbcrypto::DCRTPoly::Params> DCRTPolyParams::GetInternal() const
+{
+    return m_params;
+}
+
+// Generator functions
+std::unique_ptr<DCRTPolyParams> GenNullDCRTPolyParams()
+{
+    return std::make_unique<DCRTPolyParams>();
+}
+
+} // openfhe

+ 36 - 0
src/DCRTPoly.h

@@ -0,0 +1,36 @@
+#pragma once
+
+#include "openfhe/core/lattice/hal/lat-backend.h"
+
+namespace openfhe
+{
+
+class DCRTPoly final
+{
+    lbcrypto::DCRTPoly m_poly;
+public:
+    explicit DCRTPoly(lbcrypto::DCRTPoly&& poly) noexcept;
+    DCRTPoly(const DCRTPoly&) = delete;
+    DCRTPoly(DCRTPoly&&) = delete;
+    DCRTPoly& operator=(const DCRTPoly&) = delete;
+    DCRTPoly& operator=(DCRTPoly&&) = delete;
+};
+
+class DCRTPolyParams final
+{
+    std::shared_ptr<lbcrypto::DCRTPoly::Params> m_params;
+public:
+    DCRTPolyParams() = default;
+    explicit DCRTPolyParams(const std::shared_ptr<lbcrypto::DCRTPoly::Params>& params);
+    DCRTPolyParams(const DCRTPolyParams&) = delete;
+    DCRTPolyParams(DCRTPolyParams&&) = delete;
+    DCRTPolyParams& operator=(const DCRTPolyParams&) = delete;
+    DCRTPolyParams& operator=(DCRTPolyParams&&) = delete;
+
+    [[nodiscard]] std::shared_ptr<lbcrypto::DCRTPoly::Params> GetInternal() const;
+};
+
+// Generator functions
+[[nodiscard]] std::unique_ptr<DCRTPolyParams> GenNullDCRTPolyParams();
+
+} // openfhe

+ 10 - 0
src/DecryptResult.cc

@@ -0,0 +1,10 @@
+#include "DecryptResult.h"
+
+namespace openfhe
+{
+
+DecryptResult::DecryptResult(const lbcrypto::DecryptResult decryptResult)
+    : m_decryptResult(decryptResult)
+{ }
+
+} // openfhe

+ 19 - 0
src/DecryptResult.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include "openfhe/pke/schemebase/decrypt-result.h"
+
+namespace openfhe
+{
+
+class DecryptResult final
+{
+	lbcrypto::DecryptResult m_decryptResult;
+public:
+    explicit DecryptResult(const lbcrypto::DecryptResult decryptResult);
+    DecryptResult(const DecryptResult&) = delete;
+    DecryptResult(DecryptResult&&) = delete;
+    DecryptResult& operator=(const DecryptResult&) = delete;
+    DecryptResult& operator=(DecryptResult&&) = delete;
+};
+
+} // openfhe

+ 4 - 0
src/EncodingParams.cc

@@ -8,5 +8,9 @@ namespace openfhe
 EncodingParams::EncodingParams(const std::shared_ptr<EncodingParamsImpl>& encodingParams)
     : m_encodingParams(encodingParams)
 { }
+std::shared_ptr<EncodingParamsImpl> EncodingParams::GetInternal() const
+{
+    return m_encodingParams;
+}
 
 } // openfhe

+ 2 - 0
src/EncodingParams.h

@@ -23,6 +23,8 @@ public:
     EncodingParams(EncodingParams&&) = delete;
     EncodingParams& operator=(const EncodingParams&) = delete;
     EncodingParams& operator=(EncodingParams&&) = delete;
+
+    [[nodiscard]] std::shared_ptr<EncodingParamsImpl> GetInternal() const;
 };
 
 } // openfhe

+ 1 - 1
src/KeyPair.h

@@ -7,7 +7,7 @@
 namespace lbcrypto
 {
 
-template <class Element>
+template <typename Element>
 class KeyPair;
 
 } // lbcrypto

+ 1 - 1
src/SchemeBase.h

@@ -7,7 +7,7 @@
 namespace lbcrypto
 {
 
-template <class Element>
+template <typename Element>
 class SchemeBase;
 
 } // lbcrypto

+ 34 - 6
src/lib.rs

@@ -2,7 +2,7 @@
 #![allow(dead_code)]
 #![allow(unused_imports)]
 
-use cxx::{CxxVector, SharedPtr, let_cxx_string};
+use cxx::{CxxVector, let_cxx_string};
 pub use cxx;
 
 #[cxx::bridge(namespace = "openfhe")]
@@ -138,6 +138,16 @@ pub mod ffi
         COEFFICIENT = 1
     }
 
+    #[repr(i32)]
+    enum PlaintextEncodings
+    {
+        INVALID_ENCODING = 0,
+        COEF_PACKED_ENCODING,
+        PACKED_ENCODING,
+        STRING_ENCODING,
+        CKKS_PACKED_ENCODING,
+    }
+
     struct ComplexPair
     {
         re: f64,
@@ -150,6 +160,8 @@ pub mod ffi
         include!("openfhe/src/Ciphertext.h");
         include!("openfhe/src/CryptoContext.h");
         include!("openfhe/src/CryptoParametersBase.h");
+        include!("openfhe/src/DCRTPoly.h");
+        include!("openfhe/src/DecryptResult.h");
         include!("openfhe/src/EncodingParams.h");
         include!("openfhe/src/EvalKey.h");
         include!("openfhe/src/KeyPair.h");
@@ -171,6 +183,7 @@ pub mod ffi
         type MultipartyMode;
         type MultiplicationTechnique;
         type PKESchemeFeature;
+        type PlaintextEncodings;
         type ProxyReEncryptionMode;
         type ScalingTechnique;
         type SCHEME;
@@ -181,6 +194,7 @@ pub mod ffi
         type CiphertextDCRTPoly;
         type CryptoContextDCRTPoly;
         type CryptoParametersBaseDCRTPoly;
+        type DCRTPoly;
         type DCRTPolyParams;
         type DecryptResult;
         type EncodingParams;
@@ -497,6 +511,12 @@ pub mod ffi
                                               interactiveBootCompressionLevel0: COMPRESSION_LEVEL);
     }
 
+    // DCRTPolyParams
+    unsafe extern "C++"
+    {
+        fn GenNullDCRTPolyParams() -> UniquePtr<DCRTPolyParams>;
+    }
+
     // PublicKeyDCRTPoly
     unsafe extern "C++"
     {
@@ -751,12 +771,13 @@ pub mod ffi
                                    -> UniquePtr<Plaintext>;
         fn MakeCKKSPackedPlaintext(self: &CryptoContextDCRTPoly, value: &CxxVector<f64>,
                                    scaleDeg: /* 1 */ usize, level: /* 0 */ u32,
-                                   params: /* null() */ SharedPtr<DCRTPolyParams>,
+                                   params: /* GenNullDCRTPolyParams */ &DCRTPolyParams,
                                    slots: /* 0 */ u32) -> UniquePtr<Plaintext>;
         fn MakeCKKSPackedPlaintextByVectorOfComplex(self: &CryptoContextDCRTPoly,
                                                     value: &CxxVector<ComplexPair>,
                                                     scaleDeg: /* 1 */ usize, level: /* 0 */ u32,
-                                                    params: /* null() */ SharedPtr<DCRTPolyParams>,
+                                                    params:
+                                                    /* GenNullDCRTPolyParams */ &DCRTPolyParams,
                                                     slots: /* 0 */ u32) -> UniquePtr<Plaintext>;
         fn EvalPoly(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
                     coefficients: &CxxVector<f64>) -> UniquePtr<CiphertextDCRTPoly>;
@@ -966,6 +987,9 @@ pub mod ffi
         fn GetCryptoParameters(self: &CryptoContextDCRTPoly)
                                -> UniquePtr<CryptoParametersBaseDCRTPoly>;
         fn GetEncodingParams(self: &CryptoContextDCRTPoly) -> UniquePtr<EncodingParams>;
+        fn KeySwitchDownFirstElement(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
+                                     -> UniquePtr<DCRTPoly>;
+        fn GetElementParams(self: &CryptoContextDCRTPoly) -> UniquePtr<DCRTPolyParams>;
 
         // cxx currently does not support static class methods
         fn ClearEvalMultKeys();
@@ -991,6 +1015,8 @@ pub mod ffi
         fn GetCopyOfAllEvalMultKeys() -> UniquePtr<MapFromStringToVectorOfEvalKeys>;
         fn GetCopyOfAllEvalSumKeys() -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>;
         fn GetCopyOfAllEvalAutomorphismKeys() -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>;
+        fn GetPlaintextForDecrypt(pte: PlaintextEncodings, evp: &DCRTPolyParams,
+                                  ep: &EncodingParams) -> UniquePtr<Plaintext>;
     }
 
     // Serialize / Deserialize
@@ -1202,8 +1228,9 @@ mod tests
         _x_2.pin_mut().push(0.5);
         _x_2.pin_mut().push(0.25);
 
-        let _p_txt_1 = _cc.MakeCKKSPackedPlaintext(&_x_1, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
-        let _p_txt_2 = _cc.MakeCKKSPackedPlaintext(&_x_2, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
+        let _dcrt_poly_params = ffi::GenNullDCRTPolyParams();
+        let _p_txt_1 = _cc.MakeCKKSPackedPlaintext(&_x_1, 1, 0, &_dcrt_poly_params, 0);
+        let _p_txt_2 = _cc.MakeCKKSPackedPlaintext(&_x_2, 1, 0, &_dcrt_poly_params, 0);
 
         println!("Input x1: {}", _p_txt_1.GetString());
         println!("Input x2: {}", _p_txt_2.GetString());
@@ -1326,7 +1353,8 @@ mod tests
         _coefficients_2.pin_mut().push(-0.4);
         _coefficients_2.pin_mut().push(-0.5);
 
-        let _plain_text_1 = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, SharedPtr::<ffi::DCRTPolyParams>::null(), 0);
+        let _dcrt_poly_params = ffi::GenNullDCRTPolyParams();
+        let _plain_text_1 = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0);
         let _key_pair = _cc.KeyGen();
         print!("Generating evaluation key for homomorphic multiplication...");
         _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey());