Python CFFI bindings for Kyber post-quantum cryptography
Project description
KyberCFFI
Python CFFI buildings for post-quantum cryptography algorithm Kyber
Description
KyberCFFI provides Python bindings for the reference implementation of the Kyber cryptographic algorithm, winner of the NIST post-quantum cryptography competition. The library uses CFFI to efficiently interact with the original Kyber C code.
Supported variants
- Kyber512 - Security level 1 (equivalent to AES-128)
- Kyber768 - Security level 3 (equivalent to AES-192)
- Kyber1024 - Security level 5 (equivalent to AES-256)
Installation
pip install kybercffi
Requirements
- Python >= 3.8
- CFFI >= 1.15.0
- C compiler
Quick start
import kybercffi
# Create a Kyber768 instance
kyber = kybercffi.Kyber768()
# Generate key pair
public_key, secret_key = kyber.generate_keypair()
# Encapsulation (create shared secret)
ciphertext, shared_secret = kyber.encapsulate(public_key)
# Decapsulation (recover shared secret)
recovered_secret = kyber.decapsulate(ciphertext, secret_key)
# Verification
assert shared_secret == recovered_secret
print("Kyber работает корректно!")
Convenient functions
from kybercffi import generate_keypair, encapsulate, decapsulate
# Generate keys with specified security level
pk, sk = generate_keypair(security_level=3) # Kyber768
# Encapsulation
ct, ss = encapsulate(pk, security_level=3)
# Decapsulation
ss2 = decapsulate(ct, sk, security_level=3)
Factory method
# Creating an instance via the factory
kyber512 = kybercffi.KyberKEM.create(security_level=1) # Kyber512
kyber768 = kybercffi.KyberKEM.create(security_level=3) # Kyber768
kyber1024 = kybercffi.KyberKEM.create(security_level=5) # Kyber1024
Information about variants
# Getting information about all variants
info = kybercffi.get_kyber_info()
print(info)
# Getting version information
version_info = kybercffi.get_version_info()
print(version_info)
Size of key and encrypted text
| Variant | Public key | Secret key | Ciphertext | Shared secret |
|---|---|---|---|---|
| Kyber512 | 800 bytes | 1632 bytes | 768 bytes | 32 bytes |
| Kyber768 | 1184 bytes | 2400 bytes | 1088 bytes | 32 bytes |
| Kyber1024 | 1568 bytes | 3168 bytes | 1568 bytes | 32 bytes |
Features
- ⚡ High performance - uses an optimized C implementation
- 🛡️ Post-quantum security - resistant to attacks from quantum computers
- 🌐 Cross-platform - works on Windows, Linux, macOS
- 📦 Easy installation - automatic compilation during installation
- 🔒 Cryptographically secure - based on the NIST reference implementation
License
The project is distributed under the MIT license. See the LICENSE file for details.
Author
Denis Magnitov
- Email: pm13.magnitov@gmail.com
- GitHub: Denis872
Links
Support
If you encounter any problems or have any questions, please:
- Check existing Issues
- Create a new Issue with a detailed description of the problem
- Specify the version of Python, OS, and kybercffi
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 Distribution
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 kybercffi-1.0.0.tar.gz.
File metadata
- Download URL: kybercffi-1.0.0.tar.gz
- Upload date:
- Size: 111.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce8539ec0bdb40efd32365ea4de63b80d8cb6ebf7a5b31d5c658dc93228619b8
|
|
| MD5 |
a920f85ee655da8cf5757994acc8c0e2
|
|
| BLAKE2b-256 |
6968101013ce162801332f077f8e9a278f8de8abfcf8a834b8a926d281fa6047
|
File details
Details for the file kybercffi-1.0.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: kybercffi-1.0.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 198.6 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bce9ceec647f02f20487a96f2baa82be3c47a7c9d4383c26e15f083c5dcbb02
|
|
| MD5 |
4c2b25a0ec551552849705f013329a03
|
|
| BLAKE2b-256 |
b7dcbcdbcc28e5c622d167af5cec262d28474382f4eb67f8dd6a9e36af4ebd48
|