Kyber post-quantum key encapsulation in Rust
Project description
PyKyber
A Python library for Kyber post-quantum key encapsulation, implemented in Rust.
Installation
pip install pykyber
Quick Start
import pykyber
# Generate a keypair (Alice)
alice_keypair = pykyber.Kyber768()
# Encapsulate - create shared secret (Bob)
bob_result = pykyber.Kyber768.encapsulate(alice_keypair.public_key)
# Decapsulate - recover shared secret (Alice)
shared_secret = alice_keypair.decapsulate(bob_result.ciphertext)
# Both parties now share the same secret
print(f"Match: {bob_result.shared_secret == shared_secret}")
API Usage
import pykyber
# Create a keypair - instant generation on class instantiation
keypair = pykyber.Kyber512() # ~AES-128 security
keypair = pykyber.Kyber768() # ~AES-192 security
keypair = pykyber.Kyber1024() # ~AES-256 security
# Access raw key bytes
public_key = keypair.public_key # bytes
secret_key = keypair.secret_key # bytes
# Or unpack directly as tuple
public_key, secret_key = keypair # same as above
# Encapsulate - create ciphertext and shared secret
result = keypair.encapsulate()
# result.ciphertext - bytes to send to receiver
# result.shared_secret - 32 bytes shared secret
# Or unpack directly as tuple
ciphertext, shared_secret = keypair.encapsulate() # same as above
# Decapsulate - recover shared secret from ciphertext
shared_secret = keypair.decapsulate(result.ciphertext)
# Static methods - use without creating a keypair instance
# Encapsulate with just a public key
result = pykyber.Kyber768.encapsulate(public_key)
# Decapsulate with just ciphertext and secret key
shared_secret = pykyber.Kyber768.decapsulate(ciphertext, secret_key)
Key Sizes
| Variant | Public Key | Secret Key | Ciphertext | Shared Secret |
|---|---|---|---|---|
| Kyber-512 | 800 bytes | 1632 bytes | 768 bytes | 32 bytes |
| Kyber-768 | 1184 bytes | 2400 bytes | 1088 bytes | 32 bytes |
| Kyber-1024 | 1568 bytes | 3168 bytes | 1408 bytes | 32 bytes |
Error Handling
All operations raise KyberError when invalid input is provided:
import pykyber
try:
pykyber.Kyber768.encapsulate(b"too_short")
except pykyber.KyberError as e:
print(e)
# Output: Invalid public key for Kyber768.encapsulate: expected 1184 bytes, got 10.
# Ensure you're using the correct Kyber variant (Kyber512=800, Kyber768=1184, Kyber1024=1568).
Common error cases:
- Invalid public key size: Wrong number of bytes for the Kyber variant
- Invalid ciphertext size: Wrong number of bytes when decapsulating
- Invalid secret key size: Wrong number of bytes for the Kyber variant
Performance
Performance benchmarks (100 iterations each):
| Variant | Keypair | Encapsulate | Decapsulate |
|---|---|---|---|
| Kyber512 | 0.27 ms (3,667/s) | 0.39 ms (2,548/s) | 0.48 ms (2,101/s) |
| Kyber768 | 0.48 ms (2,069/s) | 0.62 ms (1,605/s) | 0.78 ms (1,279/s) |
| Kyber1024 | 0.78 ms (1,289/s) | 0.94 ms (1,064/s) | 1.04 ms (959/s) |
Run benchmarks and generate graphs:
make benchmark
Generated graphs:
Performance Comparison
Operation Breakdown
Scalability
Throughput
License
MIT
Project details
Release history Release notifications | RSS feed
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 pykyber-0.1.7.tar.gz.
File metadata
- Download URL: pykyber-0.1.7.tar.gz
- Upload date:
- Size: 278.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5210c801aeca6560ef5f19df07db17d865c50e7db330e4ba81d68dffa4819b6d
|
|
| MD5 |
0e41af181ab97f90cd0a526e17d19082
|
|
| BLAKE2b-256 |
26d5a366eedef9caa07ac66c1e3a1ea991e273edf08b724db1bfee936612cb7a
|
File details
Details for the file pykyber-0.1.7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pykyber-0.1.7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 316.3 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9ea193c3abfd8057b06e4f8d7f689596a96dad43c4a46da63f79e338a36c8be
|
|
| MD5 |
d08c1f101efd041854848b41afdc932f
|
|
| BLAKE2b-256 |
b8ca227f0d2c802617f4aff53cdd760c61af75295692c8aa3b92990ddd85c82e
|
File details
Details for the file pykyber-0.1.7-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl.
File metadata
- Download URL: pykyber-0.1.7-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 330.5 kB
- Tags: PyPy, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a718d34157e8a985f228c2ca5cffaa64669657caefa8b0e87eea5b12007a9e31
|
|
| MD5 |
baf09a2c66c54515e641b46394fb80ad
|
|
| BLAKE2b-256 |
8ed15c47938907b67b1180e772e15de24cee48d2ebe632aa0e419d8f31667c32
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-win_arm64.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-win_arm64.whl
- Upload date:
- Size: 162.2 kB
- Tags: CPython 3.8+, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43d4534adb288b409b07ac0701b06564ae4f12f20353eb22f7a78cde19552c2b
|
|
| MD5 |
18d26fade3f88e52c5a94f74f4821d21
|
|
| BLAKE2b-256 |
150561c1b6fc0b582152472ebd948607cea4e869d4f62075af5f487c70388dd3
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 175.2 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e7008860e3e66f87986cf261b677c9012150fc0cd7f6bb32382f52477cdcf00
|
|
| MD5 |
a01bc688fa30766bf1535757d88eb2e6
|
|
| BLAKE2b-256 |
2063186ec78e007c512a3930d4b03a4f544e37ee5ed28b2230c932d6b3dde2fe
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-win32.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-win32.whl
- Upload date:
- Size: 160.5 kB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac346ec5e3204982682fe6d9aaecab82dbc590c49b9bf611bc55fc2f32de262c
|
|
| MD5 |
77bdb6aee89c72bd4e5bbdbe692c4dc1
|
|
| BLAKE2b-256 |
96a026787fdaa9e0eaf77515136462aa72faa6d904f5940425f234f80a1f655e
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 518.4 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40be1afcaf0d2192b668e799b0d1dcd223628cb99f0a95f89f2a627a72695c0b
|
|
| MD5 |
aef04c32d6665405cedcc6e64bc2009a
|
|
| BLAKE2b-256 |
f87269f20fbb97d3d4538ec9015e30b42f86e9a34c5a64a42c2e090f6f76f6de
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-musllinux_1_2_i686.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-musllinux_1_2_i686.whl
- Upload date:
- Size: 545.5 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41c5f395307c71bfad55483d2878079b5cfffa69db4982b28bdd3a751c316a80
|
|
| MD5 |
f88ffca7ba618ab6f24eecbecddc786f
|
|
| BLAKE2b-256 |
1b3943b43b5131b7009393b5ce150d49d42c1dc3f83444ff069801bb4ba75982
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-musllinux_1_2_armv7l.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-musllinux_1_2_armv7l.whl
- Upload date:
- Size: 566.5 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
624c68296776946fdaae2bd2ed1da2d887da68e99966d1fce7f38e9627478df5
|
|
| MD5 |
4a1be89d5f7b9ed4c9f9af702eb5f6ea
|
|
| BLAKE2b-256 |
a4fd8ccb9512fb4811ec2873956a15af96dd97ce2604febb111c1685c24cc907
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 491.4 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ad576844f5747fe47f2dd13d1fdbebb19a9fcd795b1564a3442b3c3a8e5cdb9
|
|
| MD5 |
1bca3b00fefb53dafbb72b4cbc86a4a7
|
|
| BLAKE2b-256 |
eef3c11a819543143d70b1f6fb84184e11f84201ba304ae5e5eaab57dd2150ec
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 316.4 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
732580b28571143d55b7323d14d351ad2769ce3979cbd5035d2138e2c4a857f0
|
|
| MD5 |
5a88e876b22797f202b7892facc13e5b
|
|
| BLAKE2b-256 |
7c9773d4d9a7797c17262f40b76c264fe4a7b3d2b5bb866ec0b49a95d0ab7adc
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 309.3 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dbe1e45a84043805591cdf5a827c9161529838f05d8027db257ed6372c1e5be
|
|
| MD5 |
a623fdc80d6c38c4e92ecd2c1a8956e1
|
|
| BLAKE2b-256 |
b4d725ea3f54bb08307e5c4b1d78741fc40b082d11bdb0747b57d57572de212b
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
- Upload date:
- Size: 470.6 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e6ae0b83abd43f61b90943828e45ce861336e4b1b8b89e3598d95810bbcd0ee
|
|
| MD5 |
b21f3b5d83ed6ebf88207900a33830b6
|
|
| BLAKE2b-256 |
cdf0a8081796eeeddd5710b84ad2b3d47b572d8b891af890cf31358aed99dd4a
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 291.7 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c36b744a884a0f61945c5c80ca5a161a7c16e5478a6c610b2f741f15e469508e
|
|
| MD5 |
89dc6cbc73f6c0833eaba94e6de95956
|
|
| BLAKE2b-256 |
ece46794f4383d19ba08160af0c7ce8c80d2ea1b08b5d3258553eddde22926ad
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 315.8 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8f5708cc1b52966c905963a2b79e060f470e2a58071e8cef0f852331f52f808
|
|
| MD5 |
378a89143f98275e4686d50cfd5a1490
|
|
| BLAKE2b-256 |
052ff3c0438788505b79322f65c53299692304df9bb684b9fea935a6684a9362
|
File details
Details for the file pykyber-0.1.7-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl.
File metadata
- Download URL: pykyber-0.1.7-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 330.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f96ced4c36561e03c071383cc9625d33b82c59610e1762cf38f9f385c6e70388
|
|
| MD5 |
a1e641842178d02c10f839f1147b527d
|
|
| BLAKE2b-256 |
2fcb595e55fb41156f96479cfa3bc552d2729a5cc0bef2315e10540ec9979615
|