MLKEM

Enum MLKEM 

Source
#[repr(u32)]
pub enum MLKEM { MLKEM512 = 512, MLKEM768 = 768, MLKEM1024 = 1_024, }
Expand description

Security levels for the ML-KEM post-quantum key encapsulation mechanism.

ML-KEM (Module Lattice-based Key Encapsulation Mechanism) is a post-quantum key encapsulation mechanism standardized by NIST. It provides resistance against attacks from both classical and quantum computers.

Each security level offers different trade-offs between security, performance, and key/ciphertext sizes:

  • MLKEM512: NIST security level 1 (roughly equivalent to AES-128)
  • MLKEM768: NIST security level 3 (roughly equivalent to AES-192)
  • MLKEM1024: NIST security level 5 (roughly equivalent to AES-256)

The numeric values (512, 768, 1024) correspond to the parameter sets and are used in CBOR serialization.

Variants§

§

MLKEM512 = 512

ML-KEM-512 (NIST security level 1, roughly equivalent to AES-128)

§

MLKEM768 = 768

ML-KEM-768 (NIST security level 3, roughly equivalent to AES-192)

§

MLKEM1024 = 1_024

ML-KEM-1024 (NIST security level 5, roughly equivalent to AES-256)

Implementations§

Source§

impl MLKEM

Source

pub const SHARED_SECRET_SIZE: usize = 32usize

The size of a shared secret in bytes (32 bytes for all security levels).

Source

pub fn keypair(self) -> (MLKEMPrivateKey, MLKEMPublicKey)

Generates a new ML-KEM keypair with the specified security level.

§Returns

A tuple containing the private key and public key.

§Examples
use bc_components::MLKEM;

let (private_key, public_key) = MLKEM::MLKEM512.keypair();
Source

pub fn private_key_size(&self) -> usize

Returns the size of a private key in bytes for this security level.

§Returns
  • MLKEM512: 1632 bytes
  • MLKEM768: 2400 bytes
  • MLKEM1024: 3168 bytes
Source

pub fn public_key_size(&self) -> usize

Returns the size of a public key in bytes for this security level.

§Returns
  • MLKEM512: 800 bytes
  • MLKEM768: 1184 bytes
  • MLKEM1024: 1568 bytes
Source

pub fn shared_secret_size(&self) -> usize

Returns the size of a shared secret in bytes for this security level.

This is 32 bytes for all security levels.

Source

pub fn ciphertext_size(&self) -> usize

Returns the size of a ciphertext in bytes for this security level.

§Returns
  • MLKEM512: 768 bytes
  • MLKEM768: 1088 bytes
  • MLKEM1024: 1568 bytes

Trait Implementations§

Source§

impl Clone for MLKEM

Source§

fn clone(&self) -> MLKEM

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 MLKEM

Source§

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

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

impl From<MLKEM> for CBOR

Converts an MLKEM value to CBOR.

Source§

fn from(mlkem: MLKEM) -> Self

Converts to the numeric security level value (512, 768, or 1024).

Source§

impl Hash for MLKEM

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 MLKEM

Source§

fn eq(&self, other: &MLKEM) -> 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 MLKEM

Attempts to convert CBOR to an MLKEM value.

Source§

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

Converts from a CBOR-encoded security level (512, 768, or 1024).

§Errors

Returns an error if the CBOR value doesn’t represent a valid ML-KEM level.

Source§

type Error = Error

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

impl Copy for MLKEM

Source§

impl Eq for MLKEM

Source§

impl StructuralPartialEq for MLKEM

Auto Trait Implementations§

§

impl Freeze for MLKEM

§

impl RefUnwindSafe for MLKEM

§

impl Send for MLKEM

§

impl Sync for MLKEM

§

impl Unpin for MLKEM

§

impl UnwindSafe for MLKEM

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> 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> ErasedDestructor for T
where T: 'static,