Browse Source

Initial PKE binding version added.

nkaskov 11 months ago
parent
commit
7ef1a282e3

+ 3 - 0
Cargo.toml

@@ -6,3 +6,6 @@ description = "Rust package of the OpenFHE Fully Homomorphic Encryption Library.
 license-file = "LICENSE"
 
 [dependencies]
+
+[build-dependencies]
+bindgen = "0.65.1"

+ 20 - 0
build.rs

@@ -0,0 +1,20 @@
+use std::env;
+use std::path::PathBuf;
+
+fn main() {
+    println!("cargo:rustc-link-search=cpp/build/src/");
+    
+    println!("cargo:rustc-link-lib=fhecomponents");
+
+    let bindings = bindgen::Builder::default()
+        .header("cpp/include/bindings.hpp")
+        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
+        .generate()
+        .expect("Unable to generate bindings");
+    println!("cargo:rerun-if-changed=cpp/include/bindings.hpp");
+    // Write the bindings to the $OUT_DIR/bindings.rs file.
+    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
+    bindings
+        .write_to_file(out_path.join("bindings.rs"))
+        .expect("Couldn't write bindings!");
+}

+ 94 - 0
cpp/.clang-format

@@ -0,0 +1,94 @@
+---
+BasedOnStyle: WebKit
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: true
+AlwaysBreakTemplateDeclarations: Yes
+BinPackArguments: true
+BinPackParameters: true
+BreakAfterJavaFieldAnnotations: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BraceWrapping:
+    AfterClass: false
+    AfterControlStatement: false
+    AfterEnum: false
+    AfterFunction: false
+    AfterNamespace: false
+    AfterObjCDeclaration: false
+    AfterStruct: false
+    AfterUnion: false
+    AfterExternBlock: false
+    BeforeCatch: false
+    BeforeElse: false
+    IndentBraces: false
+    SplitEmptyFunction: false
+    SplitEmptyRecord: false
+    SplitEmptyNamespace: false
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializers: AfterColon
+BreakStringLiterals: true
+ColumnLimit: 120
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: true
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: true
+FixNamespaceComments: true
+ForEachMacros: ['BOOST_FOREACH']
+IncludeBlocks: Regroup
+IncludeCategories:
+    -   Regex:           '^"(<)/'
+        Priority:        1
+    -   Regex:           '^(<(boost)/)'
+        Priority:        2
+    -   Regex:           '^(<(nil\/crypto3)/)'
+        Priority:        3
+    -   Regex:           '.*'
+        Priority:        4
+IndentCaseLabels: true
+IndentPPDirectives: None
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+Language: Cpp
+NamespaceIndentation: All
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 4
+SpacesInAngles: false
+SpacesInCStyleCastParentheses: false
+SpacesInContainerLiterals: true
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+
+...

+ 29 - 0
cpp/CMakeLists.txt

@@ -0,0 +1,29 @@
+cmake_minimum_required (VERSION 3.5.1)
+
+project(openfhe_sys CXX)
+set(CMAKE_CXX_STANDARD 17)
+option( BUILD_STATIC "Set to ON to include static versions of the library" OFF)
+
+find_package(OpenFHE)
+
+set( CMAKE_CXX_FLAGS ${OpenFHE_CXX_FLAGS} )
+
+include_directories( ${OPENMP_INCLUDES} )
+include_directories( ${OpenFHE_INCLUDE} )
+include_directories( ${OpenFHE_INCLUDE}/third-party/include )
+include_directories( ${OpenFHE_INCLUDE}/core )
+include_directories( ${OpenFHE_INCLUDE}/pke )
+include_directories(${OpenFHE_INCLUDE}/binfhe)
+### add directories for other OpenFHE modules as needed for your project
+
+link_directories( ${OpenFHE_LIBDIR} )
+link_directories( ${OPENMP_LIBRARIES} )
+if(BUILD_STATIC)
+    set( CMAKE_EXE_LINKER_FLAGS "${OpenFHE_EXE_LINKER_FLAGS} -static")
+    link_libraries( ${OpenFHE_STATIC_LIBRARIES} )
+else()
+    set( CMAKE_EXE_LINKER_FLAGS ${OpenFHE_EXE_LINKER_FLAGS} )
+    link_libraries( ${OpenFHE_SHARED_LIBRARIES} )
+endif()
+
+add_subdirectory(src)

