pub struct MlDsa65PublicKey(/* private fields */);Expand description
ML-DSA-65 Public Key (1952 bytes).
Implementations§
Source§impl MlDsa65PublicKey
impl MlDsa65PublicKey
pub const fn from_bytes(bytes: [u8; 1952]) -> Self
Sourcepub fn as_bytes(&self) -> &[u8; 1952]
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
impl AsRef<[u8]> for MlDsa65PublicKey
Source§impl Clone for MlDsa65PublicKey
impl Clone for MlDsa65PublicKey
Source§fn clone(&self) -> MlDsa65PublicKey
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for MlDsa65PublicKey
Source§impl Debug for MlDsa65PublicKey
impl Debug for MlDsa65PublicKey
impl Eq for MlDsa65PublicKey
Source§impl PartialEq for MlDsa65PublicKey
impl PartialEq for MlDsa65PublicKey
impl StructuralPartialEq for MlDsa65PublicKey
Auto Trait Implementations§
impl Freeze for MlDsa65PublicKey
impl RefUnwindSafe for MlDsa65PublicKey
impl Send for MlDsa65PublicKey
impl Sync for MlDsa65PublicKey
impl Unpin for MlDsa65PublicKey
impl UnsafeUnpin for MlDsa65PublicKey
impl UnwindSafe for MlDsa65PublicKey
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