pub struct MlDsa65SecretKey(/* private fields */);Expand description
ML-DSA-65 Secret Key (4032 bytes).
Automatically cleansed from memory on drop.
Implementations§
Source§impl MlDsa65SecretKey
impl MlDsa65SecretKey
pub const fn from_bytes(bytes: [u8; 4032]) -> Self
Sourcepub fn as_bytes(&self) -> &[u8; 4032]
pub fn as_bytes(&self) -> &[u8; 4032]
Examples found in repository?
examples/dsa_sign.rs (line 32)
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 MlDsa65SecretKey
impl AsRef<[u8]> for MlDsa65SecretKey
Source§impl Clone for MlDsa65SecretKey
impl Clone for MlDsa65SecretKey
Source§fn clone(&self) -> MlDsa65SecretKey
fn clone(&self) -> MlDsa65SecretKey
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MlDsa65SecretKey
impl Debug for MlDsa65SecretKey
Source§impl Drop for MlDsa65SecretKey
impl Drop for MlDsa65SecretKey
impl Eq for MlDsa65SecretKey
Source§impl PartialEq for MlDsa65SecretKey
impl PartialEq for MlDsa65SecretKey
impl StructuralPartialEq for MlDsa65SecretKey
Auto Trait Implementations§
impl Freeze for MlDsa65SecretKey
impl RefUnwindSafe for MlDsa65SecretKey
impl Send for MlDsa65SecretKey
impl Sync for MlDsa65SecretKey
impl Unpin for MlDsa65SecretKey
impl UnsafeUnpin for MlDsa65SecretKey
impl UnwindSafe for MlDsa65SecretKey
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
Mutably borrows from an owned value. Read more