Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/include/bindings.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
//==================================================================================
// BSD 2-Clause License

// Copyright (c) 2023, OpenFHE

//
// Copyright (c) 2014-2025, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.

//
// Author TPOC: [email protected]
//
// 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
Expand All @@ -24,9 +27,9 @@
// 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_BINDINGS_H
#define OPENFHE_BINDINGS_H
//==================================================================================
#ifndef __BINDINGS_H__
#define __BINDINGS_H__

#include <pybind11/pybind11.h>

Expand All @@ -39,4 +42,5 @@ void bind_ciphertext(pybind11::module &m);
void bind_serialization(pybind11::module &m);
void bind_schemes(pybind11::module &m);
void bind_sch_swch_params(pybind11::module &m);
#endif // OPENFHE_BINDINGS_H

#endif // __BINDINGS_H__
36 changes: 15 additions & 21 deletions src/include/pke/cryptocontext_wrapper.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
//==================================================================================
// BSD 2-Clause License

// Copyright (c) 2023, OpenFHE

//
// Copyright (c) 2014-2025, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.

//
// Author TPOC: [email protected]
//
// 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
Expand All @@ -24,23 +27,14 @@
// 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 __CRYPTOCONTEXT_WRAPPER_H__
#define __CRYPTOCONTEXT_WRAPPER_H__

#ifndef OPENFHE_CRYPTOCONTEXT_BINDINGS_H
#define OPENFHE_CRYPTOCONTEXT_BINDINGS_H

#include "bindings.h"
#include "openfhe.h"

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <vector>
#include <algorithm>
#include <complex>


namespace py = pybind11;
using namespace lbcrypto;
using ParmType = typename DCRTPoly::Params;


Ciphertext<DCRTPoly> EvalFastRotationPrecomputeWrapper(CryptoContext<DCRTPoly> &self,
ConstCiphertext<DCRTPoly> ciphertext);
Expand Down Expand Up @@ -69,4 +63,4 @@ const usint GetDigitSizeWrapper(CryptoContext<DCRTPoly>& self);

void ClearEvalMultKeysWrapper();

#endif // OPENFHE_CRYPTOCONTEXT_BINDINGS_H
#endif // __CRYPTOCONTEXT_WRAPPER_H__
37 changes: 18 additions & 19 deletions src/include/pke/serialization.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
//==================================================================================
// BSD 2-Clause License

// Copyright (c) 2023, OpenFHE

//
// Copyright (c) 2014-2025, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.

//
// Author TPOC: [email protected]
//
// 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
Expand All @@ -24,16 +27,12 @@
// 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
//==================================================================================
#ifndef __SERIALIZATION_H__
#define __SERIALIZATION_H__

#include <pybind11/pybind11.h>
#include "openfhe.h"
#include "bindings.h"

using namespace lbcrypto;
namespace py = pybind11;

template <typename ST>
bool SerializeEvalMultKeyWrapper(const std::string& filename, const ST& sertype, std::string id);
Expand All @@ -48,25 +47,25 @@ template <typename T, typename ST>
std::string SerializeToStringWrapper(const T& obj, const ST& sertype);

template <typename T, typename ST>
py::bytes SerializeToBytesWrapper(const T& obj, const ST& sertype);
pybind11::bytes SerializeToBytesWrapper(const T& obj, const ST& sertype);

template <typename T, typename ST>
T DeserializeFromStringWrapper(const std::string& str, const ST& sertype);

template <typename T, typename ST>
T DeserializeFromBytesWrapper(const py::bytes& bytes, const ST& sertype);
T DeserializeFromBytesWrapper(const pybind11::bytes& bytes, const ST& sertype);

template <typename ST>
std::string SerializeEvalMultKeyToStringWrapper(const ST& sertype, const std::string& id);

template <typename ST>
py::bytes SerializeEvalMultKeyToBytesWrapper(const ST& sertype, const std::string& id);
pybind11::bytes SerializeEvalMultKeyToBytesWrapper(const ST& sertype, const std::string& id);

template <typename ST>
std::string SerializeEvalAutomorphismKeyToStringWrapper(const ST& sertype, const std::string& id);

