Explorar o código

separated file for enc/dec wrappers

Rener Oliveira (Ubuntu WSL) hai 1 ano
pai
achega
2bd20fd430

+ 2 - 0
CMakeLists.txt

@@ -19,6 +19,7 @@ include_directories( ${OpenFHE_INCLUDE}/pke )
 include_directories( ${OpenFHE_INCLUDE}/binfhe )
 # include_directories( ${OpenFHE_Py_SOURCES} )
 include_directories( ${OpenFHE_Py_INCLUDES}/pke )
+include_directories( ${OpenFHE_Py_INCLUDES}/binfhe )
 include_directories( ${OpenFHE_Py_INCLUDES} )
 ### add directories for other OpenFHE modules as needed for your project
 
@@ -42,6 +43,7 @@ endif()
 pybind11_add_module(openfhe 
                     src/bindings.cpp 
                     src/binfhe_bindings.cpp
+                    src/binfhe/binfhecontext_wrapper.cpp
                     src/pke/decryption.cpp 
                     src/pke/serialization.cpp 
                     src/pke/cryptocontext_wrapper.cpp

+ 22 - 0
include/binfhe/binfhecontext_wrapper.h

@@ -0,0 +1,22 @@
+#ifndef BINFHE_CRYPTOCONTEXT_BINDINGS_H
+#define BINFHE_CRYPTOCONTEXT_BINDINGS_H
+
+#include <pybind11/pybind11.h>
+#include <pybind11/stl.h>
+#include "openfhe.h"
+#include "binfhecontext.h"
+
+namespace py = pybind11;
+using namespace lbcrypto;
+LWECiphertext binfhe_EncryptWrapper(BinFHEContext &self,
+                                    ConstLWEPrivateKey sk,
+                                    const LWEPlaintext &m,
+                                    BINFHE_OUTPUT output,
+                                    LWEPlaintextModulus p,
+                                    uint64_t mod);
+LWEPlaintext binfhe_DecryptWrapper(BinFHEContext &self,
+                                   ConstLWEPrivateKey sk,
+                                   ConstLWECiphertext ct,
+                                   LWEPlaintextModulus p);
+
+#endif // BINFHE_CRYPTOCONTEXT_BINDINGS_H

+ 25 - 0
src/binfhe/binfhecontext_wrapper.cpp

@@ -0,0 +1,25 @@
+#include <pybind11/pybind11.h>
+#include <pybind11/stl.h>
+#include <openfhe.h>
+#include "binfhecontext_wrapper.h"
+
+using namespace lbcrypto;
+namespace py = pybind11;
+
+LWECiphertext binfhe_EncryptWrapper(BinFHEContext &self, ConstLWEPrivateKey sk, const LWEPlaintext &m, BINFHE_OUTPUT output,
+                                    LWEPlaintextModulus p, uint64_t mod)
+{
+    NativeInteger mod_native_int = NativeInteger(mod);
+    return self.Encrypt(sk, m, output, p, mod_native_int);
+}
+
+LWEPlaintext binfhe_DecryptWrapper(BinFHEContext &self,
+                                   ConstLWEPrivateKey sk,
+                                   ConstLWECiphertext ct,
+                                   LWEPlaintextModulus p)
+{
+
+    LWEPlaintext result;
+    self.Decrypt(sk, ct, &result, p);
+    return result;
+}

+ 32 - 8
src/binfhe_bindings.cpp

@@ -4,17 +4,11 @@
 #include "openfhe.h"
 #include "binfhe_bindings.h"
 #include "binfhecontext.h"
+#include "binfhecontext_wrapper.h"
 
 using namespace lbcrypto;
 namespace py = pybind11;
 
-LWECiphertext binfhe_EncryptWrapper(BinFHEContext &self, ConstLWEPrivateKey sk, const LWEPlaintext &m, BINFHE_OUTPUT output = BOOTSTRAPPED,
-                                    LWEPlaintextModulus p = 4, uint64_t mod = 0)
-{
-    NativeInteger mod_native_int = NativeInteger(mod);
-    return self.Encrypt(sk, m, output, p, mod_native_int);
-}
-
 void bind_binfhe_enums(py::module &m)
 {
     py::enum_<BINFHE_PARAMSET>(m, "BINFHE_PARAMSET")
@@ -68,6 +62,25 @@ void bind_binfhe_enums(py::module &m)
     m.attr("INVALID_OUTPUT") = py::cast(BINFHE_OUTPUT::INVALID_OUTPUT);
     m.attr("FRESH") = py::cast(BINFHE_OUTPUT::FRESH);
     m.attr("BOOTSTRAPPED") = py::cast(BINFHE_OUTPUT::BOOTSTRAPPED);
+
+    py::enum_<BINGATE>(m, "BINGATE")
+        .value("OR", BINGATE::OR)
+        .value("AND", BINGATE::AND)
+        .value("NOR", BINGATE::NOR)
+        .value("NAND", BINGATE::NAND)
+        .value("XOR_FAST", BINGATE::XOR_FAST)
+        .value("XNOR_FAST", BINGATE::XNOR_FAST)
+        .value("XOR", BINGATE::XOR)
+        .value("XNOR", BINGATE::XNOR);
+    m.attr("OR") = py::cast(BINGATE::OR);
+    m.attr("AND") = py::cast(BINGATE::AND);
+    m.attr("NOR") = py::cast(BINGATE::NOR);
+    m.attr("NAND") = py::cast(BINGATE::NAND);
+    m.attr("XOR_FAST") = py::cast(BINGATE::XOR_FAST);
+    m.attr("XNOR_FAST") = py::cast(BINGATE::XNOR_FAST);
+    m.attr("XOR") = py::cast(BINGATE::XOR);
+    m.attr("XNOR") = py::cast(BINGATE::XNOR);
+
 }
 
 void bind_binfhe_keys(py::module &m)
@@ -101,5 +114,16 @@ void bind_binfhe_context(py::module &m)
              py::arg("m"),
              py::arg("output") = BOOTSTRAPPED,
              py::arg("p") = 4, 
-             py::arg("mod") = 0);
+             py::arg("mod") = 0)
+        .def("Decrypt",&binfhe_DecryptWrapper,
+             py::arg("sk"),
+             py::arg("ct"),
+             py::arg("p") = 4)
+        .def("EvalBinGate",&BinFHEContext::EvalBinGate,
+             py::arg("gate"),
+             py::arg("ct1"),
+             py::arg("ct2"))
+        .def("EvalNOT",&BinFHEContext::EvalNOT,
+             py::arg("ct"));
+            
 }