From e52a7255e4596cca7b21379e2e3c3ebb7b823fb9 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 25 Nov 2026 07:18:41 -0500 Subject: [PATCH 1/2] New secp256k1-native advisory * gems/secp256k1-native/CVE-2026-63410.yml --- gems/secp256k1-native/CVE-2026-63410.yml | 90 ++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 gems/secp256k1-native/CVE-2026-63410.yml diff --git a/gems/secp256k1-native/CVE-2026-63410.yml b/gems/secp256k1-native/CVE-2026-63410.yml new file mode 100644 index 0000000000..c5165cf703 --- /dev/null +++ b/gems/secp256k1-native/CVE-2026-63410.yml @@ -0,0 +1,90 @@ +--- +gem: secp256k1-native +cve: 2026-63410 +ghsa: vp2j-gqfm-r3cf +url: https://nvd.nist.gov/vuln/detail/CVE-2026-63410 +title: secp256k1-native has a compiler-induced timing side channel in scalar multiplication +date: 2026-11-23 +description: |- + ## Summary + + `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.** + + The 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. + + This 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. + + ## Impact + + A 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. + + Pre-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. + + ## Affected configurations + + The defect is a property of the (source, compiler, flags) triple, not the source alone: + + - **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". + - **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. + - **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). + + ## Patch (v0.18.0) + + Introduces a value barrier (libsecp256k1/BoringSSL pattern) and routes every constant-time select mask through it: + + ```c + static inline uint64_t ct_value_barrier_u64(uint64_t x) { + #if defined(__GNUC__) || defined(__clang__) + __asm__ volatile("" : "+r"(x)); + #endif + return x; + } + + static inline uint64_t ct_mask_u64(uint64_t flag) { + return ct_value_barrier_u64(-(uint64_t)(flag != 0)); + } + ``` + + Applied 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. + + ## Workarounds (for unpatched users) + + - **Upgrade to v0.18.0** (recommended). + - Or: compile the extension at `-O0`/`-O1`, or with a compiler that does not reconstruct the select (verify with `objdump -dl`) — fragile, not recommended. + - Do not call `Point#mul` on secret scalars from a timing-observable context until patched. + + ## Verification (reproducible) + + Reference 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 ` under `chrt -f`. + + - **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. + - **Disassembly:** before — `je`/`jne` attributed to the select source lines under `objdump -dl`. After — none (0 conditional jumps / `cmov` at any select line). + - **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. + - **Functional:** `bundle exec rspec` → 416 examples, 0 failures. + + ## Lasting control + + Bare-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.** + + ## Related + + - 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) + - [docs/security.md — Empirical timing verification](https://github.com/sgbett/secp256k1-native/blob/master/docs/security.md#empirical-timing-verification) + - [docs/risks.md — What works against it](https://github.com/sgbett/secp256k1-native/blob/master/docs/risks.md#what-works-against-it) + - [docs/security-review-v1.md — Finding H-2](https://github.com/sgbett/secp256k1-native/blob/master/docs/security-review-v1.md) + - [docs/timing-verification-runbook.md](https://github.com/sgbett/secp256k1-native/blob/master/docs/timing-verification-runbook.md) + - Reparaz, Balasch, Verbauwhede (2017), *dudect: dynamic detection of constant-time code*. + - Brumley, Boneh (2005), *Remote timing attacks are practical*. + - 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). +cvss_v3: 5.9 +patched_versions: + - ">= 0.18.0" +related: + url: + - https://github.com/sgbett/secp256k1-native/security/advisories/GHSA-vp2j-gqfm-r3cf + - https://nvd.nist.gov/vuln/detail/CVE-2026-63410 + - https://github.com/sgbett/secp256k1-native/pull/32 + - https://github.com/sgbett/secp256k1-native/commit/a89bea1617a2d063c6545ad44565dc22098c880e + - https://github.com/sgbett/secp256k1-native/blob/master/docs/advisories/0001-compiler-reconstructed-ct-branch.md + - https://github.com/sgbett/secp256k1-native/releases/tag/v0.18.0 + - https://github.com/advisories/GHSA-vp2j-gqfm-r3cf From decc1f0c31faae25a4710f8ffd95a96abc12a4ed Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 25 Nov 2026 07:29:16 -0500 Subject: [PATCH 2/2] Use public disclosure date for secp256k1-native advisory The 0.18.0 release on 2026-06-30 disclosed the vulnerability in its CHANGELOG. --- gems/secp256k1-native/CVE-2026-63410.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gems/secp256k1-native/CVE-2026-63410.yml b/gems/secp256k1-native/CVE-2026-63410.yml index c5165cf703..8e0b851673 100644 --- a/gems/secp256k1-native/CVE-2026-63410.yml +++ b/gems/secp256k1-native/CVE-2026-63410.yml @@ -4,7 +4,7 @@ cve: 2026-63410 ghsa: vp2j-gqfm-r3cf url: https://nvd.nist.gov/vuln/detail/CVE-2026-63410 title: secp256k1-native has a compiler-induced timing side channel in scalar multiplication -date: 2026-11-23 +date: 2026-06-30 description: |- ## Summary