PQC Binary Format
A standardized, self-describing binary format for post-quantum cryptography encrypted data interchange.
๐ The Problem
Post-quantum cryptography (PQC) implementations suffer from the "Babel Tower problem": different implementations cannot interoperate because there is no standardized format for encrypted data. Each library uses its own proprietary format, making cross-platform and cross-language encryption impossible.
๐ก The Solution
PQC Binary Format provides a universal, algorithm-agnostic format that:
- โ Works across 51 cryptographic algorithms
- โ Self-describing metadata enables seamless decryption
- โ Integrity verification with SHA-256 checksums
- โ Cross-platform compatible (Rust, Python, JavaScript, Go, etc.)
- โ Future-proof design allows algorithm migration
- โ Minimal dependencies: serde, serde_json, sha2, base64
๐ Quick Start
Rust
Add to your Cargo.toml:
[]
= "3"
Basic Usage (Rust)
use ;
use HashMap;
// Create metadata with encryption parameters
let metadata = PqcMetadata ;
// Create encrypted data container
let encrypted_data = vec!; // Your encrypted bytes
let format = new;
// Serialize to bytes (for transmission or storage)
let bytes = format.to_bytes.unwrap;
// Deserialize from bytes (includes automatic checksum verification)
let recovered = from_bytes.unwrap;
assert_eq!;
println!;
Python
Install the Python bindings:
# Create algorithm and metadata
=
=
=
# Create and serialize format
=
=
# Deserialize and verify
=
# Verify checksum integrity
JavaScript/TypeScript
Build the WebAssembly bindings:
import init from './pqc_binary_format.js';
await ;
const algorithm = ;
const encParams = ;
const metadata = ;
const pqcFormat = ;
const serialized = pqcFormat.;
const deserialized = ;
console.log;
Go
Build the Rust library first, then use the Go bindings:
package main
import (
"fmt"
"log"
pqc "github.com/PQCrypta/pqc-binary-format/bindings/go/v3"
)
func main()
C/C++
Build the Rust library and generate the C header:
int
๐ Language Bindings
PQC Binary Format provides production-ready, fully tested bindings for multiple programming languages. All bindings support the complete API and produce cross-compatible binary formats.
Available Bindings
| Language | Status | Package | Documentation | Examples |
|---|---|---|---|---|
| Rust | โ Native | pqc-binary-format |
docs.rs | 3 examples |
| Python | โ Tested | pqc_binary_format |
Python README | 2 examples |
| JavaScript/WASM | โ Tested | pqc-binary-format (npm) |
JS README | 1 example |
| Go | โ Tested | github.com/PQCrypta/pqc-binary-format/bindings/go/v3 |
pkg.go.dev | 1 example |
| C | โ Tested | FFI via Rust | C/C++ README | 1 example |
| C++ | โ Tested | FFI via Rust | C/C++ README | 1 example |
Installation Quick Reference
# Rust
# Python
# JavaScript/WASM
# Go
# C/C++ (build from source)
# Link against target/release/libpqc_binary_format.so
Cross-Language Compatibility
All language bindings are fully interoperable! You can:
- โ Encrypt data in Python, decrypt in Rust
- โ Serialize in Go, deserialize in JavaScript
- โ Create format in C++, validate in Python
- โ Mix any combination across platforms
Example workflow:
# Create encrypted data with Python
# Verify with C++
LD_LIBRARY_PATH=target/release
# Process with Go
&&
Binding Features
All bindings support:
- โ Full algorithm suite (51 algorithms)
- โ Metadata serialization/deserialization
- โ SHA-256 integrity verification
- โ Feature flags (compression, streaming, etc.)
- โ Error handling with detailed messages
- โ Memory safety (Rust-backed)
Package Distribution Status
| Platform | Status | Notes |
|---|---|---|
| crates.io (Rust) | โ Published | |
| PyPI (Python) | โ Published | |
| npm (JavaScript) | โ Published | |
| Go module proxy | โ Published from 3.0.0 |
๐ฆ Binary Format Specification
All multi-byte integers are little-endian; the metadata section is a
UTF-8 JSON object. Fields appear in this exact order (see
draft-riddel-pqc-binary-format-00, Section 3):
+-------------------+
| Magic (4 bytes) | "PQC\x01" - Format identifier
+-------------------+
| Version (1 byte) | 0x01 - Format version
+-------------------+
| Algorithm (2 bytes)| Algorithm identifier (0x0050 - 0x0905), little-endian
+-------------------+
| Flags (1 byte) | Feature flags (reserved, 0x00 in v1)
+-------------------+
| Metadata Len (4) | Length of metadata section, little-endian
+-------------------+
| Metadata (var) | Algorithm-specific parameters (UTF-8 JSON)
+-------------------+
| Data Len (8) | Length of encrypted payload, little-endian
+-------------------+
| Data (var) | Encrypted data
+-------------------+
| Checksum (32) | SHA-256 over all preceding bytes
+-------------------+
Fixed-header size (excluding the variable metadata/data sections) is 52 bytes.
The checksum is SHA-256(magic โ version โ algorithm_id โ flags โ metadata_len โ metadata โ data_len โ data); because the JSON metadata is emitted with sorted
keys it is deterministic across implementations.
๐ Supported Algorithms
The format supports 51 cryptographic algorithm identifiers, the registry in src/algorithm.rs (Algorithm::ALL); tests/registry.rs holds this list to it:
Classical Algorithms (0x0050-0x00FF)
- Classical (0x0050): Classical cryptography: X25519 + Ed25519 + AES-256-GCM
- Password Classical (0x0051): Password-based classical encryption
Hybrid Algorithms (0x0100-0x01FF)
- Hybrid (0x0100): Hybrid: ML-KEM-1024 + X25519 + ML-DSA-87 + Ed25519 + AES-256-GCM
Post-Quantum Algorithms (0x0200-0x02FF)
- Post-Quantum (0x0200): Post-quantum: ML-KEM-1024 + ML-DSA-87 + AES-256-GCM
- Multi-Algorithm (0x0201): Multi-algorithm runtime selection
- ML-KEM-1024 (0x0202): ML-KEM-1024 with AES-256-GCM
- Multi-KEM Dual Layer (0x0203): Multi-KEM dual layer
- Multi-KEM Triple Layer (0x0204): Multi-KEM triple layer
- Quad-Layer (0x0205): Quad-layer redundant security
- Lattice-Code Hybrid (0x0206): Lattice-Code hybrid stack
- PQ3-Stack (0x0207): PQ3-Stack with forward secrecy
- X25519MLKEM768 (0x0208): X-Wing hybrid KEM: ML-KEM-768 (FIPS 203) combined with X25519, the pair TLS negotiates as X25519MLKEM768
- FrodoKEM-1344 (0x0209): FrodoKEM-1344: unstructured-lattice KEM, NIST level 5 (ISO/IEC 18033-2)
- Classic-McEliece-6960119 (0x020A): Classic McEliece 6960119: code-based KEM (ISO/IEC 18033-2)
- FrodoKEM-976 (0x020B): FrodoKEM-976: unstructured-lattice KEM, NIST level 3
Max Secure Series (0x0300-0x03FF)
- Max Secure: PQ Lightweight (0x0300): Max Secure: PQ Lightweight
- Max Secure: Pure PQ (0x0301): Max Secure: Pure PQ
- Max Secure: Hybrid (0x0302): Max Secure: Hybrid Transition
- Max Secure: Stateless (0x0303): Max Secure: Stateless
- Max Secure: Crypto-Agile (0x0304): Max Secure: Crypto-Agile
- Max Secure: PQC + ZK (0x0305): Max Secure: PQC + Zero-Knowledge
- Max Secure: Hybrid Transition (0x0306): Max Secure: Hybrid Transition
FN-DSA Series, Falcon-based (0x0400-0x04FF)
- FN-DSA 512: Compact (0x0400): FN-DSA 512: Compact
- FN-DSA 1024: High-Security (0x0401): FN-DSA 1024: High-Security
- FN-DSA: Floating-Point Hardened (0x0402): FN-DSA: Floating-Point Hardened
- FN-DSA: Dual Signature (0x0403): FN-DSA: Dual Signature
- FN-DSA: Transition Stack (0x0404): FN-DSA: Transition Stack
- FN-DSA + ZK Stack (0x0405): FN-DSA + Zero-Knowledge Stack
- FN-DSA + ZK Stack Enhanced (0x0406): FN-DSA + ZK Stack Enhanced
- FN-DSA: Transition Stack Enhanced (0x0407): FN-DSA: Transition Stack Enhanced
Experimental (0x0500-0x05FF)
- Quantum-Inspired Lattice Fusion (0x0500): Quantum-Inspired Lattice Fusion
- Post-ZK Homomorphic (0x0501): Post-ZK Homomorphic with LFHE 2023
- Quantum-Resistant Consensus (0x0502): Quantum-Resistant Consensus
- Entropy-Orchestrated (0x0503): Entropy-Orchestrated PQ Stack
- Lattice-Code Hybrid FN (0x0504): Lattice-Code Hybrid FN
- AI-Synthesized Crypto-Agile (0x0505): AI-Synthesized Crypto-Agile
- Experimental Engine (0x0506): Experimental Engine (generic)
HQC Code-Based Series, NIST 2025 Backup KEM (0x0600-0x06FF)
- HQC-128 (0x0600): HQC-128 (NIST Level 1, 128-bit security)
- HQC-192 (0x0601): HQC-192 (NIST Level 3, 192-bit security)
- HQC-256 (0x0602): HQC-256 (NIST Level 5, 256-bit security)
NIST ML-KEM Variants - FIPS 203 (0x0700-0x07FF)
- ML-KEM-512 (0x0700): ML-KEM-512 (NIST Level 1, 128-bit security)
- ML-KEM-768 (0x0701): ML-KEM-768 (NIST Level 3, 192-bit security)
NIST ML-DSA Variants - FIPS 204 (0x0800-0x08FF)
- ML-DSA-44 (0x0800): ML-DSA-44 (NIST Level 2, 128-bit security)
- ML-DSA-65 (0x0801): ML-DSA-65 (NIST Level 3, 192-bit security)
- ML-DSA-87 (0x0802): ML-DSA-87 (NIST Level 5, 256-bit security)
NIST SLH-DSA Variants - FIPS 205 (0x0900-0x09FF)
- SLH-DSA-SHA2-128s (0x0900): SLH-DSA-SHA2-128s (NIST Level 1, small signatures)
- SLH-DSA-SHA2-128f (0x0901): SLH-DSA-SHA2-128f (NIST Level 1, fast signatures)
- SLH-DSA-SHA2-192s (0x0902): SLH-DSA-SHA2-192s (NIST Level 3, small signatures)
- SLH-DSA-SHA2-192f (0x0903): SLH-DSA-SHA2-192f (NIST Level 3, fast signatures)
- SLH-DSA-SHA2-256s (0x0904): SLH-DSA-SHA2-256s (NIST Level 5, small signatures)
- SLH-DSA-SHA2-256f (0x0905): SLH-DSA-SHA2-256f (NIST Level 5, fast signatures)
๐ฏ Features
Feature Flags
Control optional behavior with feature flags:
use ;
use HashMap;
let flags = new
.with_compression // Data was compressed before encryption
.with_streaming // Streaming encryption mode
.with_additional_auth; // Additional authentication layer
let metadata = PqcMetadata ;
let format = with_flags;
assert!;
assert!;
Metadata Structure
The format includes rich metadata for decryption:
use ;
use HashMap;
let metadata = PqcMetadata ;
Custom Parameters
Add your own metadata:
use PqcMetadata;
let mut metadata = new;
metadata.add_custom;
// Later...
if let Some = metadata.get_custom
๐ Integrity Verification
Every format includes a SHA-256 checksum calculated over all fields:
use PqcBinaryFormat;
let bytes = format.to_bytes.unwrap;
// Tamper with the data
// let mut corrupted = bytes.clone();
// corrupted[50] ^= 0xFF;
// Deserialization automatically verifies checksum
match from_bytes
๐ Examples
Example 1: Basic Encryption Format
use ;
use HashMap;
Example 2: Cross-Language Interoperability
Rust (Encryption)
let format = new;
let bytes = format.to_bytes.unwrap;
// Send bytes to Python/JavaScript/Go/C++
Python (Decryption)
=
JavaScript (Decryption)
const format = ;
console.log;
console.log;
Go (Decryption)
format, _ := pqc.FromBytes(bytes)
defer format.Free()
fmt.Printf("Algorithm: %s\n", format.GetAlgorithmName())
fmt.Printf("Data: %d bytes\n", len(format.GetData()))
Example 3: Algorithm Migration
// Old data encrypted with Classical algorithm
let old_format = from_bytes?;
assert_eq!;
// Re-encrypt with Post-Quantum algorithm
let plaintext = decrypt_with_classical?;
let new_metadata = create_pq_metadata?;
let new_format = new;
// Same format, different algorithm!
๐ Use Cases
1. Cross-Platform Encryption
Encrypt in Rust, decrypt in Python, JavaScript, or Go using the same format.
2. Long-Term Archival
Self-describing format ensures data can be decrypted decades later even as algorithms evolve.
3. Algorithm Agility
Switch between algorithms without changing application code.
4. Compliance & Audit
Embedded metadata provides audit trail for regulatory compliance (GDPR, HIPAA, etc.).
5. Research & Benchmarking
Standardized format enables fair comparison of PQC algorithm performance.
๐งช Testing
# Run tests
# Run tests with output
# Run specific test
๐ Benchmarks
# Run benchmarks
# View benchmark results
Performance characteristics:
- Serialization: ~50 MB/s for typical payloads
- Deserialization: ~45 MB/s (includes checksum verification)
- Overhead: ~100 bytes + metadata size
๐ง Development
Building from Source
Running Examples
๐ค Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
Current Status
- Language Bindings: โ
Rust (native, tested on Linux, macOS and Windows), โ
Python, โ
JavaScript/WASM, โ
Go, โ
C/C++: every binding's example is built and run by CI's
bindingsjob on every pull request - Examples: โ 9 validated examples across 6 languages
- Package Distribution: โ All platforms published! crates.io, PyPI, npm, pkg.go.dev
Areas for Contribution
- Additional Language Bindings: Java, C#, Ruby, Swift, Kotlin - help us expand!
- Documentation: Tutorials, integration guides, video walkthroughs
- Testing: Additional test cases, fuzzing, property-based testing
- Performance: SIMD optimizations, benchmark improvements
- Standards: Help draft RFC for IETF standardization submission
๐ License
Licensed under either of:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
๐ Acknowledgments
This format was developed as part of the PQCrypta enterprise post-quantum cryptography platform. Special thanks to:
- NIST Post-Quantum Cryptography Project
- The Rust cryptography community
- Contributors to pqcrypto, ring, and other foundational crates
๐ References
- NIST Post-Quantum Cryptography
- ML-KEM (Kyber) Specification
- ML-DSA (Dilithium) Specification
- PQCrypta Documentation
๐ Related Projects
- pqcrypto - Rust PQC implementations
- Open Quantum Safe - PQC library collection
- CIRCL - Cloudflare's crypto library
๐ฌ Community & Support
- GitHub Issues: Report bugs
- Discussions: Ask questions
- Website: pqcrypta.com
- Documentation: docs.rs/pqc-binary-format
Made with โค๏ธ by the PQCrypta Community
Securing the future, one byte at a time.