| Crates.io | dcrypt |
| lib.rs | dcrypt |
| version | 1.2.2 |
| created_at | 2025-07-24 21:55:20.990427+00 |
| updated_at | 2025-12-10 20:23:51.844321+00 |
| description | dcrypt is a pure-Rust, software-only cryptography library providing both classical and post-quantum primitives with a focus on security, hybrid KEMs/signatures, and memory-safe, no-FFI design. |
| homepage | |
| repository | https://github.com/ioi-foundation/dcrypt |
| max_upload_size | |
| id | 1766956 |
| size | 522,718 |
dcrypt (Decentralized Cryptography) is a comprehensive cryptographic library implemented entirely in safe Rust. It bridges the gap between traditional security and the post-quantum future by providing NIST-standardized Post-Quantum Cryptography (PQC) algorithms alongside novel, production-ready hybrid constructions.
Spearheaded by the IOI Foundation as the security cornerstone for next-generation decentralized infrastructure, dcrypt eliminates foreign function interfaces (FFI) and unsafe code blocks in cryptographic logic, ensuring memory safety and cross-platform compatibility from embedded devices to enterprise servers.
dcrypt introduces capabilities critical for the transition to quantum-safe and decentralized computing:
unsafe code and full constant-time execution.ECDH P-256 + Kyber-768) and hybrid Digital Signatures, ensuring security even if one underlying primitive is compromised.Nonce, Key, and Tag prevents byte-array confusion).no_std & Cross-Platform: Fully functional in no_std environments (requiring alloc), making it suitable for IoT, embedded systems, and WASM targets.Add dcrypt to your project's Cargo.toml.
[dependencies]
dcrypt = { version = "1.0" }
Securely exchange keys using a hybrid scheme (EcdhP256 + Kyber768). This ensures security remains intact even if quantum computers break elliptic curve cryptography.
use dcrypt::hybrid::kem::EcdhP256Kyber768;
use dcrypt::api::Kem;
use rand::rngs::OsRng;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut rng = OsRng;
// 1. Alice generates a Hybrid Keypair
// (Contains both a P-256 keypair and a Kyber-768 keypair)
let (alice_pk, alice_sk) = EcdhP256Kyber768::keypair(&mut rng)?;
// 2. Bob encapsulates a shared secret against Alice's public key
let (ciphertext, shared_secret_bob) = EcdhP256Kyber768::encapsulate(&mut rng, &alice_pk)?;
// 3. Alice decapsulates the ciphertext to recover the shared secret
let shared_secret_alice = EcdhP256Kyber768::decapsulate(&alice_sk, &ciphertext)?;
// 4. Verify secrets match
assert_eq!(shared_secret_bob.as_ref(), shared_secret_alice.as_ref());
println!("Hybrid Quantum-Safe Key Exchange successful!");
Ok(())
}
Standard symmetric encryption remains a core part of the library, featuring ergonomic key management.
use dcrypt::symmetric::aes::{Aes256Gcm, Aes256Key};
use dcrypt::symmetric::cipher::{SymmetricCipher, Aead};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Generate a secure random key
let key = Aes256Key::generate();
let cipher = Aes256Gcm::new(&key)?;
let nonce = Aes256Gcm::generate_nonce();
let plaintext = b"Quantum resistance is futile... actually it's necessary.";
let aad = Some(b"metadata".as_slice());
// Encrypt
let ciphertext = cipher.encrypt(&nonce, plaintext, aad)?;
// Decrypt
let decrypted = cipher.decrypt(&nonce, &ciphertext, aad)?;
assert_eq!(plaintext.to_vec(), decrypted);
Ok(())
}
Perform bilinear pairings and hash-to-curve operations standard in decentralized identity and ZK systems.
use dcrypt::algorithms::ec::bls12_381::{
pairing, G1Projective, G2Affine, G2Projective, Scalar
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Hash a message to a point on G1 using IETF hash-to-curve
let msg = b"Decentralized Identity";
let dst = b"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_";
// hash_to_curve returns a projective point
let point_g1 = G1Projective::hash_to_curve(msg, dst)?.to_affine();
// 2. Generate a secret scalar and public G2 point
let secret = Scalar::from(42u64); // In reality, use random generation
let public_g2 = G2Affine::from(G2Projective::generator() * secret);
// 3. Compute Pairing e(H(m), [s]G2)
let result = pairing(&point_g1, &public_g2);
println!("Pairing computed successfully: {:?}", result);
Ok(())
}
dcrypt provides a unified API for classical, post-quantum, and hybrid operations:
| Category | Algorithms |
|---|---|
| Symmetric Encryption (AEAD) | AES-128/256-GCM, ChaCha20-Poly1305, XChaCha20-Poly1305 |
| Public Key Encryption (PKE) | ECIES (P-192, P-224, P-256, P-384, P-521) |
| Hash Functions | SHA-2 (224, 256, 384, 512), SHA-3, BLAKE2b/s |
| XOFs | SHAKE-128/256, BLAKE3 |
| Password Hashing | Argon2id (default), Argon2i, Argon2d, PBKDF2 |
| Key Derivation | HKDF, PBKDF2 |
| Digital Signatures | ECDSA (P-192 to P-521), Ed25519 |
| Post-Quantum Signatures | Dilithium / ML-DSA (Levels 2, 3, 5) |
| Key Exchange / KEM | ECDH (P-Curves, K-256, B-283) |
| Pairing-Friendly Curves | BLS12-381 (G1, G2, Gt, Pairings, Hash-to-Curve) |
| Post-Quantum KEMs | Kyber / ML-KEM (Levels 512, 768, 1024) |
| Hybrid Schemes | EcdhP256Kyber768, EcdhP384Kyber1024, EcdsaDilithiumHybrid |
The library is organized as a workspace of specialized crates to align type-safety boundaries with security boundaries:
dcrypt-api: Defines core traits (SymmetricCipher, Kem, Signature), error types, and fundamental data structures.dcrypt-algorithms: Low-level, constant-time implementations of cryptographic kernels (hashing, curve arithmetic, lattice math).dcrypt-common: Shared security primitives, including SecretBuffer (automatic zeroization) and SecureCompare.dcrypt-symmetric: High-level AEADs, stream ciphers, and secure key management wrappers.dcrypt-pke: Public Key Encryption schemes, specifically ECIES (Elliptic Curve Integrated Encryption Scheme) over standard NIST curves.dcrypt-kem: Implementations of Key Encapsulation Mechanisms (Kyber, ECDH, McEliece placeholders).dcrypt-sign: Implementations of Digital Signatures (Dilithium, ECDSA, Ed25519, SPHINCS+ placeholders).dcrypt-hybrid: Ready-to-use combiners for KEMs and Signatures ensuring crypto-agility.dcrypt-tests: Contains the ACVP test harness and Constant-Time Verification Suite.Security is the primary driver for dcrypt. The library employs a rigorous testing methodology:
We utilize a custom statistical analysis engine (dcrypt-tests/src/suites/constant_time) that integrates into our CI.
This project is licensed under the Apache License, Version 2.0.