pub enum EncapsulationPublicKey {
X25519(X25519PublicKey),
MLKEM(MLKEMPublicKey),
}
Expand description
A public key used for key encapsulation mechanisms (KEM).
EncapsulationPublicKey
is an enum representing different types of public
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 public keys are used to encrypt (encapsulate) shared secrets that can only be decrypted (decapsulated) by the corresponding private key holder.
Variants§
X25519(X25519PublicKey)
An X25519 public key
MLKEM(MLKEMPublicKey)
An ML-KEM public key (post-quantum)
Implementations§
Source§impl EncapsulationPublicKey
impl EncapsulationPublicKey
Sourcepub fn encapsulation_scheme(&self) -> EncapsulationScheme
pub fn encapsulation_scheme(&self) -> EncapsulationScheme
Returns the encapsulation scheme associated with this public key.
§Returns
The encapsulation scheme (X25519, MLKEM512, MLKEM768, or MLKEM1024) that corresponds to this public key.
§Example
use bc_components::{EncapsulationScheme, X25519PrivateKey};
// Generate a keypair
let private_key = X25519PrivateKey::new();
let public_key = private_key.public_key();
// Convert to encapsulation public key
let encapsulation_public_key =
bc_components::EncapsulationPublicKey::X25519(public_key);
// Check the scheme
assert_eq!(
encapsulation_public_key.encapsulation_scheme(),
EncapsulationScheme::X25519
);
Encapsulates a new shared secret using this public key.
This method performs the encapsulation operation for key exchange. It generates a new shared secret and encapsulates it using this public key.
The encapsulation process differs based on the key type:
- For X25519: Generates an ephemeral private/public key pair, derives a shared secret using Diffie-Hellman, and returns the shared secret along with the ephemeral public key
- For ML-KEM: Uses the KEM encapsulation algorithm to generate and encapsulate a random shared secret
§Returns
A tuple containing:
- The generated shared secret as a
SymmetricKey
- The encapsulation ciphertext that can be sent to the private key holder
§Example
use bc_components::EncapsulationScheme;
// Generate a key pair using the default scheme (X25519)
let (private_key, public_key) = EncapsulationScheme::default().keypair();
// Encapsulate a new shared secret
let (shared_secret, ciphertext) =
public_key.encapsulate_new_shared_secret();
// The private key holder can recover the same shared secret
let recovered_secret =
private_key.decapsulate_shared_secret(&ciphertext).unwrap();
assert_eq!(shared_secret, recovered_secret);
Trait Implementations§
Source§impl AsRef<EncapsulationPublicKey> for PublicKeys
impl AsRef<EncapsulationPublicKey> for PublicKeys
Source§fn as_ref(&self) -> &EncapsulationPublicKey
fn as_ref(&self) -> &EncapsulationPublicKey
Source§impl Clone for EncapsulationPublicKey
impl Clone for EncapsulationPublicKey
Source§fn clone(&self) -> EncapsulationPublicKey
fn clone(&self) -> EncapsulationPublicKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for EncapsulationPublicKey
impl Debug for EncapsulationPublicKey
Source§impl Encrypter for EncapsulationPublicKey
Implementation of the Encrypter
trait for EncapsulationPublicKey
.
impl Encrypter for EncapsulationPublicKey
Implementation of the Encrypter
trait for EncapsulationPublicKey
.
This allows EncapsulationPublicKey
to be used with the generic encryption
interface defined by the Encrypter
trait.
Source§fn encapsulation_public_key(&self) -> EncapsulationPublicKey
fn encapsulation_public_key(&self) -> EncapsulationPublicKey
Source§impl From<EncapsulationPublicKey> for CBOR
Conversion from EncapsulationPublicKey
to CBOR for serialization.
impl From<EncapsulationPublicKey> for CBOR
Conversion from EncapsulationPublicKey
to CBOR for serialization.
Source§fn from(public_key: EncapsulationPublicKey) -> Self
fn from(public_key: EncapsulationPublicKey) -> Self
Source§impl Hash for EncapsulationPublicKey
impl Hash for EncapsulationPublicKey
Source§impl PartialEq for EncapsulationPublicKey
impl PartialEq for EncapsulationPublicKey
Source§impl TryFrom<CBOR> for EncapsulationPublicKey
Conversion from CBOR to EncapsulationPublicKey
for deserialization.
impl TryFrom<CBOR> for EncapsulationPublicKey
Conversion from CBOR to EncapsulationPublicKey
for deserialization.