Skip to content

Import optimized X25519 (~30% faster key generation) - #10

Merged
JC-000 merged 5 commits into
masterfrom
feature/optimized-x25519
May 6, 2026
Merged

Import optimized X25519 (~30% faster key generation)#10
JC-000 merged 5 commits into
masterfrom
feature/optimized-x25519

Conversation

@JC-000

Copy link
Copy Markdown
Owner

Summary

  • Import optimized X25519/fe25519 from the c64-x25519 performance tuning project, achieving ~30% speedup in key generation (12,782 jiffies / 3.6 min vs 18,005 baseline)
  • Add 71 unit tests covering all fe25519 field operations and x25519 clamping, plus optional --slow RFC 7748 scalarmult vectors
  • Add benchmark script (bench_x25519.py) with jiffy clock timing and Python X25519 correctness verification

Optimizations imported

TechniqueTargetSavings
REU DMA multiply tablesfe_mul4 cyc/product vs mul_8x8
mult66 indirect-indexedfe_sqr~10 cyc/multiply
Self-modifying accumulationfe_mul, fe_sqr~10 cyc/iter
4x unrolled cswapfe_cswap~11 cyc/byte
Shift-before-accumulatefe_sqr cross termsEliminates 64-byte ROL pass
mul_by_38 lookup tablesfe_reduce_wide~16 cyc/reduction

Integration details

  • Optimization tables placed below $A000 to avoid BASIC ROM shadow
  • BASIC ROM banked out at boot (data buffers live at $A000-$BFFF)
  • VICE launched with -reu -reusize 512 for REU DMA support
  • Zero page lmul0/lmul1 time-shared with ChaCha20 vars

Test plan

  • python3 tools/test_x25519.py --verbose — 71/71 fast tests pass
  • python3 tools/run_all_tests.py --skip-slow — 253/253 tests pass (no regressions)
  • python3 tools/bench_x25519.py — 12,782 jiffies, correctness PASS vs Python X25519

🤖 Generated with Claude Code


Originally posted by @JC-000 on 2026-03-31

JC-000and others added 5 commits March 23, 2026 15:39
…erged
The harness wait_for_text() now calls transport.resume() between polls
internally, so the inline polling loops are no longer needed. This
replaces 13 copies of the same ~10-line loop with single wait_for_text()
calls, reducing total code by 120 lines.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…r reuse
The parallel runner had two bugs: (1) as_completed() didn't see futures added
mid-iteration, so only the first N suites were collected, and (2) reusing VICE
instances across suites caused state contamination (HKDF 0/12 on reused workers).
Fix: allocate a fresh VICE instance per suite via run_suite_in_own_instance().
Add all 10 suites (was 5). Add --skip-slow and --seed flags. 193/193 pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix parallel test runner: all 10 suites, instance-per-suite.
… tests
net_dns_resolve and net_set_tcp_dest both passed A/X parameters through
net_save_zp, which uses X as a loop counter and clobbers both registers.
This caused DNS resolution and TCP destination setup to receive garbage
pointers instead of the caller's intended addresses. Fixed by pushing
A/X to the stack before the ZP save and restoring after.
Added test_dns.py (4 tests) exercising net_dns_resolve over TAP with
dnsmasq, and test_http_integration.py (5 tests) for end-to-end plain
HTTP GET (DNS → TCP → request → response). Both use ViceInstanceManager
with ethernet_mode="rrnet" and run unprivileged (only dnsmasq via sudo).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace baseline fe25519/x25519 with optimized versions from the c64-x25519
performance tuning project, achieving ~30% speedup (12,782 jiffies / 3.6 min
per key generation vs 18,005 baseline).
Optimizations imported:
- REU DMA multiplication tables (128KB REU, 4 cyc/product vs mul_8x8)
- mult66 indirect-indexed quarter-square multiply for fe_sqr
- Self-modifying accumulation addresses in fe_mul/fe_sqr inner loops
- 4x unrolled constant-time fe_cswap (38 cyc/byte vs 49)
- Shift-before-accumulate for fe_sqr cross terms
- mul_by_38 lookup tables for fe_reduce_wide
Key integration fixes:
- Optimization tables (mul_dma, sqtab2, mul38) placed early in data.asm to
stay below $A000 and avoid BASIC ROM shadow region
- BASIC ROM banked out at boot and kept off during runtime (data buffers at
$A000+ need direct RAM access)
- VICE launched with -reu -reusize 512 for all test suites
- Zero page lmul0/lmul1 pointers time-shared with ChaCha20 vars
New files:
- tools/test_x25519.py: 71 unit tests (fe25519 field ops + x25519_clamp +
optional --slow RFC 7748 scalarmult vectors)
- tools/bench_x25519.py: key generation benchmark with jiffy clock timing
and Python X25519 verification
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JC-000
JC-000 merged commit 0391f11 into masterMay 6, 2026
@JC-000
JC-000 deleted the feature/optimized-x25519 branch May 6, 2026 19:03
Sign up for freeto 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

@JC-000