Skip to content

Specialize the constant-time Fp point formulas by curve shape (a=-3, a=0) - #183

Merged
Xor-el merged 1 commit into
masterfrom
perf/fp-curves
Aug 24, 2026
Merged

Specialize the constant-time Fp point formulas by curve shape (a=-3, a=0)#183
Xor-el merged 1 commit into
masterfrom
perf/fp-curves

Conversation

@Xor-el

@Xor-el Xor-el commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Replace the generic-a RCB2016 complete addition/doubling formulas in the constant-time Fp scalar-multiplication point layer with curve-shape specialized variants, selected per curve on a public parameter, cutting the wasted mul-by-a work that dominated the doubling-heavy hot path:

  • a=-3 (NIST secp256r1/384r1/521r1): RCB2016 Algorithm 4 (add) + Algorithm 6 (double) - drop the per-op MulByA (3 modular adds, applied 3x) in favour of mul-by-3b.
  • a=0 (secp256k1): RCB2016 Algorithm 7 (add) + Algorithm 9 (double) - drop the MulByA terms entirely (doubling falls from 13 to 9 field-muls).

A new TCTACoeff selector (General/MinusThree/Zero) dispatches the formula set per curve on public curve data (constant-time safe); curves without a specialization keep the general Algorithm 1/3 formulas unchanged. The new bodies are straight-line field ops with no secret-dependent branch or index, and remain complete (identity/exceptional inputs handled).

Also trim SelectEntry: read masked table entries straight from the table, bounded to the live N limbs, instead of copying the full max-width point struct per scanned entry.

…a=0)

Replace the generic-a RCB2016 complete addition/doubling formulas in the
constant-time Fp scalar-multiplication point layer with curve-shape
specialized variants, selected per curve on a public parameter, cutting
the wasted mul-by-a work that dominated the doubling-heavy hot path:

- a=-3 (NIST secp256r1/384r1/521r1): RCB2016 Algorithm 4 (add) +
  Algorithm 6 (double) - drop the per-op MulByA (3 modular adds, applied
  3x) in favour of mul-by-3b.
- a=0 (secp256k1): RCB2016 Algorithm 7 (add) + Algorithm 9 (double) -
  drop the MulByA terms entirely (doubling falls from 13 to 9 field-muls).

A new TCTACoeff selector (General/MinusThree/Zero) dispatches the formula
set per curve on public curve data (constant-time safe); curves without a
specialization keep the general Algorithm 1/3 formulas unchanged. The new
bodies are straight-line field ops with no secret-dependent branch or
index, and remain complete (identity/exceptional inputs handled).

Also trim SelectEntry: read masked table entries straight from the table,
bounded to the live N limbs, instead of copying the full max-width point
struct per scanned entry.
@Xor-el
Xor-el merged commit a41e97e into master Aug 24, 2026
28 checks passed
@Xor-el
Xor-el deleted the perf/fp-curves branch August 25, 2026 09:46
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.

1 participant