Repository navigation
crypto: Ed25519 signing and X25519 keys by a fixed-base comb (parity item 7) - #999
Merged
Merged
Conversation
Collaborator
Author
Review of #999, round 1 (head db5c6c5, stacked on #997)I read the commit against cd7960d, each changed file in full at the head ( I did not rebuild, because this role runs no builds. The asm spot-check below uses the implementer's branch-walk listings of the shipped code. I did not read the analysis notes or any ring or BoringSSL source. Architecture
Correctness, checked by hand
Constant time and digit erasure
FindingsNo blockers. SUGGESTION
Tests and evidence
Verdict: LAND (suggestions optional; the landing decision and the metal row are the orchestrator's). |
Japabu
force-pushed
the
wt/toyos-crypto-perf-4
branch
from
October 22, 2026 02:46
db5c6c5 to
196ae3d
Compare
Signing and Ed25519 key generation multiplied the base point by 256
doublings and complete additions with a select per bit; an X25519 public
key was a second 255-step ladder from u = 9.
The base point multiplication is now the radix-16 signed comb of
Bernstein, Duif, Lange, Schwabe and Yang ("High-speed high-security
signatures", 2012, section 4):
- a scalar below 2^255 becomes 64 digits in [-8, 8] by wrapping arithmetic
alone, held in a Workspace and erased when the multiplication returns;
- the table, j 16^(2i) B for j = 1..=8 in 32 rows (30 KiB, affine), is
built at compile time by the field's const fn arithmetic with one
simultaneous inversion;
- the odd digits' 32 entries are added, the sum doubled four times, and
the even digits' 32 added: 64 mixed additions and 4 doublings;
- each lookup reads all eight entries of its row and selects by mask, and
a negative digit swaps y + x with y - x and negates 2dxy under a mask.
An X25519 public key is u = (1 + y) / (1 - y) of the comb's [s]B (RFC 7748
section 4.1), one inversion. The fixed-schedule double-and-add is gone.
Generated code: in [profile.toyos], the first version's recoding used +=
and -= on the secret digits, and the shipped profile's overflow checks
compiled them to branches on those digits (jo on x86-64, cmp/b.ne on
aarch64). They are wrapping operations now; the inspection after the
change finds only loop counters, public lengths and the debug overlap
check on stack addresses on both targets.
New tests: the table rows against run-time addition, the recoding's
digits and sum, the comb against the verification path's Straus
multiplication (a different table and recoding), and X25519 public keys
by the comb against the ladder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Japabu
force-pushed
the
wt/toyos-crypto-perf-3
branch
from
October 22, 2026 03:33
5314dcb to
b824d27
Compare
Japabu
force-pushed
the
wt/toyos-crypto-perf-4
branch
from
October 22, 2026 03:33
196ae3d to
264138f
Compare
Collaborator
Author
Review of #999, round 2 (head 264138f)I checked the rebase and the new commit. I ran nothing. Rebase
Rewraps
Staged T14 image
My r1 verdict stands. Verdict: LAND. |
Japabu
marked this pull request as ready for review
October 22, 2026 04:40
Japabu
enabled auto-merge
October 22, 2026 04:40
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.
Builds on #997 (merged).
Problem
On the T14 at #997, ed25519/sign/64 was 6.66x ring (86.4 us against 12.9). M4 put X25519 key generation at 42.0 us against ring's 12.3. Signing and Ed25519 key generation multiplied the base point by 256 doublings and complete additions, with a select per bit. An X25519 public key was a second 255-step ladder from u = 9.
This is the analysis's item 7 for Ed25519 and X25519 (E2, X3).
The P-256 Booth comb (N4) moves to item 8, beside the P-256 field it needs. Its compile-time table needs a
constMontgomery multiplication, and item 8 rewrites that field, so doing it there avoids building it twice.What changes
Workspaceand erased when the multiplication returns.const fnarithmetic, with one simultaneous inversion. The builder is shared with crypto: Ed25519 verify by one joint multiplication, scalars by Barrett (parity items 6, E3, E4) #997's verification table.secret.rslists the comb's digits among the workspaces.Generated code
Both ToyOS targets in
[profile.toyos], fromSigningKey::sign,SigningKey::from_seedandx25519::SecretKey::public_key; inspection in the evidence below.+=and-=on the secret i8 digits. The shipped profile's overflow checks compiled those to branches whose condition came from the digits:addb …; joon x86-64,cmp w, w, sxtb; b.neon aarch64. None was ever taken. They are wrapping operations now.select's eight entries; row addresses advance by 960 bytes on the public row index);copy_nonoverlapping's debug overlap check, on stack addresses.Checks
All at db5c6c5. Logs: https://github.com/ToyOSOrg/evidence/tree/04eb191a49232f539f929ac8bf58443913da5828/pr-999/r1
cargo run -- --ci host: exit 0, 87 steps green.cargo clippy -p toyos-crypto --all-targets(adopted lints,-D warnings) andcargo test -p toyos-crypto --release, in the three CI forms: exit 0 each.x86_64-unknown-uefiandaarch64-unknown-uefi: exit 0.cargo test --test toyos-build -- crypto_instrument_prints_its_table(QEMU x86_64): exit 0.comb_table_holds_its_multiples: all 256 entries against run-time addition.radix_16_digits_recompose_the_scalar: digits in [-8, 8] that sum to the scalar, up to 2^255 - 1.the_comb_agrees_with_straus: the comb against crypto: Ed25519 verify by one joint multiplication, scalars by Barrett (parity items 6, E3, E4) #997's verification multiplication, which uses a different table and recoding.public_keys_by_the_comb_are_the_ladders: X25519 keys against the ladder from u = 9.--features sign --release --no-fail-fast, and reverted in the same run:Measurements
Readback staged at db5c6c5 (
crypto_instrument,cryptocase; exit 2 = Staged, no machine touched). The rows this PR moves are ed25519/sign/64 and x25519/ecdh (key generation is in the row), plus m4's split if the probe is rerun on it.Risks
🤖 Generated with Claude Code