Skip to content

Commit 25bc8f3

Browse files
committed
aggverify: allow NULL for msg and pk if n = 0
1 parent efd98c1 commit 25bc8f3

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

include/secp256k1_schnorrsig_halfagg.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ SECP256K1_API int secp256k1_schnorrsig_aggregate(
7777
* Returns: 1: correct signature.
7878
* 0: incorrect signature.
7979
* Args: ctx: a secp256k1 context object.
80-
* In: pubkeys: Array of n many x-only public keys.
81-
* msgs32: Array of n many 32-byte messages.
80+
* In: pubkeys: Array of n many x-only public keys. Can only be NULL if n is 0.
81+
* msgs32: Array of n many 32-byte messages. Can only be NULL if n is 0.
8282
* n: number of signatures to that have been aggregated.
8383
* aggsig: Pointer to an array of aggsig_size many bytes
8484
* containing the serialized aggregate
@@ -93,7 +93,7 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_aggverify(
9393
size_t n,
9494
const unsigned char *aggsig,
9595
size_t aggsig_len
96-
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5);
96+
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(5);
9797

9898
#ifdef __cplusplus
9999
}

src/modules/schnorrsig_halfagg/main_impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ int secp256k1_schnorrsig_aggverify(const secp256k1_context *ctx, const secp256k1
117117
int overflow;
118118

119119
VERIFY_CHECK(ctx != NULL);
120-
ARG_CHECK(pubkeys != NULL);
121-
ARG_CHECK(msgs32 != NULL);
120+
ARG_CHECK(pubkeys != NULL || n == 0);
121+
ARG_CHECK(msgs32 != NULL || n == 0);
122122
ARG_CHECK(aggsig != NULL);
123123
ARG_CHECK(secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx));
124124

src/modules/schnorrsig_halfagg/tests_impl.h

+7-14
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,14 @@ void test_schnorrsig_aggverify_spec_vectors(void) {
7676
/* Test vector 0 */
7777
{
7878
size_t n = 0;
79-
const unsigned char pubkeys_ser[32] = {
80-
0x1b, 0x84, 0xc5, 0x56, 0x7b, 0x12, 0x64, 0x40,
81-
0x99, 0x5d, 0x3e, 0xd5, 0xaa, 0xba, 0x05, 0x65,
82-
0xd7, 0x1e, 0x18, 0x34, 0x60, 0x48, 0x19, 0xff,
83-
0x9c, 0x17, 0xf5, 0xe9, 0xd5, 0xdd, 0x07, 0x8f
84-
};
85-
secp256k1_xonly_pubkey pubkeys[1]; /* C doesn't allow zero-size arrays. */
86-
const unsigned char msgs32[1] = { 0x00 };
8779
const unsigned char aggsig[32] = {
8880
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8981
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9082
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9183
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9284
};
9385
size_t aggsig_len = sizeof(aggsig);
94-
CHECK(secp256k1_xonly_pubkey_parse(CTX, &pubkeys[0], &pubkeys_ser[0]));
95-
CHECK(secp256k1_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len));
86+
CHECK(secp256k1_schnorrsig_aggverify(CTX, NULL, NULL, n, aggsig, aggsig_len));
9687
}
9788
/* Test vector 1 */
9889
{
@@ -226,10 +217,12 @@ static void test_schnorrsig_aggregate_api(void) {
226217
{
227218
size_t aggsig_len = sizeof(aggsig);
228219
CHECK(secp256k1_schnorrsig_inc_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, &sigs64[n_initial*64], n_initial, n_new));
229-
/* */
230-
/* Should not accept NULL for any pointer input. */
231-
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggverify(CTX, NULL, msgs32, n, aggsig, aggsig_len));
232-
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggverify(CTX, pubkeys, NULL, n, aggsig, aggsig_len));
220+
/* Should not accept NULL for keys or messages if n is not 0 */
221+
if (n != 0) {
222+
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggverify(CTX, NULL, msgs32, n, aggsig, aggsig_len));
223+
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggverify(CTX, pubkeys, NULL, n, aggsig, aggsig_len));
224+
}
225+
/* Should never accept NULL the aggsig */
233226
CHECK_ILLEGAL(CTX, secp256k1_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, NULL, aggsig_len));
234227
/* Should reject for invalid aggsig_len. */
235228
CHECK(secp256k1_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_len + 1) == 0);

0 commit comments

Comments
 (0)