template <typename ST>
py::bytes SerializeEvalAutomorphismKeyToBytesWrapper(const ST& sertype, const std::string& id);
pybind11::bytes SerializeEvalAutomorphismKeyToBytesWrapper(const ST& sertype, const std::string& id);

template <typename ST>
void DeserializeEvalMultKeyFromStringWrapper(const std::string& data, const ST& sertype);
Expand All @@ -80,4 +79,4 @@ void DeserializeEvalAutomorphismKeyFromStringWrapper(const std::string& data, co
template <typename ST>
void DeserializeEvalAutomorphismKeyFromBytesWrapper(const std::string& data, const ST& sertype);

#endif // OPENFHE_SERIALIZATION_BINDINGS_H
#endif // __SERIALIZATION_H__
57 changes: 44 additions & 13 deletions src/lib/bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,57 @@
#include <pybind11/pybind11.h>
//==================================================================================
// BSD 2-Clause License
//
// Copyright (c) 2014-2025, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.
//
// Author TPOC: [email protected]
//
// 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 "bindings.h"

#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/complex.h>
#include <pybind11/functional.h>
#include <pybind11/operators.h>
#include <pybind11/iostream.h>
#include <iostream>
#include <map>

#include "openfhe.h"

#include "key/key-ser.h"
#include "bindings.h"
#include "cryptocontext_wrapper.h"
#include "binfhe_bindings.h"

#include "cryptocontext_wrapper.h"
#include "cryptocontext_docs.h"
#include "cryptoparameters_docs.h"
#include "plaintext_docs.h"
#include "ciphertext_docs.h"
#include "serialization.h"

using namespace lbcrypto;
namespace py = pybind11;

// disable the PYBIND11 template-based conversion for this type
PYBIND11_MAKE_OPAQUE(std::map<usint, EvalKey<DCRTPoly>>);

template <typename T>
Expand Down Expand Up @@ -100,6 +132,12 @@ void bind_parameters(py::module &m,const std::string name)

void bind_crypto_context(py::module &m)
{
//Parameters Type
/*TODO (Oliveira): If we expose Poly's and ParmType, this block will go somewhere else */
using ParmType = typename DCRTPoly::Params;
using ParmTypePtr = std::shared_ptr<ParmType>;
py::class_<ParmType, ParmTypePtr>(m, "ParmType");

py::class_<CryptoContextImpl<DCRTPoly>, std::shared_ptr<CryptoContextImpl<DCRTPoly>>>(m, "CryptoContext")
.def(py::init<>())
.def("GetKeyGenLevel", &CryptoContextImpl<DCRTPoly>::GetKeyGenLevel, cc_GetKeyGenLevel_docs)
Expand Down Expand Up @@ -1028,15 +1066,8 @@ void bind_enums_and_constants(py::module &m)
m.attr("HEStd_256_classic") = py::cast(SecurityLevel::HEStd_256_classic);
m.attr("HEStd_NotSet") = py::cast(SecurityLevel::HEStd_NotSet);

//Parameters Type
/*TODO (Oliveira): If we expose Poly's and ParmType, this block will go somewhere else */
using ParmType = typename DCRTPoly::Params;
py::class_<ParmType, std::shared_ptr<ParmType>>(m, "ParmType");

//NATIVEINT function
m.def("get_native_int", &get_native_int);


}

void bind_keys(py::module &m)
Expand Down
52 changes: 27 additions & 25 deletions src/lib/binfhe_bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
//==================================================================================
// BSD 2-Clause License

// Copyright (c) 2023, OpenFHE

//
// Copyright (c) 2014-2025, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.

//
// Author TPOC: [email protected]
//
// 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
//
// 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.

// 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 "binfhe_bindings.h"

#include <pybind11/operators.h>

#include "openfhe.h"
#include "binfhecontext.h"
#include "binfhecontext_docs.h"
#include "binfhecontext_wrapper.h"
#include "openfhe.h"

#include "cereal/archives/binary.hpp"
#include "cereal/archives/portable_binary.hpp"
#include "core/utils/serial.h"
#include <iostream>
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
// #include "cereal/archives/portable_binary.hpp"
// #include "core/utils/serial.h"

using namespace lbcrypto;
namespace py = pybind11;
Expand Down
Loading