Skip to content

Commit 7731fea

Browse files
nickfarrowLLFourn
authored andcommitted
use NonceKeyPair::generate
1 parent 64dce45 commit 7731fea

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

schnorr_fun/src/frost.rs

+43-37
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
//! .collect();
7070
//! // create a unique session ID for this signing session
7171
//! let sid = [
72-
//! frost_key.joint_public_key.to_bytes().as_slice(),
7372
//! verification_shares_bytes.concat().as_slice(),
7473
//! b"frost-very-unique-id".as_slice(),
7574
//! b"0".as_slice(),
@@ -83,8 +82,8 @@
8382
//! # ]
8483
//! # .concat();
8584
//! // generate nonces for this signing session
86-
//! let nonce = frost.gen_nonce(&secret_share, &sid);
87-
//! # let nonce3 = frost.gen_nonce(&secret_share3, &sid3);
85+
//! let nonce = frost.gen_nonce(&secret_share, &sid, Some(frost_key.joint_public_key), None);
86+
//! # let nonce3 = frost.gen_nonce(&secret_share3, &sid3, Some(frost_key.joint_public_key), None);
8887
//! // share your public nonce with the other signing participant(s)
8988
//! # let recieved_nonce3 = nonce3.public();
9089
//! // recieve public nonces from other participants with their index
@@ -111,7 +110,6 @@ use crate::{Message, Schnorr, Signature, Vec};
111110
use core::iter;
112111
use rand_core::{CryptoRng, RngCore};
113112
use secp256kfun::{
114-
derive_nonce,
115113
digest::{generic_array::typenum::U32, Digest},
116114
g,
117115
hash::{HashAdd, Tagged},
@@ -851,36 +849,35 @@ impl<H: Digest<OutputSize = U32> + Clone, NG: NonceGen + AddTag> Frost<H, NG> {
851849
impl<H: Digest<OutputSize = U32> + Clone, NG: NonceGen + AddTag> Frost<H, NG> {
852850
/// Generate nonces for secret shares
853851
///
854-
/// It is very important that you use a unique `sid` for this signing session and to also carefully
855-
/// consider the implications of your choice of underlying [`NonceGen`].
852+
/// This method should be used carefully.
853+
/// This calls [`NonceKeyPair::generate`] internally with the `MuSig` instance's `NonceGen`.
854+
/// See documentation for that for more usage info.
856855
///
857856
/// When choosing a `secret` to use, if you are generating nonces prior to KeyGen completion,
858857
/// use the static first coefficient of your polynomial.
859858
/// Otherwise you can use your secret share of the joint FROST key.
860859
///
861860
/// The application must decide upon a unique `sid` for this FROST multisignature.
862-
/// For example, the concatenation of: my_signing_index, joint_key, verfication_shares
861+
/// For example, the concatenation of: my_signing_index, verfication_shares, purpose
863862
///
864863
/// ## Return Value
865864
///
866865
/// A NonceKeyPair comprised of secret scalars [r1, r2] and public nonces [R1, R2]
867-
pub fn gen_nonce(&self, secret: &Scalar, sid: &[u8]) -> NonceKeyPair {
868-
let r1 = derive_nonce!(
869-
nonce_gen => self.schnorr.nonce_gen(),
870-
secret => secret,
871-
public => [ b"r1-frost", sid]
872-
);
873-
let r2 = derive_nonce!(
874-
nonce_gen => self.schnorr.nonce_gen(),
875-
secret => secret,
876-
public => [ b"r2-frost", sid]
877-
);
878-
let R1 = g!(r1 * G).normalize();
879-
let R2 = g!(r2 * G).normalize();
880-
NonceKeyPair {
881-
public: Nonce([R1, R2]),
882-
secret: [r1, r2],
883-
}
866+
/// [`NonceKeyPair::generate`]: crate::binonce::NonceKeyPair::generate
867+
pub fn gen_nonce(
868+
&self,
869+
secret: &Scalar,
870+
session_id: &[u8],
871+
public_key: Option<Point<impl Normalized>>,
872+
message: Option<Message<'_>>,
873+
) -> NonceKeyPair {
874+
NonceKeyPair::generate(
875+
self.schnorr.nonce_gen(),
876+
secret,
877+
session_id,
878+
public_key,
879+
message,
880+
)
884881
}
885882
}
886883

@@ -977,7 +974,13 @@ mod test {
977974
b"frost-prop-test".as_slice(),
978975
]
979976
.concat();
980-
let nonces: Vec<NonceKeyPair> = signer_indexes.iter().map(|i| frost.gen_nonce(&secret_shares[*i as usize], &[sid.as_slice(), [*i as u8].as_slice()].concat())).collect();
977+
let nonces: Vec<NonceKeyPair> = signer_indexes.iter().map(|i|
978+
frost.gen_nonce(
979+
&secret_shares[*i as usize],
980+
&[sid.as_slice(), [*i as u8].as_slice()].concat(),
981+
Some(frost_keys[signer_indexes[0]].joint_public_key),
982+
None)
983+
).collect();
981984

982985
let mut recieved_nonces: Vec<_> = vec![];
983986
for (i, nonce) in signer_indexes.iter().zip(nonces.clone()) {
@@ -1102,36 +1105,39 @@ mod test {
11021105

11031106
// Create unique session IDs for these signing sessions
11041107
let sid1 = [
1105-
xonly_frost_key.joint_public_key.to_bytes().as_slice(),
11061108
verification_shares_bytes.concat().as_slice(),
11071109
b"frost-end-to-end-test-1".as_slice(),
11081110
b"0".as_slice(),
11091111
]
11101112
.concat();
11111113

11121114
let sid2 = [
1113-
xonly_frost_key.joint_public_key.to_bytes().as_slice(),
11141115
verification_shares_bytes.concat().as_slice(),
11151116
b"frost-end-to-end-test-2".as_slice(),
11161117
b"2".as_slice(),
11171118
]
11181119
.concat();
11191120

1120-
let nonce1 = frost.gen_nonce(&secret_share1, &sid1);
1121-
let nonce3 = frost.gen_nonce(&secret_share3, &sid2);
1121+
let message = Message::plain("test", b"test");
1122+
let nonce1 = frost.gen_nonce(
1123+
&secret_share1,
1124+
&sid1,
1125+
Some(xonly_frost_key.joint_public_key),
1126+
Some(message),
1127+
);
1128+
let nonce3 = frost.gen_nonce(
1129+
&secret_share3,
1130+
&sid2,
1131+
Some(xonly_frost_key.joint_public_key),
1132+
Some(message),
1133+
);
11221134
let nonces = vec![(0, nonce1.public()), (2, nonce3.public())];
11231135
let nonces2 = vec![(0, nonce1.public()), (2, nonce3.public())];
11241136

1125-
let session =
1126-
frost.start_sign_session(&xonly_frost_key, nonces, Message::plain("test", b"test"));
1127-
1137+
let session = frost.start_sign_session(&xonly_frost_key, nonces, message);
11281138
dbg!(&session);
11291139
{
1130-
let session2 = frost.start_sign_session(
1131-
&xonly_frost_key2,
1132-
nonces2,
1133-
Message::plain("test", b"test"),
1134-
);
1140+
let session2 = frost.start_sign_session(&xonly_frost_key2, nonces2, message);
11351141
assert_eq!(session2, session);
11361142
}
11371143

0 commit comments

Comments
 (0)