+ 65 - 0
cpp/include/pke/cryptocontext_wrapper.hpp

@@ -0,0 +1,65 @@
+// BSD 2-Clause License
+
+// Copyright (c) 2023, OpenFHE
+
+// All rights reserved.
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef OPENFHE_CRYPTOCONTEXT_BINDINGS_H
+#define OPENFHE_CRYPTOCONTEXT_BINDINGS_H
+
+#include <stdlib.h>
+#include <vector>
+#include <algorithm>
+#include <complex>
+#include "openfhe.h"
+
+using namespace lbcrypto;
+using ParmType = typename DCRTPoly::Params;
+
+Ciphertext<DCRTPoly> EvalFastRotationPrecomputeWrapper(CryptoContext<DCRTPoly>& self,
+                                                        ConstCiphertext<DCRTPoly> ciphertext);
+
+Ciphertext<DCRTPoly> EvalFastRotationWrapper(CryptoContext<DCRTPoly>& self,
+                                            ConstCiphertext<DCRTPoly> ciphertext,
+                                              const usint index,
+                                              const usint m,
+                                              ConstCiphertext<DCRTPoly> digits);
+Ciphertext<DCRTPoly> EvalFastRotationExtWrapper(CryptoContext<DCRTPoly>& self,ConstCiphertext<DCRTPoly> ciphertext, const usint index, ConstCiphertext<DCRTPoly> digits, bool addFirst);
+
+Plaintext DecryptWrapper(CryptoContext<DCRTPoly>& self,
+ConstCiphertext<DCRTPoly> ciphertext,const PrivateKey<DCRTPoly> privateKey);
+Plaintext DecryptWrapper(CryptoContext<DCRTPoly>& self,
+const PrivateKey<DCRTPoly> privateKey,ConstCiphertext<DCRTPoly> ciphertext);
+Plaintext MultipartyDecryptFusionWrapper(CryptoContext<DCRTPoly>& self,const std::vector<Ciphertext<DCRTPoly>>& partialCiphertextVec);
+
+const std::map<usint, EvalKey<DCRTPoly>> EvalAutomorphismKeyGenWrapper(CryptoContext<DCRTPoly>& self,const PrivateKey<DCRTPoly> privateKey,const std::vector<usint> &indexList);
+const std::shared_ptr<std::map<usint, EvalKey<DCRTPoly>>> GetEvalSumKeyMapWrapper(CryptoContext<DCRTPoly>& self, const std::string &id);
+const PlaintextModulus GetPlaintextModulusWrapper(CryptoContext<DCRTPoly>& self);
+const double GetModulusWrapper(CryptoContext<DCRTPoly>& self);
+void RemoveElementWrapper(Ciphertext<DCRTPoly>& self, usint index);
+const double GetScalingFactorRealWrapper(CryptoContext<DCRTPoly>& self, uint32_t l);
+const uint64_t GetModulusCKKSWrapper(CryptoContext<DCRTPoly>& self);
+const ScalingTechnique GetScalingTechniqueWrapper(CryptoContext<DCRTPoly>& self);
+const usint GetDigitSizeWrapper(CryptoContext<DCRTPoly>& self);
+#endif // OPENFHE_CRYPTOCONTEXT_BINDINGS_H

+ 44 - 0
cpp/include/pke/serialization.hpp

@@ -0,0 +1,44 @@
+// BSD 2-Clause License
+
+// Copyright (c) 2023, OpenFHE
+
+// All rights reserved.
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef OPENFHE_SERIALIZATION_BINDINGS_H
+#define OPENFHE_SERIALIZATION_BINDINGS_H
+
+#include "openfhe.h"
+
+using namespace lbcrypto;
+
+template <typename ST>
+bool SerializeEvalMultKeyWrapper(const std::string& filename, const ST& sertype, std::string id);
+
+template <typename ST>
+bool SerializeEvalAutomorphismKeyWrapper(const std::string& filename, const ST& sertype, std::string id);
+
+template <typename ST>
+bool DeserializeEvalMultKeyWrapper(const std::string& filename, const ST& sertype);
+
+#endif // OPENFHE_SERIALIZATION_BINDINGS_H

