Repository navigation
crypto: P-256 base-point comb, odd representatives off the identity, faster P-256 field (parity item 8b) - #1013
Merged
Merged
Conversation
This was referenced Oct 22, 2026
Collaborator
Author
Review of #1013, round 1 (head bb4033d, item 8b)What I read and did not run
Architecture
The exceptional-addition proofs, checkedVariable base (
Comb (
Representative.
Field, checked by hand
Constant time
FindingsBLOCKER
SUGGESTION
Tests and evidence
Verdict: SEND BACK (items 1–4, all comment wording; the arithmetic and both proofs' conclusions are correct). |
P-256 key generation ran the variable-base Booth windows from G, with 255 doublings; every addition in the window loop also computed a masked doubling; squaring was a multiplication; inversion was square-and-multiply per bit; ECDSA verify built G's odd multiples on every call; and the scalar multiplications ran on identity values for scalars whose top windows are zero. - Comb: P-256's base point multiplication reads row i of a compile-time table j 2^(5i) G (52 rows of 16 affine points, 53 KiB, built by const Montgomery arithmetic with one simultaneous inversion), one masked 16-entry scan and one mixed addition (8M + 3S) per window, with no doublings. - Odd representatives: both secret multiplications run on k + j n, the j of m and m + 1 that makes it odd, m = 1 for P-256 and 2 for P-384. Its top Booth digit is nonzero, so neither the comb nor the doubling chain ever holds the identity, and a zero digit adds the row's first entry and discards the sum by mask instead of adding an identity of zeros. - Exceptional additions: bounds on the running multiple, stated at both sites, show no addition but the last can meet equal or opposite operands. The last one doubles by mask; every other addition is the incomplete formula, which removes 51 masked doublings per ECDH. - Field: P-256's multiplication, squaring, addition and subtraction are written out word by word (the shipped profile left the generic loops rolled); squaring computes the cross products once and reduces the 8-word square with the special step; inversion is an addition chain of 255 squarings and 12 multiplications for P-256's prime and 4-bit windows for the other moduli. Const forms of the arithmetic build the tables. - Verify: u1 is recoded at width 7 over a static table of G, 3G, ..., 63G, added in affine form; Q's table builds with public additions. Exploratory, on the development Mac in a shipped-like profile: P-256 ECDH from 162 to 56 us (ring 33), P-256 verify from 82 to 48 us (ring 30). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q
- The variable-base proof covers i = 0: 32T = k' - d0 is a nonzero multiple of 32 below 4n + 16 and n is odd, so the running point is not the identity. - The comb proof says why the difference is nonzero: S_i is odd and d 2^(5i) even. - The comb is 52 KiB; the comb test's doc names d = 1..=4. - The const forms are documented for compile time and tests only, not for secrets: they lack the register barrier and `minus` branches. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q
Japabu
force-pushed
the
wt/toyos-crypto-perf-6
branch
from
October 22, 2026 13:55
bb4033d to
0193e43
Compare
Collaborator
Author
Review of #1013, round 2 (head 0193e43, item 8b)What I read and did not run
ArchitectureUnchanged since round 1, where it was accepted: the odd representative k' = k + j·n, the comb and G tables from one const Round-1 blockers
EvidenceAll three images print
FindingsBLOCKER None. SUGGESTION
PR body (orchestrator)
Verdict: LAND |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on main c2fa263, after #993 and #1015 merged. Two commits: 7a7aa26 (round 0, bb4033d rebased) and 0193e43 (round 1).
Problem
At #1000 on the T14, P-256 ECDH was 4.36x ring and ECDSA P-256 verify 2.39x.
This is item 8b: N4 (base comb), N5 (inversion chain), a dedicated squaring, and a static G table for verify (D1).
What changes
constMontgomery arithmetic with one simultaneous inversion.mulqand the square 194 with 14, both without branches.asm!and no mulx, as directed.Generated code
Inspected in
[profile.toyos]onx86_64-unknown-toyosandaarch64-unknown-toyos, from P-256 and P-384agreeandpublic_key.i == lasttest;booth's public bit-position tests;add_publicon the peer's public points;copy_nonoverlapping's debug check on stack addresses.+on secret-derived words in the new square, reduction and recoding, which would have been branches; and an iterator adaptor the shipped profile kept out of line.Constant-time acceptance (metal, 0193e43)
#993's fixed-versus-random harness (
crypto_secret_timing_curves): 1,000,000 measurements per routine, against a threshold of max |t| < 4.5. Logs: https://github.com/ToyOSOrg/evidence/tree/86e6b16f5f71dfd16c62777736bd7cda0629bec9/pr-1013/r2/metalReview round 1 (0193e43)
constforms are documented as being for compile time and tests only, not for secrets: they lack the register barrier, andminusbranches on its borrow.Fieldtrait (compile_time_montgomery_forms_match_integers), against num-bigint on its boundary values, seeded values, chains and laws.Round 1 checks, at 0193e43. Logs: https://github.com/ToyOSOrg/evidence/tree/e63da096c9d4d0eb760797f7fa0f3e974518474c/pr-1013/r2
cargo run -- --ci host: exit 0, 93 green.crypto_instrumentandcrypto_secret_timing_curves(toyos-crypto stage 4, the test side: vectors, integer oracle, differential, fuzz, controls, Miri and the constant-time harness #993's harness), DOITM off. The harness is item 8's constant-time acceptance check. A third image runs the curves harness with DOITM on every CPU, built from crypto-sec's never-landed probe 380e63bbd cherry-picked onto this code (branchwt/toyos-crypto-perf-doitm, never lands).Metal
The combined T14 boot (ec01b15, which carries round 0 unchanged) passed with judge exit 0. Ours over ring:
Checks (round 0, at bb4033d; round 1 below)
All at bb4033d. Logs: https://github.com/ToyOSOrg/evidence/tree/b4adc3c52b22430e559eb9a1a56040f847e8d4c9/pr-1013/r1
cargo run -- --ci host: exit 0, 93 steps green.-D warnings) andcargo test -p toyos-crypto --release, in the three CI forms: exit 0 each.x86_64-unknown-uefiandaarch64-unknown-uefi: exit 0.crypto_instrument_prints_its_table(QEMU x86_64): exit 0. The log's first line names the revision.static_tables_hold_their_multiples: all 832 comb entries and both odd-multiple tables against the public path.the_comb_matches_the_public_path: includes k = 2^256·d mod n for d = 1..4, where the top window doubles.the_last_addition_doubles_where_it_must: the k = 2d mod n with first digit d, one per curve.booth_digits_recompose_the_scalar, rewritten for representatives: odd, ≡ k mod n, below 2^(64N+2), top digit nonzero, ±16 reached.times,plus,minus,inverted) to the run-time ones for every modulus.--features sign --release --no-fail-fast, and reverted in the same run. All 15 go red:the_last_addition_doubles_where_it_must(green before that test was added)Measurements
Readback staged at bb4033d (
crypto_instrument,cryptocase; exit 2 = Staged, no machine touched). The rows this moves are p-256/ecdh, ecdsa-p-256 verify, and to a lesser degree the P-384 rows.Risks
long_running_const_evalis allowed at that one item).🤖 Generated with Claude Code
https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q