Key Encapsulation Mechanisms
The dcrypt-kem crate provides a unified interface for various Key Encapsulation Mechanisms (KEMs), including both traditional and post-quantum cryptographic algorithms. It is designed with a strong focus on security, type safety, and ease of use, leveraging the dcrypt::api trait system.
This crate is part of the dcrypt cryptographic library.
Features
- Broad Algorithm Support: Includes classic ECDH-based KEMs over multiple standard curves and the NIST-standardized post-quantum KEM, CRYSTALS-Kyber.
- Security-First Design:
- Strongly-Typed Keys: Utilizes distinct types for public keys, secret keys, and ciphertexts (e.g.,
EcdhP256PublicKey,KyberSecretKey) to prevent misuse. - Zeroization: Secret key and shared secret materials are automatically zeroized on drop to minimize their lifetime in memory.
- Controlled Byte Access: Deliberately avoids generic
AsRef<[u8]>implementations on sensitive types, requiring explicit serialization calls. - Validation: Incoming keys and ciphertexts are validated to prevent common attacks, such as those involving invalid curve points.
- Strongly-Typed Keys: Utilizes distinct types for public keys, secret keys, and ciphertexts (e.g.,
no_stdCompatibility: Fully operational inno_stdenvironments with theallocfeature for heap-allocated types.- Extensive Testing: Comes with a comprehensive test suite and performance benchmarks for all implemented algorithms.
- Optional Serde Support: Provides
serdeintegration for key serialization and deserialization when theserdefeature is enabled.
Implemented Algorithms
The crate provides implementations for the following KEMs, accessible via the dcrypt::api::Kem trait.
| Category | Algorithm | Struct Name | Security Level | Status |
|---|---|---|---|---|
| Elliptic Curve | ECDH over NIST P-192 | EcdhP192 |
~80-bit | Implemented |
| Elliptic Curve | ECDH over NIST P-224 | EcdhP224 |
~112-bit | Implemented |
| Elliptic Curve | ECDH over NIST P-256 | EcdhP256 |
~128-bit | Implemented |
| Elliptic Curve | ECDH over NIST P-384 | EcdhP384 |
~192-bit | Implemented |
| Elliptic Curve | ECDH over NIST P-521 | EcdhP521 |
~256-bit | Implemented |
| Elliptic Curve | ECDH over secp256k1 | EcdhK256 |
~128-bit | Implemented |
| Elliptic Curve | ECDH over sect283k1 | EcdhB283k |
~142-bit | Implemented |
| Post-Quantum | CRYSTALS-Kyber-512 | Kyber512 |
NIST Level 1 | Implemented |
| Post-Quantum | CRYSTALS-Kyber-768 | Kyber768 |
NIST Level 3 | Implemented |
| Post-Quantum | CRYSTALS-Kyber-1024 | Kyber1024 |
NIST Level 5 | Implemented |
| Post-Quantum | LightSaber | LightSaber |
- | Placeholder |
| Post-Quantum | Saber | Saber |
- | Placeholder |
| Post-Quantum | FireSaber | FireSaber |
- | Placeholder |
| Post-Quantum | Classic McEliece 348864 | McEliece348864 |
NIST Level 1 | Placeholder |
| Post-Quantum | Classic McEliece 6960119 | McEliece6960119 |
NIST Level 5 | Placeholder |
| Traditional | Diffie-Hellman (2048-bit) | Dh2048 |
- | Placeholder |
Note: Algorithms marked as Placeholder are exposed in the API but do not yet contain a full cryptographic implementation.
Installation
Add the main dcrypt crate to your Cargo.toml:
[]
= "0.12.0-beta.1"
= "0.8"
Usage Example
All KEMs in this crate implement the dcrypt::api::Kem trait, providing a consistent workflow.
Here is an example using EcdhP256:
use Kem;
use EcdhP256;
use OsRng;
The same pattern applies to post-quantum algorithms like Kyber768:
use Kem;
use Kyber768;
use OsRng;
// --- snip ---
let mut rng = OsRng;
let = keypair?;
let = encapsulate?;
let ss2 = decapsulate?;
assert_eq!;
println!;
// --- snip ---
Cargo Features
The dcrypt-kem crate provides the following features:
std(default): Enables functionality that depends on the Rust standard library.alloc: Enables usage of heap-allocated types. This is required forno_stdenvironments that have a heap allocator.no_std: Disablesstdsupport for use in bare-metal and embedded environments.serde: Enables serialization and deserialization of public key types via the Serde framework.
Benchmarks
The crate includes a comprehensive benchmark suite using criterion. To run the benchmarks and view the results:
The results will be available in the target/criterion/ directory. The benchmarks cover key generation, encapsulation, and decapsulation for all implemented algorithms, providing a clear view of their relative performance.
An ecdh_comparison suite is also included to directly compare the performance of the different elliptic curves.
License
This crate is licensed under the Apache License, Version 2.0.