+ 18 - 0
cpp/src/CMakeLists.txt

@@ -0,0 +1,18 @@
+set(LIBRARY_SOURCES
+    pke/cryptocontext_wrapper.cpp
+    pke/serialization.cpp
+    bindings.cpp
+)
+
+# Optionally, specify headers for IDEs
+set(LIBRARY_HEADERS
+    pke/cryptocontext_wrapper.hpp
+    pke/serialization.hpp
+    bindings.hpp
+)
+
+# Define the library
+add_library(openfhesys ${LIBRARY_SOURCES})
+
+# Specify include directories
+target_include_directories(openfhesys PUBLIC ../include)

+ 149 - 0
cpp/src/pke/cryptocontext_wrapper.cpp

@@ -0,0 +1,149 @@
+// BSD 2-Clause License
+
+// Copyright (c) 2023, OpenFHE
+
+// All rights reserved.
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <openfhe.h>
+#include <vector>
+#include <algorithm>
+#include <complex> 
+#include "pke/cryptocontext_wrapper.hpp"
+
+using namespace lbcrypto;
+
+Ciphertext<DCRTPoly> EvalFastRotationPrecomputeWrapper(CryptoContext<DCRTPoly> &self,ConstCiphertext<DCRTPoly> ciphertext) {
+    std::shared_ptr<std::vector<DCRTPoly>> precomp = self->EvalFastRotationPrecompute(ciphertext);
+    std::vector<DCRTPoly> elements = *(precomp.get());
+    CiphertextImpl<DCRTPoly> cipherdigits = CiphertextImpl<DCRTPoly>(self);
+    std::shared_ptr<CiphertextImpl<DCRTPoly>> cipherdigitsPtr = std::make_shared<CiphertextImpl<DCRTPoly>>(cipherdigits);
+    cipherdigitsPtr->SetElements(elements);
+    return cipherdigitsPtr;
+}
+Ciphertext<DCRTPoly> EvalFastRotationWrapper(CryptoContext<DCRTPoly>& self,ConstCiphertext<DCRTPoly> ciphertext, const usint index, const usint m,ConstCiphertext<DCRTPoly> digits) {
+    
+        std::vector<DCRTPoly> digitsElements = digits->GetElements();
+        std::shared_ptr<std::vector<DCRTPoly>> digitsElementsPtr = std::make_shared<std::vector<DCRTPoly>>(digitsElements);
+        return self->EvalFastRotation(ciphertext, index, m, digitsElementsPtr);
+    }
+
+Ciphertext<DCRTPoly> EvalFastRotationExtWrapper(CryptoContext<DCRTPoly>& self,ConstCiphertext<DCRTPoly> ciphertext, const usint index, ConstCiphertext<DCRTPoly> digits, bool addFirst) {
+    std::vector<DCRTPoly> digitsElements = digits->GetElements();
+    std::shared_ptr<std::vector<DCRTPoly>> digitsElementsPtr = std::make_shared<std::vector<DCRTPoly>>(digitsElements);
+    return self->EvalFastRotationExt(ciphertext, index, digitsElementsPtr, addFirst);
+}
+
+
+Plaintext DecryptWrapper(CryptoContext<DCRTPoly>& self,ConstCiphertext<DCRTPoly> ciphertext,const PrivateKey<DCRTPoly> privateKey){
+    Plaintext plaintextDecResult;
+    self->Decrypt(privateKey, ciphertext,&plaintextDecResult);
+    return plaintextDecResult;
+}
+Plaintext DecryptWrapper(CryptoContext<DCRTPoly>& self,const PrivateKey<DCRTPoly> privateKey,ConstCiphertext<DCRTPoly> ciphertext){
+    Plaintext plaintextDecResult;
+    self->Decrypt(privateKey, ciphertext,&plaintextDecResult);
+    return plaintextDecResult;
+}
+
+Plaintext MultipartyDecryptFusionWrapper(CryptoContext<DCRTPoly>& self,const std::vector<Ciphertext<DCRTPoly>>& partialCiphertextVec){
+    Plaintext plaintextDecResult;
+    self->MultipartyDecryptFusion(partialCiphertextVec,&plaintextDecResult);
+    return plaintextDecResult;
+}
+
+const std::map<usint, EvalKey<DCRTPoly>> EvalAutomorphismKeyGenWrapper(CryptoContext<DCRTPoly>& self,const PrivateKey<DCRTPoly> privateKey,const std::vector<usint> &indexList){
+    return *(self->EvalAutomorphismKeyGen(privateKey, indexList));
+}
+
+const std::shared_ptr<std::map<usint, EvalKey<DCRTPoly>>> GetEvalSumKeyMapWrapper(CryptoContext<DCRTPoly>& self,const std::string &id){
+    auto evalSumKeyMap = 
+        std::make_shared<std::map<usint, EvalKey<DCRTPoly>>>(self->GetEvalSumKeyMap(id));
+    return evalSumKeyMap;
+}
+
+const PlaintextModulus GetPlaintextModulusWrapper(CryptoContext<DCRTPoly>& self){
+    return self->GetCryptoParameters()->GetPlaintextModulus();
+}
+
+const double GetModulusWrapper(CryptoContext<DCRTPoly>& self){
+    return self->GetCryptoParameters()->GetElementParams()->GetModulus().ConvertToDouble();
+}
+
+void RemoveElementWrapper(Ciphertext<DCRTPoly> &self, usint index){
+    self->GetElements().erase(self->GetElements().begin()+index);
+}
+const usint GetDigitSizeWrapper(CryptoContext<DCRTPoly>& self){
+    return self->GetCryptoParameters()->GetDigitSize();
+}
+
+const double GetScalingFactorRealWrapper(CryptoContext<DCRTPoly>& self, uint32_t l){
+    if(self->getSchemeId()==SCHEME::CKKSRNS_SCHEME){
+        const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersCKKSRNS>(self->GetCryptoParameters());
+        double scFactor = cryptoParams->GetScalingFactorReal(l);
+        return scFactor;
+    }
+    else if(self->getSchemeId()==SCHEME::BFVRNS_SCHEME){
+        const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersBFVRNS>(self->GetCryptoParameters());
+        double scFactor = cryptoParams->GetScalingFactorReal(l);
+        return scFactor;
+    }
+    else if(self->getSchemeId()==SCHEME::BGVRNS_SCHEME){
+        const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersBGVRNS>(self->GetCryptoParameters());
+        double scFactor = cryptoParams->GetScalingFactorReal(l);
+        return scFactor;
+    }
+    else{
+        OPENFHE_THROW(not_available_error, "GetScalingFactorRealWrapper: Invalid scheme");
+        return 0;
+    }
+}
+
+const uint64_t GetModulusCKKSWrapper(CryptoContext<DCRTPoly> &self)
+{
+
+    const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersCKKSRNS>(self->GetCryptoParameters());
+    ILDCRTParams<DCRTPoly::Integer> elementParams = *(cryptoParams->GetElementParams());
+    auto paramsQ = elementParams.GetParams();
+    uint64_t modulus_CKKS_from = paramsQ[0]->GetModulus().ConvertToInt<uint64_t>();
+    return modulus_CKKS_from;
+}
+
+const ScalingTechnique GetScalingTechniqueWrapper(CryptoContext<DCRTPoly> & self){
+    if(self->getSchemeId()==SCHEME::CKKSRNS_SCHEME){
+        const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersCKKSRNS>(self->GetCryptoParameters());
+        return cryptoParams->GetScalingTechnique();
+    }
+    else if(self->getSchemeId()==SCHEME::BFVRNS_SCHEME){
+        const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersBFVRNS>(self->GetCryptoParameters());
+        return cryptoParams->GetScalingTechnique();
+    }
+    else if(self->getSchemeId()==SCHEME::BGVRNS_SCHEME){
+        const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersBGVRNS>(self->GetCryptoParameters());
+        return cryptoParams->GetScalingTechnique();
+    }
+    else{
+        OPENFHE_THROW(not_available_error, "GetScalingTechniqueWrapper: Invalid scheme");
+    }
+
+}

