| Crates.io | saorsa-fec |
| lib.rs | saorsa-fec |
| version | 0.4.11 |
| created_at | 2025-08-15 13:04:24.594518+00 |
| updated_at | 2025-08-29 11:09:48.500448+00 |
| description | Quantum-safe erasure coding with post-quantum cryptography using saorsa-pqc |
| homepage | https://github.com/dirvine/saorsa-fec |
| repository | https://github.com/dirvine/saorsa-fec |
| max_upload_size | |
| id | 1796723 |
| size | 906,431 |
A comprehensive Forward Error Correction library with AES‑256‑GCM authenticated encryption, SHA‑256–based key derivation, and high‑level storage pipeline APIs — plus legacy FEC‑only support.
Key derived solely from content hash → global deduplication (identical content → identical ciphertext).
Key derived from content hash + user secret → per‑user deduplication.
Per‑encryption random key → no deduplication, maximum confidentiality.
Security Note: Convergent modes can enable confirmation‑of‑file if an attacker can compute the content hash; ConvergentWithSecret mitigates this by mixing a user secret. RandomKey mode avoids dedup to maximise privacy.
use saorsa_fec::{Config, StoragePipeline, EncryptionMode, LocalStorage, FecParams, ChunkConfig};
// Configure pipeline
let fec_params = FecParams::new(16, 4)?; // 25% overhead
let chunk_config = ChunkConfig::new(64 * 1024, fec_params); // 64 KiB chunks
let config = Config::default()
.with_encryption_mode(EncryptionMode::Convergent)
.with_fec_params(16, 4)
.with_chunk_size(64 * 1024)
.with_compression(false, 0);
// Create storage backend
let storage = LocalStorage::new("./storage").await?;
let mut pipeline = StoragePipeline::new(config, storage).await?;
// Store file
let file_data = std::fs::read("example.txt")?;
let file_id = [42u8; 32]; // Application-defined identifier
let metadata = pipeline.process_file(file_id, &file_data, None).await?;
// Retrieve file
let retrieved = pipeline.retrieve_file(&metadata).await?;
assert_eq!(retrieved, file_data);
use saorsa_fec::ReedSolomon;
// Create Reed-Solomon codec
let rs = ReedSolomon::new(10, 3)?; // 10 data + 3 parity shards
// Encode data
let data_shards = vec![
vec![1, 2, 3, 4],
vec![5, 6, 7, 8],
// ... 8 more data shards
];
let all_shards = rs.encode(&data_shards)?;
// Simulate missing shards
let mut corrupted_shards = all_shards;
corrupted_shards[2] = None;
corrupted_shards[7] = None;
// Reconstruct
let reconstructed = rs.reconstruct(&mut corrupted_shards)?;
API: with_fec_params(data_shards, parity_shards) where overhead = parity/data.
| Configuration | Overhead | Use Case |
|---|---|---|
| (32, 8) | 25% | High performance |
| (16, 12) | 75% | High reliability |
| (20, 5) | 25% | Minimal storage |
| (16, 8) | 50% | Balanced reliability |
File system-based storage with CID addressing and metadata persistence.
let storage = LocalStorage::new("/path/to/storage").await?;
In-memory storage for testing and caching.
let storage = MemoryStorage::new();
Combines multiple backends with redundancy, load balancing, or failover.
let storage = MultiStorage::redundant(vec![storage1, storage2]).await?;
Each shard uses a compact 96-byte header:
version (u8) = 3
file_id (32B) = Unique file identifier
chunk_index (u32) = Index of chunk within file
shard_index (u16) = Index of shard within chunk
nspec (u8,u8) = (data_shards, parity_shards)
flags (u8) = encrypted, mode, isa-l, compressed
nonce (12B) = AES‑GCM nonce
mac (16B) = AES‑GCM tag
Header is authenticated via AEAD and included in CID calculation.
🚀 Exceptional Performance with reed-solomon-simd v0.2.1
SIMD Acceleration Support:
Performance scales with file size and benefits from SIMD instructions available on modern CPUs.
default = ["pure-rust"] - High-performance reed-solomon-simd implementationisa-l - ISA-L hardware acceleration (x86_64, optional)bench - Benchmark dependencies# Build and test
cargo build --release
cargo test --all-features
cargo clippy -- -D warnings -D clippy::correctness -D clippy::suspicious -D clippy::complexity -W clippy::perf -W clippy::style
# Run benchmarks
cargo bench --features bench
# Check performance
cargo run --example performance_test --release
Licensed under the GNU Affero General Public License v3.0 or later.
Contributions welcome! Please open issues and pull requests.