Skip to main content

Quantum-safe cryptography utilities built on top of liboqs-python

Project description

qcrypto

Version: 0.5.0

qcrypto is a lightweight Python library that provides simple, Pythonic wrappers around post-quantum cryptography (PQC) using the official liboqs-python bindings from the Open Quantum Safe project.

The library exposes unified, minimal interfaces for:

  • Post-quantum key encapsulation (KEM)
  • Post-quantum digital signatures
  • A hybrid PQC + AES-GCM authenticated encryption scheme

qcrypto is suitable for learning PQC concepts, prototyping, research, and experimentation with quantum-safe primitives.


Features

Post-Quantum Key Encapsulation (KEM)

  • Kyber (Kyber512 / Kyber768 / Kyber1024)
  • Classic McEliece (all parameter sets exposed by liboqs)
  • Public/secret key generation
  • Encapsulation → shared secret + ciphertext
  • Decapsulation → recover the same shared secret

Digital Signatures

  • Dilithium (2, 3, 5)

  • Falcon (Falcon-512, Falcon-1024)

  • SPHINCS+ (SHA2 and SHAKE variants)

  • Unified signature interface:

    • SignatureScheme for any liboqs signature algorithm
    • Convenience wrappers: DilithiumSig, FalconSig, SphincsSig

Hybrid PQC + AES-256-GCM Encryption

  • Kyber encapsulates a shared secret
  • HKDF-SHA256 derives an AES key
  • AES-256-GCM encrypts the message
  • Compact single-blob ciphertext format:
[1 byte]  version  
[1 byte]  algorithm id  
[2 bytes] Kyber ciphertext length  
[N bytes] Kyber ciphertext  
[12 bytes] AES-GCM nonce  
[M bytes] AES-GCM ciphertext+tag

High-level API:

from qcrypto import encrypt, decrypt

Legacy API retained:

encrypt_for_recipient()
decrypt_from_sender()

Key Serialization

  • save_public_key(), save_private_key()
  • KyberKEM.load_public_key(), KyberKEM.load_private_key()
  • Raw or base64 encoding

Installation

Python 3.8+:

pip install qcrypto

liboqs-python installs automatically.


Examples

All examples are located in the examples/ directory:

  • kyber_example.py
  • files_example.py
  • mceliece_example.py
  • dilithium_example.py
  • falcon_example.py
  • sphincs_example.py
  • signature_scheme_generic_example.py
  • hybrid_example.py
  • list_algorithms.py

Run an example:

python examples/kyber_example.py

Implementation Notes

  • Uses liboqs-python, which bundles optimized C implementations of PQC algorithms.
  • AES-256-GCM provided by the cryptography package.
  • Available algorithms depend on how liboqs was compiled on your platform.
  • Hybrid encryption uses HKDF-SHA256 and fresh 96-bit GCM nonces.
  • Pure Python library using modern src/ layout.

Changelog

v0.5.0 — CLI Tooling & Passphrase-Protected Keys

New Features

• Added a full command-line interface (CLI) installed as qcrypto, providing: - qcrypto gen-key — Generate Kyber keypairs - qcrypto encrypt — Encrypt files using hybrid PQC + AES-GCM - qcrypto decrypt — Decrypt files back to plaintext

• Added passphrase-based encryption for private keys using PBKDF2-HMAC-SHA256 and AES-256-GCM. Private keys can now be saved securely:

  qcrypto gen-key --pass
  qcrypto decrypt --key private.key --pass

• CLI now supports interactive passphrase prompting or inline passphrase input.

• Integrated passphrase logic with existing key serialization mechanisms.

Other Improvements

• Added files_example.py demonstrating end-to-end CLI file encryption.

• Internal refactoring of key loading/saving functions to support encrypted and unencrypted key formats transparently.

• Updated README with CLI usage examples and passphrase workflows.


v0.4.0 — File Encryption & Streaming AES-GCM

New Features

• Added encrypt_file() and decrypt_file() for real file encryption workflows. • Introduced streaming AES-256-GCM, allowing encryption/decryption of large files without loading the entire file into memory. • File ciphertext format matches the existing encrypt() API for full compatibility.

Ciphertext Format

[1 byte]    version
[1 byte]    algorithm id
[2 bytes]   Kyber ciphertext length
[N bytes]   Kyber ciphertext
[12 bytes]  AES-GCM nonce
[M bytes]   AES-GCM ciphertext + 16-byte GCM tag

Other Improvements

• Added round-trip file encryption tests. • Updated __init__.py to expose file encryption helpers. • Internal refactoring to support chunked I/O while preserving the standardized hybrid ciphertext structure.


v0.3.0 — Expanded PQC Support

New Algorithms

  • Falcon signatures (FalconSig)
  • SPHINCS+ signatures (SphincsSig)
  • Classic McEliece KEM (ClassicMcElieceKEM)

Unified Signature Interface

  • Added SignatureScheme supporting any liboqs signature algorithm.

Examples

  • Added Falcon, SPHINCS+, McEliece, and generic signature examples.

Internal Improvements

  • Restructured signatures/KEMs for easier future expansion.

v0.2.0 — Hybrid API Rewrite, Ciphertext Format, Key Serialization

  • Added new high-level hybrid encrypt() and decrypt()
  • Introduced standardized single-blob ciphertext format
  • Added key serialization helpers
  • Improved decapsulation API
  • Legacy API preserved for compatibility

Disclaimer

This library is for educational, experimental, and research use. It has not undergone formal security review and should not be used in production systems.


License

MIT License.


Resources

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

qcrypto-0.5.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

qcrypto-0.5.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file qcrypto-0.5.0.tar.gz.

File metadata

  • Download URL: qcrypto-0.5.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for qcrypto-0.5.0.tar.gz
Algorithm Hash digest
SHA256 78ddc116a5ac4fb0fbe0c7b0f57e736c5076b74a8dc1f41262c9bef436bb418e
MD5 665ddb825ef3774013c83746641e8d76
BLAKE2b-256 c9f99b1e7524075ccaa6e739788e15ecab7ac013b79e8aef934530d622263ee1

See more details on using hashes here.

File details

Details for the file qcrypto-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: qcrypto-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for qcrypto-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bd4876d749e96828bf3fe34c8365923907878cff404c743e23f0bc1c0714e4b
MD5 51769da2ebf3577a1aaa40013128877a
BLAKE2b-256 eec7051f6ac1b6f8bb8bf34eda1c870ae1207f14dbf72b3282225cc0c6b0c9e2

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