diff --git a/src/modules/schnorrsig_halfagg/main_impl.h b/src/modules/schnorrsig_halfagg/main_impl.h index 352163ce5..d317f4d74 100644 --- a/src/modules/schnorrsig_halfagg/main_impl.h +++ b/src/modules/schnorrsig_halfagg/main_impl.h @@ -95,11 +95,12 @@ int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context *ctx, unsigned ch secp256k1_scalar_set_b32(&zi, hashoutput, NULL); /* Step 2: s := s + zi*si */ + /* except if i == 0, then zi = 1 implicitly */ secp256k1_scalar_set_b32(&si, &new_sigs64[(i-n_before)*64+32], &overflow); if (overflow) { return 0; } - secp256k1_scalar_mul(&si, &si, &zi); + if (i != 0) secp256k1_scalar_mul(&si, &si, &zi); secp256k1_scalar_add(&s, &s, &si); } @@ -189,7 +190,8 @@ int secp256k1_schnorrsig_aggverify(const secp256k1_context *ctx, const secp256k1 secp256k1_gej_add_ge_var(&ti, &ti, &rp, NULL); /* Step 3: rhs = rhs + zi*T_i */ - secp256k1_ecmult(&ti, &ti, &zi, NULL); + /* Note that if i == 0, then zi = 1 implicitly */ + if (i != 0) secp256k1_ecmult(&ti, &ti, &zi, NULL); secp256k1_gej_add_var(&rhs, &rhs, &ti, NULL); } diff --git a/src/modules/schnorrsig_halfagg/tests_impl.h b/src/modules/schnorrsig_halfagg/tests_impl.h index fcbde3e6e..768d0c1ea 100644 --- a/src/modules/schnorrsig_halfagg/tests_impl.h +++ b/src/modules/schnorrsig_halfagg/tests_impl.h @@ -115,10 +115,10 @@ void test_schnorrsig_aggverify_spec_vectors(void) { 0x6f, 0x1b, 0xbf, 0xc2, 0xeb, 0x66, 0xd2, 0x9d, 0x24, 0xb0, 0xca, 0xb7, 0x4d, 0x6b, 0x74, 0x5c, 0x3c, 0xfb, 0x00, 0x9c, 0xc8, 0xfe, 0x4a, 0xa8, - 0x10, 0x8f, 0x33, 0x90, 0x76, 0x12, 0xfb, 0x74, - 0x84, 0x19, 0xeb, 0xc4, 0x00, 0x4b, 0x31, 0x69, - 0xe1, 0x6e, 0x35, 0xd5, 0xf1, 0x2b, 0x69, 0x3b, - 0x6b, 0xbc, 0x3d, 0x4a, 0x69, 0x82, 0xf2, 0xf6, + 0x0e, 0x06, 0x6c, 0x34, 0x81, 0x99, 0x36, 0x54, + 0x9f, 0xf4, 0x9b, 0x6f, 0xd4, 0xd4, 0x1e, 0xdf, + 0xc4, 0x01, 0xa3, 0x67, 0xb8, 0x7d, 0xdd, 0x59, + 0xfe, 0xe3, 0x81, 0x77, 0x96, 0x1c, 0x22, 0x5f, }; size_t aggsig_len = sizeof(aggsig); size_t i; @@ -162,10 +162,10 @@ void test_schnorrsig_aggverify_spec_vectors(void) { 0x7c, 0x8c, 0x00, 0xf1, 0xb6, 0xd7, 0xe7, 0xd3, 0x75, 0xb5, 0x45, 0x40, 0xf1, 0x37, 0x16, 0xc8, 0x7b, 0x62, 0xe5, 0x1e, 0x2f, 0x4f, 0x22, 0xff, - 0xc2, 0x11, 0xdb, 0x48, 0x47, 0x9c, 0x2f, 0x54, - 0x6d, 0x52, 0xb0, 0x79, 0x55, 0xe7, 0x64, 0xeb, - 0x6a, 0x14, 0x2d, 0x57, 0x72, 0x45, 0xf4, 0x0a, - 0x44, 0xf5, 0xde, 0xe4, 0x68, 0xda, 0x42, 0x44, + 0xbf, 0x89, 0x13, 0xec, 0x53, 0x22, 0x6a, 0x34, + 0x89, 0x2d, 0x60, 0x25, 0x2a, 0x70, 0x52, 0x61, + 0x4c, 0xa7, 0x9a, 0xe9, 0x39, 0x98, 0x68, 0x28, + 0xd8, 0x1d, 0x23, 0x11, 0x95, 0x73, 0x71, 0xad, }; size_t aggsig_len = sizeof(aggsig); size_t i;