pub struct Kem { /* private fields */ }Expand description
KEM (Key Encapsulation Mechanism) subsystem.
Provides access to post-quantum key encapsulation operations using ML-KEM (formerly Kyber).
§Example
use quantacore::{initialize, open_first_device, KemAlgorithm};
initialize().unwrap();
let device = open_first_device().unwrap();
let kem = device.kem();
// Generate key pair
let keypair = kem.generate_keypair(KemAlgorithm::MlKem768).unwrap();
// Encapsulate (sender side)
let (ciphertext, sender_secret) = kem.encapsulate(
keypair.public_key(),
KemAlgorithm::MlKem768
).unwrap();
// Decapsulate (receiver side)
let receiver_secret = kem.decapsulate(
keypair.secret_key(),
&ciphertext,
KemAlgorithm::MlKem768
).unwrap();
assert_eq!(sender_secret, receiver_secret);Implementations§
Source§impl Kem
impl Kem
Sourcepub fn generate_keypair(&self, algorithm: KemAlgorithm) -> Result<KeyPair>
pub fn generate_keypair(&self, algorithm: KemAlgorithm) -> Result<KeyPair>
Sourcepub fn generate_keypair_512(&self) -> Result<KeyPair>
pub fn generate_keypair_512(&self) -> Result<KeyPair>
Generate ML-KEM-512 key pair.
Sourcepub fn generate_keypair_768(&self) -> Result<KeyPair>
pub fn generate_keypair_768(&self) -> Result<KeyPair>
Generate ML-KEM-768 key pair.
Sourcepub fn generate_keypair_1024(&self) -> Result<KeyPair>
pub fn generate_keypair_1024(&self) -> Result<KeyPair>
Generate ML-KEM-1024 key pair.
Sourcepub fn encapsulate(
&self,
public_key: &[u8],
algorithm: KemAlgorithm,
) -> Result<(Vec<u8>, Vec<u8>)>
pub fn encapsulate( &self, public_key: &[u8], algorithm: KemAlgorithm, ) -> Result<(Vec<u8>, Vec<u8>)>
Encapsulate to generate a shared secret and ciphertext.
This is the sender’s operation. The ciphertext should be sent to the recipient who can decapsulate using their secret key.
§Arguments
public_key- The recipient’s public keyalgorithm- The KEM algorithm to use
§Returns
A tuple of (ciphertext, shared_secret).
Sourcepub fn encapsulate_result(
&self,
public_key: &[u8],
algorithm: KemAlgorithm,
) -> Result<EncapsulationResult>
pub fn encapsulate_result( &self, public_key: &[u8], algorithm: KemAlgorithm, ) -> Result<EncapsulationResult>
Encapsulate returning an EncapsulationResult.
Sourcepub fn encapsulate_512(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>
pub fn encapsulate_512(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>
Encapsulate using ML-KEM-512.
Sourcepub fn encapsulate_768(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>
pub fn encapsulate_768(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>
Encapsulate using ML-KEM-768.
Sourcepub fn encapsulate_1024(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>
pub fn encapsulate_1024(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>
Encapsulate using ML-KEM-1024.
Sourcepub fn decapsulate(
&self,
secret_key: &[u8],
ciphertext: &[u8],
algorithm: KemAlgorithm,
) -> Result<Vec<u8>>
pub fn decapsulate( &self, secret_key: &[u8], ciphertext: &[u8], algorithm: KemAlgorithm, ) -> Result<Vec<u8>>
Decapsulate to recover the shared secret.
This is the recipient’s operation. Use the secret key and received ciphertext to recover the shared secret.
§Arguments
secret_key- The recipient’s secret keyciphertext- The ciphertext received from the senderalgorithm- The KEM algorithm to use
§Returns
The shared secret (same as the sender’s).
Sourcepub fn decapsulate_512(
&self,
secret_key: &[u8],
ciphertext: &[u8],
) -> Result<Vec<u8>>
pub fn decapsulate_512( &self, secret_key: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>>
Decapsulate using ML-KEM-512.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Kem
impl RefUnwindSafe for Kem
impl Send for Kem
impl Sync for Kem
impl Unpin for Kem
impl UnwindSafe for Kem
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)