Skip to main content

Python CFFI bindings for Kyber post-quantum cryptography

Project description

KyberCFFI

Python CFFI buildings for post-quantum cryptography algorithm Kyber

Python Version License PyPI

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

Links

Support

If you encounter any problems or have any questions, please:

  1. Check existing Issues
  2. Create a new Issue with a detailed description of the problem
  3. Specify the version of Python, OS, and kybercffi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kybercffi-1.0.1.tar.gz (111.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kybercffi-1.0.1-cp310-cp310-win_amd64.whl (198.7 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file kybercffi-1.0.1.tar.gz.

File metadata

  • Download URL: kybercffi-1.0.1.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

Hashes for kybercffi-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b9f15c6c035bd4242c8b86bbe995bda17758dd1dede9e50bd1b92a2273555663
MD5 c90ac80507594f5ce4a81397b22392f7
BLAKE2b-256 888e5cdb66f59a611118078b7e22583eccd3ef504eda7a3d8e9904b4aa7de765

See more details on using hashes here.

File details

Details for the file kybercffi-1.0.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: kybercffi-1.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 198.7 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

Hashes for kybercffi-1.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e6e087fafedf6e87c041cba1450bfb8ca4937c360d7a98251995a69ed9ad6a53
MD5 cc4b77737d605eb35c494cffb2bf0b6e
BLAKE2b-256 30d245ed2ce0204306202a6f22c2bb5bd857f185bae7a39e14bfee6b16af0e13

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page