pub enum EncapsulationScheme {
X25519,
MLKEM512,
MLKEM768,
MLKEM1024,
}Expand description
Supported key encapsulation mechanisms.
Key Encapsulation Mechanisms (KEMs) are cryptographic algorithms designed to securely establish a shared secret between parties in public-key cryptography. They are often used to encapsulate (wrap) symmetric keys for secure key exchange.
This enum represents the various KEM schemes supported in this crate:
- X25519: A Diffie-Hellman key exchange mechanism using the Curve25519 elliptic curve
- ML-KEM (Module Lattice-based Key Encapsulation Mechanism): Post-quantum secure KEM at different security levels (512, 768, 1024)
Variants§
X25519
X25519 key agreement (default)
MLKEM512
ML-KEM512 post-quantum key encapsulation (NIST level 1)
MLKEM768
ML-KEM768 post-quantum key encapsulation (NIST level 3)
MLKEM1024
ML-KEM1024 post-quantum key encapsulation (NIST level 5)
Implementations§
Source§impl EncapsulationScheme
impl EncapsulationScheme
Sourcepub fn keypair(self) -> (EncapsulationPrivateKey, EncapsulationPublicKey)
pub fn keypair(self) -> (EncapsulationPrivateKey, EncapsulationPublicKey)
Generates a new random key pair for the specified encapsulation scheme.
§Returns
A tuple containing the private key and public key for the selected encapsulation scheme.
§Example
use bc_components::EncapsulationScheme;
// Generate a key pair using X25519 (default)
let (private_key, public_key) = EncapsulationScheme::default().keypair();// Generate a key pair using ML-KEM768
let (private_key, public_key) = EncapsulationScheme::MLKEM768.keypair();Sourcepub fn keypair_using(
self,
rng: &mut impl RandomNumberGenerator,
) -> Result<(EncapsulationPrivateKey, EncapsulationPublicKey)>
pub fn keypair_using( self, rng: &mut impl RandomNumberGenerator, ) -> Result<(EncapsulationPrivateKey, EncapsulationPublicKey)>
Generates a deterministic key pair using the provided random number generator.
§Parameters
rng- A mutable reference to a random number generator
§Returns
A Result containing a tuple with the private key and public key if successful, or an error if deterministic key generation is not supported for the selected scheme.
§Errors
Returns an error if deterministic key generation is not supported for the selected encapsulation scheme (currently only X25519 supports this).
§Example
use bc_components::EncapsulationScheme;
use bc_rand::SecureRandomNumberGenerator;
let mut rng = SecureRandomNumberGenerator;
let result = EncapsulationScheme::X25519.keypair_using(&mut rng);
assert!(result.is_ok());// ML-KEM schemes don't support deterministic key generation
let result = EncapsulationScheme::MLKEM512.keypair_using(&mut rng);
assert!(result.is_err());Trait Implementations§
Source§impl Clone for EncapsulationScheme
impl Clone for EncapsulationScheme
Source§fn clone(&self) -> EncapsulationScheme
fn clone(&self) -> EncapsulationScheme
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EncapsulationScheme
impl Debug for EncapsulationScheme
Source§impl Default for EncapsulationScheme
impl Default for EncapsulationScheme
Source§fn default() -> EncapsulationScheme
fn default() -> EncapsulationScheme
Source§impl PartialEq for EncapsulationScheme
impl PartialEq for EncapsulationScheme
impl Copy for EncapsulationScheme
impl StructuralPartialEq for EncapsulationScheme
Auto Trait Implementations§
impl Freeze for EncapsulationScheme
impl RefUnwindSafe for EncapsulationScheme
impl Send for EncapsulationScheme
impl Sync for EncapsulationScheme
impl Unpin for EncapsulationScheme
impl UnwindSafe for EncapsulationScheme
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)