Trait BatchScheme

Source
pub trait BatchScheme {
    type PublicKey: Array;
    type Signature: Array;

    // Required methods
    fn new() -> Self;
    fn add(
        &mut self,
        namespace: Option<&[u8]>,
        message: &[u8],
        public_key: &Self::PublicKey,
        signature: &Self::Signature,
    ) -> bool;
    fn verify<R: RngCore + CryptoRng>(self, rng: &mut R) -> bool;
}
Expand description

Interface that commonware crates rely on for batched cryptographic operations.

Required Associated Types§

Source

type PublicKey: Array

Public key used for verifying signatures.

Source

type Signature: Array

Signature generated by signing a message.

Required Methods§

Source

fn new() -> Self

Create a new batch scheme.

Source

fn add( &mut self, namespace: Option<&[u8]>, message: &[u8], public_key: &Self::PublicKey, signature: &Self::Signature, ) -> bool

Append item to the batch.

The message should not be hashed prior to calling this function. If a particular scheme requires a payload to be hashed before it is signed, it will be done internally.

A namespace should be used to prevent replay attacks. It will be prepended to the message so that a signature meant for one context cannot be used unexpectedly in another (i.e. signing a message on the network layer can’t accidentally spend funds on the execution layer). See union_unique for details.

Source

fn verify<R: RngCore + CryptoRng>(self, rng: &mut R) -> bool

Verify all items added to the batch.

Returns true if all items are valid, false otherwise.

§Why Randomness?

When performing batch verification, it is often important to add some randomness to prevent an attacker from constructing a malicious batch of signatures that pass batch verification but are invalid individually. Abstractly, think of this as there existing two valid signatures (c_1 and c_2) and an attacker proposing (c_1 + d and c_2 - d).

You can read more about this here.

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§