Skip to content

examples: randomize the context in musig, erase the keypair in schnorr - #1980

Open
fametrano wants to merge 1 commit into
bitcoin-core:masterfrom
fametrano:examples-randomize-erase-keypair
Open

fametrano wants to merge 1 commit into
bitcoin-core:masterfrom
fametrano:examples-randomize-erase-keypair

Conversation

@fametrano

Copy link
Copy Markdown
Contributor

examples/musig.c is the only example that handles secret keys without
randomizing the context, which secp256k1.h highly recommends. Randomize
it as schnorr.c does.

schnorr.c erases the secret key buffer after use, but the keypair holds
a copy of the secret key and stayed on the stack. Erase it too.

@theStack theStack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK modulo nits

Comment thread examples/musig.c Resolved
Comment thread examples/schnorr.c Resolved
@fametrano
fametrano force-pushed the examples-randomize-erase-keypair branch from 86f6a53 to a560ec6 Compare October 25, 2026 11:13

@theStack theStack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK a560ec6

examples/musig.c is the only example that handles secret keys without
randomizing the context, which secp256k1.h highly recommends. Randomize
it as schnorr.c does.

schnorr.c erases the secret key buffer after use, but the keypair holds
a copy of the secret key and stayed on the stack. Erase it too.
@fametrano
fametrano force-pushed the examples-randomize-erase-keypair branch from a560ec6 to e3b8fc3 Compare November 4, 2026 23:03
@fametrano

Copy link
Copy Markdown
Contributor Author

Rebased on master to resolve the conflict with #1986. The changes are the same; only a context line in examples/schnorr.c differs (git range-diff 307035b..a560ec67 b97f7f5..e3b8fc3).

@fametrano
fametrano requested a review from theStack November 5, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants