Sign

Struct Sign 

Source
pub struct Sign { /* private fields */ }
Expand description

Signature subsystem.

Provides access to post-quantum digital signature operations using ML-DSA (formerly Dilithium).

§Example

use quantacore::{initialize, open_first_device, SignAlgorithm};

initialize().unwrap();
let device = open_first_device().unwrap();
let sign = device.sign();

// Generate key pair
let keypair = sign.generate_keypair(SignAlgorithm::MlDsa65).unwrap();

// Sign a message
let message = b"Hello, quantum world!";
let signature = sign.sign(keypair.secret_key(), message, SignAlgorithm::MlDsa65).unwrap();

// Verify the signature
let valid = sign.verify(keypair.public_key(), message, &signature, SignAlgorithm::MlDsa65).unwrap();
assert!(valid);

Implementations§

Source§

impl Sign

Source

pub fn generate_keypair( &self, algorithm: SignAlgorithm, ) -> Result<SignatureKeyPair>

Generate a signature key pair.

§Arguments
  • algorithm - The signature algorithm to use
§Returns

A SignatureKeyPair containing the public and secret keys.

Source

pub fn generate_keypair_44(&self) -> Result<SignatureKeyPair>

Generate ML-DSA-44 key pair.

Source

pub fn generate_keypair_65(&self) -> Result<SignatureKeyPair>

Generate ML-DSA-65 key pair.

Source

pub fn generate_keypair_87(&self) -> Result<SignatureKeyPair>

Generate ML-DSA-87 key pair.

Source

pub fn sign( &self, secret_key: &[u8], message: &[u8], algorithm: SignAlgorithm, ) -> Result<Vec<u8>>

Sign a message.

§Arguments
  • secret_key - The signer’s secret key
  • message - The message to sign
  • algorithm - The signature algorithm to use
§Returns

The digital signature.

Source

pub fn sign_44(&self, secret_key: &[u8], message: &[u8]) -> Result<Vec<u8>>

Sign using ML-DSA-44.

Source

pub fn sign_65(&self, secret_key: &[u8], message: &[u8]) -> Result<Vec<u8>>

Sign using ML-DSA-65.

Source

pub fn sign_87(&self, secret_key: &[u8], message: &[u8]) -> Result<Vec<u8>>

Sign using ML-DSA-87.

Source

pub fn sign_str( &self, secret_key: &[u8], message: &str, algorithm: SignAlgorithm, ) -> Result<Vec<u8>>

Sign a string message.

Source

pub fn verify( &self, public_key: &[u8], message: &[u8], signature: &[u8], algorithm: SignAlgorithm, ) -> Result<bool>

Verify a signature.

§Arguments
  • public_key - The signer’s public key
  • message - The original message
  • signature - The signature to verify
  • algorithm - The signature algorithm to use
§Returns

true if the signature is valid, false otherwise.

Source

pub fn verify_44( &self, public_key: &[u8], message: &[u8], signature: &[u8], ) -> Result<bool>

Verify using ML-DSA-44.

Source

pub fn verify_65( &self, public_key: &[u8], message: &[u8], signature: &[u8], ) -> Result<bool>

Verify using ML-DSA-65.

Source

pub fn verify_87( &self, public_key: &[u8], message: &[u8], signature: &[u8], ) -> Result<bool>

Verify using ML-DSA-87.

Source

pub fn verify_str( &self, public_key: &[u8], message: &str, signature: &[u8], algorithm: SignAlgorithm, ) -> Result<bool>

Verify a string message.

Source

pub fn verify_or_error( &self, public_key: &[u8], message: &[u8], signature: &[u8], algorithm: SignAlgorithm, ) -> Result<()>

Verify a signature, returning an error if invalid.

Unlike verify() which returns a boolean, this method returns an error if verification fails, making it suitable for use with ?.

Trait Implementations§

Source§

impl Clone for Sign

Source§

fn clone(&self) -> Sign

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Sign

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Sign

§

impl RefUnwindSafe for Sign

§

impl Send for Sign

§

impl Sync for Sign

§

impl Unpin for Sign

§

impl UnwindSafe for Sign

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.