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 and final FIPS 203 ML-KEM.
- Security-First Design:
- Strongly-Typed Keys: Uses distinct, validated types for public keys, secret keys, and ciphertexts.
- 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.
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.
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-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 |
| Post-Quantum | FIPS 203 ML-KEM-512 | MlKem512 |
NIST Level 1 | Implemented |
| Post-Quantum | FIPS 203 ML-KEM-768 | MlKem768 |
NIST Level 3 | Implemented |
| Post-Quantum | FIPS 203 ML-KEM-1024 | MlKem1024 |
NIST Level 5 | Implemented |
P-224 is retained for transition and interoperability at approximately 112-bit security. Prefer P-256 or stronger for new deployments. The P-192 and sect283k1 surfaces were removed for v3; see the traditional-EC removal notice.
Installation
Add the main dcrypt crate to your Cargo.toml:
[]
= { = "=3.0.0", = false, = ["std", "traditional", "post-quantum"] }
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 ;
The same pattern applies to final FIPS 203 ML-KEM:
use Kem;
use MlKem768;
use ;
Cargo Features
The dcrypt-kem crate provides the following features:
std(default): Enables standard-library support andalloc.alloc: Enables usage of heap-allocated types. This is required forno_stdenvironments that have a heap allocator.no_std: Compatibility spelling for the allocation-backed profile withoutstd.traditional(default): Enables the ECDH KEM surface.post-quantum: Enables the final FIPS 203 ML-KEM surface and forwardsalloc.
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.