+ 85 - 0
cpp/src/pke/serialization.cpp

@@ -0,0 +1,85 @@
+// BSD 2-Clause License
+
+// Copyright (c) 2023, OpenFHE
+
+// All rights reserved.
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "openfhe.h"
+#include "utils/exception.h"
+// header files needed for serialization
+#include "pke/serialization.hpp"
+#include "metadata-ser.h"
+#include "ciphertext-ser.h"
+#include "cryptocontext-ser.h"
+#include "key/key-ser.h"
+#include "scheme/bfvrns/bfvrns-ser.h"
+#include "scheme/bgvrns/bgvrns-ser.h"
+#include "scheme/ckksrns/ckksrns-ser.h"
+
+using namespace lbcrypto;
+
+template <typename ST>
+bool SerializeEvalMultKeyWrapper(const std::string &filename, const ST &sertype, std::string id)
+{
+    std::ofstream outfile(filename, std::ios::out | std::ios::binary);
+    bool res;
+    res = CryptoContextImpl<DCRTPoly>::SerializeEvalMultKey<ST>(outfile, sertype, id);
+    outfile.close();
+    return res;
+}
+
+template <typename ST>
+bool SerializeEvalAutomorphismKeyWrapper(const std::string& filename, const ST& sertype, std::string id)
+{
+    std::ofstream outfile(filename, std::ios::out | std::ios::binary);
+    bool res;
+    res = CryptoContextImpl<DCRTPoly>::SerializeEvalAutomorphismKey<ST>(outfile, sertype, id);
+    outfile.close();
+    return res;
+}
+
+template <typename ST>
+bool DeserializeEvalMultKeyWrapper(const std::string &filename, const ST &sertype)
+{
+    std::ifstream emkeys(filename, std::ios::in | std::ios::binary);
+    if (!emkeys.is_open())
+    {
+        std::cerr << "I cannot read serialization from " << filename << std::endl;
+    }
+    bool res;
+    res = CryptoContextImpl<DCRTPoly>::DeserializeEvalMultKey<ST>(emkeys, sertype);
+    return res; }
+
+template <typename T, typename ST>
+std::tuple<T, bool> DeserializeFromFileWrapper(const std::string& filename, const ST& sertype) {
+    T newob;
+    bool result = Serial::DeserializeFromFile<T>(filename, newob, sertype);
+    return std::make_tuple(newob, result);
+}
+template <typename ST>
+std::tuple<CryptoContext<DCRTPoly>, bool> DeserializeCCWrapper(const std::string& filename, const ST& sertype) {
+    CryptoContext<DCRTPoly> newob;
+    bool result = Serial::DeserializeFromFile<DCRTPoly>(filename, newob, sertype);
+    return std::make_tuple(newob, result);
+}

+ 26 - 0
src/lib.rs

@@ -0,0 +1,26 @@
+#![allow(non_upper_case_globals)]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+
+include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::mem;
+
+    #[test]
+    fn testCryptoContextBFVRNSCCParams() {
+        unsafe {
+            let ccparams = CryptoContextBFVRNSCCParams::new();
+            
+            let ccparams_plaintext_modulus = ccparams.GetPlaintextModulus();
+
+            println!("ccparams_plaintext_modulus: {}", ccparams_plaintext_modulus);
+
+            let ccparams_scheme = ccparams.GetScheme();
+
+            println!("ccparams_scheme: {}", ccparams_scheme);
+        }
+    }
+}

+ 0 - 3
src/main.rs

@@ -1,3 +0,0 @@
-fn main() {
-    println!("Hello, world!");
-}