Skip to main content

QuantumGuard

CI Coverage

High-level post-quantum hybrid encryption library for Python. Uses ML-KEM (Kyber768, NIST FIPS 203) for key encapsulation and AES-256-GCM for symmetric encryption, with a simple API similar to cryptography.fernet.

Requirements

  • Compatibility: Python 3.9+
  • pypqc (PQClean bindings, Kyber768)
  • cryptography (AES-GCM)

Installation

pip install quantumguard

Quick Start

from quantumguard import QuantumGuard

# Generate key pair
public_key, private_key = QuantumGuard.generate_keypair()

# Encrypt with public key
qg = QuantumGuard(public_key)
ciphertext = qg.encrypt("Post-quantum secret message")

# Decrypt with private key
qg_private = QuantumGuard(private_key)
decrypted_text = qg_private.decrypt(ciphertext)  # bytes
print(decrypted_text.decode("utf-8"))

Key Persistence (PEM / Base64)

Keys can be exported and imported in PEM or Base64 for storage in .key files:

# Export to PEM
pem_private = QuantumGuard.key_to_pem(private_key, "private")
pem_public = QuantumGuard.key_to_pem(public_key, "public")

# Save to file
with open("private.key", "w") as f:
    f.write(pem_private)

# Load from PEM
with open("private.key") as f:
    key_bytes, kind = QuantumGuard.key_from_pem(f.read())
qg = QuantumGuard(key_bytes)  # or pass the PEM string directly: QuantumGuard(f.read())

Base64 with optional type prefix (qg.pub. / qg.priv.) is also supported via key_to_base64 and key_from_base64.

Serialization Format

  • Binary (default): Magic + version, KEM ciphertext length, KEM ciphertext, 12-byte nonce, 16-byte tag, AES ciphertext. Compact and deterministic.
  • JSON: Optional output_format="json" in encrypt() for debugging or interoperability. Payload is UTF-8 JSON with base64-encoded fields (v, k, n, t, c).

Decryption accepts both formats automatically.

API Summary

  • QuantumGuard(key) — Initialize with public or private key (bytes, PEM, or Base64).
  • generate_keypair() — Returns (public_key, private_key) as bytes.
  • encrypt(plaintext, output_format="binary"|"json") — Encrypt; returns serialized bytes.
  • decrypt(ciphertext) — Decrypt; returns plaintext bytes.
  • cleanup() — Wipe key material; do not use the instance afterward.
  • key_to_pem(key, kind), key_from_pem(pem) — PEM export/import.
  • key_to_base64(key, kind), key_from_base64(b64) — Base64 export/import.
  • secure_wipe(buffer) — Zero a bytearray (best-effort).
  • SecureBytes(length) — Context manager or .burn() for short-lived secrets.
  • __version__ (package version string), NONCE_BYTES, TAG_BYTES, MAX_KEM_CT_BYTES (max KEM ciphertext length), VERSION (serialization format version, integer), RECOMMENDED_MAX_PLAINTEXT_BYTES (recommended max plaintext size for apps to enforce; library does not enforce it) — constants for integrations.

See docstrings for full details. For a generated API Reference, build the Sphinx docs (see Contributing); output is in docs/build/html/.

Security Notes

  • Message size: The library does not impose a maximum plaintext length. Applications should enforce a maximum plaintext size per message (e.g. 1 MiB; see RECOMMENDED_MAX_PLAINTEXT_BYTES) to mitigate DoS from excessively large payloads. Practical limits are also system memory and the AES-GCM specification; use streaming or chunking for very large data if needed.
  • AAD (Additional Authenticated Data): AAD is not used in this API. For binding ciphertext to context (e.g. session id, nonce), applications must enforce that at a higher layer.
  • Memory: Sensitive key material is held in a bytearray and can be wiped with qg.cleanup(). Do not use the instance for encrypt() or decrypt() after calling cleanup(); those methods will raise InvalidKeyError. Python does not guarantee that copies do not exist (e.g. interpreter or C extensions). For custom buffers use secure_wipe(); for short-lived secrets consider SecureBytes (context manager or .burn()).
  • Dependencies: Requires pypqc >= 0.0.6.1 (KyberSlash fix). Do not use older versions.
  • Algorithms: ML-KEM-768 (FIPS 203) for KEM; AES-256-GCM for encryption.

References

License

MIT

Metadata

Release files for quantumguard 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantumguard 0.1.1
File Size Uploaded
quantumguard-0.1.1.tar.gz 20.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quantumguard 0.1.1
File Interpreter ABI Platform
quantumguard-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 35.7 kB

Release files / quantumguard-0.1.1.tar.gz

Download URL quantumguard-0.1.1.tar.gz
Size 20.4 kB
Tags Source
SHA-256 checksum
How to use checksums
830e28393d78c510a7413354769f79ee26a7861d971017bdc529c02ed40ba44b
BLAKE2b-256 checksum
How to use checksums
10eba78b1e93755214a21c903fdd8297b8aff1119eceef2128191d6144ca7bd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release files / quantumguard-0.1.1-py3-none-any.whl

Download URL quantumguard-0.1.1-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50d2b779bea1940b59ace076961f20d693cfa52084940fe3bb53eb4c51a2eb57
BLAKE2b-256 checksum
How to use checksums
581284c816e7efe598b4f52dcc3051afefe27f7bffead1515d2382130dfc7671
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page