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);pub fn public_key(&self) -> Result<EncapsulationPublicKey>
Trait Implementations§
Source§impl AsRef<EncapsulationPrivateKey> for PrivateKeys
impl AsRef<EncapsulationPrivateKey> for PrivateKeys
Source§fn as_ref(&self) -> &EncapsulationPrivateKey
fn as_ref(&self) -> &EncapsulationPrivateKey
Source§impl Clone for EncapsulationPrivateKey
impl Clone for EncapsulationPrivateKey
Source§fn clone(&self) -> EncapsulationPrivateKey
fn clone(&self) -> EncapsulationPrivateKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
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 Display for EncapsulationPrivateKey
impl Display for 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) -> Self
fn from(private_key: EncapsulationPrivateKey) -> Self
Source§impl Hash for EncapsulationPrivateKey
impl Hash for EncapsulationPrivateKey
Source§impl PartialEq for EncapsulationPrivateKey
impl PartialEq for EncapsulationPrivateKey
Source§impl ReferenceProvider for EncapsulationPrivateKey
impl ReferenceProvider for EncapsulationPrivateKey
Source§fn reference(&self) -> Reference
fn reference(&self) -> Reference
Source§fn ref_hex_short(&self) -> String
fn ref_hex_short(&self) -> String
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.