paillier
Additively homomorphic Paillier encryption: a Rust implementation on top of GMP, bound to Python through pyo3.
Add encrypted numbers without decrypting them:
import paillier
pub, sec = paillier.generate_keypair(2048)
blobs = [bytes(b) for b in paillier.encrypt_many(pub, [1.5, 2.25, -0.75])]
total = paillier.add_many(pub, blobs) # adding CIPHERTEXTS
paillier.decrypt(sec, total) # 3.0
Whoever does the adding never sees the terms. Whoever holds the private key sees only the sum.
pip install pypaillier
Wheels for CPython 3.10, 3.11, 3.12 and 3.13. No compiler and no system GMP required.
The distribution is pypaillier; the import name is paillier. PyPI
would not take paillier as a project name, and there was no reason to
carry that into the API.
Read this before using it
This is not textbook Paillier. The scheme is the Damgård–Jurik
variant with a short exponent: c = (1 + m·n) · hs^r mod n², where the
base is fixed and the exponent — |n|/2 bits — is what varies. Almost
all of the speed comes from that, and so does the consequence:
ciphertext indistinguishability rests on more than DCRA alone. It
needs an additional short-exponent assumption. That assumption is
standard and published, but it exists, and "secure under DCRA" is not a
sentence you can say here unconditionally.
There is NO constant time. Two timing side channels are closed, one stays open — about 0.118 bits out of 1024. It is named, measured, and guarded by a test that watches it does not grow.
Both statements are worked through in full, with measurements and with what the scheme does not give: documentation.
Numbers
2048-bit key, one machine, medians over five repeats:
| operation | cost |
|---|---|
| encryption, all cores | 6500+ ops/s |
| encryption, one core | 980 ops/s |
| addition | 7.3 µs per term |
| decryption | 3.75 ms |
| key generation | 1.4–2.8 s (spread 1.0–10.3) |
| ciphertext | 512–513 B |
Encryption is 98 % modular multiplications inside the window table; encoding, serialisation and the rest come to under half a percent together. Key generation has an enormous spread because it is a search: safe primes are rare and the time to a hit is random.
Everything here is reproducible from the repository:
python benches/measure.py.
Accuracy is configurable
blobs = paillier.encrypt_many(pub, values, scale_pow10=12)
The scale travels inside the ciphertext: decryption reads it from there, and addition refuses a batch that mixes scales. The two sides have nothing to agree on.
At scale_pow10 = 12 the sum error over a million sign-constant terms
drops below the resolution of f64 itself — at the cost of narrowing
the input range from |v| ≲ 9e7 to ≲ 9e3.
Checks
cargo test --release
python -m pytest
Performance and accuracy benchmarks live in benches/, each answering
one question:
reference.
Building from source
pip install maturin
maturin build --release
Needs stable Rust. GMP is built and linked statically; you do not need to install it separately.
Licences
The sources are MIT OR Apache-2.0, at your option.
The built wheels additionally contain GMP, statically linked through
rug, and therefore fall under
LGPL-3.0+ as a whole. Installing a wheel from PyPI gets you a
combined work, not only our code.
If you need a binary with no LGPL code inside, build it from the source
distribution against your own GMP:
pip install --no-binary pypaillier pypaillier.
Full breakdown, including how the LGPL §4 conditions are met and where
the techniques came from:
NOTICE.md.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypaillier-0.3.0.tar.gz.
File metadata
- Download URL: pypaillier-0.3.0.tar.gz
- Upload date:
- Size: 93.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
874fa7d18e5be8cdde5e7ab45b8c18391290072226ce48134eb99f1fb43aafe8
|
|
| MD5 |
2b54836a6d41d8bff1f6583a4110ae1c
|
|
| BLAKE2b-256 |
3b3c7f8e943c25e7af22a95f545456d858afff3a1be8c13a9fd03608bf1ccf17
|
Provenance
The following attestation bundles were made for pypaillier-0.3.0.tar.gz:
Publisher:
publish.yml on veryviolet/paillier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypaillier-0.3.0.tar.gz -
Subject digest:
874fa7d18e5be8cdde5e7ab45b8c18391290072226ce48134eb99f1fb43aafe8 - Sigstore transparency entry: 2614442242
- Sigstore integration time:
-
Permalink:
veryviolet/paillier@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/veryviolet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Trigger Event:
push
-
Statement type:
File details
Details for the file pypaillier-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pypaillier-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 510.5 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8fa2bcac754921d54beb3a8c34ffdb412dc27cd4f4385e285062d16a6b3cd1e
|
|
| MD5 |
138b10f689e8c497c3217a0b63b7388c
|
|
| BLAKE2b-256 |
f6c9c96f947c0faa36ce9a0d2532af92c2f5e06be131be397ecb69666a192c4b
|
Provenance
The following attestation bundles were made for pypaillier-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on veryviolet/paillier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypaillier-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
b8fa2bcac754921d54beb3a8c34ffdb412dc27cd4f4385e285062d16a6b3cd1e - Sigstore transparency entry: 2614443600
- Sigstore integration time:
-
Permalink:
veryviolet/paillier@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/veryviolet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Trigger Event:
push
-
Statement type:
File details
Details for the file pypaillier-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pypaillier-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 510.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ddf62e3ddc2ca085adf5b30928bd875dddccd7261ac5a30f72e2dbf582e5bbd
|
|
| MD5 |
591b4b0d9771c43fd4c40a2e83c5bfd8
|
|
| BLAKE2b-256 |
3210e0ade5d1074e1af3d50b855abfc29fc439c78ad13c0bfbe7ed98fb3b9ca9
|
Provenance
The following attestation bundles were made for pypaillier-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on veryviolet/paillier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypaillier-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
7ddf62e3ddc2ca085adf5b30928bd875dddccd7261ac5a30f72e2dbf582e5bbd - Sigstore transparency entry: 2614444400
- Sigstore integration time:
-
Permalink:
veryviolet/paillier@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/veryviolet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Trigger Event:
push
-
Statement type:
File details
Details for the file pypaillier-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pypaillier-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 510.4 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc71713238205d29eaae5425e299eb89161e7aa4663f3651aa5c42518ec5f739
|
|
| MD5 |
b73d8994e204768acc7995109ebae7ea
|
|
| BLAKE2b-256 |
271904e3dce804ea56c19e74274584c7cdcd4481e46adfefd65c6d3902d3d9b2
|
Provenance
The following attestation bundles were made for pypaillier-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on veryviolet/paillier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypaillier-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
dc71713238205d29eaae5425e299eb89161e7aa4663f3651aa5c42518ec5f739 - Sigstore transparency entry: 2614442924
- Sigstore integration time:
-
Permalink:
veryviolet/paillier@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/veryviolet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Trigger Event:
push
-
Statement type:
File details
Details for the file pypaillier-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pypaillier-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 510.4 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a69a1e374689b5813ba91c9fd43d7e17c8ba8a7aa7469a361446b396f1f1ca0d
|
|
| MD5 |
04149ac7f599cfe69a8d90c55f7120ca
|
|
| BLAKE2b-256 |
600372d2baa5fe0e8fd330dc41f8bf655fe9475ae3e0730463b6e92c154c688b
|
Provenance
The following attestation bundles were made for pypaillier-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on veryviolet/paillier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypaillier-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
a69a1e374689b5813ba91c9fd43d7e17c8ba8a7aa7469a361446b396f1f1ca0d - Sigstore transparency entry: 2614444997
- Sigstore integration time:
-
Permalink:
veryviolet/paillier@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/veryviolet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@025c90d6df010d18a41d74e93317c5a0709bdb4d -
Trigger Event:
push
-
Statement type: