Skip to content

secp: context randomize in a few places - #1594

Open
delta1 wants to merge 6 commits into
ElementsProject:masterfrom
delta1:2026-09-secp-fixes
Open

secp: context randomize in a few places #1594
delta1 wants to merge 6 commits into
ElementsProject:masterfrom
delta1:2026-09-secp-fixes

Conversation

@delta1

@delta1 delta1 commented Sep 2, 2026

Copy link
Copy Markdown
Member

Adds a few instances of secp256k1_context_randomize in areas where we are using the secp context

Side-channel hardening: pass a fresh 32-byte GetStrongRandBytes seed to
secp256k1_context_randomize immediately after context creation, matching
the randomization of secp256k1_context_sign in key.cpp. No change to
consensus behavior or key/signature formats.
Side-channel hardening: blind each SIGN-capable secp256k1 context in the
wallet with a fresh 32-byte GetRandBytes seed via secp256k1_context_randomize,
mirroring key.cpp ECC_Start. Assert on null ctx and on a 0 randomize return.
No consensus impact.
Force BPPP, ECDSA_ADAPTOR, ECDSA_S2C, and SCHNORRSIG_HALFAGG OFF alongside
the existing MUSIG OFF in src/CMakeLists.txt. These experimental modules
default to ON in libsecp256k1's CMake but have zero references in the Elements
tree; building them is dead code that enlarges the binary and attack surface.
Genuinely used modules (ECDH, RECOVERY, EXTRAKEYS, SCHNORRSIG, ELLSWIFT,
GENERATOR, RANGEPROOF, SURJECTIONPROOF, WHITELIST) remain enabled.
The wallet Schnorr-signing path passed uint256{} (all-zero) as aux_rnd, a
side-channel/key-reuse hazard. Draw a fresh strong-random aux_rnd per sign.

Adjust the upstream BIP341 key-path vector test to sign deterministically via
key.SignSchnorr with the zero aux the vectors encode, since CreateSchnorrSig
randomness makes exact-hex reproduction impossible.
@apoelstra

Copy link
Copy Markdown
Member

utACK. Only reviewed the total diff in the Github UI. It's a worthwhile change IMHO. But I assume you weighed this defense-in-depth against causing potential rebase conflicts.

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