6#ifndef SECP256K1_MODULE_MUSIG_KEYAGG_IMPL_H
7#define SECP256K1_MODULE_MUSIG_KEYAGG_IMPL_H
32 unsigned char *ptr = cache->
data;
43 secp256k1_scalar_get_b32(ptr, &cache_i->
tweak);
47 const unsigned char *ptr = cache->
data;
58 secp256k1_scalar_set_b32(&cache_i->
tweak, ptr, NULL);
65 static const uint32_t midstate[8] = {
66 0xb399d5e0ul, 0xc8fff302ul, 0x6badac71ul, 0x07c5b7f1ul,
67 0x9701e2eful, 0x2a72ecf8ul, 0x201a4c7bul, 0xab148a38ul
78 for (i = 0; i < np; i++) {
79 unsigned char ser[33];
80 size_t ser_len =
sizeof(ser);
94 static const uint32_t midstate[8] = {
95 0x6ef02c5aul, 0x06a480deul, 0x1f298665ul, 0x1d1134f2ul,
96 0x56a0b063ul, 0x52da4147ul, 0xf280d9d4ul, 0x4484be15ul
109 if (!secp256k1_ge_is_infinity(second_pk)
111 secp256k1_scalar_set_int(r, 1);
114 unsigned char buf[33];
122 secp256k1_scalar_set_b32(r, buf, NULL);
144 ret = secp256k1_pubkey_load(ctx->
ctx, pt, ctx->
pks[idx]);
163 if (agg_pk != NULL) {
164 memset(agg_pk, 0,
sizeof(*agg_pk));
168 for (i = 0; i < n_pubkeys; i++) {
172 ecmult_data.
ctx = ctx;
173 ecmult_data.
pks = pubkeys;
176 for (i = 1; i < n_pubkeys; i++) {
179 if (!secp256k1_pubkey_load(ctx, &pk, pubkeys[i])) {
198 secp256k1_ge_set_gej(&pkp, &pkj);
202 if (keyagg_cache != NULL) {
210 if (agg_pk != NULL) {
221 memset(agg_pk, 0,
sizeof(*agg_pk));
227 secp256k1_pubkey_save(agg_pk, &cache_i.
pk);
237 if (output_pubkey != NULL) {
238 memset(output_pubkey, 0,
sizeof(*output_pubkey));
246 secp256k1_scalar_set_b32(&
tweak, tweak32, &overflow);
252 secp256k1_scalar_negate(&cache_i.
tweak, &cache_i.
tweak);
261 if (output_pubkey != NULL) {
262 secp256k1_pubkey_save(output_pubkey, &cache_i.
pk);
static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak)
static SECP256K1_INLINE void secp256k1_xonly_pubkey_save(secp256k1_xonly_pubkey *pubkey, secp256k1_ge *ge)
static int secp256k1_extrakeys_ge_even_y(secp256k1_ge *r)
Keeps a group element as is if it has an even Y and otherwise negates it.
#define secp256k1_fe_normalize_var
static int secp256k1_ge_eq_var(const secp256k1_ge *a, const secp256k1_ge *b)
Check two group elements (affine) for equality in variable time.
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_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 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_ge_set_infinity(secp256k1_ge *r)
Set a group element (affine) equal to the point at infinity.
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_ge_from_bytes(secp256k1_ge *r, const unsigned char *buf)
Convert a 64-byte array into group element.
struct secp256k1_context_struct secp256k1_context
Unless explicitly stated all pointer arguments must not be NULL.
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)
static int secp256k1_musig_pubkey_agg_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data)
static void secp256k1_musig_keyaggcoef_sha256(secp256k1_sha256 *sha)
static int secp256k1_musig_pubkey_tweak_add_internal(const secp256k1_context *ctx, secp256k1_pubkey *output_pubkey, secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32, int xonly)
static void secp256k1_musig_keyagglist_sha256(secp256k1_sha256 *sha)
static const unsigned char secp256k1_musig_keyagg_cache_magic[4]
static void secp256k1_keyagg_cache_save(secp256k1_musig_keyagg_cache *cache, const secp256k1_keyagg_cache_internal *cache_i)
static void secp256k1_musig_keyaggcoef_internal(const secp256k1_hash_ctx *hash_ctx, secp256k1_scalar *r, const unsigned char *pks_hash, secp256k1_ge *pk, const secp256k1_ge *second_pk)
static int secp256k1_musig_compute_pks_hash(const secp256k1_context *ctx, unsigned char *pks_hash, const secp256k1_pubkey *const *pks, size_t np)
static int tweak(const secp256k1_context *ctx, secp256k1_xonly_pubkey *agg_pk, secp256k1_musig_keyagg_cache *cache)
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 SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
#define VERIFY_CHECK(cond)
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Serialize a pubkey object into a serialized byte sequence.
#define SECP256K1_EC_COMPRESSED
Flag to pass to secp256k1_ec_pubkey_serialize.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubkey_ec_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *output_pubkey, secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Apply plain "EC" tweaking to a public key in a given keyagg_cache by adding the generator multiplied ...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubkey_xonly_tweak_add(const secp256k1_context *ctx, secp256k1_pubkey *output_pubkey, secp256k1_musig_keyagg_cache *keyagg_cache, const unsigned char *tweak32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Apply x-only tweaking to a public key in a given keyagg_cache by adding the generator multiplied with...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubkey_get(const secp256k1_context *ctx, secp256k1_pubkey *agg_pk, const secp256k1_musig_keyagg_cache *keyagg_cache) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Obtain the aggregate public key from a keyagg_cache.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_musig_pubkey_agg(const secp256k1_context *ctx, secp256k1_xonly_pubkey *agg_pk, secp256k1_musig_keyagg_cache *keyagg_cache, const secp256k1_pubkey *const *pubkeys, size_t n_pubkeys) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(4)
Computes an aggregate public key and uses it to initialize a keyagg_cache.
secp256k1_callback error_callback
secp256k1_hash_ctx hash_ctx
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
A group element of the secp256k1 curve, in jacobian coordinates.
unsigned char pks_hash[32]
This module implements BIP 327 "MuSig2 for BIP340-compatibleMulti-Signatures" (https://github....
const secp256k1_pubkey *const * pks
unsigned char pks_hash[32]
const secp256k1_context * ctx
Opaque data structure that holds a parsed and valid public key.
A scalar modulo the group order of the secp256k1 curve.
Opaque data structure that holds a parsed and valid "x-only" public key.