Skip to content

Commit d23b70f

Browse files
committed
rearrange code - nonce_gen impl SignSession order
1 parent 89f6120 commit d23b70f

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

schnorr_fun/src/frost.rs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -730,17 +730,39 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> Frost<H, NG> {
730730
}
731731
}
732732

733-
/// Calculate the lagrange coefficient for participant with index x_j and other signers indexes x_ms
734-
fn lagrange_lambda(x_j: u32, x_ms: &[u32]) -> Scalar {
735-
let x_j = Scalar::from(x_j).expect_nonzero("target xcoord can not be zero");
736-
x_ms.iter()
737-
.map(|x_m| Scalar::from(*x_m).expect_nonzero("index can not be zero"))
738-
.fold(Scalar::one(), |acc, x_m| {
739-
let denominator = s!(x_m - x_j)
740-
.expect_nonzero("removed duplicate indexes")
741-
.invert();
742-
s!(acc * x_m * denominator)
743-
})
733+
impl<H: Digest<OutputSize = U32> + Clone, NG: NonceGen> Frost<H, NG> {
734+
/// Generate nonces for secret shares
735+
///
736+
/// This method should be used carefully.
737+
/// This calls [`NonceKeyPair::generate`] internally with the frost instance's [`NonceGen`].
738+
/// See documentation for that for more usage info.
739+
///
740+
/// When choosing a `secret` to use, if you are generating nonces prior to [`KeyGen`] completion,
741+
/// use the static first coefficient of your polynomial.
742+
/// Otherwise you can use your secret share of the frost key.
743+
///
744+
/// The application must decide upon a unique `sid` for this frost multisignature.
745+
/// For example, the concatenation of: my_signing_index, verfication_shares, purpose
746+
///
747+
/// ## Return Value
748+
///
749+
/// A NonceKeyPair comprised of secret scalars [r1, r2] and public nonces [R1, R2]
750+
/// [`NonceKeyPair::generate`]: crate::binonce::NonceKeyPair::generate
751+
pub fn gen_nonce(
752+
&self,
753+
secret: &Scalar,
754+
session_id: &[u8],
755+
public_key: Option<Point>,
756+
message: Option<Message<'_>>,
757+
) -> NonceKeyPair {
758+
NonceKeyPair::generate(
759+
self.schnorr.nonce_gen(),
760+
secret,
761+
session_id,
762+
public_key,
763+
message,
764+
)
765+
}
744766
}
745767

746768
/// A FROST signing session
@@ -768,6 +790,19 @@ impl SignSession {
768790
}
769791
}
770792

793+
/// Calculate the lagrange coefficient for participant with index x_j and other signers indexes x_ms
794+
fn lagrange_lambda(x_j: u32, x_ms: &[u32]) -> Scalar {
795+
let x_j = Scalar::from(x_j).expect_nonzero("target xcoord can not be zero");
796+
x_ms.iter()
797+
.map(|x_m| Scalar::from(*x_m).expect_nonzero("index can not be zero"))
798+
.fold(Scalar::one(), |acc, x_m| {
799+
let denominator = s!(x_m - x_j)
800+
.expect_nonzero("removed duplicate indexes")
801+
.invert();
802+
s!(acc * x_m * denominator)
803+
})
804+
}
805+
771806
impl<H: Digest<OutputSize = U32> + Clone, NG> Frost<H, NG> {
772807
/// Start a FROST signing session.
773808
///
@@ -937,41 +972,6 @@ impl<H: Digest<OutputSize = U32> + Clone, NG> Frost<H, NG> {
937972
}
938973
}
939974

940-
impl<H: Digest<OutputSize = U32> + Clone, NG: NonceGen> Frost<H, NG> {
941-
/// Generate nonces for secret shares
942-
///
943-
/// This method should be used carefully.
944-
/// This calls [`NonceKeyPair::generate`] internally with the frost instance's [`NonceGen`].
945-
/// See documentation for that for more usage info.
946-
///
947-
/// When choosing a `secret` to use, if you are generating nonces prior to [`KeyGen`] completion,
948-
/// use the static first coefficient of your polynomial.
949-
/// Otherwise you can use your secret share of the frost key.
950-
///
951-
/// The application must decide upon a unique `sid` for this frost multisignature.
952-
/// For example, the concatenation of: my_signing_index, verfication_shares, purpose
953-
///
954-
/// ## Return Value
955-
///
956-
/// A NonceKeyPair comprised of secret scalars [r1, r2] and public nonces [R1, R2]
957-
/// [`NonceKeyPair::generate`]: crate::binonce::NonceKeyPair::generate
958-
pub fn gen_nonce(
959-
&self,
960-
secret: &Scalar,
961-
session_id: &[u8],
962-
public_key: Option<Point>,
963-
message: Option<Message<'_>>,
964-
) -> NonceKeyPair {
965-
NonceKeyPair::generate(
966-
self.schnorr.nonce_gen(),
967-
secret,
968-
session_id,
969-
public_key,
970-
message,
971-
)
972-
}
973-
}
974-
975975
#[cfg(test)]
976976
mod test {
977977
use core::num::NonZeroU32;

0 commit comments

Comments
 (0)