Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2ed3978

Browse files
committedFeb 26, 2024·
aggregate and inc_aggregate: allow NULL if n is 0
1 parent 25bc8f3 commit 2ed3978

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed
 

‎include/secp256k1_schnorrsig_halfagg.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ extern "C" {
2828
* In: all_pubkeys: Array of (n_before + n_new) many x-only public keys,
2929
* including both the ones for the already aggregated signature
3030
* and the ones for the signatures that should be added.
31+
* Can only be NULL if n_before + n_new is 0.
3132
* all_msgs32: Array of (n_before + n_new) many 32-byte messages,
3233
* including both the ones for the already aggregated signature
3334
* and the ones for the signatures that should be added.
35+
* Can only be NULL if n_before + n_new is 0.
3436
* new_sigs64: Array of n_new many 64-byte signatures, containing the new
35-
* signatures that should be added.
37+
* signatures that should be added. Can only be NULL if n_new is 0.
3638
* n_before: Number of signatures that have already been aggregated
3739
* in the input aggregate signature.
3840
* n_new: Number of signatures that should now be added
@@ -47,7 +49,7 @@ SECP256K1_API int secp256k1_schnorrsig_inc_aggregate(
4749
const unsigned char *new_sigs64,
4850
size_t n_before,
4951
size_t n_new
50-
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6);
52+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
5153

5254
/** (Half-)Aggregate a sequence of Schnorr signatures.
5355
*
@@ -58,8 +60,11 @@ SECP256K1_API int secp256k1_schnorrsig_inc_aggregate(
5860
* In/Out: aggsig_len: size of the aggsig array that is passed in bytes;
5961
* will be overwritten to be the exact size of aggsig.
6062
* In: pubkeys: Array of n many x-only public keys.
63+
* Can only be NULL if n is 0.
6164
* msgs32: Array of n many 32-byte messages.
65+
* Can only be NULL if n is 0.
6266
* sigs64: Array of n many 64-byte signatures.
67+
* Can only be NULL if n is 0.
6368
* n: number of signatures to be aggregated.
6469
*/
6570
SECP256K1_API int secp256k1_schnorrsig_aggregate(
@@ -70,7 +75,7 @@ SECP256K1_API int secp256k1_schnorrsig_aggregate(
7075
const unsigned char *msgs32,
7176
const unsigned char *sigs64,
7277
size_t n
73-
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6);
78+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
7479

7580
/** Verify a (Half-)aggregate Schnorr signature.
7681
*

‎src/modules/schnorrsig_halfagg/main_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context *ctx, unsigned ch
3131
VERIFY_CHECK(ctx != NULL);
3232
ARG_CHECK(aggsig != NULL);
3333
ARG_CHECK(aggsig_len != NULL);
34-
ARG_CHECK(all_pubkeys != NULL);
35-
ARG_CHECK(all_msgs32 != NULL);
36-
ARG_CHECK(new_sigs64 != NULL);
34+
ARG_CHECK(new_sigs64 != NULL || n_new == 0);
3735

3836
/* Check that aggsig_len is large enough, i.e. aggsig_len >= 32*(n+1) */
3937
n = n_before + n_new;
4038
ARG_CHECK(n >= n_before);
39+
ARG_CHECK(all_pubkeys != NULL || n == 0);
40+
ARG_CHECK(all_msgs32 != NULL || n == 0);
4141
if ((*aggsig_len / 32) <= 0 || ((*aggsig_len / 32) - 1) < n) {
4242
return 0;
4343
}

‎src/modules/schnorrsig_halfagg/tests_impl.h

+18-9
Original file line numberDiff line numberDiff line change
@@ -179,28 +179,37 @@ static void test_schnorrsig_aggregate_api(void) {
179179
unsigned char aggsig[32*(N_MAX + 1)];
180180
test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n);
181181

182-
/* Test body 1: Check API of function aggregate.
183-
* Should not accept NULL for any pointer input. */
182+
/* Test body 1: Check API of function aggregate. */
184183
{
184+
/* Should not accept NULL for aggsig or aggsig length */
185185
size_t aggsig_len = sizeof(aggsig);
186186
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggregate(CTX, NULL, &aggsig_len, pubkeys, msgs32, sigs64, n_initial));
187187
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggregate(CTX, aggsig, NULL, pubkeys, msgs32, sigs64, n_initial));
188-
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, NULL, msgs32, sigs64, n_initial));
189-
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, NULL, sigs64, n_initial));
190-
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, NULL, n_initial));
188+
/* Should not accept NULL for keys, messages, or signatures if n_initial is not 0 */
189+
if (n_initial != 0) {
190+
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, NULL, msgs32, sigs64, n_initial));
191+
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, NULL, sigs64, n_initial));
192+
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, NULL, n_initial));
193+
}
191194
}
192195

193196
/* Test body 2: Check API of function inc_aggregate. */
194197
{
195198
size_t aggsig_len = sizeof(aggsig);
196199
CHECK(secp256k1_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, sigs64, n_initial));
197200
aggsig_len = 32*(n+1);
198-
/* Should not accept NULL for any pointer input. */
201+
/* Should not accept NULL for aggsig or aggsig length */
199202
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, NULL, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new));
200203
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, NULL, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new));
201-
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, NULL, msgs32, &sigs64[n_initial*64], n_initial, n_new));
202-
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, NULL, &sigs64[n_initial*64], n_initial, n_new));
203-
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, NULL, n_initial, n_new));
204+
/* Should not accept NULL for keys or messages if n is not 0 */
205+
if (n != 0) {
206+
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, NULL, msgs32, &sigs64[n_initial*64], n_initial, n_new));
207+
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, NULL, &sigs64[n_initial*64], n_initial, n_new));
208+
}
209+
/* Should not accept NULL for new_sigs64 if n_new is not 0 */
210+
if (n_new != 0) {
211+
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, NULL, n_initial, n_new));
212+
}
204213
/* Should not accept overflowing number of sigs. */
205214
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], SIZE_MAX, SIZE_MAX));
206215
if (n_initial > 0) {

0 commit comments

Comments
 (0)
Please sign in to comment.