Giter Club home page Giter Club logo

seal-python's Introduction

Microsoft SEAL For Python

Microsoft SEAL is an easy-to-use open-source (MIT licensed) homomorphic encryption library developed by the Cryptography Research group at Microsoft.

pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++ code.

This is a python binding for the Microsoft SEAL library.

Contents

Build

  • Linux

    Recommend: Clang++ (>= 10.0) or GNU G++ (>= 9.4), CMake (>= 3.16)

    # Optional
    sudo apt-get install git build-essential cmake python3 python3-dev python3-pip
    
    # Get the repository or download from the releases
    git clone https://github.com/Huelse/SEAL-Python.git
    cd SEAL-Python
    
    # Install dependencies
    pip3 install numpy pybind11
    
    # Init the SEAL and pybind11
    git submodule update --init --recursive
    # Get the newest repositories (dev only)
    # git submodule update --remote
    
    # Build the SEAL lib without the msgsl zlib and zstandard compression
    cd SEAL
    cmake -S . -B build -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_USE_ZSTD=OFF
    cmake --build build
    cd ..
    
    # Run the setup.py, the dynamic library will be generated in the current directory
    python3 setup.py build_ext -i
    
    # Test
    cp seal.*.so examples
    cd examples
    python3 4_bgv_basics.py

    Build examples: -DSEAL_BUILD_EXAMPLES=ON

    More cmake options

  • Windows

    Visual Studio 2019 or newer is required. x64 support only! And use the x64 Native Tools Command Prompt for VS command prompt to configure and build the Microsoft SEAL library. It's usually can be found in your Start Menu.

    # Run in "x64 Native Tools Command Prompt for VS" command prompt
    cmake -S . -B build -G Ninja -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF
    cmake --build build
    
    # Build
    pip install numpy pybind11
    python setup.py build_ext -i
    
    # Test
    cp seal.*.pyd examples
    cd examples
    python 4_bgv_basics.py

    Microsoft SEAL official docs.

  • Docker

    requires: Docker

    To build source code into a docker image (from this directory):

    docker build -t huelse/seal -f Dockerfile .

    To use the image by running it as an interactive container:

    docker run -it huelse/seal

Note

  • Serialize

    See more in examples/7_serialization.py, here is a simple example:

    cipher.save('cipher')
    load_cipher = Ciphertext()
    load_cipher.load(context, 'cipher')  # work if the context is valid.

    Supported classes: EncryptionParameters, Ciphertext, Plaintext, SecretKey, PublicKey, RelinKeys, GaloisKeys

  • Other

    There are a lot of changes in the latest SEAL lib, we try to make the API in python can be used easier, but it may remain some problems unknown, if any problems or bugs, report issues.

    Email: [email protected]

FAQ

  1. ImportError: undefined symbol

    Build a shared SEAL library cmake . -DBUILD_SHARED_LIBS=ON, and get the libseal.so,

    then change the path in setup.py, and rebuild.

  2. ImportError: libseal.so... cannot find

    a. sudo ln -s /path/to/libseal.so /usr/lib

    b. add /usr/local/lib or the SEAL/native/lib to /etc/ld.so.conf and refresh it sudo ldconfig

    c. build in cmake.

  3. BuildError:

    1. C++17 at least

    2. x86_64 is required, which x86_32 is not supported

  4. ModuleNotFoundError: No module named 'seal'

    The .so or .pyd file must be in the current directory, or you have install it already.

  5. Windows Error LNK2001, RuntimeLibrary and MT_StaticRelease mismatch

    Only x64 is supported, Choose x64 Native Tools Command Prompt for VS.

  6. Warning about building the dynamic library with static library in MacOS, etc.

    1. Build a shared SEAL library by adding a CMake option -DBUILD_SHARED_LIBS=ON

    2. Edit extra_objects in setup.py to *.dylib or else.

Contributing

seal-python's People

Contributors

carlee0 avatar desilo-seungwoojung avatar dreamingraven avatar huelse avatar uriariel avatar yuntaobc avatar zerbarus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

seal-python's Issues

Cannot deep copy certain seal objects

Hey there Huelse,
I am having some difficulty deep copying some objects of seal-python giving me:

