Skip to main content

MlDsa65PublicKey

Struct MlDsa65PublicKey 

Source
pub struct MlDsa65PublicKey(/* private fields */);
Expand description

ML-DSA-65 Public Key (1952 bytes).

Implementations§

Source§

impl MlDsa65PublicKey

Source

pub const fn from_bytes(bytes: [u8; 1952]) -> Self

Source

pub fn as_bytes(&self) -> &[u8; 1952]

Examples found in repository?
examples/dsa_sign.rs (line 28)
20fn main() {
21    println!("Rivide Rust: ML-DSA-65 Digital Signature Demonstration");
22
23    // 1. Generate signing keypair
24    println!("\n[Signer] Generating ML-DSA-65 signature keypair...");
25    let signer = MlDsa65::keypair().expect("Failed to generate signer keypair");
26    println!(
27        "  Public Key : {} bytes",
28        signer.public_key.as_bytes().len()
29    );
30    println!(
31        "  Secret Key : {} bytes",
32        signer.secret_key.as_bytes().len()
33    );
34
35    // 2. Sign arbitrary message payload
36    let message = b"Post-quantum signed contract payload: Transfer $100,000 to Bob.";
37    println!(
38        "\n[Signer] Signing message: \"{}\"...",
39        std::str::from_utf8(message).unwrap()
40    );
41    let signature = MlDsa65::sign(message, &signer.secret_key).expect("Failed to sign message");
42    println!("  Signature  : {} bytes", signature.as_bytes().len());
43
44    // 3. [Verifier] Verify signature authenticity
45    println!("\n[Verifier] Verifying signature against public key...");
46    let is_valid = MlDsa65::verify(&signature, message, &signer.public_key);
47    if is_valid {
48        println!("[SUCCESS] Signature is VALID and AUTHENTIC!");
49    } else {
50        panic!("FATAL: Signature verification failed!");
51    }
52
53    // 4. [Verifier] Test tamper rejection
54    let tampered_msg = b"Post-quantum signed contract payload: Transfer $1,000,000 to Bob.";
55    println!(
56        "\n[Verifier] Testing tampered message: \"{}\"...",
57        std::str::from_utf8(tampered_msg).unwrap()
58    );
59    let is_tampered_valid = MlDsa65::verify(&signature, tampered_msg, &signer.public_key);
60    if !is_tampered_valid {
61        println!("[SUCCESS] Tampered message correctly REJECTED!");
62    } else {
63        panic!("FATAL: Tampered message was incorrectly accepted!");
64    }
65}

Trait Implementations§

Source§

impl AsRef<[u8]> for MlDsa65PublicKey

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for MlDsa65PublicKey

Source§

fn clone(&self) -> MlDsa65PublicKey

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MlDsa65PublicKey

Source§

impl Debug for MlDsa65PublicKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MlDsa65PublicKey

Source§

impl PartialEq for MlDsa65PublicKey

Source§

fn eq(&self, other: &MlDsa65PublicKey) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MlDsa65PublicKey

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.