diff --git a/include/secp256k1_schnorrsig.h b/include/secp256k1_schnorrsig.h index c055571b2..1be9f688e 100644 --- a/include/secp256k1_schnorrsig.h +++ b/include/secp256k1_schnorrsig.h @@ -211,12 +211,12 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify( * to the aggregate signature. */ SECP256K1_API int secp256k1_schnorrsig_inc_aggregate( - const secp256k1_context* ctx, - unsigned char* aggsig, - size_t* aggsig_size, + const secp256k1_context *ctx, + unsigned char *aggsig, + size_t *aggsig_size, const secp256k1_xonly_pubkey* all_pubkeys, - const unsigned char* all_msgs32, - const unsigned char* new_sigs64, + const unsigned char *all_msgs32, + const unsigned char *new_sigs64, size_t n_before, size_t n_new ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6); @@ -238,12 +238,12 @@ SECP256K1_API int secp256k1_schnorrsig_inc_aggregate( * n: number of signatures to be aggregated. */ SECP256K1_API int secp256k1_schnorrsig_aggregate( - const secp256k1_context* ctx, - unsigned char* aggsig, - size_t* aggsig_size, - const secp256k1_xonly_pubkey* pubkeys, - const unsigned char* msgs32, - const unsigned char* sigs64, + const secp256k1_context *ctx, + unsigned char *aggsig, + size_t *aggsig_size, + const secp256k1_xonly_pubkey *pubkeys, + const unsigned char *msgs32, + const unsigned char *sigs64, size_t n ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6); @@ -263,11 +263,11 @@ SECP256K1_API int secp256k1_schnorrsig_aggregate( * aggsig_size: Size of the aggregate signature. */ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_aggverify( - const secp256k1_context* ctx, - const secp256k1_xonly_pubkey* pubkeys, - const unsigned char* msgs32, + const secp256k1_context *ctx, + const secp256k1_xonly_pubkey *pubkeys, + const unsigned char *msgs32, size_t n, - const unsigned char* aggsig, + const unsigned char *aggsig, size_t aggsig_size ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5); diff --git a/src/modules/schnorrsig/main_impl.h b/src/modules/schnorrsig/main_impl.h index 4b9d8cfab..c37452d43 100644 --- a/src/modules/schnorrsig/main_impl.h +++ b/src/modules/schnorrsig/main_impl.h @@ -282,7 +282,7 @@ void secp256k1_schnorrsig_sha256_tagged_aggregation(secp256k1_sha256 *sha) { sha->bytes = 64; } -int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context* ctx, unsigned char* aggsig, size_t* aggsig_size, const secp256k1_xonly_pubkey* all_pubkeys, const unsigned char* all_msgs32, const unsigned char* new_sigs64, size_t n_before, size_t n_new) { +int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context *ctx, unsigned char *aggsig, size_t *aggsig_size, const secp256k1_xonly_pubkey *all_pubkeys, const unsigned char *all_msgs32, const unsigned char *new_sigs64, size_t n_before, size_t n_new) { size_t i; size_t n; int overflow; @@ -368,14 +368,14 @@ int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context* ctx, unsigned ch return 1; } -int secp256k1_schnorrsig_aggregate(const secp256k1_context* ctx, unsigned char* aggsig, size_t* aggsig_size, const secp256k1_xonly_pubkey* pubkeys, const unsigned char* msgs32, const unsigned char* sigs64, size_t n) { +int secp256k1_schnorrsig_aggregate(const secp256k1_context *ctx, unsigned char *aggsig, size_t *aggsig_size, const secp256k1_xonly_pubkey *pubkeys, const unsigned char *msgs32, const unsigned char *sigs64, size_t n) { if (!secp256k1_schnorrsig_inc_aggregate(ctx, aggsig, aggsig_size, pubkeys, msgs32, sigs64, 0, n)) { return 0; } return 1; } -int secp256k1_schnorrsig_aggverify(const secp256k1_context* ctx, const secp256k1_xonly_pubkey* pubkeys, const unsigned char* msgs32, size_t n, const unsigned char* aggsig, size_t aggsig_size) { +int secp256k1_schnorrsig_aggverify(const secp256k1_context *ctx, const secp256k1_xonly_pubkey *pubkeys, const unsigned char *msgs32, size_t n, const unsigned char *aggsig, size_t aggsig_size) { size_t i; secp256k1_gej lhs, rhs; secp256k1_scalar s; diff --git a/src/modules/schnorrsig/tests_impl.h b/src/modules/schnorrsig/tests_impl.h index 7a4f57f29..ea4104584 100644 --- a/src/modules/schnorrsig/tests_impl.h +++ b/src/modules/schnorrsig/tests_impl.h @@ -1022,23 +1022,24 @@ void test_schnorrsig_aggregate(void) { void test_schnorrsig_aggregate_spec_vectors(void) { /* Test vector 0 */ { - int n, aggsig_size; - n = 0; - const secp256k1_xonly_pubkey pubkeys[0] = {}; - const unsigned char msgs32[0] = {}; + int n = 0; + int aggsig_size = 32; + /* setting size to 1, because C */ + /* complains about zero-size arrays */ + secp256k1_xonly_pubkey pubkeys[1]; + const unsigned char msgs32[1] = { 0x00 }; const unsigned char aggsig[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - aggsig_size = 32; CHECK(secp256k1_schnorrsig_aggverify(CTX, pubkeys, msgs32, n, aggsig, aggsig_size)); } /* Test vector 1 */ { - int n, aggsig_size, i; - n = 1; + int n = 1; + int aggsig_size = 32+32; const unsigned char pubkeys_ser[32] = { 0x1b, 0x84, 0xc5, 0x56, 0x7b, 0x12, 0x64, 0x40, 0x99, 0x5d, 0x3e, 0xd5, 0xaa, 0xba, 0x05, 0x65, @@ -1061,8 +1062,8 @@ void test_schnorrsig_aggregate_spec_vectors(void) { 0xe1, 0x6e, 0x35, 0xd5, 0xf1, 0x2b, 0x69, 0x3b, 0x6b, 0xbc, 0x3d, 0x4a, 0x69, 0x82, 0xf2, 0xf6, }; - aggsig_size = 32+32; secp256k1_xonly_pubkey pubkeys[1]; + int i; for (i = 0; i < n; ++i) { CHECK(secp256k1_xonly_pubkey_parse(CTX, &pubkeys[i], &pubkeys_ser[i*32])); } @@ -1070,8 +1071,8 @@ void test_schnorrsig_aggregate_spec_vectors(void) { } /* Test vector 2 */ { - int n, aggsig_size, i; - n = 2; + int n = 2; + int aggsig_size = 2*32+32; const unsigned char pubkeys_ser[2*32] = { 0x1b, 0x84, 0xc5, 0x56, 0x7b, 0x12, 0x64, 0x40, 0x99, 0x5d, 0x3e, 0xd5, 0xaa, 0xba, 0x05, 0x65, @@ -1108,8 +1109,8 @@ void test_schnorrsig_aggregate_spec_vectors(void) { 0x6a, 0x14, 0x2d, 0x57, 0x72, 0x45, 0xf4, 0x0a, 0x44, 0xf5, 0xde, 0xe4, 0x68, 0xda, 0x42, 0x44, }; - aggsig_size = 2*32+32; secp256k1_xonly_pubkey pubkeys[2]; + int i; for (i = 0; i < n; ++i) { CHECK(secp256k1_xonly_pubkey_parse(CTX, &pubkeys[i], &pubkeys_ser[i*32])); }