Skip to content

Commit 468c5c4

Browse files
committed
fixup! move musig_ge_{to,from} to group.h
1 parent 2a0d934 commit 468c5c4

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

src/group.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ static void secp256k1_ge_to_bytes(unsigned char *buf, secp256k1_ge *a);
182182
* provided buffer correctly encodes a group element. */
183183
static void secp256k1_ge_from_bytes(secp256k1_ge *r, const unsigned char *buf);
184184

185+
/** Convert a group element (that is allowed to be infinity) to a 64-byte
186+
* array. The output array is platform-dependent. */
187+
static void secp256k1_ge_to_bytes_ext(unsigned char *data, secp256k1_ge *ge);
188+
189+
/** Convert a 64-byte array into a group element. This function assumes that the
190+
* provided buffer is the output of secp256k1_ge_to_bytes_ext. */
191+
static void secp256k1_ge_from_bytes_ext(secp256k1_ge *ge, const unsigned char *data);
192+
185193
/** Determine if a point (which is assumed to be on the curve) is in the correct (sub)group of the curve.
186194
*
187195
* In normal mode, the used group is secp256k1, which has cofactor=1 meaning that every point on the curve is in the

src/group_impl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,4 +963,21 @@ static void secp256k1_ge_from_bytes(secp256k1_ge *r, const unsigned char *buf) {
963963
secp256k1_ge_from_storage(r, &s);
964964
}
965965

966+
static void secp256k1_ge_to_bytes_ext(unsigned char *data, secp256k1_ge *ge) {
967+
if (secp256k1_ge_is_infinity(ge)) {
968+
memset(data, 0, 64);
969+
} else {
970+
secp256k1_ge_to_bytes(data, ge);
971+
}
972+
}
973+
974+
static void secp256k1_ge_from_bytes_ext(secp256k1_ge *ge, const unsigned char *data) {
975+
unsigned char zeros[64] = { 0 };
976+
if (secp256k1_memcmp_var(data, zeros, sizeof(zeros)) == 0) {
977+
secp256k1_ge_set_infinity(ge);
978+
} else {
979+
secp256k1_ge_from_bytes(ge, data);
980+
}
981+
}
982+
966983
#endif /* SECP256K1_GROUP_IMPL_H */

src/modules/musig/keyagg.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ typedef struct {
2727
int parity_acc;
2828
} secp256k1_keyagg_cache_internal;
2929

30-
/* musig_ge_to_bytes_ext and musig_ge_from_bytes_ext are identical to ge_save and ge_load
31-
* except that they allow saving and loading the point at infinity */
32-
static void secp256k1_musig_ge_to_bytes_ext(unsigned char *data, secp256k1_ge *ge);
33-
34-
static void secp256k1_musig_ge_from_bytes_ext(secp256k1_ge *ge, const unsigned char *data);
35-
3630
static int secp256k1_keyagg_cache_load(const secp256k1_context* ctx, secp256k1_keyagg_cache_internal *cache_i, const secp256k1_musig_keyagg_cache *cache);
3731

3832
static void secp256k1_musig_keyaggcoef(secp256k1_scalar *r, const secp256k1_keyagg_cache_internal *cache_i, secp256k1_ge *pk);

src/modules/musig/keyagg_impl.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@
1717
#include "../../hash.h"
1818
#include "../../util.h"
1919

20-
static void secp256k1_musig_ge_to_bytes_ext(unsigned char *data, secp256k1_ge *ge) {
21-
if (secp256k1_ge_is_infinity(ge)) {
22-
memset(data, 0, 64);
23-
} else {
24-
secp256k1_ge_to_bytes(data, ge);
25-
}
26-
}
27-
28-
static void secp256k1_musig_ge_from_bytes_ext(secp256k1_ge *ge, const unsigned char *data) {
29-
unsigned char zeros[64] = { 0 };
30-
if (secp256k1_memcmp_var(data, zeros, sizeof(zeros)) == 0) {
31-
secp256k1_ge_set_infinity(ge);
32-
} else {
33-
secp256k1_ge_from_bytes(ge, data);
34-
}
35-
}
36-
3720
static const unsigned char secp256k1_musig_keyagg_cache_magic[4] = { 0xf4, 0xad, 0xbb, 0xdf };
3821

3922
/* A keyagg cache consists of
@@ -52,7 +35,7 @@ static void secp256k1_keyagg_cache_save(secp256k1_musig_keyagg_cache *cache, sec
5235
ptr += 4;
5336
secp256k1_ge_to_bytes(ptr, &cache_i->pk);
5437
ptr += 64;
55-
secp256k1_musig_ge_to_bytes_ext(ptr, &cache_i->second_pk);
38+
secp256k1_ge_to_bytes_ext(ptr, &cache_i->second_pk);
5639
ptr += 64;
5740
memcpy(ptr, cache_i->pk_hash, 32);
5841
ptr += 32;
@@ -67,7 +50,7 @@ static int secp256k1_keyagg_cache_load(const secp256k1_context* ctx, secp256k1_k
6750
ptr += 4;
6851
secp256k1_ge_from_bytes(&cache_i->pk, ptr);
6952
ptr += 64;
70-
secp256k1_musig_ge_from_bytes_ext(&cache_i->second_pk, ptr);
53+
secp256k1_ge_from_bytes_ext(&cache_i->second_pk, ptr);
7154
ptr += 64;
7255
memcpy(cache_i->pk_hash, ptr, 32);
7356
ptr += 32;

src/modules/musig/session_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void secp256k1_musig_aggnonce_save(secp256k1_musig_aggnonce* nonce, secp2
114114
int i;
115115
memcpy(&nonce->data[0], secp256k1_musig_aggnonce_magic, 4);
116116
for (i = 0; i < 2; i++) {
117-
secp256k1_musig_ge_to_bytes_ext(&nonce->data[4 + 64*i], &ge[i]);
117+
secp256k1_ge_to_bytes_ext(&nonce->data[4 + 64*i], &ge[i]);
118118
}
119119
}
120120

@@ -123,7 +123,7 @@ static int secp256k1_musig_aggnonce_load(const secp256k1_context* ctx, secp256k1
123123

124124
ARG_CHECK(secp256k1_memcmp_var(&nonce->data[0], secp256k1_musig_aggnonce_magic, 4) == 0);
125125
for (i = 0; i < 2; i++) {
126-
secp256k1_musig_ge_from_bytes_ext(&ge[i], &nonce->data[4 + 64*i]);
126+
secp256k1_ge_from_bytes_ext(&ge[i], &nonce->data[4 + 64*i]);
127127
}
128128
return 1;
129129
}

0 commit comments

Comments
 (0)