Skip to content

Commit 6045c3d

Browse files
committed
Incremental Half-Aggregation for Schnorr Signatures.
1 parent b2ccc8d commit 6045c3d

7 files changed

+738
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ schnorr_example
2323
*.trs
2424
*.sage.py
2525

26+
.vscode/
27+
2628
Makefile
2729
configure
2830
.libs/

include/secp256k1_schnorrsig.h

+75
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,81 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify(
183183
const secp256k1_xonly_pubkey *pubkey
184184
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(5);
185185

186+
187+
/** Incrementally (Half-)Aggregate a sequence of Schnorr signatures to an existing half-aggregate signature.
188+
*
189+
* Returns 1 on success, 0 on failure.
190+
* Args: ctx: a secp256k1 context object.
191+
* In/Out: aggsig: pointer to the serialized aggregate signature that is input. Will be overwritten by the new serialized aggregate signature.
192+
* aggsig_size: size of the memory allocated in aggsig. Should be large enough to hold the new serialized aggregate signature.
193+
* In: all_pubkeys: Array of x-only public keys, including both the ones for the already aggregated signature
194+
* and the ones for the signatures that should be added.
195+
* Assumed to contain n = n_before + n_new many public keys.
196+
* all_msgs32: Array of 32-byte messages, including both the ones for the already aggregated signature
197+
* and the ones for the signatures that should be added.
198+
* Assumed to contain n = n_before + n_new many messages.
199+
* new_sigs64: Array of 64-byte signatures, containing the new signatures that should be added.
200+
* Assumed to contain n_new many signatures.
201+
* n_before: Number of signatures that are already "contained" in the aggregate signature
202+
* n_new: Number of signatures that should now be added to the aggregate signature
203+
*/
204+
SECP256K1_API int secp256k1_schnorrsig_inc_aggregate(
205+
const secp256k1_context* ctx,
206+
unsigned char* aggsig,
207+
size_t* aggsig_size,
208+
const secp256k1_xonly_pubkey* all_pubkeys,
209+
const unsigned char* all_msgs32,
210+
const unsigned char* new_sigs64,
211+
size_t n_before,
212+
size_t n_new
213+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6);
214+
215+
216+
217+
/** (Half-)Aggregate a sequence of Schnorr signatures.
218+
*
219+
* Returns 1 on success, 0 on failure.
220+
* Args: ctx: a secp256k1 context object.
221+
* Out: aggsig: pointer to an array of aggsig_size many bytes to store the serialized aggregate signature
222+
* In/Out: aggsig_size: size of the aggsig array that is passed; will be overwritten to be the exact size of aggsig.
223+
* In: pubkeys: Array of x-only public keys. Assumed to contain n many public keys.
224+
* msgs32: Array of 32-byte messages. Assumed to contain n many messages.
225+
* sigs64: Array of 64-byte signatures. Assumed to contain n many signatures.
226+
* n: number of signatures to be aggregated.
227+
*/
228+
SECP256K1_API int secp256k1_schnorrsig_aggregate(
229+
const secp256k1_context* ctx,
230+
unsigned char* aggsig,
231+
size_t* aggsig_size,
232+
const secp256k1_xonly_pubkey* pubkeys,
233+
const unsigned char* msgs32,
234+
const unsigned char* sigs64,
235+
size_t n
236+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6);
237+
238+
239+
240+
/** Verify a (Half-)aggregate Schnorr signature.
241+
*
242+
* Returns: 1: correct signature
243+
* 0: incorrect signature.
244+
* Args: ctx: a secp256k1 context object.
245+
* In: pubkeys: Array of x-only public keys. Assume to contain n many public keys.
246+
* msgs32: Array of 32-byte messages. Assumed to contain n many messages.
247+
* n: number of signatures to that have been aggregated.
248+
* aggsig: Pointer to an array of aggsig_size many bytes containing the serialized aggregate signatur to be verified
249+
* aggsig_size: Size of the aggregate signature
250+
*/
251+
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_aggverify(
252+
const secp256k1_context* ctx,
253+
const secp256k1_xonly_pubkey* pubkeys,
254+
const unsigned char* msgs32,
255+
size_t n,
256+
const unsigned char* aggsig,
257+
size_t aggsig_size
258+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5);
259+
260+
186261
#ifdef __cplusplus
187262
}
188263
#endif

