pub enum MLKEMCiphertext {
MLKEM512(Box<Ciphertext>),
MLKEM768(Box<Ciphertext>),
MLKEM1024(Box<Ciphertext>),
}
Expand description
A ciphertext containing an encapsulated shared secret for ML-KEM.
MLKEMCiphertext
represents a ciphertext produced by the ML-KEM
(Module Lattice-based Key Encapsulation Mechanism) post-quantum algorithm
during the encapsulation process. It contains an encapsulated shared secret
that can only be recovered by the corresponding private key.
It supports multiple security levels through the variants:
MLKEM512
: NIST security level 1 (roughly equivalent to AES-128), 768 bytesMLKEM768
: NIST security level 3 (roughly equivalent to AES-192), 1088 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_a, ciphertext) =
public_key.encapsulate_new_shared_secret();
// Decapsulate the shared secret using the private key
let shared_secret_b =
private_key.decapsulate_shared_secret(&ciphertext).unwrap();
// Both shared secrets should be the same
assert_eq!(shared_secret_a, shared_secret_b);
Variants§
MLKEM512(Box<Ciphertext>)
An ML-KEM-512 ciphertext (NIST security level 1)
MLKEM768(Box<Ciphertext>)
An ML-KEM-768 ciphertext (NIST security level 3)
MLKEM1024(Box<Ciphertext>)
An ML-KEM-1024 ciphertext (NIST security level 5)
Implementations§
Source§impl MLKEMCiphertext
impl MLKEMCiphertext
Sourcepub fn from_bytes(level: MLKEM, bytes: &[u8]) -> Result<Self>
pub fn from_bytes(level: MLKEM, bytes: &[u8]) -> Result<Self>
Creates an ML-KEM ciphertext from raw bytes and a security level.
§Parameters
level
- The security level of the ciphertext.bytes
- The raw bytes of the ciphertext.
§Returns
An MLKEMCiphertext
if the bytes represent a valid ciphertext for the
given level, or an error otherwise.
§Errors
Returns an error if the bytes do not represent a valid ML-KEM ciphertext for the specified security level.
Trait Implementations§
Source§impl AsRef<[u8]> for MLKEMCiphertext
impl AsRef<[u8]> for MLKEMCiphertext
Source§impl CBORTagged for MLKEMCiphertext
Defines CBOR tags for ML-KEM ciphertexts.
impl CBORTagged for MLKEMCiphertext
Defines CBOR tags for ML-KEM ciphertexts.
Returns the CBOR tag for ML-KEM ciphertexts.
Source§impl CBORTaggedDecodable for MLKEMCiphertext
Implements CBOR decoding for ML-KEM ciphertexts.
impl CBORTaggedDecodable for MLKEMCiphertext
Implements CBOR decoding for ML-KEM ciphertexts.
Source§fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
Creates an MLKEMCiphertext
from untagged CBOR.
§Errors
Returns an error if the CBOR value doesn’t represent a valid ML-KEM ciphertext.
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 MLKEMCiphertext
Implements CBOR encoding for ML-KEM ciphertexts.
impl CBORTaggedEncodable for MLKEMCiphertext
Implements CBOR encoding for ML-KEM ciphertexts.
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Creates the untagged CBOR representation as an array with level and ciphertext bytes.
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Clone for MLKEMCiphertext
impl Clone for MLKEMCiphertext
Source§fn clone(&self) -> MLKEMCiphertext
fn clone(&self) -> MLKEMCiphertext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MLKEMCiphertext
Provides debug formatting for ML-KEM ciphertexts.
impl Debug for MLKEMCiphertext
Provides debug formatting for ML-KEM ciphertexts.
Source§impl From<MLKEMCiphertext> for CBOR
Converts an MLKEMCiphertext
to CBOR.
impl From<MLKEMCiphertext> for CBOR
Converts an MLKEMCiphertext
to CBOR.
Source§fn from(value: MLKEMCiphertext) -> Self
fn from(value: MLKEMCiphertext) -> Self
Converts to tagged CBOR.
Source§impl PartialEq for MLKEMCiphertext
impl PartialEq for MLKEMCiphertext
Source§impl TryFrom<CBOR> for MLKEMCiphertext
Attempts to convert CBOR to an MLKEMCiphertext
.
impl TryFrom<CBOR> for MLKEMCiphertext
Attempts to convert CBOR to an MLKEMCiphertext
.
impl StructuralPartialEq for MLKEMCiphertext
Auto Trait Implementations§
impl Freeze for MLKEMCiphertext
impl RefUnwindSafe for MLKEMCiphertext
impl Send for MLKEMCiphertext
impl Sync for MLKEMCiphertext
impl Unpin for MLKEMCiphertext
impl UnwindSafe for MLKEMCiphertext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)