{"id":"CVE-2026-63410","aliases":["CVE-2026-63410","GHSA-vp2j-gqfm-r3cf"],"related":[],"kind":"vulnerability","state":"published","title":"secp256k1-native: Compiler-reconstructed secret-dependent branch in native scalar multiplication","summary":"secp256k1-native is a native C secp256k1 implementation for Ruby. In affected native builds, native constant-time scalar multiplication through `Point#mul` or `scalar_multiply_ct` can leak timing information about a secret scalar when compiled by a toolchain that reconstructs branchless selection into a branch. The `Montgomery ladder` uses `uint256_select` with an all-zeros or all-ones mask, but affected GCC builds at `-O2` recover the original condition and emit secret-dependent `je` or `jne` jumps whose timing correlates with scalar bits. This defeats the assumption behind the 0.17.0 `jp_add_internal` infinity-branch fix. A consumer must multiply a secret private key or nonce in a context where an attacker can observe timing; repeated measurements can statistically recover scalar bits. The defect is in the compiled binary, so source review or `ctgrind` on a non-reconstructing toolchain may miss it. GCC 14.3.0, 15.1.0, and 15.2.0 reproduced the branch reconstruction, and `extconf.rb` appends `-O2`. Tested GCC versions through 12.4.0 used bitwise operations and GCC 13.3.0 used constant-time `cmov`; the pure-Ruby path is not affected by this flaw and separately makes no constant-time claim. GCC 16 and clang were untested, and point releases, targets, and flag combinations were not exhaustively bisected. `Earlier pre-0.17.0 versions had different constant-time issues rather than this introduced select idiom.` Version 0.18.0 contains the verified fix. The advisory's broad pre-0.18.0 guidance also covers earlier, different constant-time issues; whether this CVE groups those issues or only the select idiom introduced in 0.17.0 remains unresolved.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"secp256k1-native is a native C secp256k1 implementation for Ruby. In affected native builds, native constant-time scalar multiplication through `Point#mul` or `scalar_multiply_ct` can leak timing information about a secret scalar when compiled by a toolchain that reconstructs branchless selection into a branch. The `Montgomery ladder` uses `uint256_select` with an all-zeros or all-ones mask, but affected GCC builds at `-O2` recover the original condition and emit secret-dependent `je` or `jne` jumps whose timing correlates with scalar bits. This defeats the assumption behind the 0.17.0 `jp_add_internal` infinity-branch fix. A consumer must multiply a secret private key or nonce in a context where an attacker can observe timing; repeated measurements can statistically recover scalar bits. The defect is in the compiled binary, so source review or `ctgrind` on a non-reconstructing toolchain may miss it. GCC 14.3.0, 15.1.0, and 15.2.0 reproduced the branch reconstruction, and `extconf.rb` appends `-O2`. Tested GCC versions through 12.4.0 used bitwise operations and GCC 13.3.0 used constant-time `cmov`; the pure-Ruby path is not affected by this flaw and separately makes no constant-time claim. GCC 16 and clang were untested, and point releases, targets, and flag combinations were not exhaustively bisected. `Earlier pre-0.17.0 versions had different constant-time issues rather than this introduced select idiom.` Version 0.18.0 contains the verified fix. The advisory's broad pre-0.18.0 guidance also covers earlier, different constant-time issues; whether this CVE groups those issues or only the select idiom introduced in 0.17.0 remains unresolved.","source":"cvelist"},{"lang":"en","text":"## Summary\n\n`Point#mul` — the default, constant-time scalar multiplication and the library's headline secret-scalar operation — could leak timing information about the secret scalar (a private key or ECDSA-style nonce in a downstream consumer) **not because of a source-level bug, but because the compiler reconstructed a branch from branchless source.**\n\nThe Montgomery ladder selects between point candidates with `uint256_select`, written deliberately branchlessly as `r = (a & ~mask) | (b & mask)` with a mask that is all-ones or all-zeros. GCC 15.2 at `-O2` recognises this select idiom, reconstructs the original boolean condition, and emits a secret-dependent conditional jump (`je`/`jne`). The branch's taken/not-taken timing correlates with the secret scalar bits flowing through the ladder.\n\nThis silently undid the 0.17.0 fix for the historical |t|=875 infinity-branch leak, which had relied on `uint256_select` compiling to branchless code.\n\n## Impact\n\nA timing side-channel on the secret scalar in constant-time scalar multiplication. For a consumer that calls `Point#mul` (or the native `scalar_multiply_ct`) on a secret key or nonce and exposes timing to an attacker (e.g. an online signing oracle), repeated measurements can statistically recover scalar bits — the classic ECC private-key/nonce timing-attack setting (cf. Brumley–Boneh). The leak is in the *compiled binary*; the source is correct, so source review and the deterministic ctgrind check on a *non-reconstructing* toolchain do not reveal it.\n\nPre-1.0 with no published RubyGems dependents, so this is handled as fix-publish-and-document: full GHSA + CVE record without a coordinated downstream-notification timeline. The CVE is filed for citability so the empirical record (paper → review → compiler regression → fix) is permanent and searchable.\n\n## Affected configurations\n\nThe defect is a property of the (source, compiler, flags) triple, not the source alone:\n\n- **Source:** any pre-`0.18.0` build. The branchless `uint256_select` was introduced with the 0.17.0 `jp_add_internal` |t|=875 fix; the pre-0.17 versions on RubyGems (0.15, 0.16) had different CT issues which the 0.17.0 fix addressed, so the safest user guidance is \"upgrade to 0.18.0 from any earlier version\".\n- **Compiler:** one that reconstructs the all-0s/all-1s select into a branch. Confirmed: **GCC 15.2.0, `-O2`**. The extension ships with `-O2` (`extconf.rb` appends it), so the shipped binary on this compiler is affected.\n- **Not affected:** the pure-Ruby path (different code; separately not claimed constant-time), and toolchains that emit `cmov` or pure bitwise ops here (the original review's toolchain).\n\n## Patch (v0.18.0)\n\nIntroduces a value barrier (libsecp256k1/BoringSSL pattern) and routes every constant-time select mask through it:\n\n```c\nstatic inline uint64_t ct_value_barrier_u64(uint64_t x) {\n#if defined(__GNUC__) || defined(__clang__)\n    __asm__ volatile(\"\" : \"+r\"(x));\n#endif\n    return x;\n}\n\nstatic inline uint64_t ct_mask_u64(uint64_t flag) {\n    return ct_value_barrier_u64(-(uint64_t)(flag != 0));\n}\n```\n\nApplied to all nine mask-select sites: `uint256_select`; `fred`, `fadd`, `fsub`, `fneg`; `scalar_reduce`, `scalar_add`; the `jp_double` infinity select; and the ladder `cswap`. Only `uint256_select` actively branchified under GCC 15.2/`-O2`; the rest are hardened as defence-in-depth.\n\n## Workarounds (for unpatched users)\n\n- **Upgrade to v0.18.0** (recommended).\n- Or: compile the extension at `-O0`/`-O1`, or with a compiler that does not reconstruct the select (verify with `objdump -dl`) — fragile, not recommended.\n- Do not call `Point#mul` on secret scalars from a timing-observable context until patched.\n\n## Verification (reproducible)\n\nReference machine: AMD Ryzen 9 9950X (Zen 5), microcode `0xb404023`, Ubuntu 26.04 / Linux 7.0.0-14, GCC 15.2.0; `systemd-detect-virt = none`; turbo off, `performance` governor (min=max), SMT off, harness pinned with `taskset -c <core>` under `chrt -f`.\n\n- **Deterministic (ctgrind):** before — \"Conditional jump or move depends on uninitialised value\" at the `uint256_select` source lines via `jp_add_internal` → `scalar_multiply_ct_internal`. After — clean, exit 0.\n- **Disassembly:** before — `je`/`jne` attributed to the select source lines under `objdump -dl`. After — none (0 conditional jumps / `cmov` at any select line).\n- **Statistical (dudect, bare metal):** before — `scalar_multiply_ct_internal` |t| ≈ 21 (stable across runs). After — mean |t| = 0.68, max 1.57, 0/20 runs over the 4.5 threshold.\n- **Functional:** `bundle exec rspec` → 416 examples, 0 failures.\n\n## Lasting control\n\nBare-metal dudect is now a **required pre-tag release gate**, re-run whenever the known-good compiler version changes. The deterministic ctgrind check remains the primary CT evidence but runs against CI's compiler; only the statistical bare-metal run observes the timing of the binary that actually ships. **A constant-time source is not a constant-time binary.**\n\n## Related\n\n- In-repo advisory: [docs/advisories/0001-compiler-reconstructed-ct-branch.md](https://github.com/sgbett/secp256k1-native/blob/master/docs/advisories/0001-compiler-reconstructed-ct-branch.md)\n- [docs/security.md — Empirical timing verification](https://github.com/sgbett/secp256k1-native/blob/master/docs/security.md#empirical-timing-verification)\n- [docs/risks.md — What works against it](https://github.com/sgbett/secp256k1-native/blob/master/docs/risks.md#what-works-against-it)\n- [docs/security-review-v1.md — Finding H-2](https://github.com/sgbett/secp256k1-native/blob/master/docs/security-review-v1.md)\n- [docs/timing-verification-runbook.md](https://github.com/sgbett/secp256k1-native/blob/master/docs/timing-verification-runbook.md)\n- Reparaz, Balasch, Verbauwhede (2017), *dudect: dynamic detection of constant-time code*.\n- Brumley, Boneh (2005), *Remote timing attacks are practical*.\n- Bettison, S. G. (2026). *Cryptographic Implementation Security: A Review of the Empirical Evidence*. DOI: [10.13140/RG.2.2.25788.60802](https://doi.org/10.13140/RG.2.2.25788.60802).","format":"markdown","source":"ghsa"}],"published":"2026-10-30T22:48:09.173Z","modified":"2026-11-23T21:15:06.164Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N","score":5.9,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N","score":5.9,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N","score":5.9,"rating":"MEDIUM"}],"cwes":["CWE-208","CWE-1255"],"affected":[{"ranges":[{"version":">= 0.17.0, < 0.18.0","status":"affected"}],"vendor":"sgbett","product":"secp256k1-native","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.18.0"}],"ecosystem":"RubyGems","package":"secp256k1-native","purl":"pkg:gem/secp256k1-native","source":"ghsa"}],"references":[{"url":"https://github.com/sgbett/secp256k1-native/security/advisories/GHSA-vp2j-gqfm-r3cf","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/sgbett/secp256k1-native/pull/32","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/sgbett/secp256k1-native/commit/a89bea1617a2d063c6545ad44565dc22098c880e","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/sgbett/secp256k1-native/blob/master/docs/advisories/0001-compiler-reconstructed-ct-branch.md","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/sgbett/secp256k1-native/releases/tag/v0.18.0","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-63410","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/sgbett/secp256k1-native","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-11-02T14:49:39.327Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-63410","url":"https://www.cve.org/CVERecord?id=CVE-2026-63410","licence":"CVE Terms of Use","modified":"2026-11-02T14:50:09.239Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-vp2j-gqfm-r3cf","url":"https://github.com/advisories/GHSA-vp2j-gqfm-r3cf","licence":"CC-BY-4.0","modified":"2026-11-23T21:15:06.164Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-63410","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-63410","licence":"Public domain","modified":"2026-11-02T19:35:33.347Z"}],"updatedAt":"2026-11-25T22:59:48.046Z","epss":{"score":0.00477,"percentile":0.42851,"date":"2026-12-01T12:00:22.000Z"}}