pub trait Decrypter {
// Required method
fn encapsulation_private_key(&self) -> EncapsulationPrivateKey;
// Provided method
fn decapsulate_shared_secret(
&self,
ciphertext: &EncapsulationCiphertext,
) -> Result<SymmetricKey> { ... }
}Expand description
A trait for types that can decapsulate shared secrets for public key decryption.
The Decrypter trait defines an interface for decapsulating (recovering) a
shared secret using a private key. This is the counterpart to the
Encrypter trait and is used by the recipient of encapsulated messages.
Types implementing this trait provide the ability to:
- Access their encapsulation private key
- Decapsulate shared secrets from ciphertexts
This trait is typically implemented by:
- Encapsulation private keys
- Higher-level types that contain or can access encapsulation private keys
Required Methods§
Sourcefn encapsulation_private_key(&self) -> EncapsulationPrivateKey
fn encapsulation_private_key(&self) -> EncapsulationPrivateKey
Returns the encapsulation private key for this decrypter.
§Returns
The encapsulation private key that should be used for decapsulation.
Provided Methods§
Decapsulates a shared secret from a ciphertext.
This method recovers the shared secret that was encapsulated in the given ciphertext, using the private key from this decrypter.
§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.
§Errors
Returns an error if:
- The ciphertext type doesn’t match the private key type
- The decapsulation operation fails
§Example
use bc_components::{Decrypter, EncapsulationScheme, Encrypter};
// Generate a keypair
let (private_key, public_key) = EncapsulationScheme::default().keypair();
// Encapsulate a new shared secret
let (original_secret, ciphertext) =
public_key.encapsulate_new_shared_secret();
// Decapsulate the shared secret
let recovered_secret =
private_key.decapsulate_shared_secret(&ciphertext).unwrap();
// The original and recovered secrets should match
assert_eq!(original_secret, recovered_secret);Implementors§
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.
impl Decrypter for MLKEMPrivateKey
Implements the Decrypter trait for ML-KEM private keys.
impl Decrypter for PrivateKeyBase
impl Decrypter for PrivateKeys
impl Decrypter for X25519PrivateKey
Implements the Decrypter trait to support key encapsulation mechanisms.