Skip to content

Commit d9fd610

Browse files
Merge pull request #4 from Huelse/master
Origin update to huelses latest code
2 parents 32ef4d9 + 0b5f417 commit d9fd610

File tree

334 files changed

+1852
-122508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

334 files changed

+1852
-122508
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.cpp linguist-language=Python

.github/FUNDING.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['https://paypal.me/huelse99'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/ISSUE_TEMPLATE/bug_report.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
[//]: # Before submitting this issue, make sure you have already searched and still have problems.
11+
**Describe the bug**
12+
A clear and concise description of what the bug is.
13+
14+
**Device\Environment**
15+
System:
16+
Python:
17+
18+
**To Reproduce**
19+
Steps to reproduce the behavior:
20+
1.
21+
2.
22+
23+
**Expected behavior**
24+
A clear and concise description of what you expected to happen.
25+
26+
**Screenshots**
27+
If applicable, add screenshots to help explain your problem.
28+
29+
**Additional context**
30+
Add any other context about the problem here.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/ISSUE_TEMPLATE/other-issue.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Other issue
3+
about: Other issue template
4+
title: ''
5+
labels: question
6+
assignees: ''
7+
8+
---
9+
10+
**Type**
11+
illustrate your original intention.
12+
13+
**Descripe**
14+
write what you want.

.github/workflows/python-package.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
branches: [ 3.3.2 ]
9+
pull_request:
10+
branches: [ 3.3.2 ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: [3.5, 3.6, 3.7, 3.8]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
sudo apt-get install python3 python3-pip build-essential cmake
29+
python -m pip install --upgrade pip
30+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31+
- name: build seal
32+
run: |
33+
cd SEAL/native/src
34+
cmake .
35+
make
36+
- name: build seal-python
37+
run: |
38+
python3 setup.py build_ext -i
39+
python3 setup.py install
40+
41+

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "SEAL"]
2+
path = SEAL
3+
url = https://github.com/microsoft/SEAL.git
4+
[submodule "pybind11"]
5+
path = pybind11
6+
url = https://github.com/pybind/pybind11.git

Dockerfile

-44
This file was deleted.

README.md

+103-81
Original file line numberDiff line numberDiff line change
@@ -10,109 +10,131 @@ This is a python binding for the Microsoft SEAL library.
1010

1111
## Contents
1212

13-
* [Build](https://github.com/Huelse/SEAL-Python#build)
14-
* [Tests](https://github.com/Huelse/SEAL-Python#tests)
15-
* [About](https://github.com/Huelse/SEAL-Python#about)
16-
* [Contributing](https://github.com/Huelse/SEAL-Python#contributing)
13+
* [Build](#build)
14+
* [Note](#note)
15+
* [Serialize](#serialize)
16+
* [Other](#other)
17+
* [FAQ](#faq)
1718

1819

1920

2021
## Build
21-
### Linux
22-
CMake (>= 3.10), GNU G++ (>= 6.0) or Clang++ (>= 5.0), Python (>=3.6.8)
23-
24-
`sudo apt-get update && sudo apt-get install g++ make cmake git python3 python3-dev python3-pip`
25-
26-
`git clone https://github.com/Huelse/SEAL-Python.git`
27-
28-
```shell
29-
cd SEAL/native/src
30-
cmake .
31-
make
32-
33-
pip3 install -r requirements.txt
34-
35-
# Check the path at first
36-
# Setuptools (Recommend)
37-
python3 setup.py build_ext -i
38-
# or install
39-
python3 setup.py install
40-
```
41-
42-
Docs: [setuptools](https://docs.python.org/3/distutils/configfile.html) [pybind11](https://pybind11.readthedocs.io/en/master/index.html)
43-
44-
### Windows
45-
46-
Visual Studio 2017 version 15.3 or newer is required to build Microsoft SEAL.
47-
48-
Open the `SEAL/SEAL.sln` in VS, config in `x64, Release, WinSDK(17763, etc)` mode and generate it.
49-
50-
```shell
51-
python3 setup.py build_ext -i
52-
# or install
53-
python3 setup.py install
54-
```
55-
56-
Microsoft official video [SEAL in windows](https://www.microsoft.com/en-us/research/video/installing-microsoft-seal-on-windows/).
22+
* #### Linux
23+
Clang++ (>= 5.0) or GNU G++ (>= 6.0), CMake (>= 3.12)
24+
25+
```shell
26+
# Optional
27+
sudo apt-get install build-essential cmake python3 python3-dev python3-pip
28+
29+
# Get the repository or download from the releases
30+
git clone https://github.com/Huelse/SEAL-Python.git
31+
cd SEAL-Python
32+
33+
# Numpy is essential
34+
pip3 install -r requirements.txt
35+
36+
# Init the SEAL and pybind11
37+
git submodule init && git submodule update
38+
# Get the newest repositories (unnecessary)
39+
git submodule update --remote
40+
41+
# Build the SEAL lib
42+
cd SEAL
43+
cmake -S . -B build -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_USE_ZSTD=OFF
44+
cmake --build build
45+
cd ..
46+
47+
# Run the setup.py
48+
python3 setup.py build_ext -i
49+
```
50+
51+
* #### Windows
52+
53+
Visual Studio 2019 or newer is required. And use the **x64 Native Tools Command Prompt for Visual Studio 2019** command prompt to configure and build the Microsoft SEAL library. It's usually can be found in your Start Menu.
54+
55+
```shell
56+
# Same as above
57+
# Build the SEAL library
58+
cmake -S . -B build -G Ninja -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_USE_ZSTD=OFF
59+
cmake --build build
60+
61+
# Run the setup.py
62+
python setup.py build_ext -i
63+
```
64+
65+
Generally, the Ninja generator is better than the "Visual Studio 16 2019" generator, and there is more information in the Microsoft SEAL official [illustrate](https://github.com/microsoft/SEAL#building-microsoft-seal-manually).
66+
67+
68+
69+
## Note
70+
71+
* #### Serialize
72+
73+
In most situations, you can use the SEAL's native serialize API to save the data, here is an example:
74+
75+
```python
76+
cipher.save('cipher')
77+
78+
load_cipher = Ciphertext()
79+
load_cipher.load(context, 'cipher') # work if the context is valid.
80+
```
81+
82+
Support type: `Encryptionparams, Ciphertext, Plaintext, SecretKey, Publickey, Relinkeys, Galoiskeys`
83+
84+
Particularly, if you want to use the pickle to serialize your data, you need to do these things like below:
85+
86+
```shell
87+
# 1. Modify the serializable object's header file in SEAL and switch the wrapper.
88+
python helper.py
89+
90+
# 2. Rebuild the SEAL lib like above
91+
cmake --build build
92+
93+
# 3. Run the setup.py
94+
python setup.py build_ext -i
95+
```
96+
97+
Then, you can pickle the data object like this:
98+
99+
```python
100+
import pickle
101+
102+
cipher.set_parms(parms) # necessary
103+
cipher_dump = pickle.dumps(cipher)
104+
cipher_load = pickle.loads(cipher_dump)
105+
```
106+
107+
Generally, we don't use compression library.
108+
109+
* #### Other
110+
111+
There are a lot of changes in the latest SEAL lib, we try to make the API in python can be used easier, it may remain some problems we unknown, if any problems(bugs), [Issue](https://github.com/Huelse/SEAL-Python/issues) please.
112+
113+
Email: [[email protected]](mailto:[email protected]?subject=Github-SEAL-Python-Issues)
57114

58115

59116

60117
## FAQ
61118

62119
1. ImportError: undefined symbol
63120

64-
Build a shared SEAL library `cmake . -D SEAL_LIB_BUILD_TYPE=Shared`, and get the `libseal.so`
65-
66-
then change the lib path in `setup.py` or `src/CMakeLists.txt`, and rebuild.
121+
Build a shared SEAL library `cmake . -DBUILD_SHARED_LIBS=ON`, and get the `libseal.so`,
67122

123+
then change the path in `setup.py`, and rebuild.
68124

69-
70-
2. ImportError: libseal.so.3.4 cannot find
125+
2. ImportError: libseal.so... cannot find
71126

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

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

76131
c. build in cmake.
77132

133+
3. BuildError: C++17 at least
78134

135+
4. ModuleNotFoundError: No module named 'seal'
79136

80-
81-
## Tests
82-
83-
`cd tests`
84-
85-
`python3 [example_name].py`
86-
87-
* The `.so` file must be in the same folder, or you had `install` it already.
88-
89-
90-
91-
## Getting Started
92-
93-
| C++ | Python | Description |
94-
| ----------------- | ---------------- | ------------------------------------------------------------ |
95-
| 1_bfv_basics.cpp | 1_bfv_basics.py | Encrypted modular arithmetic using the BFV scheme |
96-
| 2_encoders.cpp | 2_encoders.py | Encoding more complex data into Microsoft SEAL plaintext objects |
97-
| 3_levels.cpp | 3_levels.py | Introduces the concept of levels; prerequisite for using the CKKS scheme |
98-
| 4_ckks_basics.cpp | 4_ckks_basics.py | Encrypted real number arithmetic using the CKKS scheme |
99-
| 5_rotation.cpp | 5_rotation.py | Performing cyclic rotations on encrypted vectors in the BFV and CKKS schemes |
100-
| 6_performance.cpp | 6_performance.py | Performance tests for Microsoft SEAL |
101-
102-
103-
104-
## Future
105-
106-
* pickle
107-
* microsoft gsl
108-
109-
110-
111-
## About
112-
113-
This project is still testing now, if any problems(bugs), [Issue](https://github.com/Huelse/SEAL-Python/issues) please.
114-
115-
Email: [[email protected]](mailto:[email protected]?subject=Github-SEAL-Python-Issues&[email protected])
137+
The `.so` or `.pyd` file must be in the current directory, or you have `install` it already.
116138

117139

118140

SEAL

Submodule SEAL added at 6078012

0 commit comments

Comments
 (0)