diff --git a/src/modules/aggsig/main_impl.h b/src/modules/aggsig/main_impl.h index 0af253c..3d8fa65 100644 --- a/src/modules/aggsig/main_impl.h +++ b/src/modules/aggsig/main_impl.h @@ -37,14 +37,16 @@ static int secp256k1_compute_sighash_single(const secp256k1_context *ctx, secp25 unsigned char output[32]; unsigned char buf[33]; size_t buflen = sizeof(buf); - int overflow; + secp256k1_sha256 hasher; secp256k1_sha256_initialize(&hasher); /* Encode public nonce */ CHECK(secp256k1_ec_pubkey_serialize(ctx, buf, &buflen, pubkey, SECP256K1_EC_COMPRESSED)); - secp256k1_sha256_write(&hasher, buf, sizeof(buf)); + + /* Remove the first encoding element, as it may differ depending on how we got here */ + secp256k1_sha256_write(&hasher, buf+1, sizeof(buf-1)); /* Encode message */ secp256k1_sha256_write(&hasher, msghash32, 32); diff --git a/src/modules/aggsig/tests_impl.h b/src/modules/aggsig/tests_impl.h index 00543dd..51af094 100644 --- a/src/modules/aggsig/tests_impl.h +++ b/src/modules/aggsig/tests_impl.h @@ -199,7 +199,6 @@ void test_aggsig_api(void) { /* Receiver verifies sender's Sig and signs */ CHECK(secp256k1_aggsig_verify_single(vrfy, sig, msg, &combiner_sum, &pubkeys[0], 1)); - CHECK(secp256k1_aggsig_sign_single(sign, sig2, msg, seckeys[1], sec_nonces[1], &combiner_sum, &combiner_sum, seed)); /* sender verifies receiver's Sig then creates final combined sig */ CHECK(secp256k1_aggsig_verify_single(vrfy, sig2, msg, &combiner_sum, &pubkeys[1], 1)); @@ -212,12 +211,17 @@ void test_aggsig_api(void) { pubkey_combiner[1]=&pubkeys[1]; CHECK(secp256k1_ec_pubkey_combine(ctx, &combiner_sum_2, pubkey_combiner, 2) == 1); - /* Ensure added sigs verify properly */ + /* Ensure added sigs verify properly (with and without providing nonce_sum */ CHECK(secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, &combiner_sum, &combiner_sum_2, 0)); + CHECK(secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, NULL, &combiner_sum_2, 0)); /* And anything else doesnt' */ CHECK(!secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, &pub_nonces[0], &combiner_sum_2, 0)); - CHECK(!secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, &combiner_sum, &pub_nonces[1], 0)); + CHECK(!secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, NULL, &pub_nonces[1], 0)); + msg[0]=1; + msg[1]=2; + msg[2]=3; + CHECK(!secp256k1_aggsig_verify_single(vrfy, combined_sig, msg, NULL, &combiner_sum_2, 0)); } /*** End aggsig for Grin exchange test ***/