Traceback (most recent call last):
  File "/python-fhe/fhe/fhe.py", line 123, in _merge_dictionary
    copy.deepcopy(d)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'seal.SEALContext' object

or

Traceback (most recent call last):
  File "/python-fhe/fhe/fhe.py", line 124, in _merge_dictionary
    dicts = copy.deepcopy(dicts)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/usr/lib/python3.8/copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'seal.PublicKey' object

Its interesting that deep copying results in a pickle of these objects.

Not sure if you know of a workaround, or anything I can help with in particular to make it possible to deep copy.

Thanks as usual.

Size of ciphertext in bytes

Type
To find the size of ciphertext in bytes

Describe
I want to compute the size of ciphertext in bytes. Using sys.getsizeof() on a ciphertext object gives output as 56 bytes which doesn't seem to be the actual size of the ciphertext containing the coefficients of the polynomial. A function for this is available in Microsoft seal library as mentioned in this issue microsoft/SEAL#88. I am wondering if the same is also in this library but seem have had no luck in finding any such method.

Signed integers not supported?

Hi, it seems that signed integers are not supported. Is this the case? Please see the example below and the error message.

>>> p1 = seal.Plaintext("5")
>>> p3 = seal.Plaintext("-5")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unable to parse hex_poly
>>> p2 = seal.Plaintext(-5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. seal.Plaintext()
    2. seal.Plaintext(arg0: int)
    3. seal.Plaintext(arg0: int, arg1: int)
    4. seal.Plaintext(arg0: str)
    5. seal.Plaintext(arg0: seal.Plaintext)
Invoked with: -5

I am new to c++ but I have some experience with c and quite comfortable with Python. I could give it a go to find a fix if you could point me to the direction. :)

errors when setup

Please give me some help, I get the seal.lib file, but there are errors when run setup in windows like follow
image

undefined symbol: deflateInit_

Hey Huelse,
Sorry to take more of your time.
I have found on a more up to date system (archlinux rather than ubuntu) through the recent update to 3.4.5:

archer@azuran ~ (master)> sudo pacman -Q cmake gcc clang python
cmake 3.17.0-1
gcc 9.3.0-1
clang 9.0.1-1
python 3.8.2-1

That while compilation is successfull attempting to use the seal package by calling any one of the examples results in:

archer@azuran ~ (3.4.5)> sudo docker run --gpus all -it archer/py-seal-arch python3 /seal-python/tests/4_ckks_basics.py
Traceback (most recent call last):
  File "/seal-python/tests/4_ckks_basics.py", line 2, in <module>
    from seal import *
ImportError: /usr/lib/python3.8/site-packages/seal.cpython-38-x86_64-linux-gnu.so: undefined symbol: deflateInit_

reproduce

I have a branch prepared with the issue with all of your latest commits and my dockerfiles to make reproducing easy:

https://github.com/DreamingRaven/SEAL-Python/tree/3.4.5

Build the archlinux docker, and seal-python with up-to-date packages:

sudo docker build -t archer/py-seal-arch . -f Dockerfile_archlinux

Run the archlinux docker to encounter the error:

sudo docker run -it archer/py-seal-arch python3 /seal-python/tests/4_ckks_basics.py

This does not occur and works if using older packages and build system from ubuntu:

sudo docker build -t archer/py-seal-ubuntu . -f Dockerfile
sudo docker run -it archer/py-seal-ubuntu python3 /seal-python/tests/4_ckks_basics.py

Notes