src/libsecp256k1-config.h

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/* src/libsecp256k1-config.h. Generated from libsecp256k1-config.h.in by configure. */
2+
/* src/libsecp256k1-config.h.in. Generated from configure.ac by autoheader. */
3+
4+
#ifndef LIBSECP256K1_CONFIG_H
5+
6+
#define LIBSECP256K1_CONFIG_H
7+
8+
/* Define this symbol to compile out all VERIFY code */
9+
/* #undef COVERAGE */
10+
11+
/* Set ecmult gen precision bits */
12+
#define ECMULT_GEN_PREC_BITS 4
13+
14+
/* Set window size for ecmult precomputation */
15+
#define ECMULT_WINDOW_SIZE 15
16+
17+
/* Define this symbol to enable the Bulletproofs++ module */
18+
/* #undef ENABLE_MODULE_BPPP */
19+
20+
/* Define this symbol to enable the ECDH module */
21+
/* #undef ENABLE_MODULE_ECDH */
22+
23+
/* Define this symbol to enable the ECDSA adaptor module */
24+
/* #undef ENABLE_MODULE_ECDSA_ADAPTOR */
25+
26+
/* Define this symbol to enable the ECDSA sign-to-contract module */
27+
/* #undef ENABLE_MODULE_ECDSA_S2C */
28+
29+
/* Define this symbol to enable the extrakeys module */
30+
#define ENABLE_MODULE_EXTRAKEYS 1
31+
32+
/* Define this symbol to enable the NUMS generator module */
33+
/* #undef ENABLE_MODULE_GENERATOR */
34+
35+
/* Define this symbol to enable the MuSig module */
36+
/* #undef ENABLE_MODULE_MUSIG */
37+
38+
/* Define this symbol to enable the Pedersen / zero knowledge range proof
39+
module */
40+
/* #undef ENABLE_MODULE_RANGEPROOF */
41+
42+
/* Define this symbol to enable the ECDSA pubkey recovery module */
43+
/* #undef ENABLE_MODULE_RECOVERY */
44+
45+
/* Define this symbol to enable the schnorrsig module */
46+
#define ENABLE_MODULE_SCHNORRSIG 1
47+
48+
/* Define this symbol to enable the surjection proof module */
49+
/* #undef ENABLE_MODULE_SURJECTIONPROOF */
50+
51+
/* Define this symbol to enable the key whitelisting module */
52+
/* #undef ENABLE_MODULE_WHITELIST */
53+
54+
/* Define this symbol if __builtin_clzll is available */
55+
/* #undef HAVE_BUILTIN_CLZLL */
56+
57+
/* Define this symbol if __builtin_popcount is available */
58+
/* #undef HAVE_BUILTIN_POPCOUNT */
59+
60+
/* Define to 1 if you have the <dlfcn.h> header file. */
61+
#define HAVE_DLFCN_H 1
62+
63+
/* Define to 1 if you have the <inttypes.h> header file. */
64+
#define HAVE_INTTYPES_H 1
65+
66+
/* Define to 1 if you have the <stdint.h> header file. */
67+
#define HAVE_STDINT_H 1
68+
69+
/* Define to 1 if you have the <stdio.h> header file. */
70+
#define HAVE_STDIO_H 1
71+
72+
/* Define to 1 if you have the <stdlib.h> header file. */
73+
#define HAVE_STDLIB_H 1
74+
75+
/* Define to 1 if you have the <strings.h> header file. */
76+
#define HAVE_STRINGS_H 1
77+
78+
/* Define to 1 if you have the <string.h> header file. */
79+
#define HAVE_STRING_H 1
80+
81+
/* Define to 1 if you have the <sys/stat.h> header file. */
82+
#define HAVE_SYS_STAT_H 1
83+
84+
/* Define to 1 if you have the <sys/types.h> header file. */
85+
#define HAVE_SYS_TYPES_H 1
86+
87+
/* Define to 1 if you have the <unistd.h> header file. */
88+
#define HAVE_UNISTD_H 1
89+
90+
/* Define this symbol if valgrind is installed, and it supports the host
91+
platform */
92+
/* #undef HAVE_VALGRIND */
93+
94+
/* Define to the sub-directory where libtool stores uninstalled libraries. */
95+
#define LT_OBJDIR ".libs/"
96+
97+
/* Name of package */
98+
#define PACKAGE "libsecp256k1"
99+
100+
/* Define to the address where bug reports for this package should be sent. */
101+
#define PACKAGE_BUGREPORT "https://github.com/bitcoin-core/secp256k1/issues"
102+
103+
/* Define to the full name of this package. */
104+
#define PACKAGE_NAME "libsecp256k1"
105+
106+
/* Define to the full name and version of this package. */
107+
#define PACKAGE_STRING "libsecp256k1 0.1.0-pre"
108+
109+
/* Define to the one symbol short name of this package. */
110+
#define PACKAGE_TARNAME "libsecp256k1"
111+
112+
/* Define to the home page for this package. */
113+
#define PACKAGE_URL "https://github.com/bitcoin-core/secp256k1"
114+
115+
/* Define to the version of this package. */
116+
#define PACKAGE_VERSION "0.1.0-pre"
117+
118+
/* Define to 1 if all of the C90 standard headers exist (not just the ones
119+
required in a freestanding environment). This macro is provided for
120+
backward compatibility; new code need not use it. */
121+
#define STDC_HEADERS 1
122+
123+
/* Define this symbol to enable x86_64 assembly optimizations */
124+
/* #undef USE_ASM_X86_64 */
125+
126+
/* Define this symbol if an external (non-inline) assembly implementation is
127+
used */
128+
/* #undef USE_EXTERNAL_ASM */
129+
130+
/* Define this symbol if an external implementation of the default callbacks
131+
is used */
132+
/* #undef USE_EXTERNAL_DEFAULT_CALLBACKS */
133+
134+
/* Define this symbol to force the use of the (unsigned) __int128 based wide
135+
multiplication implementation */
136+
/* #undef USE_FORCE_WIDEMUL_INT128 */
137+
138+
/* Define this symbol to force the use of the (u)int64_t based wide
139+
multiplication implementation */
140+
/* #undef USE_FORCE_WIDEMUL_INT64 */
141+
142+
/* Define this symbol to reduce SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS to 16,
143+
disabling parsing and verification */
144+
/* #undef USE_REDUCED_SURJECTION_PROOF_SIZE */
145+
146+
/* Version number of package */
147+
#define VERSION "0.1.0-pre"
148+
149+
#endif /*LIBSECP256K1_CONFIG_H*/

