Skip to content

Commit

Permalink
fix batch support after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg committed Sep 1, 2022
1 parent 351afb6 commit 0230ccb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion frost-core/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where
/// requires borrowing the message data, the `Item` type is unlinked
/// from the lifetime of the message.
pub fn verify_single(self) -> Result<(), Error> {
self.vk.verify_prehashed(&self.sig, self.c)
verify_prehashed::<C>(self.c, &self.sig, &self.vk)
}
}

Expand Down
36 changes: 23 additions & 13 deletions frost-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ pub use signature::Signature;
pub use signing_key::SigningKey;
pub use verifying_key::VerifyingKey;

/// Verify a purported `signature` with a pre-hashed [`Challenge`] made by this verification
/// key.
pub(crate) fn verify_prehashed<C: Ciphersuite>(
challenge: Challenge<C>,
signature: &Signature<C>,
public_key: &VerifyingKey<C>,
) -> Result<(), Error> {
// Verify check is h * ( - z * B + R + c * A) == 0
// h * ( z * B - c * A - R) == 0
//
// where h is the cofactor
let zB = C::Group::generator() * signature.z;
let cA = public_key.element * challenge.0;
let check = (zB - cA - signature.R) * C::Group::cofactor();

if check == C::Group::identity() {
Ok(())
} else {
Err(Error::InvalidSignature)
}
}

/// A prime order finite field GF(q) over which all scalar values for our prime order group can be
/// multiplied are defined.
///
Expand Down Expand Up @@ -208,19 +230,7 @@ pub trait Ciphersuite: Copy + Clone {
) -> Result<(), Error> {
let c = crate::challenge::<Self>(&signature.R, &public_key.element, msg);

// Verify check is h * ( - z * B + R + c * A) == 0
// h * ( z * B - c * A - R) == 0
//
// where h is the cofactor
let zB = Self::Group::generator() * signature.z;
let cA = public_key.element * c.0;
let check = (zB - cA - signature.R) * Self::Group::cofactor();

if check == Self::Group::identity() {
Ok(())
} else {
Err(Error::InvalidSignature)
}
verify_prehashed(c, signature, public_key)
}
}

Expand Down
2 changes: 1 addition & 1 deletion frost-core/src/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{self, Debug};

use hex::FromHex;

use crate::{Challenge, Ciphersuite, Error, Group, Signature};
use crate::{Ciphersuite, Error, Group, Signature};

/// A valid verifying key for Schnorr signatures over a FROST [`Ciphersuite::Group`].
#[derive(Copy, Clone, PartialEq)]
Expand Down

0 comments on commit 0230ccb

Please sign in to comment.