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
# Encapsulate - create ciphertext and shared secret
result = keypair.encapsulate()
# result.ciphertext - bytes to send to receiver
# result.shared_secret - 32 bytes shared secret
# Decapsulate - recover shared secret from ciphertext
shared_secret = keypair.decapsulate(result.ciphertext)
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
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.5.tar.gz.
File metadata
- Download URL: pykyber-0.1.5.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
b099dc30fc8ca80a08f43e0ff29409194bd5704e522c2a2bd48975ffdffdcc46
|
|
| MD5 |
9806c030717cbd99e4b85b793dc7e275
|
|
| BLAKE2b-256 |
5c61e20c6b443d3fbec35ae7e689c4cc9350a44fea1fc3f6828e41ba7c4303fa
|
File details
Details for the file pykyber-0.1.5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pykyber-0.1.5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 315.7 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
1e7d9487dee2eba877c8b6cebe49cb2f6ea8e374333f067020016756cefb05b4
|
|
| MD5 |
2e1a85378b0d1ac9315dc9f133b1f75d
|
|
| BLAKE2b-256 |
912bea828acb21d37e9f3127225f6515d295f2acaefe435b6ea862bbad3fbcc7
|
File details
Details for the file pykyber-0.1.5-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl.
File metadata
- Download URL: pykyber-0.1.5-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 329.8 kB
- Tags: PyPy, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
9e7b0f544b8b1cd175843024245eab0c4789166230c06ca3f4bdd51a4ab525b6
|
|
| MD5 |
dc7982ae3eb354e9e90f88c4834945ab
|
|
| BLAKE2b-256 |
ab95c0918633a9f9f62422b1c2a7290b333ecf20f0a70188bdfa7a0ae8d392d5
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-win_arm64.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-win_arm64.whl
- Upload date:
- Size: 161.5 kB
- Tags: CPython 3.8+, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
4b9131b7e8b5e9402ed5354f20cb9aa3b7b7b63af9563034d1a305ae49552006
|
|
| MD5 |
ef9461dca1e4e88cf0a17097bb269ace
|
|
| BLAKE2b-256 |
c95946d4a244a2e89933123cbd2cb452e6a33a2a081443bfe323521f2f7a6ffd
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 174.5 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
c20cc1f34dfe17a5ecd95290af1e6f67a6b11a4ebda76636f91d5b2cfbe95553
|
|
| MD5 |
5c59865dfa4a31495a4e90ccf450c36e
|
|
| BLAKE2b-256 |
4a6c5d6b993b170bfd82743a6f08e906c142372d63e61ca055e3363de87b5c3b
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-win32.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-win32.whl
- Upload date:
- Size: 159.9 kB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
9db2a9c515295c90245cf23f2193b36faefb1e1beb94bf37af7aec9d90864fb0
|
|
| MD5 |
7a9ce0af775084885de6912be9c1576a
|
|
| BLAKE2b-256 |
dcc96cc97c26c46453311f057fd3208410e60b99b6304fe5fed27cc4688b7acc
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 517.7 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
5cba981295c64acba033aeca2e456aa53e9ffab4a75d477becaaf1d65d91af14
|
|
| MD5 |
faf24e00003094d93cedc5abcff6a705
|
|
| BLAKE2b-256 |
970d3f97eae38a17c14502fd5eff5d1c0cde527da385f1d5712db7366ffd8cea
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-musllinux_1_2_i686.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-musllinux_1_2_i686.whl
- Upload date:
- Size: 544.9 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
d0f791a752dba1b51b2b8c63d79c8ac470f31ac2ef9ed5fca5b6f696e21be3c4
|
|
| MD5 |
552c494ee7c589ddce07c012117b412f
|
|
| BLAKE2b-256 |
3cf77982a680483605a673f1228c17d648def0d6b0d2484aee4a88186d127b41
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-musllinux_1_2_armv7l.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-musllinux_1_2_armv7l.whl
- Upload date:
- Size: 565.9 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
a2c4aa0b464d8ef7c8e8fcc6b312e8aecdd129774ee32a821982933be83091f1
|
|
| MD5 |
0a112642f3313785eddac8cd7ab8fede
|
|
| BLAKE2b-256 |
44fbb222168e4aeb60a5e03e72f6b1199fa75ca07b802289798c6fa4524c3555
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 490.8 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
be2b0d29559fa299f171acd848a5f1f33cf28141b692e2cadda0f793dc3af83d
|
|
| MD5 |
c0e14447764335cc4520c6263269ea04
|
|
| BLAKE2b-256 |
8b3f99ffcc73ed6c839ccec3e6237533d8054ed05dd472b42511d9ba80f28bb9
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 315.8 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
74a11c3fe343c4b158831c17ca8a15c6ae8a32c3eb12868613c536576f9e335f
|
|
| MD5 |
3300d1e6af76a03000681c4974b7c1a6
|
|
| BLAKE2b-256 |
85a5ecdf5cd8480854e667ea0a610e098c5dd7c944c2eccc53e604b4424729d9
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 308.6 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
cd76a18457b4c36e20724bc3fd6198a41db786c233cd2d1cf29d80284342eb77
|
|
| MD5 |
2078ff22fb7400ff7c185ebe3548ec7a
|
|
| BLAKE2b-256 |
13444a3afd6f975e51cca82248a027aab2c557d74b66d135264f2205e7ee9b6d
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
- Upload date:
- Size: 470.0 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
96a281c809e11925d33219b87240df9b7a512b20706c9c0c81623442f50d3af2
|
|
| MD5 |
6755907749137930c845e8fa4c2fdb70
|
|
| BLAKE2b-256 |
5dec1650e6ba6cb22daffaa0abccd8a0c217e18c9a0b1e18196689e122e3e699
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 290.9 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
a84118dafad6a4ea163d47bb27ad82c89f03e1f44662db4fdd5af8373729a00c
|
|
| MD5 |
93c0cfb39461d413ab1375d42648e99b
|
|
| BLAKE2b-256 |
33ad406fcd6e69555899e6533151418ca358b6a82b0ec91712f9ae6dc6197cdd
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 315.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
6a19c3e3f9bfb9f09ec4b3f4a95b0db810c18d2edfb3246b85789cd87c193c9f
|
|
| MD5 |
f0045b9b6f8be98a1f31b3aad934a5e9
|
|
| BLAKE2b-256 |
5be79e334d2faf2f7919ca214ba77909b3820a75d7be240443ed8d56f41f4793
|
File details
Details for the file pykyber-0.1.5-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl.
File metadata
- Download URL: pykyber-0.1.5-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 329.7 kB
- Tags: CPython 3.8+, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 |
afbb04aaa0de70aae0d1edba716390d9783f1235a8137460f05bb891a4da4c0c
|
|
| MD5 |
e6c430e26be1145d0c5d909410124b5e
|
|
| BLAKE2b-256 |
598a8eef1b2231784e2227c63cc63f76bde6c6b11368c81d3de95f846e0445de
|