pub enum EncapsulationPrivateKey {
X25519(X25519PrivateKey),
MLKEM(MLKEMPrivateKey),
}Expand description
A private key used for key encapsulation mechanisms (KEM).
EncapsulationPrivateKey is an enum representing different types of private
keys that can be used for key encapsulation, including:
- X25519: Curve25519-based key exchange
- ML-KEM: Module Lattice-based Key Encapsulation Mechanism at various security levels
These private keys are used to decrypt (decapsulate) shared secrets that have been encapsulated with the corresponding public keys.
Variants§
X25519(X25519PrivateKey)
An X25519 private key
MLKEM(MLKEMPrivateKey)
An ML-KEM private key (post-quantum)
Implementations§
Source§impl EncapsulationPrivateKey
impl EncapsulationPrivateKey
Sourcepub fn encapsulation_scheme(&self) -> EncapsulationScheme
pub fn encapsulation_scheme(&self) -> EncapsulationScheme
Returns the encapsulation scheme associated with this private key.
§Returns
The encapsulation scheme (X25519, MLKEM512, MLKEM768, or MLKEM1024) that corresponds to this private key.
§Example
use bc_components::{
EncapsulationPrivateKey, EncapsulationScheme, X25519PrivateKey,
};
let x25519_private_key = X25519PrivateKey::new();
let encapsulation_private_key =
EncapsulationPrivateKey::X25519(x25519_private_key);
assert_eq!(
encapsulation_private_key.encapsulation_scheme(),
EncapsulationScheme::X25519
);Decapsulates a shared secret from a ciphertext using this private key.
This method performs the decapsulation operation for key exchange. It
takes an EncapsulationCiphertext and extracts the shared secret
that was encapsulated using the corresponding public key.
§Parameters
ciphertext- The encapsulation ciphertext containing the encapsulated shared secret
§Returns
A Result containing the decapsulated SymmetricKey if successful,
or an error if the decapsulation fails or if the ciphertext type doesn’t
match the private key type.
§Errors
Returns an error if:
- The ciphertext type doesn’t match the private key type
- The decapsulation operation fails
§Example
use bc_components::EncapsulationScheme;
// Generate a key pair
let (private_key, public_key) = EncapsulationScheme::default().keypair();
// Encapsulate a new shared secret using the public key
let (secret1, ciphertext) = public_key.encapsulate_new_shared_secret();
// Decapsulate the shared secret using the private key
let secret2 = private_key.decapsulate_shared_secret(&ciphertext).unwrap();
// The original and decapsulated secrets should match
assert_eq!(secret1, secret2);Trait Implementations§
Source§impl Clone for EncapsulationPrivateKey
impl Clone for EncapsulationPrivateKey
Source§fn clone(&self) -> EncapsulationPrivateKey
fn clone(&self) -> EncapsulationPrivateKey
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EncapsulationPrivateKey
impl Debug for EncapsulationPrivateKey
Source§impl Decrypter for EncapsulationPrivateKey
Implementation of the Decrypter trait for EncapsulationPrivateKey.
impl Decrypter for EncapsulationPrivateKey
Implementation of the Decrypter trait for EncapsulationPrivateKey.
This allows EncapsulationPrivateKey to be used with the generic decryption
interface defined by the Decrypter trait.
Source§fn encapsulation_private_key(&self) -> EncapsulationPrivateKey
fn encapsulation_private_key(&self) -> EncapsulationPrivateKey
Source§impl From<EncapsulationPrivateKey> for CBOR
Conversion from EncapsulationPrivateKey to CBOR for serialization.
impl From<EncapsulationPrivateKey> for CBOR
Conversion from EncapsulationPrivateKey to CBOR for serialization.
Source§fn from(private_key: EncapsulationPrivateKey) -> CBOR
fn from(private_key: EncapsulationPrivateKey) -> CBOR
Source§impl Hash for EncapsulationPrivateKey
impl Hash for EncapsulationPrivateKey
Source§impl PartialEq for EncapsulationPrivateKey
impl PartialEq for EncapsulationPrivateKey
Source§fn eq(&self, other: &EncapsulationPrivateKey) -> bool
fn eq(&self, other: &EncapsulationPrivateKey) -> bool
self and other values to be equal, and is used by ==.Source§impl TryFrom<CBOR> for EncapsulationPrivateKey
Conversion from CBOR to EncapsulationPrivateKey for deserialization.
impl TryFrom<CBOR> for EncapsulationPrivateKey
Conversion from CBOR to EncapsulationPrivateKey for deserialization.
impl Eq for EncapsulationPrivateKey
impl StructuralPartialEq for EncapsulationPrivateKey
Auto Trait Implementations§
impl Freeze for EncapsulationPrivateKey
impl RefUnwindSafe for EncapsulationPrivateKey
impl Send for EncapsulationPrivateKey
impl Sync for EncapsulationPrivateKey
impl Unpin for EncapsulationPrivateKey
impl UnwindSafe for EncapsulationPrivateKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more