[][src]Struct schnorr::signature::Signature

pub struct Signature { /* fields omitted */ }

An Schnorr signature.

Note

These signatures are "detached"—that is, they do not include a copy of the message which has been signed.

Methods

impl Signature[src]

pub fn sign(transcript: &mut Transcript, secret_key: &SecretKey) -> Signature[src]

Sign a transcript with this keypair's secret key.

Requires a SigningTranscript, normally created from a SigningContext and a message. Returns a Schnorr signature.

Examples

Internally, we manage signature transcripts using a 128 bit secure STROBE construction based on Keccak, which itself is extremly fast and secure. You might however influence performance or security by prehashing your message, like

extern crate schnorr;
extern crate rand;
extern crate blake2;

use schnorr::*;
use rand::prelude::*; // ThreadRng,thread_rng
use blake2::Blake2b;
use blake2::digest::{Input};

let mut csprng: ThreadRng = thread_rng();
let keypair: Keypair = Keypair::generate(&mut csprng);
let message: &[u8] = b"All I want is to pet all of the dogs.";

// Create a hash digest object and feed it the message:
let prehashed = Blake2b::default().chain(message);

We require a "context" string for all signatures, which should be chosen judiciously for your project. It should represent the role the signature plays in your application. If you use the context in two purposes, and the same key, then a signature for one purpose can be substituted for the other.

let mut ctx = SigningContext::new(b"My Signing Context");

let sig: Signature = Signature::sign(&mut ctx.from_hash512(prehashed), &keypair.secret, &keypair.public);

Sign a transcript with this SecretKey.

Requires a SigningTranscript, normally created from a SigningContext and a message, as well as the public key correspodning to self. Returns a Schnorr signature.

We employ a randomized nonce here, but also incorporate the transcript like in a derandomized scheme, but only after first extending the transcript by the public key. As a result, there should be no attacks even if both the random number generator fails and the function gets called with the wrong public key.

pub fn verify(
    &self,
    transcript: &mut Transcript,
    public_key: &PublicKey
) -> Result<(), SchnorrError>
[src]

Verify a signature by keypair's public key on a transcript.

Requires a SigningTranscript, normally created from a SigningContext and a message, as well as the signature to be verified.

Examples

extern crate schnorr;
extern crate rand;

use schnorr::*;
use rand::prelude::*; // ThreadRng,thread_rng

let mut csprng: ThreadRng = thread_rng();
let keypair: Keypair = Keypair::generate(&mut csprng);
let message: &[u8] = b"All I want is to pet all of the dogs.";

let mut ctx = SigningContext::new(b"Some context string");

let sig: Signature = Signature::sign(&mut ctx.bytes(message), &keypair.secret);

assert!( sig.verify(&mut ctx.bytes(message), &keypair.public).is_ok() );

Verify a signature on a message with this keypair's public key.

Return

Returns Ok(()) if the signature is valid, and Err otherwise.

pub fn verify_batched(
    &self,
    transcript: &mut Transcript,
    public_key: &PublicKey,
    batch: &mut impl BatchVerification
)
[src]

Verify a batch of signatures on messages with their respective public_keys.

Inputs

  • messages is a slice of byte slices, one per signed message.
  • transcript is a slice of Signatures. They need messages fed in before and discarded after
  • signatures is a slice of Signatures.
  • public_keys is a slice of PublicKeys.
  • csprng is an implementation of Rng + CryptoRng, such as rand::ThreadRng.

Panics

This function will panic if the messages, signatures, and public_keys` slices are not equal length.

Returns

  • A Result whose Ok value is an emtpy tuple and whose Err value is a SignatureError containing a description of the internal error which occured.

Examples

extern crate schnorr;
extern crate rand;
extern crate bacteria;

use schnorr::*;
use rand::thread_rng;
use rand::rngs::ThreadRng;
use bacteria::Transcript;


let ctx = SigningContext::new(b"some batch");
let mut csprng: ThreadRng = thread_rng();
let keypairs: Vec<Keypair> = (0..64).map(|_| Keypair::generate(&mut csprng)).collect();
let msg: &[u8] = b"They're good dogs Brant"; 
let signatures:  Vec<Signature> = keypairs.iter().map(|key| Signature::sign(&mut ctx.bytes(&msg), &key.secret)).collect();
let public_keys: Vec<PublicKey> = keypairs.iter().map(|key| key.public).collect();
let mut batch = BatchVerifier::new(rand::thread_rng());

let mut transcripts: Vec<Transcript> = ::std::iter::once(ctx.bytes(msg)).cycle().take(64).collect();;
for i in 0..signatures.len() {
     signatures[i].verify_batched(&mut transcripts[i], &public_keys[i], &mut batch);
}
 
assert!(batch.verify().is_ok());

Trait Implementations

impl Multisignature for Signature[src]

fn verify_multi<M: AsRef<[u8]>>(
    &self,
    transcript: &mut Transcript,
    messages: Vec<(PublicKey, M)>
) -> Result<(), SchnorrError>
[src]

Verifies a signature for a multimessage context

impl Clone for Signature[src]

impl Copy for Signature[src]

impl Eq for Signature[src]

impl PartialEq<Signature> for Signature[src]

impl Debug for Signature[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]