pqblocks-qse-sdk
Post-quantum cryptography SDK for ML-KEM, ML-DSA, and SLH-DSA (FIPS 203/204/205)
Part of the PQBlocks suite of post-quantum cryptography tools and high-assurance protocol adapters. Maintained by The PQBlocks Authors under the Apache-2.0 license.
Why PQBlocks / pqblocks-qse-sdk
Post-quantum algorithm migration requires rock-solid correctness, constant-time guarantees, and zero tolerance for malformed input regressions. Standard legacy cryptographic stacks cannot handle the larger key sizes, structured lattice matrices, or algebraic parameter sets mandated by modern NIST standards (FIPS 203 / ML-KEM, FIPS 204 / ML-DSA, FIPS 205 / SLH-DSA).
pqblocks-qse-sdk addresses this by providing:
- Deterministic Execution: Strict validation bounds prevent buffer overruns and malformed wire structures.
- Standard Alignment: Built specifically to satisfy the strict requirements of FIPS 203 (ML-KEM), FIPS 204 (ML-DSA), and FIPS 205 (SLH-DSA).
- Zero-Overhead Integration: Drop-in compatibility designed for modern backend, serverless, and embedded systems.
- Verified Correctness: Covered by official NIST ACVP test vectors, automated fuzzing, and regression suites.
Architecture
The system operates across three distinct structural tiers: input isolation, cryptographic core processing, and serialized output verification.
┌────────────────────────────────────────────────────────┐
│ Consumer / Application Layer │
└───────────────────────────┬────────────────────────────┘
│ (Request / Data Input)
▼
┌────────────────────────────────────────────────────────┐
│ Input Normalization & Bounds Check │
│ ┌───────────────────────┐ ┌──────────────────────┐ │
│ │ Memory Range Asserts │ │ Strict Type Enforcer │ │
│ └───────────────────────┘ └──────────────────────┘ │
└───────────────────────────┬────────────────────────────┘
│ (Validated Parameters)
▼
┌────────────────────────────────────────────────────────┐
│ Core Processing & Transform Engine │
│ ┌──────────────────────────────────────────────────┐ │
│ │ High-Assurance Computational Core │ │
│ │ (Constant-Time Operations, Zero-Allocation Buff) │ │
│ └──────────────────────────────────────────────────┘ │
└───────────────────────────┬────────────────────────────┘
│ (Verified Output Payload)
▼
┌────────────────────────────────────────────────────────┐
│ Output & Serialization Layer │
└────────────────────────────────────────────────────────┘
The isolation boundaries ensure sensitive cryptographic buffers are tightly scoped and cleaned immediately upon execution completion.
Installation
Install the release package from PyPI or via direct Git reference:
pip install pqblocks-qse-sdk
Or install directly from the source repository:
pip install git+https://github.com/PQBlocks/pqblock-qse-sdk
System Requirements
- Python >= 3.11
- Operating System: Linux (x86_64, aarch64), macOS (Apple Silicon / Intel), or Windows
Usage
Quickstart
from pqblocks_qse_sdk import keypair, encapsulate, decapsulate, sign, verify
# Key encapsulation (ML-KEM-768)
pk, sk = keypair("ml-kem-768")
ct, ss_sender = encapsulate(pk, "ml-kem-768")
ss_receiver = decapsulate(sk, ct, "ml-kem-768")
assert ss_sender == ss_receiver
# Digital signature (ML-DSA-65)
pk_sig, sk_sig = keypair("ml-dsa-65")
sig = sign(sk_sig, b"sample payload", "ml-dsa-65")
valid = verify(pk_sig, sig, b"sample payload", "ml-dsa-65")
assert valid is True
print("Verified output:", valid)
CLI Interface
Run directly from the terminal:
python -m pqblocks_qse_sdk --help
API Reference
The public interface provides unified, high-level façades for post-quantum key encapsulation, digital signatures, deterministic test vector generation, and AST migration auditing.
1. Key Encapsulation Mechanism (FIPS 203 ML-KEM)
Unified KEM operations supporting ml-kem-512, ml-kem-768, and ml-kem-1024.
| Function | Parameters | Returns | Description |
|---|---|---|---|
keypair(algorithm) |
algorithm: str |
Tuple[bytes, bytes] |
Generate public encapsulation key and secret decapsulation key pair using system CSPRNG (os.urandom). |
encapsulate(pk, algorithm) |
pk: bytes, algorithm: str |
Tuple[bytes, bytes] |
Encapsulate a freshly generated 32-byte shared secret against recipient public key pk. Returns (ciphertext, shared_secret). |
decapsulate(sk, ct, algorithm) |
sk: bytes, ct: bytes, algorithm: str |
bytes |
Decapsulate shared secret from ct using secret key sk. Enforces FIPS 203 implicit rejection on invalid ciphertexts without leaking timing information. |
from pqblocks_qse_sdk import keypair, encapsulate, decapsulate
pk, sk = keypair("ml-kem-768")
ct, ss_sender = encapsulate(pk, "ml-kem-768")
ss_receiver = decapsulate(sk, ct, "ml-kem-768")
assert ss_sender == ss_receiver
2. Digital Signatures (FIPS 204 ML-DSA & FIPS 205 SLH-DSA)
Unified digital signature operations supporting ML-DSA (ml-dsa-44, ml-dsa-65, ml-dsa-87) and SLH-DSA parameter sets.
| Function | Parameters | Returns | Description |
|---|---|---|---|
keypair(algorithm) |
algorithm: str |
Tuple[bytes, bytes] |
Generate public verification key and private signing key pair using system CSPRNG (os.urandom). |
sign(sk, message, algorithm) |
sk: bytes, message: bytes, algorithm: str |
bytes |
Generate a post-quantum digital signature for message using private signing key sk. |
verify(pk, signature, message, algorithm) |
pk: bytes, signature: bytes, message: bytes, algorithm: str |
bool |
Verify digital signature against message using verification key pk. Returns False on invalid signature or mismatched length without throwing exceptions. |
from pqblocks_qse_sdk import keypair, sign, verify
pk, sk = keypair("ml-dsa-65")
sig = sign(sk, b"Secure transmission payload", "ml-dsa-65")
is_valid = verify(pk, sig, b"Secure transmission payload", "ml-dsa-65")
assert is_valid is True
3. Parameter Sizes & Length Validation
Direct access to NIST FIPS parameter dimensions and validation guards.
| Function | Parameters | Returns | Description |
|---|---|---|---|
get_size(algorithm, field) |
algorithm: str, field: str |
int |
Query canonical size in bytes for pk_len, sk_len, ct_len, ss_len, or sig_len. |
validate_keymaterial_length(alg, name, val, expected) |
alg: str, name: str, val: bytes, expected: int |
None |
Validate that key material buffer matches expected FIPS byte length; raises ValueError on mismatch. |
validate_sig_length(alg, sig, expected) |
alg: str, sig: bytes, expected: int |
None |
Validate signature byte length against standard table for specified algorithm. |
4. Deterministic Corpus & PRNG Engine
Reproducible multi-algorithm test vector generation using 64-bit SplitMix PRNG and SHA-256 derivation.
| Symbol | Kind | Parameters / Signature | Description |
|---|---|---|---|
SplitMix64(seed) |
Class | seed: int |
Fast 64-bit pseudo-random number generator with 64-bit state and modulo $2^{64}$ wrapping arithmetic. |
.next_u64() |
Method | () -> int |
Advance internal state and return next pseudo-random unsigned 64-bit integer. |
.next_u32() |
Method | () -> int |
Advance internal state and return next pseudo-random unsigned 32-bit integer. |
.to_bytes(length) |
Method | (length: int) -> bytes |
Generate byte sequence of specified length from successive 64-bit little-endian words. |
SplitMix64_from_seed(seed) |
Function | seed: bytes -> SplitMix64 |
Initialize a SplitMix64 instance from a 32-byte cryptographic seed. |
SplitMix64_from_i(master_seed, i) |
Function | master_seed: bytes, i: int -> SplitMix64 |
Derive $i$-th PRNG stream from master_seed using SHA-256 expansion. |
derive_seed(master_seed, i) |
Function | master_seed: bytes, i: int -> bytes |
Compute deterministic 32-byte seed: `SHA-256(master_seed |
corpus_generate(output_dir, count, master_seed) |
Function | output_dir: str, count: int = 100, master_seed: Optional[bytes] = None |
Write deterministic cross-language vector corpus into structured directory hierarchy. |
5. Static Analysis & Migration Guard
AST-based code scanner detecting deprecated classical cryptography implementations.
| Symbol | Kind | Parameters / Signature | Description |
|---|---|---|---|
harden_check_unsafe_api(target) |
Function | target: Union[str, Any] -> Dict[str, Any] |
Scan Python file, directory tree, or module object for deprecated classical RSA/ECC cryptography imports. |
UnsafeAPIDetector |
Class | ast.NodeVisitor |
AST visitor class that flags legacy import rsa, import ec, and cryptography.hazmat.primitives.asymmetric imports. |
from pqblocks_qse_sdk import harden_check_unsafe_api
report = harden_check_unsafe_api("./my_service")
print(f"Detected {report["count"]} legacy cryptographic references:")
for finding in report["findings"]:
print(f" {finding["file"]}:{finding["line"]} - {finding["pattern"]} ({finding["severity"]})")
6. Exception Classes
Structured exception hierarchy for cryptographic operations.
| Exception Class | Base Class | Description |
|---|---|---|
QSEKemError |
Exception |
Raised when an invalid KEM algorithm or malformed parameter is provided. |
QSESignError |
Exception |
Raised when an invalid signature algorithm or malformed secret key is provided. |
7. CLI Command-Line Interface
| Function | Parameters | Returns | Description |
|---|---|---|---|
main(argv=None) |
argv: Optional[List[str]] = None |
int |
CLI entry point supporting --help, status reporting, and deterministic corpus generation. |
Limitations
- Hardware Acceleration: Native vector extensions (AVX-512 / ARM Neon) are leveraged where available, but pure fallback implementations are bound by runtime interpreter performance.
- Algorithm Constraints: Only standardized parameter sets are supported. Non-standardized variations are explicitly rejected to prevent security interoperability failures.
- Memory Boundaries: Maximum contiguous input buffers are restricted to prevent denial-of-service memory exhaustion.
Security Notes
Security is designed into the component invariants:
- Constant-Time Operations: Critical primitive routines avoid secret-dependent branching or memory address lookups to mitigate side-channel leakage.
- Implicit Rejection: FIPS 203 KEM decapsulation returns a deterministic pseudo-random shared secret upon receiving an invalid ciphertext, mitigating adaptive chosen-ciphertext attacks.
- Zeroization: Sensitive memory structures, ephemeral buffers, and intermediate states are wiped immediately after use.
- Entropy & Randomness: Production key generation requires system cryptographically secure pseudorandom number generators (
os.urandom). - Vulnerability Reporting: Report suspected security issues through GitHub Security Advisories, open a security issue on GitHub, or contact the author / maintainers directly.
- Validation Statement: This package is verified against official NIST ACVP and Project Wycheproof vectors; it is not itself FIPS 140-3 / CMVP validated.
Verification
Every release is continuously verified using rigorous test harnesses:
- Official Vectors: Known Answer Tests (KAT) verified against official published test corpuses.
- Automated Fuzzing: Continuous mutation fuzzing validating robustness against malformed payloads.
- Audit: Automated static analysis, type checking, and leak gates confirm clean boundaries.
Detailed reports are documented in:
- TESTING.md — Comprehensive test execution and coverage details.
- VERIFICATION_REPORT.md — Exact verification methodology and evidence.
- BENCHMARKS.md — Latency, throughput, and memory consumption metrics.
- SECURITY_NOTES.md — Threat model and defensive posture.
Part of PQBlocks
pqblocks-qse-sdk is an integral part of the PQBlocks ecosystem, an open-source initiative providing production-ready,
verified post-quantum cryptographic primitives, containers, and migration tools.
- GitHub: https://github.com/PQBlocks
- License: Apache License, Version 2.0. See LICENSE for details.
- Copyright: (c) 2026 The PQBlocks Authors.
Metadata
Release files for pqblocks-qse-sdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pqblocks_qse_sdk-0.1.0.tar.gz | 47.7 kB | Without provenance | Details for pqblocks_qse_sdk-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pqblocks_qse_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pqblocks_qse_sdk-0.1.0-py3-none-any.whl |
Total release size: 72.4 kB
Release files / pqblocks_qse_sdk-0.1.0.tar.gz
| Download URL | pqblocks_qse_sdk-0.1.0.tar.gz |
|---|---|
| Size | 47.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
afe50e2b81866616933ff1e70f50851093774d09d6587bcd1638bd6918425ac0
|
|
BLAKE2b-256 checksum How to use checksums |
52e55072c785b6647e35efe952b0844430ba613b257a37de9bd1d25e9d90b2e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Garuda Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pqblocks_qse_sdk-0.1.0-py3-none-any.whl
| Download URL | pqblocks_qse_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 24.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6f5b7555b14e2cde2b7fb80f2f9ea8a49ec6ea6d8c5714782d9a13d6ff4bff0
|
|
BLAKE2b-256 checksum How to use checksums |
47b581dab8b202260f65634fb21a10506f88d66a68964512980bd0e4fb970741
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Garuda Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for pqblocks-qse-sdk 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.