This worked on both ubuntu and archlinux prior to updating to seal v3.4.5 (as can be verified in https://github.com/DreamingRaven/SEAL-Python/tree/dev). Im wondering if you have any input into what could be causing this recent undefined symbol?

serialization results space cost not acceptable

I use BFV encryption to encrypt my numbers and I want to save them, but save function created a binary file with size 128KB for each cipher text!
The raw data is simply a 4Bytes int, the size increased by 32768 times which is not acceptable in my case.
I didn't use Batch Encoder because I have to do independent addition on each number, can we manipulate numbers in a cipher text by index?
If not, how can I have a smaller serialization of an encrypted number?
I have tried pickle, it gave me 44K bytes, smaller but not really meaningful.

build question

In the SEAL-Python step, when I type python3 setup.py build_ext -i. error
wrapper.cpp: 91: 20: error: ‘py :: array_t’ has not been declared
    .def ("numpy", [] (py :: array_t in) {

So I went to download the compiled SO file, but when I opened it with pycharm, some classes showed a red line error, but the operation passed. This has troubled me for a long time, hoping to get a solution.
20200107102802

Not able to perform multiplication beyond depth 3

The code following performs multiplication over a, b, c, and d. Till a, b, and c, I get correct results but then it doesn't work. I do apply relinearization keys in order to keep the noise budget in control but that doesn't seem to help.

from seal import *

def print_h(hex_string):
  print(int(hex_string, 16))


parms = EncryptionParameters(scheme_type.BFV)

poly_modulus_degree = 4096
parms.set_poly_modulus_degree(poly_modulus_degree)
parms.set_coeff_modulus(CoeffModulus.BFVDefault(poly_modulus_degree))
parms.set_plain_modulus(256)

context = SEALContext.Create(parms)

keygen = KeyGenerator(context)
public_key = keygen.public_key()
secret_key = keygen.secret_key()

relin_keys = keygen.relin_keys()

encryptor = Encryptor(context, public_key)
evaluator = Evaluator(context)
decryptor = Decryptor(context, secret_key)

a = Plaintext("2")
b = Plaintext("5")
c = Plaintext("1")
d = Plaintext("1")

a_enc = Ciphertext()
b_enc = Ciphertext()
c_enc = Ciphertext()
d_enc = Ciphertext()

ab = Plaintext()
abc = Plaintext()
abcd = Plaintext()

ab_enc = Ciphertext()
abc_enc = Ciphertext()
abcd_enc = Ciphertext()

encryptor.encrypt(a, a_enc)
encryptor.encrypt(b, b_enc)
encryptor.encrypt(c, c_enc)
encryptor.encrypt(d, d_enc)

evaluator.multiply(a_enc, b_enc, ab_enc)
evaluator.relinearize_inplace(ab_enc, relin_keys)
decryptor.decrypt(ab_enc, ab)
print_h(ab.to_string())

evaluator.multiply(ab_enc, c_enc, abc_enc)
evaluator.relinearize_inplace(abc_enc, relin_keys)
decryptor.decrypt(abc_enc, abc)
print_h(abc.to_string())

evaluator.multiply(abc_enc, d_enc, abcd_enc)
evaluator.relinearize_inplace(abcd_enc, relin_keys)
decryptor.decrypt(abcd_enc, abcd)
print_h(abcd.to_string())

Output -

10
10
Traceback (most recent call last):
  File "custom_test.py", line 62, in <module>
    print_h(abcd.to_string())
  File "custom_test.py", line 4, in print_h
    print(int(hex_string, 16))
ValueError: invalid literal for int() with base 16: '20x^4095 + 20x^4094 + 20x^4093 + 20x^4092 + 20x^4091 + 20x^4090 + 20x^4089 + 20x^4088 + 20x^4087 + 20x^4086 + 20x^4085 + 20x^4084 + 20x^4083 + 20x^4082 + 20x^4081 + 20x^4080 + 20x^4079 + 20x^4078 + 2

./SEAL/native/src/seal/util/locks.h:49:18: error: 'shared_mutex' is unavailable: introduced in macOS 10.12

I use macos 10.15.7, SEAL-Python3.3.2.1

when I run python setup.py build_ext -i in terminals, I get a error:

In file included from src/wrapper.cpp:6:
In file included from ./SEAL/native/src/seal/seal.h:6:
In file included from ./SEAL/native/src/seal/biguint.h:9:
In file included from ./SEAL/native/src/seal/memorymanager.h:11:
In file included from ./SEAL/native/src/seal/util/mempool.h:19:
./SEAL/native/src/seal/util/locks.h:15:50: error: 'shared_mutex' is unavailable: introduced in macOS 10.12
        using ReaderLock = std::shared_lock<std::shared_mutex>;
                                                 ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/shared_mutex:179:58: note: 'shared_mutex' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex
                                                         ^
In file included from src/wrapper.cpp:6:
In file included from ./SEAL/native/src/seal/seal.h:6:
In file included from ./SEAL/native/src/seal/biguint.h:9:
In file included from ./SEAL/native/src/seal/memorymanager.h:11:
In file included from ./SEAL/native/src/seal/util/mempool.h:19:
./SEAL/native/src/seal/util/locks.h:17:50: error: 'shared_mutex' is unavailable: introduced in macOS 10.12
        using WriterLock = std::unique_lock<std::shared_mutex>;
                                                 ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/shared_mutex:179:58: note: 'shared_mutex' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex
                                                         ^
In file included from src/wrapper.cpp:6:
In file included from ./SEAL/native/src/seal/seal.h:6:
In file included from ./SEAL/native/src/seal/biguint.h:9:
In file included from ./SEAL/native/src/seal/memorymanager.h:11:
In file included from ./SEAL/native/src/seal/util/mempool.h:19:
./SEAL/native/src/seal/util/locks.h:49:18: error: 'shared_mutex' is unavailable: introduced in macOS 10.12
            std::shared_mutex rw_lock_mutex_{};
                 ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/shared_mutex:179:58: note: 'shared_mutex' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex
                                                         ^

And according to Apple dev presentation the shared_timed_mutex will be available starting with macOS 10.12

MSGSL docker build issue

Hey Huelse,
thanks for updating to seal v3.4.5, and I realise this is not you however when I attempt to build the dockerfile CMake cannot find MSGSL at this line:

find_package(MSGSL MODULE)

giving this error message:

CMake Warning at CMakeLists.txt:280 (find_package):
  No "FindMSGSL.cmake" found in CMAKE_MODULE_PATH.


CMake Warning (dev) at CMakeLists.txt:280 (find_package):
  FindMSGSL.cmake must either be part of this project itself, in this case
  adjust CMAKE_MODULE_PATH so that it points to the correct location inside
  its source tree.

  Or it must be installed by a package which has already been found via
  find_package().  In this case make sure that package has indeed been found
  and adjust CMAKE_MODULE_PATH to contain the location where that package has
  installed FindMSGSL.cmake.  This must be a location provided by that
  package.  This error in general means that the buildsystem of this project
  is relying on a Find-module without ensuring that it is actually available.

This warning is for project developers.  Use -Wno-dev to suppress it.

and

CMake Error at cmake_install.cmake:64 (file):
  file INSTALL cannot find "/app/SEAL/native/src/cmake/FindMSGSL.cmake".


make: *** [Makefile:118: install] Error 1

I will add in MSGSL to the dockerfile but im not sure what it is, Is it this? https://github.com/Microsoft/GSL Side note nothing is specified in https://github.com/Huelse/SEAL-Python#linux section about MSGSL.

TLDR: Trying to find out what MSGSL is so I can add it in to the Dockerfile so we can verify it works on linux, and more easily reproduce seal-python.

EncryptionParameters setup problem

Hi, I was using BFV with the following setup:
`
parms = EncryptionParameters(scheme_type.bfv)

poly_modulus_degree = 2048

parms.set_poly_modulus_degree(poly_modulus_degree)

parms.set_coeff_modulus(CoeffModulus.Create(poly_modulus_degree, [27, 27]))
`
My encrypted numbers take part into only addition, no multiplication, so I set two coefficient modulus.
Everything was fine, but I still want to make it faster so I cut the poly_modulus_degree to 1024, and I think that means I have to change coefficient modulus from 27, 27 to 13, 13.
And then it threw logit error: failed to find enough qualifying primes
But I cannot increase that coefficient modulus bit length, right? 14+14=28>27
In the example code 1_bfv_basics.cpp Microsoft said 1024 was a legal poly_modulus_degree, I just wonder how to use it, or Microsoft made a mistake?

segmentation fault in set_parms

[//]: # Before submitting this issue, make sure you have already searched and still have problems.
Describe the bug
A clear and concise description of what the bug is.

Device\Environment
System: Ubuntu18.04
Python: 3.8.5

To Reproduce
Steps to reproduce the behavior:

  1. Using seal with pickle
  2. scheme type bfv
  3. poly modulus degree 8192
  4. plain modulus generated with PlainModulus.Batching(8192, 20)
  5. coeff modulus generated with CoeffModulus.Create(8192, [60, 40, 40, 60])
  6. generate secret key by key generator, for example with variable name sk

Expected behavior
A clear and concise description of what you expected to happen.
7. if only sk.set_parms(parms) in the code, it can run but report segmentation fault after return
8. if sk.set_parms(parms) and then pickle.dumps(sk), the code break and report segmentation fault at once

Pickling support

Hi, it is quite inconvenient to always have to save and load from a binary file when working with the library. Another issue is the binary file compatibility (rather lack of) across different operating systems.

So I went ahead and added support for pickling (inspired by your earlier release and lab41's repo). It is quite useful to be able to pickle.dumps() the python object to a printable string to pass to a different process. I can open a PR if the feature is desired. Cheers!

errors when run "python3 setup.py"

Hello,
when I run "python3 setup.py", it returns an error as follows:

image
I have followed your instructions correctly, could you please give me some help?
Thanks

NameError: name 'FractionalEncoder' is not defined

Hi,

Actually, I am facing an issue while declaring an encoder as FractionalEncoder. It's working with the IntegerEncoder but it's showing (NameError "FractionalEncoder" doesn't exist) while declaring the variable encoder=FractionalEncoder(context).

I think it doesn't exist in python-seal but I need it as I was dealing with Float Numbers. Do you have any idea or is there any other encoder to encode Fractional values.

Please find the screenshot below for reference.
Screenshot from 2020-11-17 00-14-24

Ubuntu 16.04中make发生错误

您好,我在ubuntu服务器上安装了环境,将SEAL-Python clone了下来,执行cmake .时并没有发生错误,在执行make时报错。目前人在外面,后续补上具体报错信息的截图,基本报错的内容都是说"}"不匹配。
系统为ubuntu 16.04,cmake版本为3.14,gcc版本为7,python版本为3.7。
希望您看到后能够解答我的疑惑。谢谢

Is the library compatible backward and forward?

Hi, I found that many APIs have been updated in the past months, the previous engineer left things like Ciphertext().release() in my codes which is no longer found in the newest library.

The codes conflict can be fixed but what I'm worrying about is that if the ciphers encrypted by the old version seal can still be decrypted by future version?
How about the other way around?

python3 setup.py install报错

抱歉我可能又要来提问了……
我在使用Ubuntu 20.04安装seal时,在执行python3 setup.py install或执行python3 setup.py build_ext -i后均产生报错error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

我尝试了很多办法也无法去解决这个问题……在issue中找到了类似的问题,不过他是clang并且那个issue并没有解决emmmm

不知道您是否找到了解决方案呢?虽然我觉得我自己去回退版本可能是一个好的选择……

install pyseal on windows

when i execute "python3 setup.py build_ext -i", an error was reported "Can not find the seal lib"(windows)
setup.py writing "./SEAL/native/lib/libseal-3.4.a",but i can not find libseal-3.4.a in the path
could you give me some solution when i install pyseal on windows 10,thanks

How to use BFV algorithm?

最近重新编译安装了一下,现在dir(seal)显示只有BatchEncoder和CKKSEncoder,BFV怎么用呢?原来的IntegerEncoder是BFV吗?现在没了

运行案例问题

貌似只能是通过cmd命令行方式来运行案例,我用pycharm编辑器跑不了 报没有seal模块。

Problems of windows compilation errors

I pull the code down from GitHub and follow the steps.When I run the ‘python3 setup.py build_ext -i’,it shows some errors like C2059,C2334,C7586.And when I run the python script , it shows me 'No module named ‘seal’ '.And my compilation environment is Windows VS Native2019 x64.Please give the advice, thank you!

ModuleNotFoundError: No module named 'seal'

I successfully build the seal lib using your instructions in Linux, but it returns that error when I run your examples. So how can I find that seal?
Wish for your reply.

can't pickle seal.IntegerEncoder objects

Hi, I had some code with the master from before March 30th. And now it complains that

c = seal.Ciphertext()
c2 = copy.deepcopy(c)
can't pickle seal.IntegerEncoder objects

I noticed that the object Ciphertext does not have the setstate and getstate methods anymore (the same with the Plaintext object), which explains why they cannot be pickled. Will it be possible to bring back the serialization? It would be a useful feature to be able to copy the objects.

Thank you!

plaintext decode out of range

I set up the SEAL context with the following values:

params = seal.EncryptionParameters(seal.scheme_type.BFV)
poly_modulus_degree = 16384
params.set_poly_modulus_degree(poly_modulus_degree)
params.set_coeff_modulus(seal.CoeffModulus.BFVDefault(poly_modulus_degree))
plain_mod = 2424833
params.set_plain_modulus(plain_mod)

I am also using the IntegerEncoder, like this:
encoder = seal.IntegerEncoder(context)
value1 = -7
plain1 = seal.Plaintext(encoder.encode(value1))
value2 = 25
plain2 = seal.Plaintext(encoder.encode(value2))

Afterwards, I perform some computations (squarings and multiplications). While the noise budget stays in the double digits, decoding the result to int becomes imposible as I get a Value error.

Traceback (most recent call last):
File "/.../Python-Tests/test.py", line 551, in
tmp = encoder.decode_int64(plain_result)
ValueError: output out of range

Shouldn't the result remain in a decoding-range for int64 if it is set to the value above? I also noticed that with smaller input values, I can still decode, but the value is not mod plaintext_modulus either. Am I missing something about the purpose of the plain_modulus?

Windows support?

Is there a way to build this project on a Windows machine? Thank You

Python2.7封装后,使用PlainModulus.Batching()初始化plain_modulus出现错误

下面是报错的提示.

File "5_rotation.py", line 12, in example_rotation_bfv
    parms.set_plain_modulus(PlainModulus.Batching(poly_modulus_degree, 20))
TypeError: unbound method Batching() must be called with PlainModulus instance as first argument (got int instance instead)

定位到这句话

parms.set_plain_modulus(PlainModulus.Batching(poly_modulus_degree, 20))

请问老哥,你觉得这问题是因为
1.Python2.7封装时就不能支持这个操作
还是因为
2.Python版本差异,参数传递方式不同,需要修改5_rotation.py.

如果是原因2的话,是不是可以修改修改,来支持Python2.7啊?可以往哪方面搜?

另外python2.7运行1_bfv_basic.py以及2_encoders.pyexample_integer_encoder()倒是没什么问题.

pop_back() on DoubleVector returns None

Hi.
pop_back() method on a DoubleVector object returns None. Is this expected behavior?
If yes, then how can data be cast from DoubleVector to python data types?

Thanks!

slot_count method missing for BatchEncoder

Description
In the new version the slot_count method of the BatchEncoder class is missing.

Solution
Adding .def("slot_count", &BatchEncoder::slot_count) to the BatchEncoder wrappers.

demo questions

could you give me some help? i want encryptor and decryptor string "abc#123#**#12:30#11" and get the size of ciphertext,could you give me some simple demo? i fix tests demo in this project but it occurs errors.

can not find the seal lib

hello, i open the .sln with vs2017, and generate the three solutions successufully ,but when i run the command ' python setup.py build_ext -i ' ,it says 'can not find the seal lib' ,how to solve it? thank you for you answer!

Precision for operations in CKKS

I am trying to multiply a small constant(of order e-04) with a variable x.

        a = Plaintext()
	b = Plaintext()
	temp = Plaintext()
	encoder.encode(-1.11308404e-04, scale, a)
	encoder.encode(1.17652073e-01, scale, b)
	encoder.encode(x, scale, temp)
	X = Ciphertext()
	encryptor.encrypt(temp, X)
	evaluator.multiply_plain_inplace(X, a)
	evaluator.mod_switch_to_inplace(b, X.parms_id())
	X.scale(scale)
	evaluator.add_plain_inplace(X, b)

But when I perform this, I get the following error:-

evaluator.multiply_plain_inplace(X, a)
RuntimeError: result ciphertext is transparent

Changing e-04 to e-03 works fine. So, what is the amount of precision allowed in CKKS? Or can it be changed?

Issues in the output of test scripts

python 1_bfv_basics.py 
+-------------------------------------+
|         Example: BFV Basics         |
+-------------------------------------+
--------------------------------------------------
Set encryption parameters and print
/
| Encryption parameters:
| scheme: BFV
| poly_modulus_degree: 4096
| coeff_modulus size: 109(36 + 36 + 37) bits
| plain_modulus: 256
\
~~~~~~ A naive way to calculate 2(x^2+1)(x+1)^2. ~~~~~~
--------------------------------------------------
Express x = 6 as a plaintext polynomial 0x6.
--------------------------------------------------
Encrypt x_plain to x_encrypted.
    + size of freshly encrypted x: 2
    + noise budget in freshly encrypted x: 57 bits
    + decryption of x_encrypted: 0x6 ...... Correct.
--------------------------------------------------
Compute x_sq_plus_one (x^2+1).
    + size of x_sq_plus_one: 3
    + noise budget in x_sq_plus_one: 37 bits
    + decryption of x_sq_plus_one: 0x25 ...... Correct.
--------------------------------------------------
Compute x_plus_one_sq ((x+1)^2).
    + size of x_plus_one_sq: 3
    + noise budget in x_plus_one_sq: 37 bits
    + decryption of x_plus_one_sq: 0x31 ...... Correct.
--------------------------------------------------
Compute encrypted_result (4(x^2+1)(x+1)^2).
    + size of encrypted_result: 5
    + noise budget in encrypted_result: 9 bits
NOTE: Decryption can be incorrect if noise budget is zero.

~~~~~~ A better way to calculate 4(x^2+1)(x+1)^2. ~~~~~~
--------------------------------------------------
Generate relinearization keys.
--------------------------------------------------
Compute and relinearize x_squared (x^2),
             then compute x_sq_plus_one (x^2+1)
    + size of x_squared: 3
    + size of x_squared (after relinearization): 2
    + noise budget in x_sq_plus_one: 37 bits
    + decryption of x_sq_plus_one: 0x25 ...... Correct.
--------------------------------------------------
Compute x_plus_one (x+1),
             then compute and relinearize x_plus_one_sq ((x+1)^2).
    + size of x_plus_one_sq: 3
    + noise budget in x_plus_one_sq: 37 bits
    + decryption of x_plus_one_sq: 0x31 ...... Correct.
--------------------------------------------------
Compute and relinearize encrypted_result (4(x^2+1)(x+1)^2).
    + size of encrypted_result: 3
    + size of encrypted_result (after relinearization): 2
    + noise budget in encrypted_result: 16 bits

NOTE: Notice the increase in remaining noise budget.
--------------------------------------------------
Decrypt encrypted_result (4(x^2+1)(x+1)^2).
    + decryption of 4(x^2+1)(x+1)^2 = 0x54 ...... Correct.

Not sure why x^2 + 1 should be 25 if you have x=6, shouldn't it be 37. Same is the case with other outputs as well.
EDIT: Tried on two different systems Mac and Ubuntu, getting same output.

python3 setup.py build_ext -i

hi, when I excute the command, find some error:

wrapper.cpp: In function 'void pybind11_init_seal(pybind11::module&)':
wrapper.cpp:136:20: error: 'py::array_t' has not been declared

clang failed with exit status 1

[//]: # Before submitting this issue, make sure you have already searched and still have problems.
Describe the bug
After "python3 setup.py build_ext -i", shows as follows:

error: use of undeclared identifier '_subborrow_u64'
error: use of undeclared identifier '_addcarry_u64'
error: use of undeclared identifier '_subborrow_u64'
error: command 'clang' failed with exit status 1

Device\Environment
System: macOS Big Sur 11.2.3
Python: 3.8

Screenshots
截屏2021-03-24 13 29 41

Is there a function for sum of an encrypted vector?

I checked the methods of Evaluator class and failed to find a sum or mean value calculator.
Currently, I'm doing it like rotate vector by one slot and add it to the sum. But this is too slow to apply out of a demo.
Is there a solution or seal is not going to support such operations?

python3 setup.py build_ext -i

Hi, I followed the Linux installation instructions step by step, then I tried to run the files under the tests folder, and an error was reported.
**root@1be2fda826a0:/workspace/SEAL-Python/tests# python3 0_data_type.py
Traceback (most recent call last):
File "0_data_type.py", line 1, in
from seal import *
ImportError: /workspace/SEAL-Python/tests/seal.cpython-37m-x86_64-linux-gnu.so: undefined symbol: deflateInit
**_
Then, I try to use the first solution of FAQ, but another error occured:
the SEAL_LIB_BUILD_TYPE=Shared don't exist.
Please help me!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.