Bitcoin Core 31.99.0
P2P Digital Currency
session_impl.h
Go to the documentation of this file.
1/***********************************************************************
2 * Distributed under the MIT software license, see the accompanying *
3 * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
4 ***********************************************************************/
5
6#ifndef SECP256K1_MODULE_MUSIG_SESSION_IMPL_H
7#define SECP256K1_MODULE_MUSIG_SESSION_IMPL_H
8
9#include <string.h>
10
11#include "../../../include/secp256k1.h"
12#include "../../../include/secp256k1_extrakeys.h"
13#include "../../../include/secp256k1_musig.h"
14
15#include "keyagg.h"
16#include "session.h"
17#include "../../eckey.h"
18#include "../../hash.h"
19#include "../../scalar.h"
20#include "../../util.h"
21
22/* Outputs 33 zero bytes if the given group element is the point at infinity and
23 * otherwise outputs the compressed serialization */
24static void secp256k1_musig_ge_serialize_ext(unsigned char *out33, secp256k1_ge* ge) {
26 memset(out33, 0, 33);
27 } else {
28 /* Serialize must succeed because the point is not at infinity */
30 }
31}
32
33/* Outputs the point at infinity if the given byte array is all zero, otherwise
34 * attempts to parse compressed point serialization. */
35static int secp256k1_musig_ge_parse_ext(secp256k1_ge* ge, const unsigned char *in33) {
36 unsigned char zeros[33] = { 0 };
37
38 if (secp256k1_memcmp_var(in33, zeros, sizeof(zeros)) == 0) {
40 return 1;
41 }
42 if (!secp256k1_eckey_pubkey_parse(ge, in33, 33)) {
43 return 0;
44 }
46}
47
48static const unsigned char secp256k1_musig_secnonce_magic[4] = { 0x22, 0x0e, 0xdc, 0xf1 };
49
51 memcpy(&secnonce->data[0], secp256k1_musig_secnonce_magic, 4);
52 secp256k1_scalar_get_b32(&secnonce->data[4], &k[0]);
53 secp256k1_scalar_get_b32(&secnonce->data[36], &k[1]);
54 secp256k1_ge_to_bytes(&secnonce->data[68], pk);
55}
56
58 int is_zero;
60 /* We make very sure that the nonce isn't invalidated by checking the values
61 * in addition to the magic. */
62 is_zero = secp256k1_is_zero_array(&secnonce->data[4], 2 * 32);
63 secp256k1_declassify(ctx, &is_zero, sizeof(is_zero));
64 ARG_CHECK(!is_zero);
65
66 secp256k1_scalar_set_b32(&k[0], &secnonce->data[4], NULL);
67 secp256k1_scalar_set_b32(&k[1], &secnonce->data[36], NULL);
68 secp256k1_ge_from_bytes(pk, &secnonce->data[68]);
69 return 1;
70}
71
72/* If flag is 1, invalidate the secnonce; if flag is 0, leave it.
73 * Constant-time. Flag must be 0 or 1. */
75 secp256k1_memczero(secnonce->data, sizeof(secnonce->data), flag);
76 /* The flag argument is usually classified. So, the line above makes the
77 * magic and public key classified. However, we need both to be
78 * declassified. Note that we don't declassify the entire object, because if
79 * flag is 0, then k[0] and k[1] have not been zeroed. */
81 secp256k1_declassify(ctx, &secnonce->data[68], 64);
82}
83
84static const unsigned char secp256k1_musig_pubnonce_magic[4] = { 0xf5, 0x7a, 0x3d, 0xa0 };
85
86/* Saves two group elements into a pubnonce. Requires that none of the provided
87 * group elements is infinity. */
89 int i;
90 memcpy(&nonce->data[0], secp256k1_musig_pubnonce_magic, 4);
91 for (i = 0; i < 2; i++) {
92 secp256k1_ge_to_bytes(nonce->data + 4+64*i, &ges[i]);
93 }
94}
95
96/* Loads two group elements from a pubnonce. Returns 1 unless the nonce wasn't
97 * properly initialized */
99 int i;
100
102 for (i = 0; i < 2; i++) {
103 secp256k1_ge_from_bytes(&ges[i], nonce->data + 4 + 64*i);
104 }
105 return 1;
106}
107
108static const unsigned char secp256k1_musig_aggnonce_magic[4] = { 0xa8, 0xb7, 0xe4, 0x67 };
109
111 int i;
112 memcpy(&nonce->data[0], secp256k1_musig_aggnonce_magic, 4);
113 for (i = 0; i < 2; i++) {
114 secp256k1_ge_to_bytes_ext(&nonce->data[4 + 64*i], &ges[i]);
115 }
116}
117
119 int i;
120
122 for (i = 0; i < 2; i++) {
123 secp256k1_ge_from_bytes_ext(&ges[i], &nonce->data[4 + 64*i]);
124 }
125 return 1;
126}
127
128static const unsigned char secp256k1_musig_session_cache_magic[4] = { 0x9d, 0xed, 0xe9, 0x17 };
129
130/* A session consists of
131 * - 4 byte session cache magic
132 * - 1 byte the parity of the final nonce
133 * - 32 byte serialized x-only final nonce
134 * - 32 byte nonce coefficient b
135 * - 32 byte signature challenge hash e
136 * - 32 byte scalar s that is added to the partial signatures of the signers
137 */
139 unsigned char *ptr = session->data;
140
142 ptr += 4;
143 *ptr = session_i->fin_nonce_parity;
144 ptr += 1;
145 memcpy(ptr, session_i->fin_nonce, 32);
146 ptr += 32;
147 secp256k1_scalar_get_b32(ptr, &session_i->noncecoef);
148 ptr += 32;
149 secp256k1_scalar_get_b32(ptr, &session_i->challenge);
150 ptr += 32;
151 secp256k1_scalar_get_b32(ptr, &session_i->s_part);
152}
153
155 const unsigned char *ptr = session->data;
156
158 ptr += 4;
159 session_i->fin_nonce_parity = *ptr;
160 ptr += 1;
161 memcpy(session_i->fin_nonce, ptr, 32);
162 ptr += 32;
163 secp256k1_scalar_set_b32(&session_i->noncecoef, ptr, NULL);
164 ptr += 32;
165 secp256k1_scalar_set_b32(&session_i->challenge, ptr, NULL);
166 ptr += 32;
167 secp256k1_scalar_set_b32(&session_i->s_part, ptr, NULL);
168 return 1;
169}
170
171static const unsigned char secp256k1_musig_partial_sig_magic[4] = { 0xeb, 0xfb, 0x1a, 0x32 };
172
174 memcpy(&sig->data[0], secp256k1_musig_partial_sig_magic, 4);
176}
177
179 int overflow;
180
182 secp256k1_scalar_set_b32(s, &sig->data[4], &overflow);
183 /* Parsed signatures can not overflow */
184 VERIFY_CHECK(!overflow);
185 return 1;
186}
187
189 secp256k1_ge ges[2];
190 int i;
191
192 VERIFY_CHECK(ctx != NULL);
193 ARG_CHECK(nonce != NULL);
194 ARG_CHECK(in66 != NULL);
195
196 for (i = 0; i < 2; i++) {
197 if (!secp256k1_eckey_pubkey_parse(&ges[i], &in66[33*i], 33)) {
198 return 0;
199 }
201 return 0;
202 }
203 }
205 return 1;
206}
207
209 secp256k1_ge ges[2];
210 int i;
211
212 VERIFY_CHECK(ctx != NULL);
213 ARG_CHECK(out66 != NULL);
214 memset(out66, 0, 66);
215 ARG_CHECK(nonce != NULL);
216
217 if (!secp256k1_musig_pubnonce_load(ctx, ges, nonce)) {
218 return 0;
219 }
220 for (i = 0; i < 2; i++) {
221 /* serialize must succeed because the point was just loaded */
222 secp256k1_eckey_pubkey_serialize33(&ges[i], &out66[33*i]);
223 }
224 return 1;
225}
226
228 secp256k1_ge ges[2];
229 int i;
230
231 VERIFY_CHECK(ctx != NULL);
232 ARG_CHECK(nonce != NULL);
233 ARG_CHECK(in66 != NULL);
234
235 for (i = 0; i < 2; i++) {
236 if (!secp256k1_musig_ge_parse_ext(&ges[i], &in66[33*i])) {
237 return 0;
238 }
239 }
241 return 1;
242}
243
245 secp256k1_ge ges[2];
246 int i;
247
248 VERIFY_CHECK(ctx != NULL);
249 ARG_CHECK(out66 != NULL);
250 memset(out66, 0, 66);
251 ARG_CHECK(nonce != NULL);
252
253 if (!secp256k1_musig_aggnonce_load(ctx, ges, nonce)) {
254 return 0;
255 }
256 for (i = 0; i < 2; i++) {
257 secp256k1_musig_ge_serialize_ext(&out66[33*i], &ges[i]);
258 }
259 return 1;
260}
261
264 int overflow;
265 VERIFY_CHECK(ctx != NULL);
266 ARG_CHECK(sig != NULL);
267 ARG_CHECK(in32 != NULL);
268
269 /* Ensure that using the signature will fail if parsing fails (and the user
270 * doesn't check the return value). */
271 memset(sig, 0, sizeof(*sig));
272
273 secp256k1_scalar_set_b32(&tmp, in32, &overflow);
274 if (overflow) {
275 return 0;
276 }
278 return 1;
279}
280
282 VERIFY_CHECK(ctx != NULL);
283 ARG_CHECK(out32 != NULL);
284 ARG_CHECK(sig != NULL);
286
287 memcpy(out32, &sig->data[4], 32);
288 return 1;
289}
290
291/* Write optional inputs into the hash */
292static void secp256k1_nonce_function_musig_helper(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *sha, unsigned int prefix_size, const unsigned char *data, unsigned char len) {
293 unsigned char zero[7] = { 0 };
294 /* The spec requires length prefixes to be between 1 and 8 bytes
295 * (inclusive) */
296 VERIFY_CHECK(prefix_size >= 1 && prefix_size <= 8);
297 /* Since the length of all input data fits in a byte, we can always pad the
298 * length prefix with prefix_size - 1 zero bytes. */
299 secp256k1_sha256_write(hash_ctx, sha, zero, prefix_size - 1);
300 if (data != NULL) {
301 secp256k1_sha256_write(hash_ctx, sha, &len, 1);
302 secp256k1_sha256_write(hash_ctx, sha, data, len);
303 } else {
304 len = 0;
305 secp256k1_sha256_write(hash_ctx, sha, &len, 1);
306 }
307}
308
309/* Initializes SHA256 with fixed midstate. This midstate was computed by applying
310 * SHA256 to SHA256("MuSig/aux")||SHA256("MuSig/aux"). */
312 static const uint32_t midstate[8] = {
313 0xa19e884bul, 0xf463fe7eul, 0x2f18f9a2ul, 0xbeb0f9fful,
314 0x0f37e8b0ul, 0x06ebd26ful, 0xe3b243d2ul, 0x522fb150ul
315 };
316 secp256k1_sha256_initialize_midstate(sha, 64, midstate);
317}
318
319/* Initializes SHA256 with fixed midstate. This midstate was computed by applying
320 * SHA256 to SHA256("MuSig/nonce")||SHA256("MuSig/nonce"). */
322 static const uint32_t midstate[8] = {
323 0x07101b64ul, 0x18003414ul, 0x0391bc43ul, 0x0e6258eeul,
324 0x29d26b72ul, 0x8343937eul, 0xb7a0a4fbul, 0xff568a30ul
325 };
326 secp256k1_sha256_initialize_midstate(sha, 64, midstate);
327}
328
329static void secp256k1_nonce_function_musig(const secp256k1_hash_ctx *hash_ctx, secp256k1_scalar *k, const unsigned char *session_secrand, const unsigned char *msg32, const unsigned char *seckey32, const unsigned char *pk33, const unsigned char *agg_pk32, const unsigned char *extra_input32) {
331 unsigned char rand[32];
332 unsigned char i;
333 unsigned char msg_present;
334
335 if (seckey32 != NULL) {
337 secp256k1_sha256_write(hash_ctx, &sha, session_secrand, 32);
338 secp256k1_sha256_finalize(hash_ctx, &sha, rand);
339 for (i = 0; i < 32; i++) {
340 rand[i] ^= seckey32[i];
341 }
342 } else {
343 memcpy(rand, session_secrand, sizeof(rand));
344 }
345
347 secp256k1_sha256_write(hash_ctx, &sha, rand, sizeof(rand));
348 secp256k1_nonce_function_musig_helper(hash_ctx, &sha, 1, pk33, 33);
349 secp256k1_nonce_function_musig_helper(hash_ctx, &sha, 1, agg_pk32, 32);
350 msg_present = msg32 != NULL;
351 secp256k1_sha256_write(hash_ctx, &sha, &msg_present, 1);
352 if (msg_present) {
353 secp256k1_nonce_function_musig_helper(hash_ctx, &sha, 8, msg32, 32);
354 }
355 secp256k1_nonce_function_musig_helper(hash_ctx, &sha, 4, extra_input32, 32);
356
357 for (i = 0; i < 2; i++) {
358 unsigned char buf[32];
359 secp256k1_sha256 sha_tmp = sha;
360 secp256k1_sha256_write(hash_ctx, &sha_tmp, &i, 1);
361 secp256k1_sha256_finalize(hash_ctx, &sha_tmp, buf);
362 secp256k1_scalar_set_b32(&k[i], buf, NULL);
363
364 /* Attempt to erase secret data */
365 secp256k1_memclear_explicit(buf, sizeof(buf));
366 secp256k1_sha256_clear(&sha_tmp);
367 }
368 secp256k1_memclear_explicit(rand, sizeof(rand));
370}
371
372static int secp256k1_musig_nonce_gen_internal(const secp256k1_context* ctx, secp256k1_musig_secnonce *secnonce, secp256k1_musig_pubnonce *pubnonce, const unsigned char *input_nonce, const unsigned char *seckey, const secp256k1_pubkey *pubkey, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32) {
374 secp256k1_ge nonce_pts[2];
375 secp256k1_gej nonce_ptj[2];
376 int i;
377 unsigned char pk_ser[33];
378 unsigned char aggpk_ser[32];
379 unsigned char *aggpk_ser_ptr = NULL;
381 int ret = 1;
382
383 ARG_CHECK(pubnonce != NULL);
384 memset(pubnonce, 0, sizeof(*pubnonce));
385 ARG_CHECK(pubkey != NULL);
387
388 /* Check that the seckey is valid to be able to sign for it later. */
389 if (seckey != NULL) {
393 }
394
395 if (keyagg_cache != NULL) {
397 if (!secp256k1_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) {
398 return 0;
399 }
400 /* The loaded point cache_i.pk can not be the point at infinity. */
401 secp256k1_fe_get_b32(aggpk_ser, &cache_i.pk.x);
402 aggpk_ser_ptr = aggpk_ser;
403 }
404 if (!secp256k1_pubkey_load(ctx, &pk, pubkey)) {
405 return 0;
406 }
407 /* A pubkey cannot be the point at infinity */
409
410 secp256k1_nonce_function_musig(secp256k1_get_hash_context(ctx), k, input_nonce, msg32, seckey, pk_ser, aggpk_ser_ptr, extra_input32);
415
416 /* Compute pubnonce as two gejs */
417 for (i = 0; i < 2; i++) {
418 secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &nonce_ptj[i], &k[i]);
420 }
421
422 /* Batch convert to two public ges */
423 secp256k1_ge_set_all_gej(nonce_pts, nonce_ptj, 2);
424 for (i = 0; i < 2; i++) {
425 secp256k1_gej_clear(&nonce_ptj[i]);
426 }
427
428 for (i = 0; i < 2; i++) {
429 secp256k1_declassify(ctx, &nonce_pts[i], sizeof(nonce_pts[i]));
430 }
431 /* None of the nonce_pts will be infinity because k != 0 with overwhelming
432 * probability */
433 secp256k1_musig_pubnonce_save(pubnonce, nonce_pts);
434 return ret;
435}
436
437int secp256k1_musig_nonce_gen(const secp256k1_context* ctx, secp256k1_musig_secnonce *secnonce, secp256k1_musig_pubnonce *pubnonce, unsigned char *session_secrand32, const unsigned char *seckey, const secp256k1_pubkey *pubkey, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32) {
438 int ret = 1;
439
440 VERIFY_CHECK(ctx != NULL);
441 ARG_CHECK(secnonce != NULL);
442 memset(secnonce, 0, sizeof(*secnonce));
443 ARG_CHECK(session_secrand32 != NULL);
444
445 /* Check in constant time that the session_secrand32 is not 0 as a
446 * defense-in-depth measure that may protect against a faulty RNG. */
447 ret &= !secp256k1_is_zero_array(session_secrand32, 32);
448
449 /* We can declassify because branching on ret is only relevant when this
450 * function called with an invalid session_secrand32 argument */
451 secp256k1_declassify(ctx, &ret, sizeof(ret));
452 if (ret == 0) {
453 secp256k1_musig_secnonce_invalidate(ctx, secnonce, 1);
454 return 0;
455 }
456
457 ret &= secp256k1_musig_nonce_gen_internal(ctx, secnonce, pubnonce, session_secrand32, seckey, pubkey, msg32, keyagg_cache, extra_input32);
458
459 /* Set the session_secrand32 buffer to zero to prevent the caller from using
460 * nonce_gen multiple times with the same buffer. */
461 secp256k1_memczero(session_secrand32, 32, ret);
462 return ret;
463}
464
465int secp256k1_musig_nonce_gen_counter(const secp256k1_context* ctx, secp256k1_musig_secnonce *secnonce, secp256k1_musig_pubnonce *pubnonce, uint64_t nonrepeating_cnt, const secp256k1_keypair *keypair, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32) {
466 unsigned char buf[32] = { 0 };
467 unsigned char seckey[32];
468 secp256k1_pubkey pubkey;
469 int ret;
470
471 VERIFY_CHECK(ctx != NULL);
472 ARG_CHECK(secnonce != NULL);
473 memset(secnonce, 0, sizeof(*secnonce));
474 ARG_CHECK(keypair != NULL);
475
476 secp256k1_write_be64(buf, nonrepeating_cnt);
477 /* keypair_sec and keypair_pub do not fail if the arguments are not NULL */
478 ret = secp256k1_keypair_sec(ctx, seckey, keypair);
480 ret = secp256k1_keypair_pub(ctx, &pubkey, keypair);
482#ifndef VERIFY
483 (void) ret;
484#endif
485
486 if (!secp256k1_musig_nonce_gen_internal(ctx, secnonce, pubnonce, buf, seckey, &pubkey, msg32, keyagg_cache, extra_input32)) {
487 return 0;
488 }
489 secp256k1_memclear_explicit(seckey, sizeof(seckey));
490 return 1;
491}
492
493static int secp256k1_musig_sum_pubnonces(const secp256k1_context* ctx, secp256k1_gej *summed_pubnonces, const secp256k1_musig_pubnonce * const* pubnonces, size_t n_pubnonces) {
494 size_t i;
495 int j;
496
497 secp256k1_gej_set_infinity(&summed_pubnonces[0]);
498 secp256k1_gej_set_infinity(&summed_pubnonces[1]);
499
500 for (i = 0; i < n_pubnonces; i++) {
501 secp256k1_ge nonce_pts[2];
502 if (!secp256k1_musig_pubnonce_load(ctx, nonce_pts, pubnonces[i])) {
503 return 0;
504 }
505 for (j = 0; j < 2; j++) {
506 secp256k1_gej_add_ge_var(&summed_pubnonces[j], &summed_pubnonces[j], &nonce_pts[j], NULL);
507 }
508 }
509 return 1;
510}
511
512int secp256k1_musig_nonce_agg(const secp256k1_context* ctx, secp256k1_musig_aggnonce *aggnonce, const secp256k1_musig_pubnonce * const* pubnonces, size_t n_pubnonces) {
513 secp256k1_gej aggnonce_ptsj[2];
514 secp256k1_ge aggnonce_pts[2];
515 size_t i;
516
517 VERIFY_CHECK(ctx != NULL);
518 ARG_CHECK(aggnonce != NULL);
519 ARG_CHECK(pubnonces != NULL);
520 ARG_CHECK(n_pubnonces > 0);
521 for (i = 0; i < n_pubnonces; i++) {
522 ARG_CHECK(pubnonces[i] != NULL);
523 }
524
525 if (!secp256k1_musig_sum_pubnonces(ctx, aggnonce_ptsj, pubnonces, n_pubnonces)) {
526 return 0;
527 }
528 secp256k1_ge_set_all_gej_var(aggnonce_pts, aggnonce_ptsj, 2);
529 secp256k1_musig_aggnonce_save(aggnonce, aggnonce_pts);
530 return 1;
531}
532
533/* Initializes SHA256 with fixed midstate. This midstate was computed by applying
534 * SHA256 to SHA256("MuSig/noncecoef")||SHA256("MuSig/noncecoef"). */
536 static const uint32_t midstate[8] = {
537 0x2c7d5a45ul, 0x06bf7e53ul, 0x89be68a6ul, 0x971254c0ul,
538 0x60ac12d2ul, 0x72846dcdul, 0x6c81212ful, 0xde7a2500ul
539 };
540 secp256k1_sha256_initialize_midstate(sha, 64, midstate);
541}
542
543/* tagged_hash(aggnonce[0], aggnonce[1], agg_pk, msg) */
544static void secp256k1_musig_compute_noncehash(const secp256k1_hash_ctx *hash_ctx, unsigned char *noncehash, secp256k1_ge *aggnonce, const unsigned char *agg_pk32, const unsigned char *msg) {
545 unsigned char buf[33];
547 int i;
548
550 for (i = 0; i < 2; i++) {
551 secp256k1_musig_ge_serialize_ext(buf, &aggnonce[i]);
552 secp256k1_sha256_write(hash_ctx, &sha, buf, sizeof(buf));
553 }
554 secp256k1_sha256_write(hash_ctx, &sha, agg_pk32, 32);
555 secp256k1_sha256_write(hash_ctx, &sha, msg, 32);
556 secp256k1_sha256_finalize(hash_ctx, &sha, noncehash);
557}
558
559/* out_nonce = nonce_pts[0] + b*nonce_pts[1] */
560static void secp256k1_effective_nonce(secp256k1_gej *out_nonce, const secp256k1_ge *nonce_pts, const secp256k1_scalar *b) {
561 secp256k1_gej tmp;
562
563 secp256k1_gej_set_ge(&tmp, &nonce_pts[1]);
564 secp256k1_ecmult(out_nonce, &tmp, b, NULL);
565 secp256k1_gej_add_ge_var(out_nonce, out_nonce, &nonce_pts[0], NULL);
566}
567
568static void secp256k1_musig_nonce_process_internal(const secp256k1_context *ctx, int *fin_nonce_parity, unsigned char *fin_nonce, secp256k1_scalar *b, secp256k1_ge *aggnonce_pts, const unsigned char *agg_pk32, const unsigned char *msg) {
569 unsigned char noncehash[32];
570 secp256k1_ge fin_nonce_pt;
571 secp256k1_gej fin_nonce_ptj;
572
573 secp256k1_musig_compute_noncehash(secp256k1_get_hash_context(ctx), noncehash, aggnonce_pts, agg_pk32, msg);
574 secp256k1_scalar_set_b32(b, noncehash, NULL);
575 /* fin_nonce = aggnonce_pts[0] + b*aggnonce_pts[1] */
576 secp256k1_effective_nonce(&fin_nonce_ptj, aggnonce_pts, b);
577 secp256k1_ge_set_gej(&fin_nonce_pt, &fin_nonce_ptj);
578 if (secp256k1_ge_is_infinity(&fin_nonce_pt)) {
579 fin_nonce_pt = secp256k1_ge_const_g;
580 }
581 /* fin_nonce_pt is not the point at infinity */
582 secp256k1_fe_normalize_var(&fin_nonce_pt.x);
583 secp256k1_fe_get_b32(fin_nonce, &fin_nonce_pt.x);
584 secp256k1_fe_normalize_var(&fin_nonce_pt.y);
585 *fin_nonce_parity = secp256k1_fe_is_odd(&fin_nonce_pt.y);
586}
587
588int secp256k1_musig_nonce_process(const secp256k1_context* ctx, secp256k1_musig_session *session, const secp256k1_musig_aggnonce *aggnonce, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache) {
590 secp256k1_ge aggnonce_pts[2];
591 unsigned char fin_nonce[32];
593 unsigned char agg_pk32[32];
594
595 VERIFY_CHECK(ctx != NULL);
596 ARG_CHECK(session != NULL);
597 ARG_CHECK(aggnonce != NULL);
598 ARG_CHECK(msg32 != NULL);
599 ARG_CHECK(keyagg_cache != NULL);
600
601 if (!secp256k1_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) {
602 return 0;
603 }
604 secp256k1_fe_get_b32(agg_pk32, &cache_i.pk.x);
605
606 if (!secp256k1_musig_aggnonce_load(ctx, aggnonce_pts, aggnonce)) {
607 return 0;
608 }
609
610 secp256k1_musig_nonce_process_internal(ctx, &session_i.fin_nonce_parity, fin_nonce, &session_i.noncecoef, aggnonce_pts, agg_pk32, msg32);
611 secp256k1_schnorrsig_challenge(secp256k1_get_hash_context(ctx), &session_i.challenge, fin_nonce, msg32, 32, agg_pk32);
612
613 /* If there is a tweak then set `challenge` times `tweak` to the `s`-part.*/
614 secp256k1_scalar_set_int(&session_i.s_part, 0);
615 if (!secp256k1_scalar_is_zero(&cache_i.tweak)) {
616 secp256k1_scalar e_tmp;
617 secp256k1_scalar_mul(&e_tmp, &session_i.challenge, &cache_i.tweak);
618 if (secp256k1_fe_is_odd(&cache_i.pk.y)) {
619 secp256k1_scalar_negate(&e_tmp, &e_tmp);
620 }
621 session_i.s_part = e_tmp;
622 }
623 memcpy(session_i.fin_nonce, fin_nonce, sizeof(session_i.fin_nonce));
624 secp256k1_musig_session_save(session, &session_i);
625 return 1;
626}
627
632}
633
636 secp256k1_ge pk, keypair_pk;
641 int ret;
642
643 VERIFY_CHECK(ctx != NULL);
644
645 ARG_CHECK(secnonce != NULL);
646 /* Fails if the magic doesn't match */
647 ret = secp256k1_musig_secnonce_load(ctx, k, &pk, secnonce);
648 /* Set nonce to zero to avoid nonce reuse. This will cause subsequent calls
649 * of this function to fail */
650 secp256k1_memzero_explicit(secnonce, sizeof(*secnonce));
651 if (!ret) {
653 return 0;
654 }
655
656 ARG_CHECK(partial_sig != NULL);
657 ARG_CHECK(keypair != NULL);
658 ARG_CHECK(keyagg_cache != NULL);
659 ARG_CHECK(session != NULL);
660
661 if (!secp256k1_keypair_load(ctx, &sk, &keypair_pk, keypair)) {
663 return 0;
664 }
665 ARG_CHECK(secp256k1_fe_equal(&pk.x, &keypair_pk.x)
666 && secp256k1_fe_equal(&pk.y, &keypair_pk.y));
667 if (!secp256k1_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) {
669 return 0;
670 }
671
672 /* Negate sk if secp256k1_fe_is_odd(&cache_i.pk.y)) XOR cache_i.parity_acc.
673 * This corresponds to the line "Let d = gâ‹…gaccâ‹…d' mod n" in the
674 * specification. */
675 if ((secp256k1_fe_is_odd(&cache_i.pk.y)
676 != cache_i.parity_acc)) {
678 }
679
680 /* Multiply KeyAgg coefficient */
682 secp256k1_scalar_mul(&sk, &sk, &mu);
683
684 if (!secp256k1_musig_session_load(ctx, &session_i, session)) {
686 return 0;
687 }
688
689 if (session_i.fin_nonce_parity) {
690 secp256k1_scalar_negate(&k[0], &k[0]);
691 secp256k1_scalar_negate(&k[1], &k[1]);
692 }
693
694 /* Sign */
695 secp256k1_scalar_mul(&s, &session_i.challenge, &sk);
696 secp256k1_scalar_mul(&k[1], &session_i.noncecoef, &k[1]);
697 secp256k1_scalar_add(&k[0], &k[0], &k[1]);
698 secp256k1_scalar_add(&s, &s, &k[0]);
699 secp256k1_musig_partial_sig_save(partial_sig, &s);
701 return 1;
702}
703
707 secp256k1_scalar mu, e, s;
708 secp256k1_gej pkj;
709 secp256k1_ge nonce_pts[2];
710 secp256k1_gej rj;
711 secp256k1_gej tmp;
712 secp256k1_ge pkp;
713
714 VERIFY_CHECK(ctx != NULL);
715 ARG_CHECK(partial_sig != NULL);
716 ARG_CHECK(pubnonce != NULL);
717 ARG_CHECK(pubkey != NULL);
718 ARG_CHECK(keyagg_cache != NULL);
719 ARG_CHECK(session != NULL);
720
721 if (!secp256k1_musig_session_load(ctx, &session_i, session)) {
722 return 0;
723 }
724
725 if (!secp256k1_musig_pubnonce_load(ctx, nonce_pts, pubnonce)) {
726 return 0;
727 }
728 /* Compute "effective" nonce rj = nonce_pts[0] + b*nonce_pts[1] */
729 /* TODO: use multiexp to compute -s*G + e*mu*pubkey + nonce_pts[0] + b*nonce_pts[1] */
730 secp256k1_effective_nonce(&rj, nonce_pts, &session_i.noncecoef);
731
732 if (!secp256k1_pubkey_load(ctx, &pkp, pubkey)) {
733 return 0;
734 }
735 if (!secp256k1_keyagg_cache_load(ctx, &cache_i, keyagg_cache)) {
736 return 0;
737 }
738 /* Multiplying the challenge by the KeyAgg coefficient is equivalent
739 * to multiplying the signer's public key by the coefficient, except
740 * much easier to do. */
742 secp256k1_scalar_mul(&e, &session_i.challenge, &mu);
743
744 /* Negate e if secp256k1_fe_is_odd(&cache_i.pk.y)) XOR cache_i.parity_acc.
745 * This corresponds to the line "Let g' = gâ‹…gacc mod n" and the multiplication "g'â‹…e"
746 * in the specification. */
747 if (secp256k1_fe_is_odd(&cache_i.pk.y)
748 != cache_i.parity_acc) {
750 }
751
752 if (!secp256k1_musig_partial_sig_load(ctx, &s, partial_sig)) {
753 return 0;
754 }
755 /* Compute -s*G + e*pkj + rj (e already includes the keyagg coefficient mu) */
757 secp256k1_gej_set_ge(&pkj, &pkp);
758 secp256k1_ecmult(&tmp, &pkj, &e, &s);
759 if (session_i.fin_nonce_parity) {
760 secp256k1_gej_neg(&rj, &rj);
761 }
762 secp256k1_gej_add_var(&tmp, &tmp, &rj, NULL);
763
764 return secp256k1_gej_is_infinity(&tmp);
765}
766
767int secp256k1_musig_partial_sig_agg(const secp256k1_context* ctx, unsigned char *sig64, const secp256k1_musig_session *session, const secp256k1_musig_partial_sig * const* partial_sigs, size_t n_sigs) {
768 size_t i;
770
771 VERIFY_CHECK(ctx != NULL);
772 ARG_CHECK(sig64 != NULL);
773 ARG_CHECK(session != NULL);
774 ARG_CHECK(partial_sigs != NULL);
775 ARG_CHECK(n_sigs > 0);
776 for (i = 0; i < n_sigs; i++) {
777 ARG_CHECK(partial_sigs[i] != NULL);
778 }
779
780 if (!secp256k1_musig_session_load(ctx, &session_i, session)) {
781 return 0;
782 }
783 for (i = 0; i < n_sigs; i++) {
784 secp256k1_scalar term;
785 if (!secp256k1_musig_partial_sig_load(ctx, &term, partial_sigs[i])) {
786 return 0;
787 }
788 secp256k1_scalar_add(&session_i.s_part, &session_i.s_part, &term);
789 }
790 secp256k1_scalar_get_b32(&sig64[32], &session_i.s_part);
791 memcpy(&sig64[0], session_i.fin_nonce, 32);
792 return 1;
793}
794
795#endif
int ret
static void secp256k1_eckey_pubkey_serialize33(secp256k1_ge *elem, unsigned char *pub33)
Serialize a group element (that is not allowed to be infinity) to a compressed public key (33 bytes).
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
Double multiply: R = na*A + ng*G.
static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp256k1_gej *r, const secp256k1_scalar *a)
Multiply with the generator: R = a*G.
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ctx)
static int secp256k1_keypair_load(const secp256k1_context *ctx, secp256k1_scalar *sk, secp256k1_ge *pk, const secp256k1_keypair *keypair)
Definition: main_impl.h:176
#define secp256k1_fe_is_odd
Definition: field.h:85
#define secp256k1_fe_normalize_var
Definition: field.h:80
#define secp256k1_fe_get_b32
Definition: field.h:89
static int secp256k1_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b)
Determine whether two field elements are equal.
static void secp256k1_gej_clear(secp256k1_gej *r)
Clear a secp256k1_gej to prevent leaking sensitive information.
static void secp256k1_gej_set_infinity(secp256k1_gej *r)
Set a group element (jacobian) equal to the point at infinity.
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
Check whether a group element is the point at infinity.
static void secp256k1_gej_add_ge_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_ge *b, secp256k1_fe *rzr)
Set r equal to the sum of a and b (with b given in affine coordinates).
static void secp256k1_ge_to_bytes_ext(unsigned char *data, const secp256k1_ge *ge)
Convert a group element (that is allowed to be infinity) to a 64-byte array.
static void secp256k1_ge_from_bytes_ext(secp256k1_ge *ge, const unsigned char *data)
Convert a 64-byte array into a group element.
static void secp256k1_gej_add_var(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_gej *b, secp256k1_fe *rzr)
Set r equal to the sum of a and b.
static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a)
Set a group element equal to another which is given in jacobian coordinates.
static int secp256k1_ge_is_in_correct_subgroup(const secp256k1_ge *ge)
Determine if a point (which is assumed to be on the curve) is in the correct (sub)group of the curve.
static void secp256k1_ge_set_all_gej(secp256k1_ge *r, const secp256k1_gej *a, size_t len)
Set group elements r[0:len] (affine) equal to group elements a[0:len] (jacobian).
static int secp256k1_ge_is_infinity(const secp256k1_ge *a)
Check whether a group element is the point at infinity.
static void secp256k1_ge_set_infinity(secp256k1_ge *r)
Set a group element (affine) equal to the point at infinity.
static void secp256k1_ge_set_all_gej_var(secp256k1_ge *r, const secp256k1_gej *a, size_t len)
Set group elements r[0:len] (affine) equal to group elements a[0:len] (jacobian).
static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a)
Set a group element (jacobian) equal to another which is given in affine coordinates.
static void secp256k1_ge_to_bytes(unsigned char *buf, const secp256k1_ge *a)
Convert a group element that is not infinity to a 64-byte array.
static void secp256k1_gej_neg(secp256k1_gej *r, const secp256k1_gej *a)
Set r equal to the inverse of a (i.e., mirrored around the X axis)
static void secp256k1_ge_from_bytes(secp256k1_ge *r, const unsigned char *buf)
Convert a 64-byte array into group element.
static const secp256k1_ge secp256k1_ge_const_g
Definition: group_impl.h:72
static void secp256k1_musig_keyaggcoef(const secp256k1_hash_ctx *hash_ctx, secp256k1_scalar *r, const secp256k1_keyagg_cache_internal *cache_i, secp256k1_ge *pk)
static int secp256k1_keyagg_cache_load(const secp256k1_context *ctx, secp256k1_keyagg_cache_internal *cache_i, const secp256k1_musig_keyagg_cache *cache)
unsigned int nonce
Definition: miner_tests.cpp:82
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
Set a scalar from a big endian byte array.
static int secp256k1_scalar_set_b32_seckey(secp256k1_scalar *r, const unsigned char *bin)
Set a scalar from a big endian byte array and returns 1 if it is a valid seckey and 0 otherwise.
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
Check whether a scalar equals zero.
static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v)
Set a scalar to an unsigned integer.
static void secp256k1_scalar_get_b32(unsigned char *bin, const secp256k1_scalar *a)
Convert a scalar to a byte array.
static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Add two scalars together (modulo the group order).
static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Multiply two scalars (modulo the group order).
static void secp256k1_scalar_negate(secp256k1_scalar *r, const secp256k1_scalar *a)
Compute the complement of a scalar (modulo the group order).
static void secp256k1_scalar_clear(secp256k1_scalar *r)
Clear a scalar to prevent the leak of sensitive data.
static void secp256k1_schnorrsig_challenge(const secp256k1_hash_ctx *hash_ctx, secp256k1_scalar *e, const unsigned char *r32, const unsigned char *msg, size_t msglen, const unsigned char *pubkey32)
Definition: main_impl.h:106
static void secp256k1_sha256_finalize(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_sha256_initialize_midstate(secp256k1_sha256 *hash, uint64_t bytes, const uint32_t state[8])
static void secp256k1_sha256_write(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, const unsigned char *data, size_t size)
static void secp256k1_sha256_clear(secp256k1_sha256 *hash)
static SECP256K1_INLINE void secp256k1_memclear_explicit(void *ptr, size_t len)
Definition: util.h:258
static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
Definition: util.h:271
static SECP256K1_INLINE void secp256k1_memzero_explicit(void *ptr, size_t len)
Definition: util.h:226
static SECP256K1_INLINE int secp256k1_is_zero_array(const unsigned char *s, size_t len)
Definition: util.h:286
static SECP256K1_INLINE void secp256k1_write_be64(unsigned char *p, uint64_t x)
Definition: util.h:446
#define VERIFY_CHECK(cond)
Definition: util.h:159
static SECP256K1_INLINE void secp256k1_memczero(void *s, size_t len, int flag)
Definition: util.h:210
#define ARG_CHECK(cond)
Definition: secp256k1.c:45
static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context *ctx, const void *p, size_t len)
Definition: secp256k1.c:255
static int secp256k1_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_pubkey *pubkey)
Definition: secp256k1.c:259
static SECP256K1_INLINE const secp256k1_hash_ctx * secp256k1_get_hash_context(const secp256k1_context *ctx)
Definition: secp256k1.c:238
SECP256K1_API int secp256k1_keypair_pub(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const secp256k1_keypair *keypair) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Get the public key from a keypair.
Definition: main_impl.h:224
SECP256K1_API int secp256k1_keypair_sec(const secp256k1_context *ctx, unsigned char *seckey, const secp256k1_keypair *keypair) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Get the secret key from a keypair.
Definition: main_impl.h:214
static void secp256k1_musig_secnonce_save(secp256k1_musig_secnonce *secnonce, const secp256k1_scalar *k, const secp256k1_ge *pk)
Definition: session_impl.h:50
static int secp256k1_musig_nonce_gen_internal(const secp256k1_context *ctx, secp256k1_musig_secnonce *secnonce, secp256k1_musig_pubnonce *pubnonce, const unsigned char *input_nonce, const unsigned char *seckey, const secp256k1_pubkey *pubkey, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32)
Definition: session_impl.h:372
int secp256k1_musig_partial_sign(const secp256k1_context *ctx, secp256k1_musig_partial_sig *partial_sig, secp256k1_musig_secnonce *secnonce, const secp256k1_keypair *keypair, const secp256k1_musig_keyagg_cache *keyagg_cache, const secp256k1_musig_session *session)
Produces a partial signature.
Definition: session_impl.h:634
static void secp256k1_musig_compute_noncehash(const secp256k1_hash_ctx *hash_ctx, unsigned char *noncehash, secp256k1_ge *aggnonce, const unsigned char *agg_pk32, const unsigned char *msg)
Definition: session_impl.h:544
static const unsigned char secp256k1_musig_aggnonce_magic[4]
Definition: session_impl.h:108
static void secp256k1_musig_ge_serialize_ext(unsigned char *out33, secp256k1_ge *ge)
Definition: session_impl.h:24
int secp256k1_musig_nonce_gen(const secp256k1_context *ctx, secp256k1_musig_secnonce *secnonce, secp256k1_musig_pubnonce *pubnonce, unsigned char *session_secrand32, const unsigned char *seckey, const secp256k1_pubkey *pubkey, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32)
Starts a signing session by generating a nonce.
Definition: session_impl.h:437
int secp256k1_musig_aggnonce_serialize(const secp256k1_context *ctx, unsigned char *out66, const secp256k1_musig_aggnonce *nonce)
Serialize an aggregate public nonce.
Definition: session_impl.h:244
static const unsigned char secp256k1_musig_secnonce_magic[4]
Definition: session_impl.h:48
static int secp256k1_musig_sum_pubnonces(const secp256k1_context *ctx, secp256k1_gej *summed_pubnonces, const secp256k1_musig_pubnonce *const *pubnonces, size_t n_pubnonces)
Definition: session_impl.h:493
int secp256k1_musig_partial_sig_serialize(const secp256k1_context *ctx, unsigned char *out32, const secp256k1_musig_partial_sig *sig)
Serialize a MuSig partial signature.
Definition: session_impl.h:281
int secp256k1_musig_nonce_gen_counter(const secp256k1_context *ctx, secp256k1_musig_secnonce *secnonce, secp256k1_musig_pubnonce *pubnonce, uint64_t nonrepeating_cnt, const secp256k1_keypair *keypair, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *extra_input32)
Alternative way to generate a nonce and start a signing session.
Definition: session_impl.h:465
static int secp256k1_musig_partial_sig_load(const secp256k1_context *ctx, secp256k1_scalar *s, const secp256k1_musig_partial_sig *sig)
Definition: session_impl.h:178
static void secp256k1_musig_aggnonce_save(secp256k1_musig_aggnonce *nonce, const secp256k1_ge *ges)
Definition: session_impl.h:110
int secp256k1_musig_partial_sig_agg(const secp256k1_context *ctx, unsigned char *sig64, const secp256k1_musig_session *session, const secp256k1_musig_partial_sig *const *partial_sigs, size_t n_sigs)
Aggregates partial signatures.
Definition: session_impl.h:767
static const unsigned char secp256k1_musig_partial_sig_magic[4]
Definition: session_impl.h:171
static int secp256k1_musig_pubnonce_load(const secp256k1_context *ctx, secp256k1_ge *ges, const secp256k1_musig_pubnonce *nonce)
Definition: session_impl.h:98
static const unsigned char secp256k1_musig_session_cache_magic[4]
Definition: session_impl.h:128
static void secp256k1_musig_compute_noncehash_sha256_tagged(secp256k1_sha256 *sha)
Definition: session_impl.h:535
static void secp256k1_nonce_function_musig_sha256_tagged_aux(secp256k1_sha256 *sha)
Definition: session_impl.h:311
static int secp256k1_musig_secnonce_load(const secp256k1_context *ctx, secp256k1_scalar *k, secp256k1_ge *pk, const secp256k1_musig_secnonce *secnonce)
Definition: session_impl.h:57
static void secp256k1_nonce_function_musig_sha256_tagged(secp256k1_sha256 *sha)
Definition: session_impl.h:321
static void secp256k1_musig_partial_sig_save(secp256k1_musig_partial_sig *sig, secp256k1_scalar *s)
Definition: session_impl.h:173
static void secp256k1_musig_secnonce_invalidate(const secp256k1_context *ctx, secp256k1_musig_secnonce *secnonce, int flag)
Definition: session_impl.h:74
int secp256k1_musig_partial_sig_verify(const secp256k1_context *ctx, const secp256k1_musig_partial_sig *partial_sig, const secp256k1_musig_pubnonce *pubnonce, const secp256k1_pubkey *pubkey, const secp256k1_musig_keyagg_cache *keyagg_cache, const secp256k1_musig_session *session)
Verifies an individual signer's partial signature.
Definition: session_impl.h:704
static void secp256k1_musig_session_save(secp256k1_musig_session *session, const secp256k1_musig_session_internal *session_i)
Definition: session_impl.h:138
int secp256k1_musig_aggnonce_parse(const secp256k1_context *ctx, secp256k1_musig_aggnonce *nonce, const unsigned char *in66)
Parse an aggregate public nonce.
Definition: session_impl.h:227
static void secp256k1_effective_nonce(secp256k1_gej *out_nonce, const secp256k1_ge *nonce_pts, const secp256k1_scalar *b)
Definition: session_impl.h:560
int secp256k1_musig_nonce_process(const secp256k1_context *ctx, secp256k1_musig_session *session, const secp256k1_musig_aggnonce *aggnonce, const unsigned char *msg32, const secp256k1_musig_keyagg_cache *keyagg_cache)
Takes the aggregate nonce and creates a session that is required for signing and verification of part...
Definition: session_impl.h:588
static int secp256k1_musig_ge_parse_ext(secp256k1_ge *ge, const unsigned char *in33)
Definition: session_impl.h:35
static int secp256k1_musig_session_load(const secp256k1_context *ctx, secp256k1_musig_session_internal *session_i, const secp256k1_musig_session *session)
Definition: session_impl.h:154
static void secp256k1_nonce_function_musig_helper(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *sha, unsigned int prefix_size, const unsigned char *data, unsigned char len)
Definition: session_impl.h:292
int secp256k1_musig_nonce_agg(const secp256k1_context *ctx, secp256k1_musig_aggnonce *aggnonce, const secp256k1_musig_pubnonce *const *pubnonces, size_t n_pubnonces)
Aggregates the nonces of all signers into a single nonce.
Definition: session_impl.h:512
static void secp256k1_musig_nonce_process_internal(const secp256k1_context *ctx, int *fin_nonce_parity, unsigned char *fin_nonce, secp256k1_scalar *b, secp256k1_ge *aggnonce_pts, const unsigned char *agg_pk32, const unsigned char *msg)
Definition: session_impl.h:568
static void secp256k1_musig_partial_sign_clear(secp256k1_scalar *sk, secp256k1_scalar *k)
Definition: session_impl.h:628
static const unsigned char secp256k1_musig_pubnonce_magic[4]
Definition: session_impl.h:84
int secp256k1_musig_partial_sig_parse(const secp256k1_context *ctx, secp256k1_musig_partial_sig *sig, const unsigned char *in32)
Parse a MuSig partial signature.
Definition: session_impl.h:262
int secp256k1_musig_pubnonce_parse(const secp256k1_context *ctx, secp256k1_musig_pubnonce *nonce, const unsigned char *in66)
Parse a signer's public nonce.
Definition: session_impl.h:188
static int secp256k1_musig_aggnonce_load(const secp256k1_context *ctx, secp256k1_ge *ges, const secp256k1_musig_aggnonce *nonce)
Definition: session_impl.h:118
static void secp256k1_nonce_function_musig(const secp256k1_hash_ctx *hash_ctx, secp256k1_scalar *k, const unsigned char *session_secrand, const unsigned char *msg32, const unsigned char *seckey32, const unsigned char *pk33, const unsigned char *agg_pk32, const unsigned char *extra_input32)
Definition: session_impl.h:329
static void secp256k1_musig_pubnonce_save(secp256k1_musig_pubnonce *nonce, const secp256k1_ge *ges)
Definition: session_impl.h:88
int secp256k1_musig_pubnonce_serialize(const secp256k1_context *ctx, unsigned char *out66, const secp256k1_musig_pubnonce *nonce)
Serialize a signer's public nonce.
Definition: session_impl.h:208
secp256k1_ecmult_gen_context ecmult_gen_ctx
Definition: secp256k1.c:62
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Definition: group.h:16
secp256k1_fe x
Definition: group.h:17
secp256k1_fe y
Definition: group.h:18
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:28
secp256k1_scalar tweak
Definition: keyagg.h:22
Opaque data structure that holds a keypair consisting of a secret and a public key.
Opaque data structure that holds an aggregate public nonce.
This module implements BIP 327 "MuSig2 for BIP340-compatible Multi-Signatures" (https://github....
Opaque data structure that holds a partial MuSig signature.
Opaque data structure that holds a signer's public nonce.
Opaque data structure that holds a signer's secret nonce.
unsigned char data[132]
secp256k1_scalar noncecoef
Definition: session.h:17
secp256k1_scalar s_part
Definition: session.h:19
secp256k1_scalar challenge
Definition: session.h:18
unsigned char fin_nonce[32]
Definition: session.h:16
Opaque data structure that holds a MuSig session.
unsigned char data[133]
Opaque data structure that holds a parsed and valid public key.
Definition: secp256k1.h:62
A scalar modulo the group order of the secp256k1 curve.
Definition: scalar_4x64.h:13