Skip to content

tests: refactor tagged hash verification #1725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

josibake
Copy link
Member

Opened in response to #1698 (comment)


We use tagged hashes in modules/musig, modules/schnorrsig, modules/ellswift, and the proposed modules/silentpayments. In looking for inspiration on how to add tagged hash midstate verification for #1698, it seemed like a good opportunity to DRY up the code across all of the modules.

I chose the convention used in the musig module as this seemed the most readable to me as a reviewer, and also allows for easily grepping for the string values. Since the tags are normally specified as strings in the BIPs, using the string values in the tests seems preferable to specifying the tags character by character (as was done in the schnorrsig and ellswift modules).

If its deemed too invasive to refactor the existing modules in this PR, I'm happy to drop the refactor commits for the ellswift and schnorrsig modules. All I need for #1698 is the first commit which moves the utility function out of the musig module to make it available to use in the silent payments module.

Move the sha256_tag_test_internal function out of the musig module
and into tests.c.

This makes it available to other modules wishing to verify tagged
hashes without needing to duplicate the function.
Use the sha256_tag_test_internal helper function.
Restructure to match the musig tag hash tests.

Using this structure makes it easy for reviewers to quickly
verify the correct tags are being used.
Use the sha256_tag_test_internal helper function.
Restructure to match the musig tag hash tests.

Using this structure makes it easier for reviewers to quickly
verify the correct tags are being used.

Specifying as strings also makes finding the values via grep
much easier.
test_sha256_eq(&sha, &sha_optimized);
secp256k1_sha256 sha_optimized;
{
unsigned char tag[] = "secp256k1_ellswift_encode";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8a17983:

fa67b67 can be relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants