topayz512 is a multi-language reference implementation of a post-quantum 512-bit encryption library designed for the next generation of secure communications. It provides quantum-safe cryptographic primitives with a revolutionary fragmented-block architecture that enables parallel processing across devices from smartphones to supercomputers.
- 🔐 Quantum-Safe Security: Post-quantum cryptographic algorithms resistant to quantum computer attacks
- 🧩 Fragmented-Block Architecture: Parallel processing for 40% higher throughput and mobile device participation
- ⚡ High Performance: Sub-microsecond key generation, <50ms mobile latency
- 🌐 Multi-Platform: Rust, Go, and JavaScript/TypeScript implementations
- 📱 Mobile-First: Optimized for smartphones and IoT devices
- 🔗 Blockchain-Ready: Scalable to 3+ billion nodes with distributed consensus
What is Fragmentation? Fragmentation is the revolutionary architecture that breaks large cryptographic operations into smaller, parallel-processable chunks. Think of it like breaking a large puzzle into smaller pieces so multiple people can work on it simultaneously.
Key Features:
- Fragment Size: 256 bytes per fragment for optimal processing
- Maximum Fragments: Up to 64 fragments per operation
- Parallel Processing: Utilizes multiple CPU cores simultaneously
- Mobile Optimization: Enables smartphones and IoT devices to participate
- Integrity Protection: Each fragment includes cryptographic hash verification
How It Works:
- 📊 Data Splitting: Large data is divided into 256-byte fragments
- 🚀 Parallel Processing: Each fragment processed independently across cores
- 🔒 Integrity Verification: Hash-based verification ensures data integrity
- 🔧 Reconstruction: Fragments combined to produce final result
Performance Benefits:
- 40% Higher Throughput: Through parallel processing
- <50ms Mobile Latency: Optimized for mobile devices
- Scalable Architecture: Supports 3+ billion nodes
- Energy Efficient: Reduced computational overhead
Use Cases:
- Blockchain transaction processing
- Distributed consensus mechanisms
- Mobile wallet operations
- IoT device participation
- Large-scale cryptographic operations
What is KEM? KEM is a quantum-safe method for securely sharing secret keys over insecure channels. It's like a digital lockbox where Alice can put a secret that only Bob can open, even if everyone can see the lockbox.
How KEM Works:
- 🔑 Key Generation: Bob creates a public/private key pair
- 📦 Encapsulation: Alice uses Bob's public key to create a "lockbox" (ciphertext) containing a shared secret
- 🔓 Decapsulation: Bob uses his private key to open the lockbox and extract the same shared secret
- ✅ Verification: Both parties now have the same secret key for secure communication
Technical Specifications:
- Key Sizes: All keys are exactly 64 bytes (512 bits)
- Public Key: 64 bytes - safe to share publicly
- Secret Key: 64 bytes - must be kept private
- Ciphertext: 64 bytes - the encrypted "lockbox"
- Shared Secret: 64 bytes - the resulting shared key
Security Properties:
- Quantum-Safe: Resistant to quantum computer attacks
- Perfect Forward Secrecy: Each session uses unique keys
- Non-Interactive: No back-and-forth communication required
- Deterministic: Same inputs always produce same outputs
Performance Metrics:
- Key Generation: ~2µs average time
- Encapsulation: ~15µs average time
- Decapsulation: ~15µs average time
- Complete KEM Operation: ~30µs total
Real-World Applications:
- HTTPS/TLS connections
- Messaging app encryption
- Cryptocurrency wallets
- VPN connections
- Secure file sharing
What is Hashing? Cryptographic hashing transforms any input data into a fixed-size, unique "fingerprint" that cannot be reversed. It's like creating a unique DNA signature for digital data.
Hash Properties:
- Fixed Output Size: Always produces 64-byte (512-bit) hash
- Deterministic: Same input always produces same hash
- Avalanche Effect: Tiny input changes cause dramatic hash changes
- One-Way Function: Computationally impossible to reverse
- Collision Resistant: Extremely difficult to find two inputs with same hash
Hash Operations:
- Basic Hashing:
Hash::new(data)- Hash any data - Combined Hashing:
Hash::combine(data1, data2)- Hash multiple inputs - Hash Concatenation:
Hash::concat([hash1, hash2])- Combine existing hashes - Hex Conversion:
hash.to_hex()- Convert to readable format
Technical Features:
- Input Size: Unlimited (can hash any amount of data)
- Output Size: Always 64 bytes (512 bits)
- Performance: Optimized for speed and security
- Memory Efficient: Constant memory usage regardless of input size
Use Cases:
- Data integrity verification
- Digital signatures
- Blockchain block hashing
- Password storage (with salt)
- Merkle tree construction
- Proof-of-work algorithms
What are Key Pairs? A key pair consists of two mathematically related keys: a public key (shareable) and a secret key (private). They work together to enable secure communication and digital signatures.
Key Pair Components:
- Public Key: 64 bytes - Safe to share with anyone
- Secret Key: 64 bytes - Must be kept absolutely private
- Mathematical Relationship: Keys are cryptographically linked but one cannot derive the other
Key Generation Process:
- 🎲 Entropy Collection: Gather high-quality random data
- 🔢 Mathematical Generation: Use post-quantum algorithms
- ✅ Validation: Verify key pair correctness
- 🔒 Secure Storage: Store secret key safely
Key Operations:
- Generation:
KeyPair::generate()- Create new key pair - Public Key Extraction:
keypair.public_key()- Get public key - Serialization:
key.to_bytes()- Convert to bytes for storage - Deserialization:
Key::from_bytes()- Restore from bytes - Validation: Built-in integrity checking
Security Features:
- Post-Quantum Safe: Resistant to quantum attacks
- Perfect Key Separation: Public key cannot reveal secret key
- Tamper Detection: Built-in integrity verification
- Secure Generation: Uses cryptographically secure randomness
Performance Metrics:
- Key Generation: ~2µs average time
- Serialization: <1µs for conversion operations
- Validation: <1µs for integrity checks
- Memory Usage: Minimal overhead
Storage & Transport:
- Hex Encoding: Human-readable format for display
- Binary Format: Efficient storage and transmission
- Cross-Platform: Compatible across all implementations
- Version Agnostic: Forward and backward compatible
use topayz512::{KeyPair, Hash, Kem};
// Generate a key pair
let keypair = KeyPair::generate();
println!("Public key: {}", keypair.public_key().to_hex());
// Hash some data
let data = b"Hello, TOPAY-Z512!";
let hash = Hash::new(data);
println!("Hash: {}", hash.to_hex());
// KEM operation
let (kem_public, kem_secret) = Kem::keygen();
let (ciphertext, shared_secret1) = Kem::encapsulate(&kem_public);
let shared_secret2 = Kem::decapsulate(&ciphertext, &kem_secret);
assert_eq!(shared_secret1.as_bytes(), shared_secret2.as_bytes());
println!("KEM operation successful!");
// Fragmentation (with feature flag)
#[cfg(feature = "fragmentation")]
{
use topayz512::fragment::FragmentEngine;
let large_data = vec![0u8; 1000];
let fragments = FragmentEngine::fragment_data(&large_data)?;
let reconstructed = FragmentEngine::reconstruct_data(&fragments)?;
assert_eq!(large_data, reconstructed);
println!("Fragmentation successful!");
}# Basic usage examples
cargo run --example quick_start
cargo run --example interactive_guide
# Component-specific examples
cargo run --example keypair_example
cargo run --example kem_example
cargo run --example hash_example
# Advanced features
cargo run --example fragmentation_example --features fragmentation
# Educational examples
cargo run --example what_is_kem
cargo run --example what_is_fragment --features fragmentation| Operation | Average Time | Throughput |
|---|---|---|
| Key Generation | ~2µs | 500K ops/sec |
| Hash (1KB data) | ~5µs | 200K ops/sec |
| KEM Encapsulation | ~15µs | 67K ops/sec |
| KEM Decapsulation | ~15µs | 67K ops/sec |
| Fragment (1KB) | ~10µs | 100K ops/sec |
| Mobile KEM | <50ms | 20 ops/sec |
- Post-Quantum Security: Resistant to both classical and quantum attacks
- 512-bit Security Level: Equivalent to 256-bit symmetric security
- Perfect Forward Secrecy: Compromise of long-term keys doesn't affect past sessions
- Side-Channel Resistance: Protected against timing and power analysis attacks
- Formal Verification: Mathematically proven security properties
- Constant-Time Operations: Prevents timing-based attacks
| Platform | Status | Performance | Features |
|---|---|---|---|
| Rust | ✅ Complete | Fastest | All features |
| Go | 🚧 In Progress | Fast | Core features |
| JavaScript | 🚧 In Progress | Good | Web-optimized |
| Mobile | ✅ Supported | Optimized | Fragment-enabled |
| IoT | ✅ Supported | Efficient | Lightweight |
topayz512/ # Root monorepo
├── LICENSE # Apache-2.0 License
├── README.md # This file
├── docs/ # Shared design spec & API references
│ ├── design_spec.md
│ ├── api_reference.md
│ └── keypair.md
├── ci/ # CI workflows for each language
│ ├── rust.yml
│ ├── go.yml
│ └── js.yml
├── test-vectors/ # Canonical test vectors & KATs
│ ├── 002_hash.json
│ └── 003_keypair.json
├── rust/ # Rust implementation (Cargo project)
│ └── ...
├── go/ # Go implementation (Go module)
│ └── ...
└── js/ # JavaScript/TypeScript implementation (npm package)
└── ...
- Rust (stable toolchain) for the
rust/directory - Go (>=1.18) for the
go/directory - Node.js (>=14) and npm/yarn for the
js/directory
From the project root, you can run each language’s CI script manually:
# Rust
cd rust && cargo test && cargo bench
# Go
cd go && go test ./... && go test -bench=.
# JS/TS
cd js && npm install && npm test && npm run benchOr rely on GitHub Actions workflows under .github/workflows/ which automate these steps on push/PR.
The fragmentation system is available as an optional feature to keep the core library lightweight:
# Enable fragmentation features
cargo run --example fragmentation_example --features fragmentation
cargo test --features fragmentation
# Build with all features
cargo build --features fragmentation --releaseAll implementations maintain binary compatibility for keys and hashes:
// Keys generated in Rust work in Go and JavaScript
let keypair = KeyPair::generate();
let public_key_bytes = keypair.public_key().to_bytes();
// These bytes can be used in any other implementationFor maximum performance in production:
# Release build with optimizations
cargo build --release
# Profile-guided optimization
cargo build --release --features pgo
# Target-specific optimizations
cargo build --release --target x86_64-unknown-linux-gnu# Run all tests
cargo test
# Run with fragmentation features
cargo test --features fragmentation
# Run integration tests
cargo test --test integration_tests
# Run benchmarks
cargo bench- Unit Tests: 15 tests covering core functionality
- Integration Tests: 8 tests for cross-component interaction
- Performance Tests: Benchmarks for all operations
- Compatibility Tests: Cross-platform validation
- Security Tests: Cryptographic property verification
The library includes standardized test vectors:
# Validate against known test vectors
cargo test test_known_vectors
# Generate new test vectors
cargo run --example generate_test_vectorsRust (Cargo.toml):
[dependencies]
topayz512 = "0.1.0"
# With fragmentation support
topayz512 = { version = "0.1.0", features = ["fragmentation"] }Go (go.mod):
require github.com/TOPAY-FOUNDATION/TOPAY_Z512/go v0.1.0JavaScript (package.json):
{
"dependencies": {
"topayz512": "^0.1.0"
}
}All implementations provide identical APIs:
| Operation | Rust | Go | JavaScript |
|---|---|---|---|
| Key Generation | KeyPair::generate() |
GenerateKeyPair() |
generateKeyPair() |
| Hashing | Hash::new(data) |
NewHash(data) |
hash(data) |
| KEM Keygen | Kem::keygen() |
KemKeygen() |
kemKeygen() |
| Encapsulation | Kem::encapsulate(pk) |
Encapsulate(pk) |
encapsulate(pk) |
Consistent error handling across platforms:
// Rust
match operation() {
Ok(result) => println!("Success: {:?}", result),
Err(e) => eprintln!("Error: {}", e),
}Build Errors:
# Update Rust toolchain
rustup update
# Clean build cache
cargo clean && cargo build
# Check dependencies
cargo checkPerformance Issues:
# Use release builds for benchmarking
cargo build --release
# Enable CPU-specific optimizations
RUSTFLAGS="-C target-cpu=native" cargo build --releaseFeature Compilation:
# List available features
cargo metadata --format-version 1 | jq '.packages[0].features'
# Build with specific features
cargo build --features "fragmentation,std"Windows:
- Requires Visual Studio Build Tools or MinGW
- Use PowerShell for best compatibility
- May need to set
RUSTFLAGSfor optimization
macOS:
- Requires Xcode Command Line Tools
- Apple Silicon (M1/M2) fully supported
- Use Homebrew for dependencies
Linux:
- Works on all major distributions
- Requires
build-essentialpackage - Optimized for both x86_64 and ARM64
| Operation | Memory Usage | Notes |
|---|---|---|
| Key Generation | ~1KB | Temporary allocation |
| Hashing | ~64 bytes | Constant regardless of input |
| KEM Operations | ~256 bytes | Includes all intermediate values |
| Fragmentation | ~16KB | For maximum fragment count |
- 🔮 Zero-Knowledge Proofs: Privacy-preserving verification
- 🌊 Streaming Operations: Process data larger than memory
- 🔗 Blockchain Integration: Direct integration with popular chains
- 📱 Mobile SDKs: Native iOS and Android libraries
- 🌐 WebAssembly: Browser-native cryptography
- ⚡ Hardware Acceleration: GPU and specialized crypto chips
- v0.1.x: Core cryptographic primitives
- v0.2.x: Enhanced fragmentation and mobile optimization
- v0.3.x: Zero-knowledge proof integration
- v1.0.x: Production-ready with formal security audit
We welcome contributions! Please see:
- Code Style: Follow language-specific conventions
- Testing: All PRs must include tests
- Documentation: Update docs for new features
- Security: Report vulnerabilities privately
- Performance: Include benchmarks for optimizations
For detailed design rationale and API usage, see the shared docs:
Each language folder also contains its own README with language-specific examples, installation, and usage instructions.
Please read docs/contributing.md for guidelines on:
- Coding style and linting
- Test vector updates (sync across languages)
- Pull request process and review criteria
This project is licensed under the Apache-2.0 License. See LICENSE for full terms.