Skip to content

Commit 0a154c8

Browse files
committed
Add nonce combine function
1 parent d515c34 commit 0a154c8

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

include/secp256k1_frost.h

+8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ SECP256K1_API int secp256k1_frost_pubkey_combine(
7373
const secp256k1_pubkey *pubkeys
7474
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
7575

76+
SECP256K1_API int secp256k1_frost_nonce_combine(
77+
const secp256k1_context* ctx,
78+
const secp256k1_pubkey *pubkeys,
79+
size_t n_signers,
80+
int *nonce_parity,
81+
secp256k1_xonly_pubkey *combined_pk
82+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5);
83+
7684
#ifdef __cplusplus
7785
}
7886
#endif

src/modules/frost/main_impl.h

+15
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ int secp256k1_frost_pubkey_combine(const secp256k1_context *ctx, secp256k1_scrat
142142
return 1;
143143
}
144144

145+
int secp256k1_frost_nonce_combine(const secp256k1_context* ctx, const secp256k1_pubkey *pubkeys, size_t n_signers, int *nonce_parity, secp256k1_xonly_pubkey *combined_pk) {
146+
secp256k1_frost_keygen_session session;
147+
148+
session.n_signers = n_signers;
149+
150+
if (!secp256k1_frost_pubkey_combine(ctx, NULL, &session, pubkeys)) {
151+
return 0;
152+
}
153+
154+
*nonce_parity = session.pk_parity;
155+
*combined_pk = session.combined_pk;
156+
157+
return 1;
158+
}
159+
145160
static void secp256k1_frost_lagrange_coefficient(secp256k1_scalar *r, const size_t *participant_indexes, const size_t n_participants, const size_t my_index) {
146161
size_t i;
147162
secp256k1_scalar num;

src/modules/frost/tests_impl.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ void run_frost_tests(void) {
3232
secp256k1_keypair keypair;
3333
secp256k1_frost_secnonce k;
3434
secp256k1_frost_keygen_session sessions[N_SIGNERS];
35+
secp256k1_xonly_pubkey combined_nonce;
36+
int combined_nonce_parity;
3537
int i, j;
3638

3739
/* Round 1.1, 1.2, 1.3, and 1.4 */
@@ -104,9 +106,8 @@ void run_frost_tests(void) {
104106
secp256k1_ge_set_gej(&rp, &rj);
105107
secp256k1_pubkey_save(&pubkeys[i], &rp);
106108
}
107-
sessions[0].n_signers = THRESHOLD;
108-
CHECK(secp256k1_frost_pubkey_combine(ctx, NULL, &sessions[0], pubkeys));
109-
CHECK(secp256k1_xonly_pubkey_serialize(ctx, pk2, &sessions[0].combined_pk));
109+
CHECK(secp256k1_frost_nonce_combine(ctx, pubkeys, THRESHOLD, &combined_nonce_parity, &combined_nonce));
110+
CHECK(secp256k1_xonly_pubkey_serialize(ctx, pk2, &combined_nonce));
110111
/* sign */
111112
for (i = 0; i < THRESHOLD; i++) {
112113
/* compute challenge hash */
@@ -116,10 +117,10 @@ void run_frost_tests(void) {
116117
secp256k1_frost_lagrange_coefficient(&l, participants, THRESHOLD, sessions[i].my_index);
117118
secp256k1_scalar_mul(&s1, &s1, &l);
118119
secp256k1_scalar_mul(&s2, &s2, &s1);
119-
CHECK(secp256k1_xonly_pubkey_serialize(ctx, pk2, &sessions[0].combined_pk));
120+
CHECK(secp256k1_xonly_pubkey_serialize(ctx, pk2, &combined_nonce));
120121
secp256k1_nonce_function_frost(&k, id, sessions[i].agg_share.data, msg, &pk1[1], frost_algo, 9, NULL);
121122
secp256k1_scalar_set_b32(&s1, k.data, NULL);
122-
if (sessions[0].pk_parity) {
123+
if (combined_nonce_parity) {
123124
secp256k1_scalar_negate(&s1, &s1);
124125

125126
}

0 commit comments

Comments
 (0)