EncapsulationPrivateKey

Enum EncapsulationPrivateKey 

Source
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

Source

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
);
Source

pub fn decapsulate_shared_secret( &self, ciphertext: &EncapsulationCiphertext, ) -> Result<SymmetricKey>

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 AsRef<EncapsulationPrivateKey> for PrivateKeys

Source§

fn as_ref(&self) -> &EncapsulationPrivateKey

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for EncapsulationPrivateKey

Source§

fn clone(&self) -> EncapsulationPrivateKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EncapsulationPrivateKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Returns the encapsulation private key for this decrypter. Read more
Source§

fn decapsulate_shared_secret( &self, ciphertext: &EncapsulationCiphertext, ) -> Result<SymmetricKey>

Decapsulates a shared secret from a ciphertext. Read more
Source§

impl From<EncapsulationPrivateKey> for CBOR

Conversion from EncapsulationPrivateKey to CBOR for serialization.

Source§

fn from(private_key: EncapsulationPrivateKey) -> Self

Converts to this type from the input type.
Source§

impl Hash for EncapsulationPrivateKey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for EncapsulationPrivateKey

Source§

fn eq(&self, other: &EncapsulationPrivateKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<CBOR> for EncapsulationPrivateKey

Conversion from CBOR to EncapsulationPrivateKey for deserialization.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(cbor: CBOR) -> Result<Self, Error>

Performs the conversion.
Source§

impl Eq for EncapsulationPrivateKey

Source§

impl StructuralPartialEq for EncapsulationPrivateKey

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CBORDecodable for T
where T: TryFrom<CBOR, Error = Error>,

Source§

fn try_from_cbor(cbor: &CBOR) -> Result<Self, Error>

Source§

impl<T> CBOREncodable for T
where T: Into<CBOR> + Clone,

Source§

fn to_cbor(&self) -> CBOR

Converts this value to a CBOR object. Read more
Source§

fn to_cbor_data(&self) -> Vec<u8>

Converts this value directly to binary CBOR data. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> CBORCodable for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,