pub enum MLKEMPrivateKey {
MLKEM512(Box<SecretKey>),
MLKEM768(Box<SecretKey>),
MLKEM1024(Box<SecretKey>),
}
Expand description
A private key for the ML-KEM post-quantum key encapsulation mechanism.
MLKEMPrivateKey
represents a private key that can be used to decapsulate
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), 1632 bytesMLKEM768
: NIST security level 3 (roughly equivalent to AES-192), 2400 bytesMLKEM1024
: NIST security level 5 (roughly equivalent to AES-256), 3168 bytes
§Security
ML-KEM private keys should be kept secure and never exposed. They provide resistance against attacks from both classical and quantum computers.
§Examples
use bc_components::MLKEM;
// Generate a keypair
let (private_key, public_key) = MLKEM::MLKEM512.keypair();
// Party A encapsulates a shared secret using the public key
let (shared_secret_a, ciphertext) = public_key.encapsulate_new_shared_secret();
// Party B decapsulates the shared secret using the private key and ciphertext
let shared_secret_b = private_key.decapsulate_shared_secret(&ciphertext).unwrap();
// Both parties now have the same shared secret
assert_eq!(shared_secret_a, shared_secret_b);
Variants§
MLKEM512(Box<SecretKey>)
An ML-KEM-512 private key (NIST security level 1)
MLKEM768(Box<SecretKey>)
An ML-KEM-768 private key (NIST security level 3)
MLKEM1024(Box<SecretKey>)
An ML-KEM-1024 private key (NIST security level 5)
Implementations§
Source§impl MLKEMPrivateKey
impl MLKEMPrivateKey
Sourcepub fn from_bytes(level: MLKEM, bytes: &[u8]) -> Result<Self>
pub fn from_bytes(level: MLKEM, bytes: &[u8]) -> Result<Self>
Creates an ML-KEM private 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 MLKEMPrivateKey
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 private key for the specified security level.
Decapsulates a shared secret from a ciphertext using this private key.
§Parameters
ciphertext
- The ciphertext containing the encapsulated shared secret.
§Returns
A SymmetricKey
containing the decapsulated shared secret, or an error
if decapsulation fails.
§Errors
Returns an error if the security level of the ciphertext doesn’t match the security level of this private key, or if decapsulation fails for any other reason.
§Panics
Panics if the security level of the ciphertext doesn’t match the security level of this private key.
Trait Implementations§
Source§impl AsRef<[u8]> for MLKEMPrivateKey
impl AsRef<[u8]> for MLKEMPrivateKey
Source§impl CBORTagged for MLKEMPrivateKey
Defines CBOR tags for ML-KEM private keys.
impl CBORTagged for MLKEMPrivateKey
Defines CBOR tags for ML-KEM private keys.
Returns the CBOR tag for ML-KEM private keys.
Source§impl CBORTaggedDecodable for MLKEMPrivateKey
Implements CBOR decoding for ML-KEM private keys.
impl CBORTaggedDecodable for MLKEMPrivateKey
Implements CBOR decoding for ML-KEM private keys.
Source§fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
Creates an MLKEMPrivateKey
from untagged CBOR.
§Errors
Returns an error if the CBOR value doesn’t represent a valid ML-KEM private 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 MLKEMPrivateKey
Implements CBOR encoding for ML-KEM private keys.
impl CBORTaggedEncodable for MLKEMPrivateKey
Implements CBOR encoding for ML-KEM private 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 MLKEMPrivateKey
impl Clone for MLKEMPrivateKey
Source§fn clone(&self) -> MLKEMPrivateKey
fn clone(&self) -> MLKEMPrivateKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MLKEMPrivateKey
Provides debug formatting for ML-KEM private keys.
impl Debug for MLKEMPrivateKey
Provides debug formatting for ML-KEM private keys.
Source§impl Decrypter for MLKEMPrivateKey
Implements the Decrypter
trait for ML-KEM private keys.
impl Decrypter for MLKEMPrivateKey
Implements the Decrypter
trait for ML-KEM private keys.
Source§fn encapsulation_private_key(&self) -> EncapsulationPrivateKey
fn encapsulation_private_key(&self) -> EncapsulationPrivateKey
Returns this key as an EncapsulationPrivateKey
.
Source§impl From<MLKEMPrivateKey> for CBOR
Converts an MLKEMPrivateKey
to CBOR.
impl From<MLKEMPrivateKey> for CBOR
Converts an MLKEMPrivateKey
to CBOR.
Source§fn from(value: MLKEMPrivateKey) -> Self
fn from(value: MLKEMPrivateKey) -> Self
Converts to tagged CBOR.
Source§impl Hash for MLKEMPrivateKey
Implements hashing for ML-KEM private keys.
impl Hash for MLKEMPrivateKey
Implements hashing for ML-KEM private keys.
Source§impl PartialEq for MLKEMPrivateKey
impl PartialEq for MLKEMPrivateKey
Source§impl TryFrom<CBOR> for MLKEMPrivateKey
Attempts to convert CBOR to an MLKEMPrivateKey
.
impl TryFrom<CBOR> for MLKEMPrivateKey
Attempts to convert CBOR to an MLKEMPrivateKey
.
impl Eq for MLKEMPrivateKey
impl StructuralPartialEq for MLKEMPrivateKey
Auto Trait Implementations§
impl Freeze for MLKEMPrivateKey
impl RefUnwindSafe for MLKEMPrivateKey
impl Send for MLKEMPrivateKey
impl Sync for MLKEMPrivateKey
impl Unpin for MLKEMPrivateKey
impl UnwindSafe for MLKEMPrivateKey
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
)