Public Key Encryption
Part of the dcrypt library, this crate provides Public Key Encryption (PKE) schemes. It specifically contains implementations of the Elliptic Curve Integrated Encryption Scheme (ECIES).
The library is designed with a focus on security, modularity, and no_std compatibility (with alloc), ensuring it can be used in a wide range of Rust projects, including those in constrained environments like embedded systems or WebAssembly.
Features
- ECIES Implementations: Provides ECIES using several standard NIST elliptic curves.
- Authenticated Encryption: All schemes use an Authenticated Encryption with Associated Data (AEAD) cipher to ensure both confidentiality and integrity of messages.
- Secure Key Derivation: Utilizes HKDF (HMAC-based Key Derivation Function) with various SHA-2 hash functions to derive strong symmetric keys from the elliptic curve shared secret.
- Modern AEAD Ciphers: Employs
ChaCha20Poly1305andAES-256-GCMfor the symmetric encryption part of the ECIES protocol. no_stdSupport: Fully compatible withno_stdenvironments by using thealloccrate for necessary dynamic data structures.- Consistent API: Adheres to the
Pketrait fromdcrypt-api, providing a uniform interface for key generation, encryption, and decryption.
Supported Schemes
The crate provides the following ECIES configurations, each corresponding to a specific NIST curve and a set of cryptographic primitives:
| Struct | Elliptic Curve | Key Derivation Function | AEAD Cipher |
|---|---|---|---|
EciesP192 |
NIST P-192 | HKDF-SHA256 | ChaCha20Poly1305 |
EciesP224 |
NIST P-224 | HKDF-SHA256 | ChaCha20Poly1305 |
EciesP256 |
NIST P-256 | HKDF-SHA256 | ChaCha20Poly1305 |
EciesP384 |
NIST P-384 | HKDF-SHA384 | AES-256-GCM |
EciesP521 |
NIST P-521 | HKDF-SHA512 | AES-256-GCM |
Installation
Add the crate to your Cargo.toml file:
[]
= "0.12.0-beta.1"
# For random number generation, required for keypair generation and encryption
= "0.8"
Usage Example
Here is a basic example of how to generate a keypair, encrypt a message, and then decrypt it using EciesP256.
use EciesP256;
use Pke;
use OsRng;
```
## `no_std` Support
This crate is designed to work in `no_std` environments. To use it this way, you must disable the default features and enable the `alloc` feature in your `Cargo.toml`. This will replace the standard library dependency with the `alloc` crate.
```toml
dcrypt-pke =
rand =
License
This crate is licensed under the terms of the workspace license. (Please refer to the license file in the root of the dcrypt repository).