Trait Signature

Source
pub trait Signature {
    type PublicKey: AsRef<[u8]> + AsMut<[u8]> + Clone;
    type SecretKey: Zeroize + AsRef<[u8]> + AsMut<[u8]> + Clone;
    type SignatureData: AsRef<[u8]> + AsMut<[u8]> + Clone;
    type KeyPair: Clone;

    // Required methods
    fn name() -> &'static str;
    fn keypair<R: CryptoRng + RngCore>(rng: &mut R) -> Result<Self::KeyPair>;
    fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey;
    fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey;
    fn sign(
        message: &[u8],
        secret_key: &Self::SecretKey,
    ) -> Result<Self::SignatureData>;
    fn verify(
        message: &[u8],
        signature: &Self::SignatureData,
        public_key: &Self::PublicKey,
    ) -> Result<()>;

    // Provided methods
    fn batch_sign(
        messages: &[&[u8]],
        secret_key: &Self::SecretKey,
    ) -> Result<Vec<Self::SignatureData>> { ... }
    fn batch_verify(
        message_signature_pairs: &[(&[u8], &Self::SignatureData)],
        public_key: &Self::PublicKey,
    ) -> Result<()> { ... }
}
Expand description

Trait for digital signature schemes with domain-specific types

Required Associated Types§

Source

type PublicKey: AsRef<[u8]> + AsMut<[u8]> + Clone

Public key type

Source

type SecretKey: Zeroize + AsRef<[u8]> + AsMut<[u8]> + Clone

Secret key type with security guarantees

Source

type SignatureData: AsRef<[u8]> + AsMut<[u8]> + Clone

Signature type

Source

type KeyPair: Clone

Keypair type for efficient storage of related keys

Required Methods§

Source

fn name() -> &'static str

Returns the signature algorithm name

Source

fn keypair<R: CryptoRng + RngCore>(rng: &mut R) -> Result<Self::KeyPair>

Generate a new keypair

Source

fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey

Extract public key from keypair

Source

fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey

Extract secret key from keypair

Source

fn sign( message: &[u8], secret_key: &Self::SecretKey, ) -> Result<Self::SignatureData>

Sign a message using the secret key

Source

fn verify( message: &[u8], signature: &Self::SignatureData, public_key: &Self::PublicKey, ) -> Result<()>

Verify a signature on a message using the public key

Provided Methods§

Source

fn batch_sign( messages: &[&[u8]], secret_key: &Self::SecretKey, ) -> Result<Vec<Self::SignatureData>>

Sign multiple messages in batch (may be more efficient for some algorithms)

Source

fn batch_verify( message_signature_pairs: &[(&[u8], &Self::SignatureData)], public_key: &Self::PublicKey, ) -> Result<()>

Verify multiple signatures in batch (may be more efficient for some algorithms)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§