From 0230ccb29dcb7a7965bcd09b8ee86475c2ea499e Mon Sep 17 00:00:00 2001 From: Conrado Gouvea Date: Thu, 1 Sep 2022 17:40:20 -0300 Subject: [PATCH] fix batch support after rebase --- frost-core/src/batch.rs | 2 +- frost-core/src/lib.rs | 36 +++++++++++++++++++++------------ frost-core/src/verifying_key.rs | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/frost-core/src/batch.rs b/frost-core/src/batch.rs index 8547120e..b8d22133 100644 --- a/frost-core/src/batch.rs +++ b/frost-core/src/batch.rs @@ -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::(self.c, &self.sig, &self.vk) } } diff --git a/frost-core/src/lib.rs b/frost-core/src/lib.rs index 272712b5..524d6ec0 100644 --- a/frost-core/src/lib.rs +++ b/frost-core/src/lib.rs @@ -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( + challenge: Challenge, + signature: &Signature, + public_key: &VerifyingKey, +) -> 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. /// @@ -208,19 +230,7 @@ pub trait Ciphersuite: Copy + Clone { ) -> Result<(), Error> { let c = crate::challenge::(&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) } } diff --git a/frost-core/src/verifying_key.rs b/frost-core/src/verifying_key.rs index 2d1429ec..fd68cee4 100644 --- a/frost-core/src/verifying_key.rs +++ b/frost-core/src/verifying_key.rs @@ -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)]