pub enum MLDSAPrivateKey {
MLDSA44(Box<SecretKey>),
MLDSA65(Box<SecretKey>),
MLDSA87(Box<SecretKey>),
}Expand description
A private key for the ML-DSA post-quantum digital signature algorithm.
MLDSAPrivateKey represents a private key that can be used to create digital
signatures using the ML-DSA (Module Lattice-based Digital Signature Algorithm)
post-quantum algorithm. It supports multiple security levels through the variants:
MLDSA44: NIST security level 2 (roughly equivalent to AES-128)MLDSA65: NIST security level 3 (roughly equivalent to AES-192)MLDSA87: NIST security level 5 (roughly equivalent to AES-256)
§Security
ML-DSA private keys should be kept secure and never exposed. They provide resistance against attacks from both classical and quantum computers.
§Examples
use bc_components::MLDSA;
// Generate a keypair
let (private_key, public_key) = MLDSA::MLDSA44.keypair();
// Sign a message
let message = b"Hello, post-quantum world!";
let signature = private_key.sign(message);Variants§
MLDSA44(Box<SecretKey>)
An ML-DSA44 private key (NIST security level 2)
MLDSA65(Box<SecretKey>)
An ML-DSA65 private key (NIST security level 3)
MLDSA87(Box<SecretKey>)
An ML-DSA87 private key (NIST security level 5)
Implementations§
Source§impl MLDSAPrivateKey
impl MLDSAPrivateKey
Sourcepub fn sign(&self, message: impl AsRef<[u8]>) -> MLDSASignature
pub fn sign(&self, message: impl AsRef<[u8]>) -> MLDSASignature
Signs a message using this ML-DSA private key.
§Parameters
message- The message to sign.
§Returns
An MLDSASignature for the message, using the same security level as this private key.
§Examples
use bc_components::MLDSA;
let (private_key, _) = MLDSA::MLDSA44.keypair();
let message = b"Hello, world!";
let signature = private_key.sign(message);Sourcepub fn from_bytes(level: MLDSA, bytes: &[u8]) -> Result<Self>
pub fn from_bytes(level: MLDSA, bytes: &[u8]) -> Result<Self>
Creates an ML-DSA 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 MLDSAPrivateKey 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-DSA private key for the specified security level.
Trait Implementations§
Source§impl CBORTagged for MLDSAPrivateKey
Defines CBOR tags for ML-DSA private keys.
impl CBORTagged for MLDSAPrivateKey
Defines CBOR tags for ML-DSA private keys.
Returns the CBOR tag for ML-DSA private keys.
Source§impl CBORTaggedDecodable for MLDSAPrivateKey
Implements CBOR decoding for ML-DSA private keys.
impl CBORTaggedDecodable for MLDSAPrivateKey
Implements CBOR decoding for ML-DSA private keys.
Source§fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
Creates an MLDSAPrivateKey from untagged CBOR.
§Errors
Returns an error if the CBOR value doesn’t represent a valid ML-DSA 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 MLDSAPrivateKey
Implements CBOR encoding for ML-DSA private keys.
impl CBORTaggedEncodable for MLDSAPrivateKey
Implements CBOR encoding for ML-DSA 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 MLDSAPrivateKey
impl Clone for MLDSAPrivateKey
Source§fn clone(&self) -> MLDSAPrivateKey
fn clone(&self) -> MLDSAPrivateKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MLDSAPrivateKey
Provides debug formatting for ML-DSA private keys.
impl Debug for MLDSAPrivateKey
Provides debug formatting for ML-DSA private keys.
Source§impl From<MLDSAPrivateKey> for CBOR
Converts an MLDSAPrivateKey to CBOR.
impl From<MLDSAPrivateKey> for CBOR
Converts an MLDSAPrivateKey to CBOR.
Source§fn from(value: MLDSAPrivateKey) -> Self
fn from(value: MLDSAPrivateKey) -> Self
Converts to tagged CBOR.
Source§impl PartialEq for MLDSAPrivateKey
impl PartialEq for MLDSAPrivateKey
Source§impl TryFrom<CBOR> for MLDSAPrivateKey
Attempts to convert CBOR to an MLDSAPrivateKey.
impl TryFrom<CBOR> for MLDSAPrivateKey
Attempts to convert CBOR to an MLDSAPrivateKey.