Kem

Struct Kem 

Source
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

Source

pub fn generate_keypair(&self, algorithm: KemAlgorithm) -> Result<KeyPair>

Generate a KEM key pair.

§Arguments
  • algorithm - The KEM algorithm to use
§Returns

A KeyPair containing the public and secret keys.

Source

pub fn generate_keypair_512(&self) -> Result<KeyPair>

Generate ML-KEM-512 key pair.

Source

pub fn generate_keypair_768(&self) -> Result<KeyPair>

Generate ML-KEM-768 key pair.

Source

pub fn generate_keypair_1024(&self) -> Result<KeyPair>

Generate ML-KEM-1024 key pair.

Source

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 key
  • algorithm - The KEM algorithm to use
§Returns

A tuple of (ciphertext, shared_secret).

Source

pub fn encapsulate_result( &self, public_key: &[u8], algorithm: KemAlgorithm, ) -> Result<EncapsulationResult>

Encapsulate returning an EncapsulationResult.

Source

pub fn encapsulate_512(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>

Encapsulate using ML-KEM-512.

Source

pub fn encapsulate_768(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>

Encapsulate using ML-KEM-768.

Source

pub fn encapsulate_1024(&self, public_key: &[u8]) -> Result<(Vec<u8>, Vec<u8>)>

Encapsulate using ML-KEM-1024.

Source

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 key
  • ciphertext - The ciphertext received from the sender
  • algorithm - The KEM algorithm to use
§Returns

The shared secret (same as the sender’s).

Source

pub fn decapsulate_512( &self, secret_key: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>>

Decapsulate using ML-KEM-512.

Source

pub fn decapsulate_768( &self, secret_key: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>>

Decapsulate using ML-KEM-768.

Source

pub fn decapsulate_1024( &self, secret_key: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>>

Decapsulate using ML-KEM-1024.

Trait Implementations§

Source§

impl Clone for Kem

Source§

fn clone(&self) -> Kem

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Kem

Source§

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

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.