pub enum MLDSAPublicKey {
MLDSA44(Box<PublicKey>),
MLDSA65(Box<PublicKey>),
MLDSA87(Box<PublicKey>),
}
Expand description
A public key for the ML-DSA post-quantum digital signature algorithm.
MLDSAPublicKey
represents a public key that can be used to verify digital
signatures created with 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)
§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);
// Verify the signature
assert!(public_key.verify(&signature, message).unwrap());
Variants§
MLDSA44(Box<PublicKey>)
An ML-DSA44 public key (NIST security level 2)
MLDSA65(Box<PublicKey>)
An ML-DSA65 public key (NIST security level 3)
MLDSA87(Box<PublicKey>)
An ML-DSA87 public key (NIST security level 5)
Implementations§
Source§impl MLDSAPublicKey
impl MLDSAPublicKey
Sourcepub fn verify(
&self,
signature: &MLDSASignature,
message: impl AsRef<[u8]>,
) -> Result<bool>
pub fn verify( &self, signature: &MLDSASignature, message: impl AsRef<[u8]>, ) -> Result<bool>
Verifies an ML-DSA signature for a message using this public key.
§Parameters
signature
- The signature to verify.message
- The message that was signed.
§Returns
Ok(true)
if the signature is valid for the message and this public
key, Ok(false)
if the signature is invalid, or an error if the
security levels of the signature and public key don’t match.
§Errors
Returns an error if the security level of the signature doesn’t match the security level of this public key.
§Examples
use bc_components::MLDSA;
let (private_key, public_key) = MLDSA::MLDSA44.keypair();
let message = b"Hello, world!";
let signature = private_key.sign(message);
assert!(public_key.verify(&signature, message).unwrap());
Sourcepub fn from_bytes(level: MLDSA, bytes: &[u8]) -> Result<Self>
pub fn from_bytes(level: MLDSA, bytes: &[u8]) -> Result<Self>
Creates an ML-DSA 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 MLDSAPublicKey
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 public key for the specified security level.
Trait Implementations§
Source§impl AsRef<[u8]> for MLDSAPublicKey
impl AsRef<[u8]> for MLDSAPublicKey
Source§impl CBORTagged for MLDSAPublicKey
Defines CBOR tags for ML-DSA public keys.
impl CBORTagged for MLDSAPublicKey
Defines CBOR tags for ML-DSA public keys.
Returns the CBOR tag for ML-DSA public keys.
Source§impl CBORTaggedDecodable for MLDSAPublicKey
Implements CBOR decoding for ML-DSA public keys.
impl CBORTaggedDecodable for MLDSAPublicKey
Implements CBOR decoding for ML-DSA public keys.
Source§fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
Creates an MLDSAPublicKey
from untagged CBOR.
§Errors
Returns an error if the CBOR value doesn’t represent a valid ML-DSA 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 MLDSAPublicKey
Implements CBOR encoding for ML-DSA public keys.
impl CBORTaggedEncodable for MLDSAPublicKey
Implements CBOR encoding for ML-DSA 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 MLDSAPublicKey
impl Clone for MLDSAPublicKey
Source§fn clone(&self) -> MLDSAPublicKey
fn clone(&self) -> MLDSAPublicKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MLDSAPublicKey
Provides debug formatting for ML-DSA public keys.
impl Debug for MLDSAPublicKey
Provides debug formatting for ML-DSA public keys.
Source§impl From<MLDSAPublicKey> for CBOR
Converts an MLDSAPublicKey
to CBOR.
impl From<MLDSAPublicKey> for CBOR
Converts an MLDSAPublicKey
to CBOR.
Source§fn from(value: MLDSAPublicKey) -> Self
fn from(value: MLDSAPublicKey) -> Self
Converts to tagged CBOR.
Source§impl Hash for MLDSAPublicKey
Implements hashing for ML-DSA public keys.
impl Hash for MLDSAPublicKey
Implements hashing for ML-DSA public keys.
Source§impl PartialEq for MLDSAPublicKey
Implements equality comparison for ML-DSA public keys.
impl PartialEq for MLDSAPublicKey
Implements equality comparison for ML-DSA public keys.
Source§impl TryFrom<CBOR> for MLDSAPublicKey
Attempts to convert CBOR to an MLDSAPublicKey
.
impl TryFrom<CBOR> for MLDSAPublicKey
Attempts to convert CBOR to an MLDSAPublicKey
.
impl Eq for MLDSAPublicKey
Auto Trait Implementations§
impl Freeze for MLDSAPublicKey
impl RefUnwindSafe for MLDSAPublicKey
impl Send for MLDSAPublicKey
impl Sync for MLDSAPublicKey
impl Unpin for MLDSAPublicKey
impl UnwindSafe for MLDSAPublicKey
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
)