src/libsecp256k1-config.h.in

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/* src/libsecp256k1-config.h.in. Generated from configure.ac by autoheader. */
2+
3+
#ifndef LIBSECP256K1_CONFIG_H
4+
5+
#define LIBSECP256K1_CONFIG_H
6+
7+
/* Define this symbol to compile out all VERIFY code */
8+
#undef COVERAGE
9+
10+
/* Set ecmult gen precision bits */
11+
#undef ECMULT_GEN_PREC_BITS
12+
13+
/* Set window size for ecmult precomputation */
14+
#undef ECMULT_WINDOW_SIZE
15+
16+
/* Define this symbol to enable the Bulletproofs++ module */
17+
#undef ENABLE_MODULE_BPPP
18+
19+
/* Define this symbol to enable the ECDH module */
20+
#undef ENABLE_MODULE_ECDH
21+
22+
/* Define this symbol to enable the ECDSA adaptor module */
23+
#undef ENABLE_MODULE_ECDSA_ADAPTOR
24+
25+
/* Define this symbol to enable the ECDSA sign-to-contract module */
26+
#undef ENABLE_MODULE_ECDSA_S2C
27+
28+
/* Define this symbol to enable the extrakeys module */
29+
#undef ENABLE_MODULE_EXTRAKEYS
30+
31+
/* Define this symbol to enable the NUMS generator module */
32+
#undef ENABLE_MODULE_GENERATOR
33+
34+
/* Define this symbol to enable the MuSig module */
35+
#undef ENABLE_MODULE_MUSIG
36+
37+
/* Define this symbol to enable the Pedersen / zero knowledge range proof
38+
module */
39+
#undef ENABLE_MODULE_RANGEPROOF
40+
41+
/* Define this symbol to enable the ECDSA pubkey recovery module */
42+
#undef ENABLE_MODULE_RECOVERY
43+
44+
/* Define this symbol to enable the schnorrsig module */
45+
#undef ENABLE_MODULE_SCHNORRSIG
46+
47+
/* Define this symbol to enable the surjection proof module */
48+
#undef ENABLE_MODULE_SURJECTIONPROOF
49+
50+
/* Define this symbol to enable the key whitelisting module */
51+
#undef ENABLE_MODULE_WHITELIST
52+
53+
/* Define this symbol if __builtin_clzll is available */
54+
#undef HAVE_BUILTIN_CLZLL
55+
56+
/* Define this symbol if __builtin_popcount is available */
57+
#undef HAVE_BUILTIN_POPCOUNT
58+
59+
/* Define to 1 if you have the <dlfcn.h> header file. */
60+
#undef HAVE_DLFCN_H
61+
62+
/* Define to 1 if you have the <inttypes.h> header file. */
63+
#undef HAVE_INTTYPES_H
64+
65+
/* Define to 1 if you have the <stdint.h> header file. */
66+
#undef HAVE_STDINT_H
67+
68+
/* Define to 1 if you have the <stdio.h> header file. */
69+
#undef HAVE_STDIO_H
70+
71+
/* Define to 1 if you have the <stdlib.h> header file. */
72+
#undef HAVE_STDLIB_H
73+
74+
/* Define to 1 if you have the <strings.h> header file. */
75+
#undef HAVE_STRINGS_H
76+
77+
/* Define to 1 if you have the <string.h> header file. */
78+
#undef HAVE_STRING_H
79+
80+
/* Define to 1 if you have the <sys/stat.h> header file. */
81+
#undef HAVE_SYS_STAT_H
82+
83+
/* Define to 1 if you have the <sys/types.h> header file. */
84+
#undef HAVE_SYS_TYPES_H
85+
86+
/* Define to 1 if you have the <unistd.h> header file. */
87+
#undef HAVE_UNISTD_H
88+
89+
/* Define this symbol if valgrind is installed, and it supports the host
90+
platform */
91+
#undef HAVE_VALGRIND
92+
93+
/* Define to the sub-directory where libtool stores uninstalled libraries. */
94+
#undef LT_OBJDIR
95+
96+
/* Name of package */
97+
#undef PACKAGE
98+
99+
/* Define to the address where bug reports for this package should be sent. */
100+
#undef PACKAGE_BUGREPORT
101+
102+
/* Define to the full name of this package. */
103+
#undef PACKAGE_NAME
104+
105+
/* Define to the full name and version of this package. */
106+
#undef PACKAGE_STRING
107+
108+
/* Define to the one symbol short name of this package. */
109+
#undef PACKAGE_TARNAME
110+
111+
/* Define to the home page for this package. */
112+
#undef PACKAGE_URL
113+
114+
/* Define to the version of this package. */
115+
#undef PACKAGE_VERSION
116+
117+
/* Define to 1 if all of the C90 standard headers exist (not just the ones
118+
required in a freestanding environment). This macro is provided for
119+
backward compatibility; new code need not use it. */
120+
#undef STDC_HEADERS
121+
122+
/* Define this symbol to enable x86_64 assembly optimizations */
123+
#undef USE_ASM_X86_64
124+
125+
/* Define this symbol if an external (non-inline) assembly implementation is
126+
used */
127+
#undef USE_EXTERNAL_ASM
128+
129+
/* Define this symbol if an external implementation of the default callbacks
130+
is used */
131+
#undef USE_EXTERNAL_DEFAULT_CALLBACKS
132+
133+
/* Define this symbol to force the use of the (unsigned) __int128 based wide
134+
multiplication implementation */
135+
#undef USE_FORCE_WIDEMUL_INT128
136+
137+
/* Define this symbol to force the use of the (u)int64_t based wide
138+
multiplication implementation */
139+
#undef USE_FORCE_WIDEMUL_INT64
140+
141+
/* Define this symbol to reduce SECP256K1_SURJECTIONPROOF_MAX_N_INPUTS to 16,
142+
disabling parsing and verification */
143+
#undef USE_REDUCED_SURJECTION_PROOF_SIZE
144+
145+
/* Version number of package */
146+
#undef VERSION
147+
148+
#endif /*LIBSECP256K1_CONFIG_H*/

0 commit comments

Comments
 (0)