pub enum MLKEMPublicKey {
MLKEM512(Box<PublicKey>),
MLKEM768(Box<PublicKey>),
MLKEM1024(Box<PublicKey>),
}Expand description
A public key for the ML-KEM post-quantum key encapsulation mechanism.
MLKEMPublicKey represents a public key that can be used to encapsulate shared secrets
using the ML-KEM (Module Lattice-based Key Encapsulation Mechanism) post-quantum algorithm.
It supports multiple security levels through the variants:
MLKEM512: NIST security level 1 (roughly equivalent to AES-128), 800 bytesMLKEM768: NIST security level 3 (roughly equivalent to AES-192), 1184 bytesMLKEM1024: NIST security level 5 (roughly equivalent to AES-256), 1568 bytes
§Examples
use bc_components::MLKEM;
// Generate a keypair
let (private_key, public_key) = MLKEM::MLKEM512.keypair();
// Encapsulate a shared secret using the public key
let (shared_secret, ciphertext) = public_key.encapsulate_new_shared_secret();Variants§
MLKEM512(Box<PublicKey>)
An ML-KEM-512 public key (NIST security level 1)
MLKEM768(Box<PublicKey>)
An ML-KEM-768 public key (NIST security level 3)
MLKEM1024(Box<PublicKey>)
An ML-KEM-1024 public key (NIST security level 5)
Implementations§
Source§impl MLKEMPublicKey
impl MLKEMPublicKey
Sourcepub fn from_bytes(level: MLKEM, bytes: &[u8]) -> Result<Self>
pub fn from_bytes(level: MLKEM, bytes: &[u8]) -> Result<Self>
Creates an ML-KEM public key from raw bytes and a security level.
§Parameters
level- The security level of the key.bytes- The raw bytes of the key.
§Returns
An MLKEMPublicKey if the bytes represent a valid key for the given level,
or an error otherwise.
§Errors
Returns an error if the bytes do not represent a valid ML-KEM public key for the specified security level.
Encapsulates a new shared secret using this public key.
This method generates a random shared secret and encapsulates it using this public key, producing a ciphertext that can only be decapsulated by the corresponding private key.
§Returns
A tuple containing:
- A
SymmetricKeywith the shared secret (32 bytes) - An
MLKEMCiphertextwith the encapsulated shared secret
§Examples
use bc_components::MLKEM;
// Generate a keypair
let (private_key, public_key) = MLKEM::MLKEM512.keypair();
// Encapsulate a shared secret
let (shared_secret, ciphertext) = public_key.encapsulate_new_shared_secret();
// The private key holder can decapsulate the same shared secret
let decapsulated_secret = private_key.decapsulate_shared_secret(&ciphertext).unwrap();
assert_eq!(shared_secret, decapsulated_secret);Trait Implementations§
Source§impl CBORTagged for MLKEMPublicKey
Defines CBOR tags for ML-KEM public keys.
impl CBORTagged for MLKEMPublicKey
Defines CBOR tags for ML-KEM public keys.
Returns the CBOR tag for ML-KEM public keys.
Source§impl CBORTaggedDecodable for MLKEMPublicKey
Implements CBOR decoding for ML-KEM public keys.
impl CBORTaggedDecodable for MLKEMPublicKey
Implements CBOR decoding for ML-KEM public keys.
Source§fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
Creates an MLKEMPublicKey from untagged CBOR.
§Errors
Returns an error if the CBOR value doesn’t represent a valid ML-KEM public key.
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for MLKEMPublicKey
Implements CBOR encoding for ML-KEM public keys.
impl CBORTaggedEncodable for MLKEMPublicKey
Implements CBOR encoding for ML-KEM public keys.
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Creates the untagged CBOR representation as an array with level and key bytes.
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Clone for MLKEMPublicKey
impl Clone for MLKEMPublicKey
Source§fn clone(&self) -> MLKEMPublicKey
fn clone(&self) -> MLKEMPublicKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MLKEMPublicKey
Provides debug formatting for ML-KEM public keys.
impl Debug for MLKEMPublicKey
Provides debug formatting for ML-KEM public keys.
Source§impl From<MLKEMPublicKey> for CBOR
Converts an MLKEMPublicKey to CBOR.
impl From<MLKEMPublicKey> for CBOR
Converts an MLKEMPublicKey to CBOR.
Source§fn from(value: MLKEMPublicKey) -> Self
fn from(value: MLKEMPublicKey) -> Self
Converts to tagged CBOR.
Source§impl Hash for MLKEMPublicKey
Implements hashing for ML-KEM public keys.
impl Hash for MLKEMPublicKey
Implements hashing for ML-KEM public keys.
Source§impl PartialEq for MLKEMPublicKey
Implements equality comparison for ML-KEM public keys.
impl PartialEq for MLKEMPublicKey
Implements equality comparison for ML-KEM public keys.
Source§impl TryFrom<CBOR> for MLKEMPublicKey
Attempts to convert CBOR to an MLKEMPublicKey.
impl TryFrom<CBOR> for MLKEMPublicKey
Attempts to convert CBOR to an MLKEMPublicKey.