Skip to main content

pqblocks-primitives

Production-ready integrated post-quantum cryptographic primitives (ML-KEM, ML-DSA, SLH-DSA, and hybrid schemes).

CI License Python 3.11+


Overview

pqblocks-primitives is a unified, high-performance post-quantum cryptography library providing FIPS 203, FIPS 204, and FIPS 205 compliant algorithms alongside hybrid classical/post-quantum mechanisms.

Built on top of liboqs and cryptography, pqblocks-primitives exposes a clean, pythonic API with strict input validation, deterministic sizing, and fail-safe error handling.

Standards Alignment

  • NIST FIPS 203: Module-Lattice-Based Key-Encapsulation Mechanism (ML-KEM-512, ML-KEM-768, ML-KEM-1024).
  • NIST FIPS 204: Module-Lattice-Based Digital Signature Standard (ML-DSA-44, ML-DSA-65, ML-DSA-87).
  • NIST FIPS 205: Stateless Hash-Based Digital Signature Standard (SLH-DSA-SHA2 variants).
  • Hybrid Key Exchange: ML-KEM + X25519 combined with HKDF (RFC 5869) using SHA-256 or SHA-384.

Installation

pip install pqblocks-primitives

Dependencies & Environment

Requires Python 3.11+, cryptography>=43.0.0, and liboqs-python>=0.16.0.
System liboqs shared library (liboqs.so.9 or later) should be discoverable via standard system library paths or specified via OQS_LIB_PATH:

export OQS_LIB_PATH=/path/to/liboqs.so.9
export LD_LIBRARY_PATH=/path/to/lib:$LD_LIBRARY_PATH

Quickstart

Key Encapsulation (ML-KEM)

from pqblocks_primitives import kem_keygen, kem_encaps, kem_decaps

# Generate ML-KEM-768 keypair
pk, sk = kem_keygen("768")

# Encapsulate shared secret
ct, shared_secret_sender = kem_encaps(pk, "768")

# Decapsulate shared secret
shared_secret_receiver = kem_decaps(sk, ct, "768")

assert shared_secret_sender == shared_secret_receiver

Digital Signatures (ML-DSA)

from pqblocks_primitives import dsa_keygen, dsa_sign, dsa_verify

# Generate ML-DSA-65 keypair
pk, sk = dsa_keygen("ML-DSA-65")

message = b"Quantum-safe transaction payload"
signature = dsa_sign(message, pk, sk, "ML-DSA-65")

# Verify signature
assert dsa_verify(message, signature, pk, "ML-DSA-65")

Hybrid Key Exchange (ML-KEM-768 + X25519)

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import x25519
from pqblocks_primitives import kem_keygen, hybrid_encaps, hybrid_decaps

# 1. Generate hybrid keypair
kem_pk, kem_sk = kem_keygen("768")
x_sk = x25519.X25519PrivateKey.generate()
x_pk = x_sk.public_key().public_bytes(serialization.Encoding.Raw, serialization.PublicFormat.Raw)
x_sk_bytes = x_sk.private_bytes(serialization.Encoding.Raw, serialization.PrivateFormat.Raw, serialization.NoEncryption())

hybrid_pk = kem_pk + x_pk
hybrid_sk = kem_sk + x_sk_bytes

# 2. Encapsulate
encap = hybrid_encaps(hybrid_pk, "768", kdf="HKDF-SHA256")
wire_ciphertext = encap.serialize()

# 3. Decapsulate
shared_secret = hybrid_decaps(hybrid_sk, wire_ciphertext, "768", kdf="HKDF-SHA256")
assert encap.shared_secret == shared_secret

Features

  • Standard Post-Quantum Primitives: Complete support for NIST standardized lattice-based and hash-based algorithms.
  • Fail-Secure Boundary Checks: Strict byte length validation (SizeMismatchError) on keys, ciphertexts, and signatures.
  • High Throughput: Over 37,000 ML-KEM-768 encapsulations/sec and 18,000 ML-DSA-65 verifications/sec on modern x86_64 CPUs.
  • ACVP Validated: 248 automated tests including regression tests against official NIST ACVP golden vectors.

Documentation


License

Apache-2.0. See LICENSE and NOTICE for details.

Metadata

Release files for pqblocks-primitives 0.1.0

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

Source distribution (sdist)

Source distribution for pqblocks-primitives 0.1.0
File Size Uploaded Provenance Actions
pqblocks_primitives-0.1.0.tar.gz 33.5 kB Without provenance Details for pqblocks_primitives-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pqblocks-primitives 0.1.0
File Interpreter ABI Platform Actions
pqblocks_primitives-0.1.0-py3-none-any.whl Python 3 none any Details for pqblocks_primitives-0.1.0-py3-none-any.whl

Total release size: 48.3 kB

Release files / pqblocks_primitives-0.1.0.tar.gz

Download URL pqblocks_primitives-0.1.0.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
09472feb3d88dadf191264a13ec1ebf2870ba7379a0d1f2cb11a8b526b0e8554
BLAKE2b-256 checksum
How to use checksums
32859aa483d6d3c613363bffecca4ad62d7c9528b2e7f21723841530af47dfd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pqblocks_primitives-0.1.0-py3-none-any.whl

Download URL pqblocks_primitives-0.1.0-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29e1102b60e28c97d40924abf7368baff2cb4f18a9977ecbd3baeb02fc7bd200
BLAKE2b-256 checksum
How to use checksums
c12283fe82f61a0235fc3a6a45669d30663e8c27c74d67bb27dad3e3162eb5b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for pqblocks-primitives 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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