[−][src]Struct schnorr::signature::Signature
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]
&self,
transcript: &mut Transcript,
public_key: &PublicKey
) -> Result<(), SchnorrError>
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]
&self,
transcript: &mut Transcript,
public_key: &PublicKey,
batch: &mut impl BatchVerification
)
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 ofSignature
s. They need messages fed in before and discarded aftersignatures
is a slice ofSignature
s.public_keys
is a slice ofPublicKey
s.csprng
is an implementation ofRng + CryptoRng
, such asrand::ThreadRng
.
Panics
This function will panic if the messages,
signatures, and
public_keys`
slices are not equal length.
Returns
- A
Result
whoseOk
value is an emtpy tuple and whoseErr
value is aSignatureError
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 sign_multi<P, M>(
privkeys: P,
messages: Vec<(PublicKey, M)>,
transcript: &mut Transcript
) -> Result<Signature, SchnorrError> where
M: AsRef<[u8]>,
P: IntoIterator,
P::Item: Borrow<Scalar>,
P::IntoIter: ExactSizeIterator,
[src]
privkeys: P,
messages: Vec<(PublicKey, M)>,
transcript: &mut Transcript
) -> Result<Signature, SchnorrError> where
M: AsRef<[u8]>,
P: IntoIterator,
P::Item: Borrow<Scalar>,
P::IntoIter: ExactSizeIterator,
fn verify_multi<M: AsRef<[u8]>>(
&self,
transcript: &mut Transcript,
messages: Vec<(PublicKey, M)>
) -> Result<(), SchnorrError>
[src]
&self,
transcript: &mut Transcript,
messages: Vec<(PublicKey, M)>
) -> Result<(), SchnorrError>
Verifies a signature for a multimessage context
fn verify_multi_batched<M: AsRef<[u8]>>(
&self,
transcript: &mut Transcript,
messages: Vec<(PublicKey, M)>,
batch: &mut impl BatchVerification
)
[src]
&self,
transcript: &mut Transcript,
messages: Vec<(PublicKey, M)>,
batch: &mut impl BatchVerification
)
impl Clone for Signature
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[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
impl Send for Signature
impl Sync for Signature
impl Unpin for Signature
impl UnwindSafe for Signature
impl RefUnwindSafe for Signature
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
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>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
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>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,